]> git.lyx.org Git - features.git/commitdiff
Close a tab on middle-click (#10288)
authorScott Kostyshak <skostysh@lyx.org>
Wed, 13 Jul 2016 06:42:35 +0000 (02:42 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Fri, 22 Jul 2016 02:31:29 +0000 (22:31 -0400)
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

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

index 72a043e0bfd280955f361be383da7e87464b0e1d..b9e5e8ec87a361777fe0dd0668621146d9011a24 100644 (file)
@@ -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()) {
index 9e4b1ab7a41268232b197f656b9d5e4309f28583..a039f0e9b5d3eddc054cc9c1fca7b333e8d32c09 100644 (file)
@@ -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