diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index 27788d57117..f0db3135e93 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "ui_generalsettings.h" @@ -46,6 +47,7 @@ namespace Core { namespace Internal { const char settingsKeyDPI[] = "Core/EnableHighDpiScaling"; +const char settingsKeyShortcutsInContextMenu[] = "General/ShowShortcutsInContextMenu"; GeneralSettings::GeneralSettings() : m_page(nullptr), m_dialog(nullptr) @@ -56,6 +58,8 @@ GeneralSettings::GeneralSettings() setDisplayCategory(QCoreApplication::translate("Core", "Environment")); setCategoryIcon(Utils::Icon({{":/core/images/settingscategory_core.png", Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint)); + m_defaultShowShortcutsInContextMenu = QGuiApplication::styleHints() + ->showShortcutsInContextMenus(); } static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrPath) @@ -107,8 +111,15 @@ QWidget *GeneralSettings::widget() m_page->colorButton->setColor(StyleHelper::requestedBaseColor()); m_page->resetWarningsButton->setEnabled(canResetWarnings()); + m_page->showShortcutsInContextMenus->setText( + tr("Show keyboard shortcuts in context menus (default: %1)") + .arg(QLatin1String(m_defaultShowShortcutsInContextMenu ? "on" : "off"))); + m_page->showShortcutsInContextMenus->setChecked(showShortcutsInContextMenu()); +#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0)) + m_page->showShortcutsInContextMenus->setVisible(false); +#endif + if (Utils::HostOsInfo().isMacHost()) { - m_page->dpiLabel->setVisible(false); m_page->dpiCheckbox->setVisible(false); } else { const bool defaultValue = Utils::HostOsInfo().isWindowsHost(); @@ -134,6 +145,7 @@ void GeneralSettings::apply() return; int currentIndex = m_page->languageBox->currentIndex(); setLanguage(m_page->languageBox->itemData(currentIndex, Qt::UserRole).toString()); + setShowShortcutsInContextMenu(m_page->showShortcutsInContextMenus->isChecked()); // Apply the new base color if accepted StyleHelper::setBaseColor(m_page->colorButton->color()); m_page->themeChooser->apply(); @@ -146,6 +158,14 @@ void GeneralSettings::finish() m_page = nullptr; } +bool GeneralSettings::showShortcutsInContextMenu() const +{ + return ICore::settings() + ->value(settingsKeyShortcutsInContextMenu, + QGuiApplication::styleHints()->showShortcutsInContextMenus()) + .toBool(); +} + void GeneralSettings::resetInterfaceColor() { m_page->colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR); @@ -189,5 +209,16 @@ void GeneralSettings::setLanguage(const QString &locale) settings->setValue(QLatin1String("General/OverrideLanguage"), locale); } +void GeneralSettings::setShowShortcutsInContextMenu(bool show) +{ + if (show == m_defaultShowShortcutsInContextMenu) + ICore::settings()->remove(settingsKeyShortcutsInContextMenu); + else + ICore::settings()->setValue(settingsKeyShortcutsInContextMenu, show); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)) + QGuiApplication::styleHints()->setShowShortcutsInContextMenus(show); +#endif +} + } // namespace Internal } // namespace Core diff --git a/src/plugins/coreplugin/generalsettings.h b/src/plugins/coreplugin/generalsettings.h index ed0f1775328..bdd6597755c 100644 --- a/src/plugins/coreplugin/generalsettings.h +++ b/src/plugins/coreplugin/generalsettings.h @@ -48,6 +48,9 @@ public: void apply() override; void finish() override; + bool showShortcutsInContextMenu() const; + void setShowShortcutsInContextMenu(bool show); + private: void resetInterfaceColor(); void resetWarnings(); @@ -57,9 +60,11 @@ private: void fillLanguageBox() const; QString language() const; void setLanguage(const QString&); + Ui::GeneralSettings *m_page; QPointer m_dialog; QPointer m_widget; + bool m_defaultShowShortcutsInContextMenu; }; } // namespace Internal diff --git a/src/plugins/coreplugin/generalsettings.ui b/src/plugins/coreplugin/generalsettings.ui index 0302314d645..93edf245369 100644 --- a/src/plugins/coreplugin/generalsettings.ui +++ b/src/plugins/coreplugin/generalsettings.ui @@ -16,21 +16,7 @@ User Interface - - - - - Color: - - - - - - - Language: - - - + @@ -38,6 +24,9 @@ + + + @@ -84,16 +73,6 @@ - - - - Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter). - - - Reset Warnings - - - @@ -121,37 +100,41 @@ - - + + + + Color: + + + + + + + Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter). + + + Reset Warnings + + + + + + + Language: + + - - - - - Enable high DPI scaling - - - - - - - Qt::Horizontal - - - - 285 - 20 - - - - - - - - + - High DPI scaling: + Enable high DPI scaling + + + + + + + diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index c55411d5ec0..732f4858242 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -149,6 +149,8 @@ MainWindow::MainWindow() } QApplication::setStyle(new ManhattanStyle(baseName)); + m_generalSettings->setShowShortcutsInContextMenu( + m_generalSettings->showShortcutsInContextMenu()); setDockNestingEnabled(true);