Skip to content

Commit

Permalink
feat: add option to hide menubar
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pesader authored and trollixx committed Sep 8, 2024
1 parent 5f6b55d commit 07bdc91
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libs/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QKeySequence>();
settings->endGroup();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/libs/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class Settings final : public QObject
// Tabs Behavior
bool openNewTabAfterActive;

// Appearance
bool hideMenuBar;

// Search
bool isFuzzySearchEnabled;

Expand Down
20 changes: 20 additions & 0 deletions src/libs/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/libs/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<addaction name="separator"/>
<addaction name="actionPreferences"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
<string>&amp;View</string>
</property>
<addaction name="actionHideMenu"/>
</widget>
<widget class="QMenu" name="menu_Tools">
<property name="title">
<string>&amp;Tools</string>
Expand All @@ -102,6 +108,7 @@
</widget>
<addaction name="menuFile"/>
<addaction name="menu_Edit"/>
<addaction name="menu_View"/>
<addaction name="menu_Tools"/>
<addaction name="menuHelp"/>
</widget>
Expand Down Expand Up @@ -175,6 +182,11 @@
<string>&amp;Find</string>
</property>
</action>
<action name="actionHideMenu">
<property name="text">
<string>&amp;Hide menubar</string>
</property>
</action>
<action name="actionDocsets">
<property name="text">
<string>&amp;Docsets…</string>
Expand Down

0 comments on commit 07bdc91

Please sign in to comment.