diff --git a/settingsdialog/optioncategory.h b/settingsdialog/optioncategory.h index f10a9d6..6472aa8 100644 --- a/settingsdialog/optioncategory.h +++ b/settingsdialog/optioncategory.h @@ -31,6 +31,7 @@ public: void setIcon(const QIcon &icon); const QList &pages() const; void assignPages(const QList &pages); + template PageType *page(); bool applyAllPages(); void resetAllPages(); bool matches(const QString &searchKeyWord) const; @@ -89,6 +90,19 @@ inline const QList &OptionCategory::pages() const return m_pages; } +/*! + * \brief Returns the first page with the specified \tp PageType or nullptr if there is no such page. + */ +template PageType *OptionCategory::page() +{ + for (auto *const genericPage : m_pages) { + if (const auto *const page = qobject_cast(genericPage)) { + return page; + } + } + return nullptr; +} + /*! * \brief Returns the index of the currently shown page. * \remarks The returned index might be invalid/out of range. diff --git a/settingsdialog/qtsettings.cpp b/settingsdialog/qtsettings.cpp index 46438c3..7455bd4 100644 --- a/settingsdialog/qtsettings.cpp +++ b/settingsdialog/qtsettings.cpp @@ -29,38 +29,35 @@ using namespace std; namespace QtUtilities { +#if defined(Q_OS_WINDOWS) || defined(Q_OS_DARWIN) +#define QT_UTILITIES_CAN_ENFORCE_FREETYPE 1 +#endif +#if defined(Q_OS_WINDOWS) +#define QT_UTILITIES_CAN_ENABLE_DARKMODE 1 +#endif + struct QtSettingsData { - QtSettingsData(); + QtSettingsData() = default; QFont font; QPalette palette; QString widgetStyle; QString styleSheetPath; - QString iconTheme; + QString iconTheme = QIcon::themeName(); QLocale defaultLocale; - QString localeName; + QString localeName = defaultLocale.name(); QString additionalPluginDirectory; QString additionalIconThemeSearchPath; - bool customFont; - bool customPalette; - bool customWidgetStyle; - bool customStyleSheet; - bool customIconTheme; - bool customLocale; + QString fontEngine; + bool customFont = false; + bool customPalette = false; + bool customWidgetStyle = false; + bool customStyleSheet = false; + bool customIconTheme = false; + bool customLocale = false; + bool enableDarkmode = false; }; -inline QtSettingsData::QtSettingsData() - : iconTheme(QIcon::themeName()) - , localeName(defaultLocale.name()) - , customFont(false) - , customPalette(false) - , customWidgetStyle(false) - , customStyleSheet(false) - , customIconTheme(false) - , customLocale(false) -{ -} - /*! * \brief Creates a new settings object. * \remarks Settings are not restored automatically. Instead, some values (font, @@ -114,6 +111,8 @@ void QtSettings::restore(QSettings &settings) m_d->additionalPluginDirectory = settings.value(QStringLiteral("plugindir")).toString(); m_d->additionalIconThemeSearchPath = settings.value(QStringLiteral("iconthemepath")).toString(); TranslationFiles::additionalTranslationFilePath() = settings.value(QStringLiteral("trpath")).toString(); + m_d->fontEngine = settings.value(QStringLiteral("fontengine")).toString(); + m_d->enableDarkmode = settings.value(QStringLiteral("enabledarkmode")).toBool(); settings.endGroup(); } @@ -138,17 +137,28 @@ void QtSettings::save(QSettings &settings) const settings.setValue(QStringLiteral("plugindir"), m_d->additionalPluginDirectory); settings.setValue(QStringLiteral("iconthemepath"), m_d->additionalIconThemeSearchPath); settings.setValue(QStringLiteral("trpath"), QVariant(TranslationFiles::additionalTranslationFilePath())); + settings.setValue(QStringLiteral("enforcefreetype"), m_d->fontEngine); + settings.setValue(QStringLiteral("enabledarkmode"), m_d->enableDarkmode); settings.endGroup(); } /*! - * \brief Applies the current configuration. + * \brief Applies values from the current configuration which need to be set before the platform plugin has been + * instantiated. + */ +void QtSettings::applyPlatformSettings() +{ + +} + +/*! + * \brief Applies the current configuration except values which need to be set before the platform plugin has been + * instantiated. * \remarks * - Some settings take only affect after restarting the application. * - QApplication/QGuiApplication must be instantiated before calling this - * method. - * - Hence it makes most sense to call this directly after instantiating - * QApplication/QGuiApplication. + * method. Hence it makes most sense to call this directly after instantiating + * QApplication/QGuiApplication. */ void QtSettings::apply() { @@ -205,8 +215,7 @@ void QtSettings::apply() * - The QtSettings instance does not keep the ownership over the returned * category. * - The pages of the returned category require the QtSetings instance which - * hence - * must be present as long as all pages are destroyed. + * hence must be present until all pages are destroyed. */ OptionCategory *QtSettings::category() { diff --git a/settingsdialog/qtsettings.h b/settingsdialog/qtsettings.h index 2c6dbf6..f6b1584 100644 --- a/settingsdialog/qtsettings.h +++ b/settingsdialog/qtsettings.h @@ -15,8 +15,12 @@ struct QtSettingsData; BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(QtAppearanceOptionPage) public: +enum PresetFlags { Dark }; explicit QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr); +Q_SIGNALS: +void presetsApplied(PresetFlags flags); + private: DECLARE_SETUP_WIDGETS QtSettingsData &m_settings; @@ -47,6 +51,7 @@ public: void restore(QSettings &settings); void save(QSettings &settings) const; + void applyPlatformSettings(); void apply(); bool hasCustomFont() const;