mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
Move TabWidget related code to TabWorkArea class in GuiWorkArea.{cpp,h}
The close button is back... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20787 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c2f54cd891
commit
3435635a7b
@ -63,9 +63,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QStatusBar>
|
||||
#include <QTabBar>
|
||||
#include <QToolBar>
|
||||
#include <QTabWidget>
|
||||
#include <QUrl>
|
||||
|
||||
using std::endl;
|
||||
@ -123,16 +121,9 @@ private:
|
||||
QPixmap * splash_;
|
||||
};
|
||||
|
||||
|
||||
class TabWidget : public QTabWidget {
|
||||
public:
|
||||
void showBar(bool show) { tabBar()->setVisible(show); }
|
||||
};
|
||||
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
struct GuiViewBase::GuiViewPrivate
|
||||
{
|
||||
string cur_title;
|
||||
@ -140,7 +131,7 @@ struct GuiViewBase::GuiViewPrivate
|
||||
int posx_offset;
|
||||
int posy_offset;
|
||||
|
||||
TabWidget * tab_widget_;
|
||||
TabWorkArea * tab_widget_;
|
||||
QStackedWidget * stack_widget_;
|
||||
BackgroundWidget * bg_widget_;
|
||||
/// view's menubar
|
||||
@ -241,31 +232,9 @@ GuiViewBase::GuiViewBase(int id)
|
||||
setWindowIcon(QPixmap(toqstr(iconname.absFilename())));
|
||||
#endif
|
||||
|
||||
d.tab_widget_ = new TabWidget;
|
||||
|
||||
QPushButton * closeTabButton = new QPushButton(this);
|
||||
FileName const file = support::libFileSearch("images", "closetab", "png");
|
||||
if (!file.empty()) {
|
||||
QPixmap pm(toqstr(file.absFilename()));
|
||||
closeTabButton->setIcon(QIcon(pm));
|
||||
closeTabButton->setMaximumSize(pm.size());
|
||||
closeTabButton->setFlat(true);
|
||||
} else {
|
||||
closeTabButton->setText("Close");
|
||||
}
|
||||
closeTabButton->setCursor(Qt::ArrowCursor);
|
||||
closeTabButton->setToolTip(tr("Close tab"));
|
||||
closeTabButton->setEnabled(true);
|
||||
|
||||
QObject::connect(d.tab_widget_, SIGNAL(currentChanged(int)),
|
||||
this, SLOT(currentTabChanged(int)));
|
||||
QObject::connect(closeTabButton, SIGNAL(clicked()),
|
||||
this, SLOT(closeCurrentTab()));
|
||||
|
||||
d.tab_widget_->setCornerWidget(closeTabButton);
|
||||
#if QT_VERSION >= 0x040200
|
||||
d.tab_widget_->setUsesScrollButtons(true);
|
||||
#endif
|
||||
d.tab_widget_ = new TabWorkArea;
|
||||
QObject::connect(d.tab_widget_, SIGNAL(currentWorkAreaChanged(GuiWorkArea *)),
|
||||
this, SLOT(on_currentWorkAreaChanged(GuiWorkArea *)));
|
||||
|
||||
d.initBackground();
|
||||
if (d.bg_widget_) {
|
||||
@ -639,26 +608,12 @@ void GuiViewBase::update_view_state_qt()
|
||||
}
|
||||
|
||||
|
||||
void GuiViewBase::closeCurrentTab()
|
||||
{
|
||||
dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
|
||||
}
|
||||
|
||||
|
||||
void GuiViewBase::currentTabChanged(int i)
|
||||
void GuiViewBase::on_currentWorkAreaChanged(GuiWorkArea * wa)
|
||||
{
|
||||
disconnectBuffer();
|
||||
disconnectBufferView();
|
||||
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(d.tab_widget_->widget(i));
|
||||
BOOST_ASSERT(wa);
|
||||
BufferView & bv = wa->bufferView();
|
||||
connectBufferView(bv);
|
||||
connectBuffer(bv.buffer());
|
||||
bv.updateMetrics(false);
|
||||
bv.cursor().fixIfBroken();
|
||||
wa->setUpdatesEnabled(true);
|
||||
wa->redraw();
|
||||
wa->setFocus();
|
||||
connectBufferView(wa->bufferView());
|
||||
connectBuffer(wa->bufferView().buffer());
|
||||
|
||||
updateToc();
|
||||
// Buffer-dependent dialogs should be updated or
|
||||
@ -669,9 +624,6 @@ void GuiViewBase::currentTabChanged(int i)
|
||||
updateLayoutChoice();
|
||||
updateWindowTitle();
|
||||
updateStatusBar();
|
||||
|
||||
LYXERR(Debug::GUI) << "currentTabChanged " << i
|
||||
<< "File" << bv.buffer().fileName() << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -921,7 +873,7 @@ void GuiViewBase::setCurrentWorkArea(WorkArea * work_area)
|
||||
d.tab_widget_->setCurrentWidget(wa);
|
||||
else
|
||||
// Make sure the work area is up to date.
|
||||
currentTabChanged(d.tab_widget_->currentIndex());
|
||||
d.tab_widget_->on_currentTabChanged(d.tab_widget_->currentIndex());
|
||||
wa->setFocus();
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QAction>
|
||||
#include <QCloseEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QTabWidget>
|
||||
#include <QTimer>
|
||||
|
||||
class QDragEnterEvent;
|
||||
@ -32,6 +33,7 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class GuiToolbar;
|
||||
class GuiWorkArea;
|
||||
|
||||
QWidget * mainWindow();
|
||||
|
||||
@ -95,8 +97,8 @@ public Q_SLOTS:
|
||||
/// idle timeout
|
||||
void update_view_state_qt();
|
||||
|
||||
void currentTabChanged(int index);
|
||||
void closeCurrentTab();
|
||||
///
|
||||
void on_currentWorkAreaChanged(GuiWorkArea *);
|
||||
|
||||
/// slots to change the icon size
|
||||
void smallSizedIcons();
|
||||
@ -166,6 +168,7 @@ private:
|
||||
GuiViewPrivate& d;
|
||||
};
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -20,10 +20,12 @@
|
||||
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferView.h"
|
||||
#include "Color.h"
|
||||
#include "debug.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "LyXRC.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -36,7 +38,9 @@
|
||||
#include <QLayout>
|
||||
#include <QMainWindow>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QScrollBar>
|
||||
#include <QTabBar>
|
||||
#include <QTimer>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
@ -687,6 +691,66 @@ QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// TabWorkArea implementation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
TabWorkArea::TabWorkArea(QWidget * parent): QTabWidget(parent)
|
||||
{
|
||||
QPushButton * closeTabButton = new QPushButton(this);
|
||||
FileName const file = support::libFileSearch("images", "closetab", "png");
|
||||
if (!file.empty()) {
|
||||
QPixmap pm(toqstr(file.absFilename()));
|
||||
closeTabButton->setIcon(QIcon(pm));
|
||||
closeTabButton->setMaximumSize(pm.size());
|
||||
closeTabButton->setFlat(true);
|
||||
} else {
|
||||
closeTabButton->setText("Close");
|
||||
}
|
||||
closeTabButton->setCursor(Qt::ArrowCursor);
|
||||
closeTabButton->setToolTip(tr("Close tab"));
|
||||
closeTabButton->setEnabled(true);
|
||||
|
||||
QObject::connect(this, SIGNAL(currentChanged(int)),
|
||||
this, SLOT(on_currentTabChanged(int)));
|
||||
QObject::connect(closeTabButton, SIGNAL(clicked()),
|
||||
this, SLOT(closeCurrentTab()));
|
||||
|
||||
setCornerWidget(closeTabButton);
|
||||
#if QT_VERSION >= 0x040200
|
||||
setUsesScrollButtons(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void TabWorkArea::showBar(bool show)
|
||||
{
|
||||
tabBar()->setVisible(show);
|
||||
}
|
||||
|
||||
|
||||
void TabWorkArea::on_currentTabChanged(int i)
|
||||
{
|
||||
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
|
||||
BOOST_ASSERT(wa);
|
||||
BufferView & bv = wa->bufferView();
|
||||
bv.updateMetrics(false);
|
||||
bv.cursor().fixIfBroken();
|
||||
wa->setUpdatesEnabled(true);
|
||||
wa->redraw();
|
||||
wa->setFocus();
|
||||
///
|
||||
currentWorkAreaChanged(wa);
|
||||
|
||||
LYXERR(Debug::GUI) << "currentTabChanged " << i
|
||||
<< "File" << bv.buffer().fileName() << endl;
|
||||
}
|
||||
|
||||
|
||||
void TabWorkArea::closeCurrentTab()
|
||||
{
|
||||
lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -19,11 +19,12 @@
|
||||
#include "support/Timeout.h"
|
||||
|
||||
#include <QAbstractScrollArea>
|
||||
#include <QMouseEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
#include <QPixmap>
|
||||
#include <QResizeEvent>
|
||||
#include <QTabWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#include <queue>
|
||||
|
||||
@ -170,7 +171,26 @@ private:
|
||||
bool schedule_redraw_;
|
||||
///
|
||||
int preedit_lines_;
|
||||
};
|
||||
}; //GuiWorkArea
|
||||
|
||||
/// A tabbed set of GuiWorkAreas.
|
||||
class TabWorkArea : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TabWorkArea(QWidget * parent = 0);
|
||||
void showBar(bool show);
|
||||
|
||||
Q_SIGNALS:
|
||||
///
|
||||
void currentWorkAreaChanged(GuiWorkArea *);
|
||||
|
||||
public Q_SLOTS:
|
||||
///
|
||||
void on_currentTabChanged(int index);
|
||||
///
|
||||
void closeCurrentTab();
|
||||
}; // TabWorkArea
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
Loading…
Reference in New Issue
Block a user