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);