]> git.lyx.org Git - features.git/commitdiff
Implementation of the conclusion of the "LyX/Mac 1.6 -- Window issues" thread:
authorStefan Schimanski <sts@lyx.org>
Sat, 15 Mar 2008 01:00:25 +0000 (01:00 +0000)
committerStefan Schimanski <sts@lyx.org>
Sat, 15 Mar 2008 01:00:25 +0000 (01:00 +0000)
* add tab popup menu to hide and close a buffer.
* remove the very non-standard hide-button on the left of the tabbar.

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

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

index 23429f634e41e2e45a0b616c7dfa63a4bb9190a8..392224eef0d1c2d4c397d68cbad020b708321af6 100644 (file)
@@ -1166,7 +1166,8 @@ NoTabFrameMacStyle noTabFrameMacStyle;
 #endif
 
 
-TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
+TabWorkArea::TabWorkArea(QWidget * parent)
+       : QTabWidget(parent), clicked_tab_(-1)
 {
 #ifdef Q_WS_MACX
        setStyle(&noTabFrameMacStyle);
@@ -1196,17 +1197,10 @@ TabWorkArea::TabWorkArea(QWidget * parent) : QTabWidget(parent)
                this, SLOT(closeCurrentBuffer()));
        setCornerWidget(closeBufferButton, Qt::TopRightCorner);
 
-       QToolButton * closeTabButton = new QToolButton(this);
-       closeTabButton->setPalette(pal);
-       closeTabButton->setIcon(QIcon(":/images/hidetab.png"));
-       closeTabButton->setText("Hide tab");
-       closeTabButton->setAutoRaise(true);
-       closeTabButton->setCursor(Qt::ArrowCursor);
-       closeTabButton->setToolTip(qt_("Hide tab"));
-       closeTabButton->setEnabled(true);
-       QObject::connect(closeTabButton, SIGNAL(clicked()),
-               this, SLOT(closeCurrentTab()));
-       setCornerWidget(closeTabButton, Qt::TopLeftCorner);
+       // make us responsible for the context menu of the tabbar
+       tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
+       connect(tabBar(), SIGNAL(customContextMenuRequested(const QPoint &)),
+               this, SLOT(showContextMenu(const QPoint &)));
 
        setUsesScrollButtons(true);
 }
@@ -1351,13 +1345,22 @@ void TabWorkArea::on_currentTabChanged(int i)
 
 void TabWorkArea::closeCurrentBuffer()
 {
+       if (clicked_tab_ != -1)
+               setCurrentIndex(clicked_tab_);
+
        lyx::dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
 }
 
 
 void TabWorkArea::closeCurrentTab()
 {
-       removeWorkArea(currentWorkArea());
+       if (clicked_tab_ == -1)
+               removeWorkArea(currentWorkArea());
+       else {
+               GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_)); 
+               BOOST_ASSERT(wa);
+               removeWorkArea(wa);
+       }
 }
 
 
@@ -1369,6 +1372,25 @@ void TabWorkArea::updateTabText(GuiWorkArea * wa)
        setTabText(i, wa->windowTitle());
 }
 
+
+void TabWorkArea::showContextMenu(const QPoint & pos)
+{
+       // which tab?
+       clicked_tab_ = tabBar()->tabAt(pos);
+       if (clicked_tab_ != -1) {
+               // show tab popup
+               QMenu popup;
+               popup.addAction(QIcon(":/images/hidetab.png"),
+                        qt_("Hide tab"), this, SLOT(closeCurrentTab()));
+               popup.addAction(QIcon(":/images/closetab.png"),
+                        qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
+               popup.exec(tabBar()->mapToGlobal(pos));
+               
+               clicked_tab_ = -1;
+       }
+}
+
+
 } // namespace frontend
 } // namespace lyx
 
index 8e1a0aa68cc221857d68853e94381ffe0a73c027..034bef285b6be7e0c6d5be56434214bacbb7da45 100644 (file)
@@ -264,12 +264,19 @@ Q_SIGNALS:
 public Q_SLOTS:
        ///
        void on_currentTabChanged(int index);
-       ///
+       /// close current buffer, or the one given by \c clicked_tab_
        void closeCurrentBuffer();
-       ///
+       /// close current tab, or the one given by \c clicked_tab_
        void closeCurrentTab();
        ///
        void updateTabText(GuiWorkArea *);
+       
+private Q_SLOTS:
+       ///
+       void showContextMenu(const QPoint & pos);
+
+private:
+       int clicked_tab_;
 }; // TabWorkArea
 
 } // namespace frontend