diff options
author | Federico Guerinoni <guerinoni.federico@gmail.com> | 2023-02-05 03:26:20 +0100 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-02-16 11:26:44 +0000 |
commit | 1296aa108b6fccce45655c78fccdc10f102d33fc (patch) | |
tree | 1e6c5ffe38cd7ec059adfbe6c71a8311761308df /Ladybird | |
parent | d5f77710390fe83abdb3867a533a5da13815c041 (diff) | |
download | serenity-1296aa108b6fccce45655c78fccdc10f102d33fc.zip |
Ladybird: Close tab clicking wheel of the mouse
Diffstat (limited to 'Ladybird')
-rw-r--r-- | Ladybird/BrowserWindow.cpp | 18 | ||||
-rw-r--r-- | Ladybird/BrowserWindow.h | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Ladybird/BrowserWindow.cpp b/Ladybird/BrowserWindow.cpp index faccfc978a..14cc23dfe7 100644 --- a/Ladybird/BrowserWindow.cpp +++ b/Ladybird/BrowserWindow.cpp @@ -22,6 +22,7 @@ #include <QGuiApplication> #include <QInputDialog> #include <QPlainTextEdit> +#include <QTabBar> extern DeprecatedString s_serenity_resource_root; extern Browser::Settings* s_settings; @@ -31,6 +32,7 @@ BrowserWindow::BrowserWindow(Browser::CookieJar& cookie_jar, StringView webdrive , m_webdriver_content_ipc_path(webdriver_content_ipc_path) { m_tabs_container = new QTabWidget(this); + m_tabs_container->installEventFilter(this); m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight); m_tabs_container->setMovable(true); m_tabs_container->setTabsClosable(true); @@ -504,3 +506,19 @@ void BrowserWindow::copy_selected_text() clipboard->setText(qstring_from_ak_deprecated_string(text)); } } + +bool BrowserWindow::eventFilter(QObject* obj, QEvent* event) +{ + if (event->type() == QEvent::MouseButtonRelease) { + auto const* const mouse_event = static_cast<QMouseEvent*>(event); + if (mouse_event->button() == Qt::MouseButton::MiddleButton) { + if (obj == m_tabs_container) { + auto const tab_index = m_tabs_container->tabBar()->tabAt(mouse_event->pos()); + close_tab(tab_index); + return true; + } + } + } + + return QMainWindow::eventFilter(obj, event); +} diff --git a/Ladybird/BrowserWindow.h b/Ladybird/BrowserWindow.h index 790421d868..5a5438dc94 100644 --- a/Ladybird/BrowserWindow.h +++ b/Ladybird/BrowserWindow.h @@ -54,6 +54,9 @@ public slots: void select_all(); void copy_selected_text(); +protected: + bool eventFilter(QObject* obj, QEvent* event); + private: void debug_request(DeprecatedString const& request, DeprecatedString const& argument = ""); |