From ff31c58c0578578e7e4044a85041cf8163beed19 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Tue, 29 Oct 2024 23:54:30 +0100 Subject: [PATCH] VerticalTabs: Override Alt+9 keyboard shortcut Signed-off-by: Juraj Oravec --- src/lib/app/browserwindow.cpp | 5 +++++ src/lib/app/browserwindow.h | 2 ++ .../VerticalTabs/verticaltabscontroller.cpp | 11 ++++++++++ .../VerticalTabs/verticaltabswidget.cpp | 22 +++++++++++++++++++ src/plugins/VerticalTabs/verticaltabswidget.h | 2 ++ 5 files changed, 42 insertions(+) diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index fe1a9400b..72145400a 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -725,6 +725,11 @@ TabMruModel *BrowserWindow::tabMruModel() const return m_tabMruModel; } +bool BrowserWindow::useTabNumberShortcuts() const +{ + return m_useTabNumberShortcuts; +} + void BrowserWindow::setWindowTitle(const QString &t) { QString title = t; diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index 6cd64f942..2aa982369 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -125,6 +125,8 @@ public: TabModel *tabModel() const; TabMruModel *tabMruModel() const; + bool useTabNumberShortcuts() const; + Q_SIGNALS: void startingCompleted(); void aboutToClose(); diff --git a/src/plugins/VerticalTabs/verticaltabscontroller.cpp b/src/plugins/VerticalTabs/verticaltabscontroller.cpp index a67095da1..56ec0b00b 100644 --- a/src/plugins/VerticalTabs/verticaltabscontroller.cpp +++ b/src/plugins/VerticalTabs/verticaltabscontroller.cpp @@ -19,6 +19,7 @@ #include "verticaltabsplugin.h" #include "verticaltabswidget.h" +#include "browserwindow.h" #include "tabwidget.h" #include @@ -100,6 +101,16 @@ bool VerticalTabsController::handleKeyPress(QKeyEvent *event, TabWidget *tabWidg } break; + case Qt::Key_9: + if ((event->modifiers() & Qt::AltModifier) && tabWidget->browserWindow()->useTabNumberShortcuts()) { + VerticalTabsWidget *widget = m_widgets.value(tabWidget->browserWindow()); + if (widget) { + widget->switchToLastTab(); + return true; + } + } + break; + default: break; } diff --git a/src/plugins/VerticalTabs/verticaltabswidget.cpp b/src/plugins/VerticalTabs/verticaltabswidget.cpp index 6d35cb751..93160a128 100644 --- a/src/plugins/VerticalTabs/verticaltabswidget.cpp +++ b/src/plugins/VerticalTabs/verticaltabswidget.cpp @@ -116,6 +116,14 @@ void VerticalTabsWidget::switchToPreviousTab() } } +void VerticalTabsWidget::switchToLastTab() +{ + WebTab *tab = lastTab(); + if (tab) { + tab->makeCurrentTab(); + } +} + WebTab *VerticalTabsWidget::nextTab() const { QModelIndex next; @@ -158,6 +166,20 @@ WebTab *VerticalTabsWidget::previousTab() const return previous.data(TabModel::WebTabRole).value(); } +WebTab * VerticalTabsWidget::lastTab() const +{ + QModelIndex last; + auto rows = m_normalView->model()->rowCount(); + if (rows > 0) { + last = m_normalView->model()->index(rows - 1, 0); + } + else { + last = m_pinnedView->model()->index(m_pinnedView->model()->rowCount(), 0); + } + + return last.data(TabModel::WebTabRole).value(); +} + void VerticalTabsWidget::wheelEvent(QWheelEvent *event) { if (!qzSettings->alwaysSwitchTabsWithWheel && m_normalView->verticalScrollBar()->isVisible()) { diff --git a/src/plugins/VerticalTabs/verticaltabswidget.h b/src/plugins/VerticalTabs/verticaltabswidget.h index ccc4e5bd0..b349be32c 100644 --- a/src/plugins/VerticalTabs/verticaltabswidget.h +++ b/src/plugins/VerticalTabs/verticaltabswidget.h @@ -42,12 +42,14 @@ public: void switchToNextTab(); void switchToPreviousTab(); + void switchToLastTab(); void addChildTab(); private: WebTab *nextTab() const; WebTab *previousTab() const; + WebTab *lastTab() const; void wheelEvent(QWheelEvent *event) override; void updateGroupMenu();