1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-05 20:34:56 +00:00

Ladybird: Close tab clicking wheel of the mouse

This commit is contained in:
Federico Guerinoni 2023-02-05 03:26:20 +01:00 committed by Sam Atkins
parent d5f7771039
commit 1296aa108b
2 changed files with 21 additions and 0 deletions

View File

@ -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);
}

View File

@ -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 = "");