Core: Move GeneralSettings setup structure closer to new normal

Change-Id: I3ffbe1b28971912510582a174bf37a0e3f9d4ff4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-07-26 17:52:12 +02:00
parent 424898873d
commit fa2124f037
4 changed files with 61 additions and 64 deletions

View File

@@ -8,6 +8,7 @@
#include "themechooser.h" #include "themechooser.h"
#include <coreplugin/dialogs/restartdialog.h> #include <coreplugin/dialogs/restartdialog.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
@@ -35,18 +36,45 @@
using namespace Utils; using namespace Utils;
using namespace Layouting; using namespace Layouting;
namespace Core { namespace Core::Internal {
namespace Internal {
const char settingsKeyDPI[] = "Core/EnableHighDpiScaling"; const char settingsKeyDPI[] = "Core/EnableHighDpiScaling";
const char settingsKeyShortcutsInContextMenu[] = "General/ShowShortcutsInContextMenu";
const char settingsKeyCodecForLocale[] = "General/OverrideCodecForLocale"; const char settingsKeyCodecForLocale[] = "General/OverrideCodecForLocale";
const char settingsKeyToolbarStyle[] = "General/ToolbarStyle"; const char settingsKeyToolbarStyle[] = "General/ToolbarStyle";
static bool defaultShowShortcutsInContextMenu()
{
return QGuiApplication::styleHints()->showShortcutsInContextMenus();
}
GeneralSettings &generalSettings()
{
static GeneralSettings theSettings;
return theSettings;
}
GeneralSettings::GeneralSettings()
{
setAutoApply(false);
showShortcutsInContextMenus.setSettingsKey("General/ShowShortcutsInContextMenu");
showShortcutsInContextMenus.setDefaultValue(defaultShowShortcutsInContextMenu());
showShortcutsInContextMenus.setLabelText(
Tr::tr("Show keyboard shortcuts in context menus (default: %1)")
.arg(defaultShowShortcutsInContextMenu() ? Tr::tr("on") : Tr::tr("off")));
connect(&showShortcutsInContextMenus, &BaseAspect::changed, this, [this] {
QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus,
!showShortcutsInContextMenus());
});
readSettings();
}
class GeneralSettingsWidget final : public IOptionsPageWidget class GeneralSettingsWidget final : public IOptionsPageWidget
{ {
public: public:
explicit GeneralSettingsWidget(GeneralSettings *q); GeneralSettingsWidget();
void apply() final; void apply() final;
@@ -63,21 +91,17 @@ public:
static void setCodecForLocale(const QByteArray&); static void setCodecForLocale(const QByteArray&);
void fillToolbarSyleBox() const; void fillToolbarSyleBox() const;
GeneralSettings *q;
QComboBox *m_languageBox; QComboBox *m_languageBox;
QComboBox *m_codecBox; QComboBox *m_codecBox;
QCheckBox *m_showShortcutsInContextMenus;
QtColorButton *m_colorButton; QtColorButton *m_colorButton;
ThemeChooser *m_themeChooser; ThemeChooser *m_themeChooser;
QPushButton *m_resetWarningsButton; QPushButton *m_resetWarningsButton;
QComboBox *m_toolbarStyleBox; QComboBox *m_toolbarStyleBox;
}; };
GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q) GeneralSettingsWidget::GeneralSettingsWidget()
: q(q) : m_languageBox(new QComboBox)
, m_languageBox(new QComboBox)
, m_codecBox(new QComboBox) , m_codecBox(new QComboBox)
, m_showShortcutsInContextMenus(new QCheckBox)
, m_colorButton(new QtColorButton) , m_colorButton(new QtColorButton)
, m_themeChooser(new ThemeChooser) , m_themeChooser(new ThemeChooser)
, m_resetWarningsButton(new QPushButton) , m_resetWarningsButton(new QPushButton)
@@ -123,7 +147,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q)
}); });
} }
form.addRow({empty, m_showShortcutsInContextMenus}); form.addRow({empty, generalSettings().showShortcutsInContextMenus});
form.addRow({Row{m_resetWarningsButton, st}}); form.addRow({Row{m_resetWarningsButton, st}});
form.addRow({Tr::tr("Text codec for tools:"), m_codecBox, st}); form.addRow({Tr::tr("Text codec for tools:"), m_codecBox, st});
Column{Group{title(Tr::tr("User Interface")), form}}.attachTo(this); Column{Group{title(Tr::tr("User Interface")), form}}.attachTo(this);
@@ -135,11 +159,6 @@ GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q)
m_colorButton->setColor(StyleHelper::requestedBaseColor()); m_colorButton->setColor(StyleHelper::requestedBaseColor());
m_resetWarningsButton->setEnabled(canResetWarnings()); m_resetWarningsButton->setEnabled(canResetWarnings());
m_showShortcutsInContextMenus->setText(
Tr::tr("Show keyboard shortcuts in context menus (default: %1)")
.arg(q->m_defaultShowShortcutsInContextMenu ? Tr::tr("on") : Tr::tr("off")));
m_showShortcutsInContextMenus->setChecked(GeneralSettings::showShortcutsInContextMenu());
connect(resetColorButton, connect(resetColorButton,
&QAbstractButton::clicked, &QAbstractButton::clicked,
this, this,
@@ -191,11 +210,13 @@ void GeneralSettingsWidget::fillLanguageBox() const
void GeneralSettingsWidget::apply() void GeneralSettingsWidget::apply()
{ {
generalSettings().apply();
generalSettings().writeSettings();
int currentIndex = m_languageBox->currentIndex(); int currentIndex = m_languageBox->currentIndex();
setLanguage(m_languageBox->itemData(currentIndex, Qt::UserRole).toString()); setLanguage(m_languageBox->itemData(currentIndex, Qt::UserRole).toString());
currentIndex = m_codecBox->currentIndex(); currentIndex = m_codecBox->currentIndex();
setCodecForLocale(m_codecBox->itemText(currentIndex).toLocal8Bit()); setCodecForLocale(m_codecBox->itemText(currentIndex).toLocal8Bit());
q->setShowShortcutsInContextMenu(m_showShortcutsInContextMenus->isChecked());
// Apply the new base color if accepted // Apply the new base color if accepted
StyleHelper::setBaseColor(m_colorButton->color()); StyleHelper::setBaseColor(m_colorButton->color());
m_themeChooser->apply(); m_themeChooser->apply();
@@ -210,14 +231,6 @@ void GeneralSettingsWidget::apply()
} }
} }
bool GeneralSettings::showShortcutsInContextMenu()
{
return ICore::settings()
->value(settingsKeyShortcutsInContextMenu,
QGuiApplication::styleHints()->showShortcutsInContextMenus())
.toBool();
}
void GeneralSettingsWidget::resetInterfaceColor() void GeneralSettingsWidget::resetInterfaceColor()
{ {
m_colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR); m_colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR);
@@ -305,31 +318,27 @@ void GeneralSettingsWidget::fillToolbarSyleBox() const
m_toolbarStyleBox->setCurrentIndex(curId); m_toolbarStyleBox->setCurrentIndex(curId);
} }
void GeneralSettings::setShowShortcutsInContextMenu(bool show)
{
ICore::settings()->setValueWithDefault(settingsKeyShortcutsInContextMenu,
show,
m_defaultShowShortcutsInContextMenu);
QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, !show);
}
void GeneralSettings::applyToolbarStyleFromSettings() void GeneralSettings::applyToolbarStyleFromSettings()
{ {
StyleHelper::setToolbarStyle(toolbarStylefromSettings()); StyleHelper::setToolbarStyle(toolbarStylefromSettings());
} }
GeneralSettings::GeneralSettings() // GeneralSettingsPage
class GeneralSettingsPage final : public IOptionsPage
{
public:
GeneralSettingsPage()
{ {
setId(Constants::SETTINGS_ID_INTERFACE); setId(Constants::SETTINGS_ID_INTERFACE);
setDisplayName(Tr::tr("Interface")); setDisplayName(Tr::tr("Interface"));
setCategory(Constants::SETTINGS_CATEGORY_CORE); setCategory(Constants::SETTINGS_CATEGORY_CORE);
setDisplayCategory(Tr::tr("Environment")); setDisplayCategory(Tr::tr("Environment"));
setCategoryIconPath(":/core/images/settingscategory_core.png"); setCategoryIconPath(":/core/images/settingscategory_core.png");
setWidgetCreator([this] { return new GeneralSettingsWidget(this); }); setWidgetCreator([] { return new GeneralSettingsWidget; });
m_defaultShowShortcutsInContextMenu = QGuiApplication::styleHints()
->showShortcutsInContextMenus();
} }
};
} // namespace Internal const GeneralSettingsPage settingsPage;
} // namespace Core
} // Core::Internal

