commit 4803c7697b27fb420a4b9cdffc6b8ad5092f4ce2
Author: Scott Kostyshak <[email protected]>
Date: Wed Jul 13 02:42:35 2016 -0400
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
---
src/frontends/qt4/GuiWorkArea.cpp | 22 +++++++++++++++++++++-
src/frontends/qt4/GuiWorkArea.h | 5 +++++
2 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/src/frontends/qt4/GuiWorkArea.cpp
b/src/frontends/qt4/GuiWorkArea.cpp
index 72a043e..b9e5e8e 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 9e4b1ab..a039f0e 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