Add option for shortcut visibility in context menus

Fixes: QTCREATORBUG-22502
Change-Id: I49587a6a8b575a3a1453104a829cd91ad3566d7e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Eike Ziller
2019-09-09 16:50:16 +02:00
parent f0a3779513
commit b34102ceea
4 changed files with 75 additions and 54 deletions

View File

@@ -37,6 +37,7 @@
#include <QLibraryInfo>
#include <QMessageBox>
#include <QSettings>
#include <QStyleHints>
#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

View File

@@ -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<QMessageBox> m_dialog;
QPointer<QWidget> m_widget;
bool m_defaultShowShortcutsInContextMenu;
};
} // namespace Internal

View File

@@ -16,21 +16,7 @@
<property name="title">
<string>User Interface</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="colorLabel">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="languageLabel">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="themeLabel">
<property name="text">
@@ -38,6 +24,9 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Core::Internal::ThemeChooser" name="themeChooser" native="true"/>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -84,16 +73,6 @@
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="resetWarningsButton">
<property name="toolTip">
<string>Re-enable warnings that were suppressed by selecting &quot;Do Not Show Again&quot; (for example, missing highlighter).</string>
</property>
<property name="text">
<string comment="Button text">Reset Warnings</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
@@ -121,37 +100,41 @@
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="Core::Internal::ThemeChooser" name="themeChooser" native="true"/>
<item row="0" column="0">
<widget class="QLabel" name="colorLabel">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="resetWarningsButton">
<property name="toolTip">
<string>Re-enable warnings that were suppressed by selecting &quot;Do Not Show Again&quot; (for example, missing highlighter).</string>
</property>
<property name="text">
<string comment="Button text">Reset Warnings</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="languageLabel">
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="dpiCheckbox">
<property name="text">
<string>Enable high DPI scaling</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>285</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="dpiLabel">
<widget class="QCheckBox" name="dpiCheckbox">
<property name="text">
<string>High DPI scaling:</string>
<string>Enable high DPI scaling</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="showShortcutsInContextMenus">
<property name="text">
<string/>
</property>
</widget>
</item>

View File

@@ -149,6 +149,8 @@ MainWindow::MainWindow()
}
QApplication::setStyle(new ManhattanStyle(baseName));
m_generalSettings->setShowShortcutsInContextMenu(
m_generalSettings->showShortcutsInContextMenu());
setDockNestingEnabled(true);