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.
This commit is contained in:
luddens 2019-08-08 12:05:49 +02:00
parent 24da6a5395
commit 4ad392c68e
2 changed files with 13 additions and 1 deletions

View File

@ -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()));
}
}

View File

@ -6,6 +6,7 @@
#include <memory>
#include "webview.h"
#include "contentmanagerview.h"
#include <QMouseEvent>
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);