From: Stefan Schimanski Date: Sat, 15 Mar 2008 01:00:25 +0000 (+0000) Subject: Implementation of the conclusion of the "LyX/Mac 1.6 -- Window issues" thread: X-Git-Tag: 1.6.10~5623 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b607775ad7d9adf6288eb0a98aa910a11cafe3e3;p=features.git Implementation of the conclusion of the "LyX/Mac 1.6 -- Window issues" thread: * 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 --- diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 23429f634e..392224eef0 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -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(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 diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 8e1a0aa68c..034bef285b 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -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