From 775efc65ed111dfe807796c4201c00b608808633 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 27 Apr 2024 23:27:19 -0400 Subject: [PATCH] QMenubar option to show/hide itself (#10341) -------- Co-authored-by: Mikko Saarinki Co-authored-by: Jonathan White --- share/translations/keepassxc_en.ts | 18 ++++++++++----- src/core/Config.cpp | 1 + src/core/Config.h | 1 + src/gui/MainWindow.cpp | 36 +++++++++++++++++++++++++----- src/gui/MainWindow.ui | 15 +++++++++++++ 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index b3666f3bc..5f5ac1881 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -3671,11 +3671,6 @@ This may cause the affected plugins to malfunction. Confirm Overwrite Attachment - - Attachment "%1" already exists. -Would you like to overwrite the existing attachment? - - Confirm Attachment @@ -3705,6 +3700,11 @@ Do you want to save the changes to your database? Error: %1 + + Attachment "%1" already exists. +Would you like to overwrite the existing attachment? + + EntryAttributesModel @@ -5533,6 +5533,10 @@ Are you sure you want to continue with this file? Classic (Platform-native) + + Show Menubar + + Show Toolbar @@ -5687,6 +5691,10 @@ We recommend you use the AppImage available on our downloads page. No Tags + + Toggle Show Menubar + + ManageDatabase diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 0cf2e65e1..b7b550f7c 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -92,6 +92,7 @@ static const QHash configStrings = { // GUI {Config::GUI_Language, {QS("GUI/Language"), Roaming, QS("system")}}, + {Config::GUI_HideMenubar, {QS("GUI/HideMenubar"), Roaming, false}}, {Config::GUI_HideToolbar, {QS("GUI/HideToolbar"), Roaming, false}}, {Config::GUI_MovableToolbar, {QS("GUI/MovableToolbar"), Roaming, false}}, {Config::GUI_HidePreviewPanel, {QS("GUI/HidePreviewPanel"), Roaming, false}}, diff --git a/src/core/Config.h b/src/core/Config.h index 25f2e4b10..4ef29417e 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -73,6 +73,7 @@ public: LastDir, GUI_Language, + GUI_HideMenubar, GUI_HideToolbar, GUI_MovableToolbar, GUI_HidePreviewPanel, diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index efcbd914b..a9976f84f 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -583,6 +583,7 @@ MainWindow::MainWindow() m_ui->menubar->installEventFilter(eventFilter); m_ui->toolBar->installEventFilter(eventFilter); m_ui->tabWidget->tabBar()->installEventFilter(eventFilter); + installEventFilter(eventFilter); #endif #ifdef Q_OS_MACOS @@ -1675,6 +1676,7 @@ void MainWindow::applySettingsChanges() m_inactivityTimer->deactivate(); } + m_ui->menubar->setHidden(config()->get(Config::GUI_HideMenubar).toBool()); m_ui->toolBar->setHidden(config()->get(Config::GUI_HideToolbar).toBool()); auto movable = config()->get(Config::GUI_MovableToolbar).toBool(); m_ui->toolBar->setMovable(movable); @@ -2037,6 +2039,16 @@ void MainWindow::initViewMenu() } }); +#ifdef Q_OS_MACOS + m_ui->actionShowMenubar->setVisible(false); +#else + m_ui->actionShowMenubar->setChecked(!config()->get(Config::GUI_HideMenubar).toBool()); + connect(m_ui->actionShowMenubar, &QAction::toggled, this, [this](bool checked) { + config()->set(Config::GUI_HideMenubar, !checked); + applySettingsChanges(); + }); +#endif + m_ui->actionShowToolbar->setChecked(!config()->get(Config::GUI_HideToolbar).toBool()); connect(m_ui->actionShowToolbar, &QAction::toggled, this, [this](bool checked) { config()->set(Config::GUI_HideToolbar, !checked); @@ -2080,6 +2092,7 @@ MainWindowEventFilter::MainWindowEventFilter(QObject* parent) /** * MainWindow event filter to initiate empty-area drag on the toolbar, menubar, and tabbar. + * Also shows menubar with Alt when menubar itself is hidden. */ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) { @@ -2088,10 +2101,11 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) return QObject::eventFilter(watched, event); } - if (event->type() == QEvent::MouseButtonPress) { + auto eventType = event->type(); + if (eventType == QEvent::MouseButtonPress) { + auto mouseEvent = dynamic_cast(event); if (watched == mainWindow->m_ui->menubar) { - auto* m = static_cast(event); - if (!mainWindow->m_ui->menubar->actionAt(m->pos())) { + if (!mainWindow->m_ui->menubar->actionAt(mouseEvent->pos())) { mainWindow->windowHandle()->startSystemMove(); return false; } @@ -2101,12 +2115,24 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) return false; } } else if (watched == mainWindow->m_ui->tabWidget->tabBar()) { - auto* m = static_cast(event); - if (mainWindow->m_ui->tabWidget->tabBar()->tabAt(m->pos()) == -1) { + if (mainWindow->m_ui->tabWidget->tabBar()->tabAt(mouseEvent->pos()) == -1) { mainWindow->windowHandle()->startSystemMove(); return true; } } + } else if (eventType == QEvent::KeyRelease) { + if (watched == mainWindow) { + auto keyEvent = dynamic_cast(event); + if (keyEvent->key() == Qt::Key_Alt && !keyEvent->modifiers() + && config()->get(Config::GUI_HideMenubar).toBool()) { + auto menubar = mainWindow->m_ui->menubar; + menubar->setVisible(!menubar->isVisible()); + if (menubar->isVisible()) { + menubar->setActiveAction(mainWindow->m_ui->menuFile->menuAction()); + } + return false; + } + } } return QObject::eventFilter(watched, event); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index 48574049e..a1dc25c58 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -384,6 +384,7 @@ + @@ -1040,6 +1041,20 @@ Classic (Platform-native) + + + true + + + true + + + Show Menubar + + + Toggle Show Menubar + + true