View File

@@ -3,25 +3,20 @@
#pragma once #pragma once
#include <coreplugin/dialogs/ioptionspage.h> #include <utils/aspects.h>
namespace Core { namespace Core::Internal {
namespace Internal {
class GeneralSettings : public IOptionsPage class GeneralSettings : public Utils::AspectContainer
{ {
public: public:
GeneralSettings(); GeneralSettings();
static bool showShortcutsInContextMenu(); Utils::BoolAspect showShortcutsInContextMenus{this};
void setShowShortcutsInContextMenu(bool show);
static void applyToolbarStyleFromSettings(); static void applyToolbarStyleFromSettings();
private:
friend class GeneralSettingsWidget;
bool m_defaultShowShortcutsInContextMenu;
}; };
} // namespace Internal GeneralSettings &generalSettings();
} // namespace Core
} // Core::Internal

View File

@@ -22,7 +22,6 @@
#include "fileutils.h" #include "fileutils.h"
#include "find/basetextfind.h" #include "find/basetextfind.h"
#include "findplaceholder.h" #include "findplaceholder.h"
#include "generalsettings.h"
#include "helpmanager.h" #include "helpmanager.h"
#include "icore.h" #include "icore.h"
#include "idocumentfactory.h" #include "idocumentfactory.h"
@@ -130,7 +129,6 @@ MainWindow::MainWindow()
, m_jsExpander(JsExpander::createGlobalJsExpander()) , m_jsExpander(JsExpander::createGlobalJsExpander())
, m_vcsManager(new VcsManager) , m_vcsManager(new VcsManager)
, m_modeStack(new FancyTabWidget(this)) , m_modeStack(new FancyTabWidget(this))
, m_generalSettings(new GeneralSettings)
, m_systemSettings(new SystemSettings) , m_systemSettings(new SystemSettings)
, m_shortcutSettings(new ShortcutSettings) , m_shortcutSettings(new ShortcutSettings)
, m_toolSettings(new ToolSettings) , m_toolSettings(new ToolSettings)
@@ -165,8 +163,6 @@ MainWindow::MainWindow()
} }
QApplication::setStyle(new ManhattanStyle(baseName)); QApplication::setStyle(new ManhattanStyle(baseName));
m_generalSettings->setShowShortcutsInContextMenu(
GeneralSettings::showShortcutsInContextMenu());
setDockNestingEnabled(true); setDockNestingEnabled(true);
@@ -279,8 +275,6 @@ MainWindow::~MainWindow()
m_messageManager = nullptr; m_messageManager = nullptr;
delete m_shortcutSettings; delete m_shortcutSettings;
m_shortcutSettings = nullptr; m_shortcutSettings = nullptr;
delete m_generalSettings;
m_generalSettings = nullptr;
delete m_systemSettings; delete m_systemSettings;
m_systemSettings = nullptr; m_systemSettings = nullptr;
delete m_toolSettings; delete m_toolSettings;

View File

@@ -160,7 +160,6 @@ private:
std::unordered_map<QWidget *, IContext *> m_contextWidgets; std::unordered_map<QWidget *, IContext *> m_contextWidgets;
GeneralSettings *m_generalSettings = nullptr;
SystemSettings *m_systemSettings = nullptr; SystemSettings *m_systemSettings = nullptr;
ShortcutSettings *m_shortcutSettings = nullptr; ShortcutSettings *m_shortcutSettings = nullptr;
ToolSettings *m_toolSettings = nullptr; ToolSettings *m_toolSettings = nullptr;