From 4ad392c68e59f6baaa26cdde6426707e9694a2ae Mon Sep 17 00:00:00 2001 From: luddens Date: Thu, 8 Aug 2019 12:05:49 +0200 Subject: [PATCH] scroll wheel click closes tab add an event listener on the mouse click event, if it's the middle button (the scroll wheel click) it closes the tab on which the cursor is. In the closeTab() method, add a security to prevent closing the "new tab button" tab. --- src/tabbar.cpp | 9 ++++++++- src/tabbar.h | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tabbar.cpp b/src/tabbar.cpp index 74bed11..12bd3a9 100644 --- a/src/tabbar.cpp +++ b/src/tabbar.cpp @@ -196,7 +196,7 @@ void TabBar::triggerWebPageAction(QWebEnginePage::WebAction action, WebView *web void TabBar::closeTab(int index) { - if (index == 0) + if (index == 0 || index == this->count() - 1) return; setSelectionBehaviorOnRemove(index); auto webview = widget(index); @@ -235,3 +235,10 @@ void TabBar::onCurrentChanged(int index) QTimer::singleShot(0, [=](){emit currentTitleChanged("");}); } } + +void TabBar::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::MiddleButton) { + closeTab(this->tabAt(event->pos())); + } +} \ No newline at end of file diff --git a/src/tabbar.h b/src/tabbar.h index 013c780..3bb60ab 100644 --- a/src/tabbar.h +++ b/src/tabbar.h @@ -6,6 +6,7 @@ #include #include "webview.h" #include "contentmanagerview.h" +#include class TabBar : public QTabBar { @@ -35,6 +36,10 @@ public: QString currentArticleUrl(); QString currentArticleTitle(); virtual QSize tabSizeHint(int index) const; + +protected: + void mousePressEvent(QMouseEvent *event); + signals: void webActionEnabledChanged(QWebEnginePage::WebAction action, bool enabled); void currentZimIdChanged(const QString& zimId);