Browse Source

Merge pull request #13465 from WillDaSilva/mid-click-close-tabs

Enable the use of middle-click to close tabs
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
1c663adee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      src/gui/search/searchwidget.cpp
  2. 4
      src/gui/search/searchwidget.h

23
src/gui/search/searchwidget.cpp

@ -1,5 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2020, Will Da Silva <will@willdasilva.xyz>
* Copyright (C) 2015, 2018 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2015, 2018 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
@ -36,7 +37,10 @@
#endif #endif
#include <QDebug> #include <QDebug>
#include <QEvent>
#include <QMessageBox> #include <QMessageBox>
#include <QMouseEvent>
#include <QObject>
#include <QRegularExpression> #include <QRegularExpression>
#include <QShortcut> #include <QShortcut>
#include <QTextStream> #include <QTextStream>
@ -83,6 +87,7 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
, m_isNewQueryString(false) , m_isNewQueryString(false)
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->tabWidget->tabBar()->installEventFilter(this);
QString searchPatternHint; QString searchPatternHint;
QTextStream stream(&searchPatternHint, QIODevice::WriteOnly); QTextStream stream(&searchPatternHint, QIODevice::WriteOnly);
@ -141,6 +146,24 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
connect(focusSearchHotkey, &QShortcut::activated, this, &SearchWidget::toggleFocusBetweenLineEdits); 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<QMouseEvent *>(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() void SearchWidget::fillCatCombobox()
{ {
m_ui->comboCategory->clear(); m_ui->comboCategory->clear();

4
src/gui/search/searchwidget.h

@ -1,5 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2020, Will Da Silva <will@willdasilva.xyz>
* Copyright (C) 2015, 2018 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2015, 2018 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
@ -33,6 +34,8 @@
#include <QPointer> #include <QPointer>
#include <QWidget> #include <QWidget>
class QEvent;
class QObject;
class QTabWidget; class QTabWidget;
class MainWindow; class MainWindow;
@ -59,6 +62,7 @@ private slots:
void on_pluginsButton_clicked(); void on_pluginsButton_clicked();
private: private:
bool eventFilter(QObject *object, QEvent *event) override;
void tabChanged(int index); void tabChanged(int index);
void closeTab(int index); void closeTab(int index);
void tabStatusChanged(QWidget *tab); void tabStatusChanged(QWidget *tab);

Loading…
Cancel
Save