aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/mainwindow.cpp
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2023-08-15 18:06:29 +0200
committerCristian Adam <cristian.adam@qt.io>2023-09-08 07:59:50 +0000
commita6e779606db6c8536c715470ddb73f10c7431e8b (patch)
treea77cbe5e79f0373ed401d69264ba51b74b3c8960 /src/plugins/coreplugin/mainwindow.cpp
parent3c3a9f6786610e0c1975563e8a36276ccb61d116 (diff)
Core: Add action to hide the menu bar
This will only affect the platforms that do not have a native menu bar e.g. Windows and Linux excepting Unity. Fixes: QTCREATORBUG-29498 Change-Id: I17a654cfa50342f3e506bf0a2b14225c4d3a6bee Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/plugins/coreplugin/mainwindow.cpp')
-rw-r--r--src/plugins/coreplugin/mainwindow.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index b4f55b5414..de58123bdf 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -60,6 +60,7 @@
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <utils/touchbar/touchbar.h>
+#include <utils/checkablemessagebox.h>
#include <utils/terminalcommand.h>
#include <utils/utilsicons.h>
@@ -106,6 +107,7 @@ static const char colorKey[] = "Color";
static const char windowGeometryKey[] = "WindowGeometry";
static const char windowStateKey[] = "WindowState";
static const char modeSelectorLayoutKey[] = "ModeSelectorLayout";
+static const char menubarVisibleKey[] = "MenubarVisible";
static const bool askBeforeExitDefault = false;
@@ -833,6 +835,27 @@ void MainWindow::registerDefaultActions()
mview->addAction(cmd, Constants::G_VIEW_VIEWS);
m_toggleRightSideBarButton->setEnabled(false);
+ // Show Menubar Action
+ if (menuBar() && !menuBar()->isNativeMenuBar()) {
+ m_toggleMenubarAction = new QAction(Tr::tr("Show Menubar"), this);
+ m_toggleMenubarAction->setCheckable(true);
+ cmd = ActionManager::registerAction(m_toggleMenubarAction, Constants::TOGGLE_MENUBAR);
+ cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+M")));
+ connect(m_toggleMenubarAction, &QAction::toggled, this, [this, cmd](bool visible) {
+ if (!visible) {
+ CheckableMessageBox::information(
+ Core::ICore::dialogParent(),
+ Tr::tr("Hide Menubar"),
+ Tr::tr(
+ "This will hide the menu bar completely. You can show it again by typing ")
+ + cmd->keySequence().toString(QKeySequence::NativeText),
+ QString("ToogleMenuBarHint"));
+ }
+ menuBar()->setVisible(visible);
+ });
+ mview->addAction(cmd, Constants::G_VIEW_VIEWS);
+ }
+
registerModeSelectorStyleActions();
// Window->Views
@@ -1184,6 +1207,14 @@ void MainWindow::readSettings()
updateModeSelectorStyleMenu();
}
+ if (menuBar() && !menuBar()->isNativeMenuBar()) {
+ const bool isVisible = settings->value(menubarVisibleKey, true).toBool();
+
+ menuBar()->setVisible(isVisible);
+ if (m_toggleMenubarAction)
+ m_toggleMenubarAction->setChecked(isVisible);
+ }
+
settings->endGroup();
EditorManagerPrivate::readSettings();
@@ -1202,6 +1233,9 @@ void MainWindow::saveSettings()
StyleHelper::requestedBaseColor(),
QColor(StyleHelper::DEFAULT_BASE_COLOR));
+ if (menuBar() && !menuBar()->isNativeMenuBar())
+ settings->setValue(menubarVisibleKey, menuBar()->isVisible());
+
settings->endGroup();
DocumentManager::saveSettings();