Compare commits

...

1 Commits

3 changed files with 55 additions and 27 deletions

View File

@ -31,6 +31,7 @@ public:
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
const QList<OptionPage *> &pages() const; const QList<OptionPage *> &pages() const;
void assignPages(const QList<OptionPage *> &pages); void assignPages(const QList<OptionPage *> &pages);
template<typename PageType> PageType *page();
bool applyAllPages(); bool applyAllPages();
void resetAllPages(); void resetAllPages();
bool matches(const QString &searchKeyWord) const; bool matches(const QString &searchKeyWord) const;
@ -89,6 +90,19 @@ inline const QList<OptionPage *> &OptionCategory::pages() const
return m_pages; return m_pages;
} }
/*!
* \brief Returns the first page with the specified \tp PageType or nullptr if there is no such page.
*/
template<typename PageType> PageType *OptionCategory::page()
{
for (auto *const genericPage : m_pages) {
if (const auto *const page = qobject_cast<PageType *>(genericPage)) {
return page;
}
}
return nullptr;
}
/*! /*!
* \brief Returns the index of the currently shown page. * \brief Returns the index of the currently shown page.
* \remarks The returned index might be invalid/out of range. * \remarks The returned index might be invalid/out of range.

View File

@ -29,38 +29,35 @@ using namespace std;
namespace QtUtilities { 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 { struct QtSettingsData {
QtSettingsData(); QtSettingsData() = default;
QFont font; QFont font;
QPalette palette; QPalette palette;
QString widgetStyle; QString widgetStyle;
QString styleSheetPath; QString styleSheetPath;
QString iconTheme; QString iconTheme = QIcon::themeName();
QLocale defaultLocale; QLocale defaultLocale;
QString localeName; QString localeName = defaultLocale.name();
QString additionalPluginDirectory; QString additionalPluginDirectory;
QString additionalIconThemeSearchPath; QString additionalIconThemeSearchPath;
bool customFont; QString fontEngine;
bool customPalette; bool customFont = false;
bool customWidgetStyle; bool customPalette = false;
bool customStyleSheet; bool customWidgetStyle = false;
bool customIconTheme; bool customStyleSheet = false;
bool customLocale; 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. * \brief Creates a new settings object.
* \remarks Settings are not restored automatically. Instead, some values (font, * \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->additionalPluginDirectory = settings.value(QStringLiteral("plugindir")).toString();
m_d->additionalIconThemeSearchPath = settings.value(QStringLiteral("iconthemepath")).toString(); m_d->additionalIconThemeSearchPath = settings.value(QStringLiteral("iconthemepath")).toString();
TranslationFiles::additionalTranslationFilePath() = settings.value(QStringLiteral("trpath")).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(); settings.endGroup();
} }
@ -138,17 +137,28 @@ void QtSettings::save(QSettings &settings) const
settings.setValue(QStringLiteral("plugindir"), m_d->additionalPluginDirectory); settings.setValue(QStringLiteral("plugindir"), m_d->additionalPluginDirectory);
settings.setValue(QStringLiteral("iconthemepath"), m_d->additionalIconThemeSearchPath); settings.setValue(QStringLiteral("iconthemepath"), m_d->additionalIconThemeSearchPath);
settings.setValue(QStringLiteral("trpath"), QVariant(TranslationFiles::additionalTranslationFilePath())); settings.setValue(QStringLiteral("trpath"), QVariant(TranslationFiles::additionalTranslationFilePath()));
settings.setValue(QStringLiteral("enforcefreetype"), m_d->fontEngine);
settings.setValue(QStringLiteral("enabledarkmode"), m_d->enableDarkmode);
settings.endGroup(); 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 * \remarks
* - Some settings take only affect after restarting the application. * - Some settings take only affect after restarting the application.
* - QApplication/QGuiApplication must be instantiated before calling this * - QApplication/QGuiApplication must be instantiated before calling this
* method. * method. Hence it makes most sense to call this directly after instantiating
* - Hence it makes most sense to call this directly after instantiating * QApplication/QGuiApplication.
* QApplication/QGuiApplication.
*/ */
void QtSettings::apply() void QtSettings::apply()
{ {
@ -205,8 +215,7 @@ void QtSettings::apply()
* - The QtSettings instance does not keep the ownership over the returned * - The QtSettings instance does not keep the ownership over the returned
* category. * category.
* - The pages of the returned category require the QtSetings instance which * - The pages of the returned category require the QtSetings instance which
* hence * hence must be present until all pages are destroyed.
* must be present as long as all pages are destroyed.
*/ */
OptionCategory *QtSettings::category() OptionCategory *QtSettings::category()
{ {

View File

@ -15,8 +15,12 @@ struct QtSettingsData;
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(QtAppearanceOptionPage) BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(QtAppearanceOptionPage)
public: public:
enum PresetFlags { Dark };
explicit QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr); explicit QtAppearanceOptionPage(QtSettingsData &settings, QWidget *parentWidget = nullptr);
Q_SIGNALS:
void presetsApplied(PresetFlags flags);
private: private:
DECLARE_SETUP_WIDGETS DECLARE_SETUP_WIDGETS
QtSettingsData &m_settings; QtSettingsData &m_settings;
@ -47,6 +51,7 @@ public:
void restore(QSettings &settings); void restore(QSettings &settings);
void save(QSettings &settings) const; void save(QSettings &settings) const;
void applyPlatformSettings();
void apply(); void apply();
bool hasCustomFont() const; bool hasCustomFont() const;