]> git.lyx.org Git - features.git/commitdiff
Move TabWidget related code to TabWorkArea class in GuiWorkArea.{cpp,h}
authorAbdelrazak Younes <younes@lyx.org>
Sat, 6 Oct 2007 15:48:58 +0000 (15:48 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 6 Oct 2007 15:48:58 +0000 (15:48 +0000)
The close button is back...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20787 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h

index ac2e1fd4a453e52563931e2d4c4d197aac6dfe22..a50889e0fe9aedd802b45dccce753e7aab9b4093 100644 (file)
@@ -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();
 }
 
index 4b8b6b536b82d03d04355b527bf482ec55cfbea8..0b429e1d5d26e65d7370f66eefda77708aad058e 100644 (file)
@@ -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
 
index 9853a56930563075aedeb1f08cbedf9a7ebfc00c..c25d392531655d0338d7fb7af34a69818d00581b 100644 (file)
 
 #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
 
index 2bafbeb5b3669ccbf5322bcbd6e9f63876cea3be..dc9c84c2a4f8df4d5b8b17a1c878085c363d33af 100644 (file)
 #include "support/Timeout.h"
 
 #include <QAbstractScrollArea>
+#include <QKeyEvent>
 #include <QMouseEvent>
+#include <QPixmap>
 #include <QResizeEvent>
-#include <QKeyEvent>
+#include <QTabWidget>
 #include <QTimer>
-#include <QPixmap>
 
 #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