mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
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
This commit is contained in:
parent
b236450e61
commit
4803c7697b
@ -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()) {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user