diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 9e4ab965a..c183a8137 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -1,5 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2020, Will Da Silva * Copyright (C) 2015, 2018 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * @@ -36,7 +37,10 @@ #endif #include +#include #include +#include +#include #include #include #include @@ -83,6 +87,7 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) , m_isNewQueryString(false) { m_ui->setupUi(this); + m_ui->tabWidget->tabBar()->installEventFilter(this); QString searchPatternHint; QTextStream stream(&searchPatternHint, QIODevice::WriteOnly); @@ -141,6 +146,24 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) connect(focusSearchHotkey, &QShortcut::activated, this, &SearchWidget::toggleFocusBetweenLineEdits); } +bool SearchWidget::eventFilter(QObject *object, QEvent *event) +{ + if (object == m_ui->tabWidget->tabBar()) { + // Close tabs when middle-clicked + if (event->type() != QEvent::MouseButtonRelease) + return false; + + const auto mouseEvent = static_cast(event); + const int tabIndex = m_ui->tabWidget->tabBar()->tabAt(mouseEvent->pos()); + if ((mouseEvent->button() == Qt::MiddleButton) && (tabIndex >= 0)) { + closeTab(tabIndex); + return true; + } + return false; + } + return QWidget::eventFilter(object, event); +} + void SearchWidget::fillCatCombobox() { m_ui->comboCategory->clear(); diff --git a/src/gui/search/searchwidget.h b/src/gui/search/searchwidget.h index d692096eb..ce54dfd0c 100644 --- a/src/gui/search/searchwidget.h +++ b/src/gui/search/searchwidget.h @@ -1,5 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2020, Will Da Silva * Copyright (C) 2015, 2018 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * @@ -33,6 +34,8 @@ #include #include +class QEvent; +class QObject; class QTabWidget; class MainWindow; @@ -59,6 +62,7 @@ private slots: void on_pluginsButton_clicked(); private: + bool eventFilter(QObject *object, QEvent *event) override; void tabChanged(int index); void closeTab(int index); void tabStatusChanged(QWidget *tab);