From 6a8dd760cb74a607c9e0ef3f29ac3db782b110fd Mon Sep 17 00:00:00 2001 From: pesader <0f983427-355c-4bc4-8ac0-9c0f3dce504a@anonaddy.me> Date: Mon, 14 Nov 2022 16:34:45 -0300 Subject: [PATCH] feat: add option to hide menubar Add a "View" submenu to the menubar, that allows the user hide the menubar. Also add a keyboard shortcut (Ctrl + M) to toggle the visibility of the menubar. This preference is saved, so it can be restored once the user closes and reopens Zeal. This preference is tipically only accessible through the menubar, so don't add an entry for it in the "Preferences" window. --- src/libs/core/settings.cpp | 4 ++++ src/libs/core/settings.h | 3 +++ src/libs/ui/mainwindow.cpp | 20 ++++++++++++++++++++ src/libs/ui/mainwindow.ui | 12 ++++++++++++ 4 files changed, 39 insertions(+) diff --git a/src/libs/core/settings.cpp b/src/libs/core/settings.cpp index 38873388..abb8aae2 100644 --- a/src/libs/core/settings.cpp +++ b/src/libs/core/settings.cpp @@ -114,6 +114,8 @@ void Settings::load() minimizeToSystray = settings->value(QStringLiteral("minimize_to_systray"), false).toBool(); hideOnClose = settings->value(QStringLiteral("hide_on_close"), false).toBool(); + hideMenuBar = settings->value(QStringLiteral("hide_menu_bar"), false).toBool(); + settings->beginGroup(GroupGlobalShortcuts); showShortcut = settings->value(QStringLiteral("show")).value(); settings->endGroup(); @@ -246,6 +248,8 @@ void Settings::save() settings->setValue(QStringLiteral("minimize_to_systray"), minimizeToSystray); settings->setValue(QStringLiteral("hide_on_close"), hideOnClose); + settings->setValue(QStringLiteral("hide_menu_bar"), hideMenuBar); + settings->beginGroup(GroupGlobalShortcuts); settings->setValue(QStringLiteral("show"), showShortcut); settings->endGroup(); diff --git a/src/libs/core/settings.h b/src/libs/core/settings.h index be755d47..19cd7a6d 100644 --- a/src/libs/core/settings.h +++ b/src/libs/core/settings.h @@ -58,6 +58,9 @@ class Settings final : public QObject // Tabs Behavior bool openNewTabAfterActive; + // Appearance + bool hideMenuBar; + // Search bool isFuzzySearchEnabled; diff --git a/src/libs/ui/mainwindow.cpp b/src/libs/ui/mainwindow.cpp index 440aaf67..9269e85e 100644 --- a/src/libs/ui/mainwindow.cpp +++ b/src/libs/ui/mainwindow.cpp @@ -154,6 +154,19 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent) dialog->exec(); }); + // View Menu + ui->actionHideMenu->setShortcut(QStringLiteral("Ctrl+m")); + connect(ui->actionHideMenu, &QAction::triggered, this, [this]() { + if (ui->menuBar->isVisible()) { + m_settings->hideMenuBar = true; + } + else { + m_settings->hideMenuBar = false; + } + applySettings(); + }); + addAction(ui->actionHideMenu); + // Help Menu connect(ui->actionSubmitFeedback, &QAction::triggered, []() { QDesktopServices::openUrl(QUrl(QStringLiteral("https://github.com/zealdocs/zeal/issues"))); @@ -533,6 +546,13 @@ void MainWindow::applySettings() m_globalShortcut->setShortcut(m_settings->showShortcut); } + if (m_settings->hideMenuBar){ + ui->menuBar->hide(); + } + else { + ui->menuBar->show(); + } + if (m_settings->showSystrayIcon) createTrayIcon(); else diff --git a/src/libs/ui/mainwindow.ui b/src/libs/ui/mainwindow.ui index ed423fbe..87fe8ee8 100644 --- a/src/libs/ui/mainwindow.ui +++ b/src/libs/ui/mainwindow.ui @@ -94,6 +94,12 @@ + + + &View + + + &Tools @@ -102,6 +108,7 @@ + @@ -175,6 +182,11 @@ &Find + + + &Hide menubar + + &Docsets…