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 <coreplugin/dialogs/restartdialog.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <extensionsystem/pluginmanager.h>
@@ -35,18 +36,45 @@
using namespace Utils;
using namespace Layouting;
namespace Core {
namespace Internal {
namespace Core::Internal {
const char settingsKeyDPI[] = "Core/EnableHighDpiScaling";
const char settingsKeyShortcutsInContextMenu[] = "General/ShowShortcutsInContextMenu";
const char settingsKeyCodecForLocale[] = "General/OverrideCodecForLocale";
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
{
public:
explicit GeneralSettingsWidget(GeneralSettings *q);
GeneralSettingsWidget();
void apply() final;
@@ -63,21 +91,17 @@ public:
static void setCodecForLocale(const QByteArray&);
void fillToolbarSyleBox() const;
GeneralSettings *q;
QComboBox *m_languageBox;
QComboBox *m_codecBox;
QCheckBox *m_showShortcutsInContextMenus;
QtColorButton *m_colorButton;
ThemeChooser *m_themeChooser;
QPushButton *m_resetWarningsButton;
QComboBox *m_toolbarStyleBox;
};
GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q)
: q(q)
, m_languageBox(new QComboBox)
GeneralSettingsWidget::GeneralSettingsWidget()
: m_languageBox(new QComboBox)
, m_codecBox(new QComboBox)
, m_showShortcutsInContextMenus(new QCheckBox)
, m_colorButton(new QtColorButton)
, m_themeChooser(new ThemeChooser)
, 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({Tr::tr("Text codec for tools:"), m_codecBox, st});
Column{Group{title(Tr::tr("User Interface")), form}}.attachTo(this);
@@ -135,11 +159,6 @@ GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q)
m_colorButton->setColor(StyleHelper::requestedBaseColor());
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,
&QAbstractButton::clicked,
this,
@@ -191,11 +210,13 @@ void GeneralSettingsWidget::fillLanguageBox() const
void GeneralSettingsWidget::apply()
{
generalSettings().apply();
generalSettings().writeSettings();
int currentIndex = m_languageBox->currentIndex();
setLanguage(m_languageBox->itemData(currentIndex, Qt::UserRole).toString());
currentIndex = m_codecBox->currentIndex();
setCodecForLocale(m_codecBox->itemText(currentIndex).toLocal8Bit());
q->setShowShortcutsInContextMenu(m_showShortcutsInContextMenus->isChecked());
// Apply the new base color if accepted
StyleHelper::setBaseColor(m_colorButton->color());
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()
{
m_colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR);
@@ -305,31 +318,27 @@ void GeneralSettingsWidget::fillToolbarSyleBox() const
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()
{
StyleHelper::setToolbarStyle(toolbarStylefromSettings());
}
GeneralSettings::GeneralSettings()
// GeneralSettingsPage
class GeneralSettingsPage final : public IOptionsPage
{
public:
GeneralSettingsPage()
{
setId(Constants::SETTINGS_ID_INTERFACE);
setDisplayName(Tr::tr("Interface"));
setCategory(Constants::SETTINGS_CATEGORY_CORE);
setDisplayCategory(Tr::tr("Environment"));
setCategoryIconPath(":/core/images/settingscategory_core.png");
setWidgetCreator([this] { return new GeneralSettingsWidget(this); });
setWidgetCreator([] { return new GeneralSettingsWidget; });
}
};
m_defaultShowShortcutsInContextMenu = QGuiApplication::styleHints()
->showShortcutsInContextMenus();
}
const GeneralSettingsPage settingsPage;
} // namespace Internal
} // namespace Core
} // Core::Internal

View File

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

View File

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

View File

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