From: Scott Kostyshak Date: Wed, 13 Jul 2016 06:42:35 +0000 (-0400) Subject: Close a tab on middle-click (#10288) X-Git-Tag: 2.3.0alpha1~1223 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4803c7697b27fb420a4b9cdffc6b8ad5092f4ce2;p=features.git Close a tab on middle-click (#10288) This is the default behavior of Chromium and Firefox. The main appeal is that instead of having to precisely click on the 'x' to close a tab, one can more easily middle-click anywhere in the tab. The tab is closed if the middle button is pressed on a tab and is relased on the same tab. After pressing, the user may move the mouse over other tabs but as long as they move it back to the tab where they initiated the press before they release, the close will execute. This is how the feature works in Chromium and Firefox. Nothing is done if the user middle-clicks on the blank part of the tab bar. This is consistent with Chromium. Firefox, on the other hand, opens a new tab. In LyX one can already double-click the blank part to open a new tab, and in feedback from lyx-users [1] most expected and desired that nothing be done in this case. [1] https://www.mail-archive.com/search?l=mid&q=20160720063306.6fyarf3kywexbxvd%40steph --- diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 72a043e0bf..b9e5e8ec87 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1557,7 +1557,7 @@ NoTabFrameMacStyle noTabFrameMacStyle; TabWorkArea::TabWorkArea(QWidget * parent) - : QTabWidget(parent), clicked_tab_(-1) + : QTabWidget(parent), clicked_tab_(-1), midpressed_tab_(-1) { #ifdef Q_OS_MAC setStyle(&noTabFrameMacStyle); @@ -1605,6 +1605,26 @@ TabWorkArea::TabWorkArea(QWidget * parent) } +void TabWorkArea::mousePressEvent(QMouseEvent *me) +{ + if (me->button() == Qt::MidButton) + midpressed_tab_ = tabBar()->tabAt(me->pos()); + else + QTabWidget::mousePressEvent(me); +} + + +void TabWorkArea::mouseReleaseEvent(QMouseEvent *me) +{ + if (me->button() == Qt::MidButton) { + int const midreleased_tab = tabBar()->tabAt(me->pos()); + if (midpressed_tab_ == midreleased_tab && posIsTab(me->pos())) + closeTab(midreleased_tab); + } else + QTabWidget::mouseReleaseEvent(me); +} + + void TabWorkArea::paintEvent(QPaintEvent * event) { if (tabBar()->isVisible()) { diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 9e4b1ab7a4..a039f0e9b5 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -230,6 +230,9 @@ private Q_SLOTS: void on_currentTabChanged(int index); /// void showContextMenu(const QPoint & pos); + /// enable closing tab on middle-click + void mousePressEvent(QMouseEvent * me); + void mouseReleaseEvent(QMouseEvent * me); /// void mouseDoubleClickEvent(QMouseEvent * event); @@ -239,6 +242,8 @@ private: int clicked_tab_; /// + int midpressed_tab_; + /// QToolButton * closeBufferButton; }; // TabWorkArea