From 9b43745bb2c75ef26366513624e503d1a376e0b2 Mon Sep 17 00:00:00 2001 From: Mikko Saarinki Date: Wed, 28 Feb 2024 21:08:02 +0200 Subject: [PATCH] QMenubar option to show/hide itself --- share/translations/keepassxc_en.ts | 18 +++++++++++++----- src/core/Config.cpp | 1 + src/core/Config.h | 1 + src/gui/MainWindow.cpp | 28 +++++++++++++++++++++++++++- src/gui/MainWindow.ui | 15 +++++++++++++++ 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 514cf49a17..e611c67fc2 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -3700,11 +3700,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 @@ -3734,6 +3729,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 @@ -5380,6 +5380,10 @@ Are you sure you want to continue with this file? Classic (Platform-native) + + Show Menubar + + Show Toolbar @@ -5718,6 +5722,10 @@ We recommend you use the AppImage available on our downloads page. Set Theme: Classic + + Toggle Show Menubar + + Toggle Show Toolbar diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 0c4551fefd..eee509c8d0 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 53cc66742e..853005729c 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -74,6 +74,7 @@ class Config : public QObject LastDir, GUI_Language, + GUI_HideMenubar, GUI_HideToolbar, GUI_MovableToolbar, GUI_HidePreviewPanel, diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 2b92894f3b..74e2a968df 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -553,6 +553,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 @@ -1655,6 +1656,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); @@ -2017,6 +2019,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); @@ -2122,6 +2134,9 @@ void MainWindow::initActionCollection() m_ui->actionThemeDark, m_ui->actionThemeClassic, m_ui->actionCompactMode, +#ifndef Q_OS_MACOS + m_ui->actionShowMenubar, +#endif m_ui->actionShowToolbar, m_ui->actionShowPreviewPanel, m_ui->actionAllowScreenCapture, @@ -2199,6 +2214,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) { @@ -2207,7 +2223,8 @@ 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) { if (watched == mainWindow->m_ui->menubar) { auto* m = static_cast(event); if (!mainWindow->m_ui->menubar->actionAt(m->pos())) { @@ -2226,6 +2243,15 @@ bool MainWindowEventFilter::eventFilter(QObject* watched, QEvent* event) return true; } } + } else if (eventType == QEvent::KeyRelease) { + if (watched == mainWindow) { + auto m = static_cast(event); + if (m->key() == Qt::Key_Alt && config()->get(Config::GUI_HideMenubar).toBool()) { + auto menubar = mainWindow->m_ui->menubar; + menubar->setVisible(!menubar->isVisible()); + return false; + } + } } return QObject::eventFilter(watched, event); diff --git a/src/gui/MainWindow.ui b/src/gui/MainWindow.ui index d34d802b27..cdbdaaa8b8 100644 --- a/src/gui/MainWindow.ui +++ b/src/gui/MainWindow.ui @@ -392,6 +392,7 @@ + @@ -1138,6 +1139,20 @@ Set Theme: Classic + + + true + + + true + + + Show Menubar + + + Toggle Show Menubar + + true