From 73d11206aec4c90aa5ef63fdfe888298c9aa7e0c Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Fri, 14 Oct 2011 23:32:12 +0200 Subject: [PATCH] Adding the possibility to close a tab by middle-clicking it. --- src/webview/tabbar.cpp | 14 ++++++++++++++ src/webview/tabbar.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/webview/tabbar.cpp b/src/webview/tabbar.cpp index f7d9f35d8..ea3d56317 100644 --- a/src/webview/tabbar.cpp +++ b/src/webview/tabbar.cpp @@ -230,3 +230,17 @@ void TabBar::mouseDoubleClickEvent(QMouseEvent* event) } QTabBar::mouseDoubleClickEvent(event); } + +void TabBar::mousePressEvent(QMouseEvent* event) +{ + TabWidget* tabWidget = qobject_cast(parentWidget()); + if (!tabWidget) + return; + + int id = tabAt(event->pos()); + if (id != -1 && event->buttons() == Qt::MiddleButton) { + tabWidget->closeTab(id); + return; + } + QTabBar::mousePressEvent(event); +} diff --git a/src/webview/tabbar.h b/src/webview/tabbar.h index a13540ed5..c4614676d 100644 --- a/src/webview/tabbar.h +++ b/src/webview/tabbar.h @@ -70,6 +70,7 @@ private slots: private: void mouseDoubleClickEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent* event); QSize tabSizeHint(int index) const; // void tabInserted(int index);