Skip to content

Commit 6baf948

Browse files
committed
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.
1 parent 7ea03e4 commit 6baf948

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

src/libs/core/settings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void Settings::load()
7676
minimizeToSystray = settings->value(QStringLiteral("minimize_to_systray"), false).toBool();
7777
hideOnClose = settings->value(QStringLiteral("hide_on_close"), false).toBool();
7878

79+
hideMenuBar = settings->value(QStringLiteral("hide_menu_bar"), false).toBool();
80+
7981
settings->beginGroup(GroupGlobalShortcuts);
8082
showShortcut = settings->value(QStringLiteral("show")).value<QKeySequence>();
8183
settings->endGroup();
@@ -197,6 +199,8 @@ void Settings::save()
197199
settings->setValue(QStringLiteral("minimize_to_systray"), minimizeToSystray);
198200
settings->setValue(QStringLiteral("hide_on_close"), hideOnClose);
199201

202+
settings->setValue(QStringLiteral("hide_menu_bar"), hideMenuBar);
203+
200204
settings->beginGroup(GroupGlobalShortcuts);
201205
settings->setValue(QStringLiteral("show"), showShortcut);
202206
settings->endGroup();

src/libs/core/settings.h

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class Settings final : public QObject
5858
// Tabs Behavior
5959
bool openNewTabAfterActive;
6060

61+
// Appearance
62+
bool hideMenuBar;
63+
6164
// Search
6265
bool fuzzySearchEnabled;
6366

src/libs/ui/mainwindow.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ MainWindow::MainWindow(Core::Application *app, QWidget *parent)
145145
dialog->exec();
146146
});
147147

148+
// View Menu
149+
ui->actionHideMenu->setShortcut(QStringLiteral("Ctrl+m"));
150+
connect(ui->actionHideMenu, &QAction::triggered, this, [this]() {
151+
if (ui->menuBar->isVisible()) {
152+
m_settings->hideMenuBar = true;
153+
}
154+
else {
155+
m_settings->hideMenuBar = false;
156+
}
157+
applySettings();
158+
});
159+
addAction(ui->actionHideMenu);
160+
148161
// Help Menu
149162
connect(ui->actionSubmitFeedback, &QAction::triggered, []() {
150163
QDesktopServices::openUrl(QUrl(QStringLiteral("https://github.com/zealdocs/zeal/issues")));
@@ -523,6 +536,13 @@ void MainWindow::applySettings()
523536
m_globalShortcut->setShortcut(m_settings->showShortcut);
524537
}
525538

539+
if (m_settings->hideMenuBar){
540+
ui->menuBar->hide();
541+
}
542+
else {
543+
ui->menuBar->show();
544+
}
545+
526546
if (m_settings->showSystrayIcon)
527547
createTrayIcon();
528548
else

src/libs/ui/mainwindow.ui

+12
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@
9494
<addaction name="separator"/>
9595
<addaction name="actionPreferences"/>
9696
</widget>
97+
<widget class="QMenu" name="menu_View">
98+
<property name="title">
99+
<string>&amp;View</string>
100+
</property>
101+
<addaction name="actionHideMenu"/>
102+
</widget>
97103
<widget class="QMenu" name="menu_Tools">
98104
<property name="title">
99105
<string>&amp;Tools</string>
@@ -102,6 +108,7 @@
102108
</widget>
103109
<addaction name="menuFile"/>
104110
<addaction name="menu_Edit"/>
111+
<addaction name="menu_View"/>
105112
<addaction name="menu_Tools"/>
106113
<addaction name="menuHelp"/>
107114
</widget>
@@ -199,6 +206,11 @@
199206
<string>&amp;Find</string>
200207
</property>
201208
</action>
209+
<action name="actionHideMenu">
210+
<property name="text">
211+
<string>&amp;Hide menubar</string>
212+
</property>
213+
</action>
202214
<action name="actionDocsets">
203215
<property name="text">
204216
<string>&amp;Docsets...</string>

0 commit comments

Comments
 (0)