From 0bae463b71aff03c16d8d1573a498b77ee36188b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Cuj=C3=A9?= Date: Mon, 1 Jul 2019 23:11:47 +0200 Subject: [PATCH] Close tab with middle mouse click (#363) --- common/lc_mainwindow.cpp | 20 ++++++++++++++++++++ common/lc_mainwindow.h | 14 ++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index c0614404..bc73b110 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -30,6 +30,26 @@ lcMainWindow* gMainWindow; #define LC_TAB_LAYOUT_VERSION 0x0001 +void lcTabBar::mouseReleaseEvent(QMouseEvent *event) +{ + if (event->type() == QEvent::MouseButtonRelease && event->button() == Qt::MidButton) + tabCloseRequested(tabAt(event->pos())); + else + QTabBar::mouseReleaseEvent(event); +} + +lcTabWidget::lcTabWidget() + : QTabWidget() +{ + setTabBar(new lcTabBar()); +} + +lcTabWidget::~lcTabWidget() +{ + if (tabBar()) + delete tabBar(); +} + void lcModelTabWidget::ResetLayout() { QLayout* TabLayout = layout(); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 850d53ee..3c447ad2 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -30,18 +30,24 @@ struct lcSearchOptions char Name[256]; }; -#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) -typedef QTabWidget lcTabWidget; -#else +class lcTabBar : public QTabBar +{ +protected: + void mouseReleaseEvent(QMouseEvent *event); +}; + class lcTabWidget : public QTabWidget { public: + lcTabWidget(); + ~lcTabWidget(); +#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) QTabBar* tabBar() { return QTabWidget::tabBar(); } -}; #endif +}; class lcModelTabWidget : public QWidget {