Add option to always show menu bar instead of toolbar

For those who like keyboard navigation at the expense of aesthetics.
This commit is contained in:
Kenneth Chew 2022-04-15 18:25:37 -04:00
parent f6605bc3f8
commit 1303771b58
No known key found for this signature in database
GPG Key ID: F17D3E14A07739DA
5 changed files with 51 additions and 11 deletions

View File

@ -613,6 +613,8 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// Remembered state
m_settings->registerSetting("LastUsedGroupForNewInstance", QString());
m_settings->registerSetting("MenuBarInsteadOfToolBar", false);
QString defaultMonospace;
int defaultSize = 11;
#ifdef Q_OS_WIN32

View File

@ -309,6 +309,7 @@ public:
void createMainToolbar(QMainWindow *MainWindow)
{
mainToolBar = TranslatedToolbar(MainWindow);
mainToolBar->setVisible(menuBar->isNativeMenuBar() || !APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool());
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
mainToolBar->setMovable(true);
mainToolBar->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
@ -471,8 +472,7 @@ public:
void createMenuBar(MainWindow *MainWindow)
{
menuBar = new QMenuBar(MainWindow);
// There's already a toolbar, so hide this menu bar by default unless 'alt' is pressed on systems without native menu bar
menuBar->setVisible(false);
menuBar->setVisible(APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool());
createMenuActions(MainWindow);
// TODO: only enable options while an instance is selected (if applicable)
@ -909,10 +909,10 @@ public:
MainWindow->setAccessibleName(BuildConfig.LAUNCHER_NAME);
#endif
createMainToolbar(MainWindow);
createMenuBar(dynamic_cast<class MainWindow *>(MainWindow));
createMainToolbar(MainWindow);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
horizontalLayout = new QHBoxLayout(centralWidget);
@ -1135,7 +1135,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
#ifndef Q_OS_MAC
void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
if(event->key()==Qt::Key_Alt)
if(event->key()==Qt::Key_Alt && !APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool())
ui->menuBar->setVisible(!ui->menuBar->isVisible());
else
QMainWindow::keyReleaseEvent(event);
@ -1294,6 +1294,12 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
myMenu.exec(view->mapToGlobal(pos));
}
void MainWindow::updateMainToolBar()
{
ui->menuBar->setVisible(APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool());
ui->mainToolBar->setVisible(ui->menuBar->isNativeMenuBar() || !APPLICATION->settings()->get("MenuBarInsteadOfToolBar").toBool());
}
void MainWindow::updateToolsMenu()
{
QToolButton *launchButton = dynamic_cast<QToolButton*>(ui->instanceToolBar->widgetForAction(ui->actionLaunchInstance));
@ -1966,6 +1972,7 @@ void MainWindow::globalSettingsClosed()
APPLICATION->instances()->loadList();
proxymodel->invalidate();
proxymodel->sort(0);
updateMainToolBar();
updateToolsMenu();
updateStatusCenter();
update();

View File

@ -151,6 +151,8 @@ private slots:
void showInstanceContextMenu(const QPoint &);
void updateMainToolBar();
void updateToolsMenu();
void instanceActivated(QModelIndex);

View File

@ -41,6 +41,7 @@
#include <QMessageBox>
#include <QDir>
#include <QTextCharFormat>
#include <QMenuBar>
#include "updater/UpdateChecker.h"
@ -322,6 +323,8 @@ void LauncherPage::applySettings()
APPLICATION->setApplicationTheme(newAppTheme, false);
}
s->set("MenuBarInsteadOfToolBar", ui->preferMenuBarCheckBox->isChecked());
// Console settings
s->set("ShowConsole", ui->showConsoleCheck->isChecked());
s->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
@ -410,6 +413,10 @@ void LauncherPage::loadSettings()
}
}
// Toolbar/menu bar settings (not applicable if native menu bar is present)
ui->toolsBox->setVisible(!QMenuBar().isNativeMenuBar());
ui->preferMenuBarCheckBox->setChecked(s->get("MenuBarInsteadOfToolBar").toBool());
// Console settings
ui->showConsoleCheck->setChecked(s->get("ShowConsole").toBool());
ui->autoCloseConsoleCheck->setChecked(s->get("AutoCloseConsole").toBool());

View File

@ -290,6 +290,16 @@
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Colors</string>
</property>
<property name="buddy">
<cstring>themeComboBoxColors</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="themeComboBoxColors">
<property name="sizePolicy">
@ -303,13 +313,25 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="toolsBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Tools</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="preferMenuBarCheckBox">
<property name="text">
<string>Colors</string>
</property>
<property name="buddy">
<cstring>themeComboBoxColors</cstring>
<string>Always show menu bar instead of tool bar (more keyboard friendly, less pretty)</string>
</property>
</widget>
</item>