mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 19:46:12 -04:00
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:
parent
24da6a5395
commit
4ad392c68e
@ -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()));
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user