Add function to re-evaluate the palette and default icon theme
This commit is contained in:
parent
5430edc5fc
commit
bbb65ae0dd
|
@ -49,6 +49,7 @@ struct QtSettingsData {
|
||||||
bool customStyleSheet;
|
bool customStyleSheet;
|
||||||
bool customIconTheme;
|
bool customIconTheme;
|
||||||
bool customLocale;
|
bool customLocale;
|
||||||
|
bool isPaletteDark;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QtSettingsData::QtSettingsData()
|
inline QtSettingsData::QtSettingsData()
|
||||||
|
@ -60,6 +61,7 @@ inline QtSettingsData::QtSettingsData()
|
||||||
, customStyleSheet(false)
|
, customStyleSheet(false)
|
||||||
, customIconTheme(false)
|
, customIconTheme(false)
|
||||||
, customLocale(false)
|
, customLocale(false)
|
||||||
|
, isPaletteDark(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,6 +229,7 @@ void QtSettings::apply()
|
||||||
if (m_d->customPalette) {
|
if (m_d->customPalette) {
|
||||||
QGuiApplication::setPalette(m_d->palette);
|
QGuiApplication::setPalette(m_d->palette);
|
||||||
}
|
}
|
||||||
|
m_d->isPaletteDark = isPaletteDark();
|
||||||
if (m_d->customIconTheme) {
|
if (m_d->customIconTheme) {
|
||||||
QIcon::setThemeName(m_d->iconTheme);
|
QIcon::setThemeName(m_d->iconTheme);
|
||||||
} else if (QIcon::themeName().isEmpty()) {
|
} else if (QIcon::themeName().isEmpty()) {
|
||||||
|
@ -237,7 +240,7 @@ void QtSettings::apply()
|
||||||
// icon theme available as "default" and the first dark icon theme available as "default-dark". An icon theme
|
// icon theme available as "default" and the first dark icon theme available as "default-dark". An icon theme
|
||||||
// is considered dark if it ends with "-dark".
|
// is considered dark if it ends with "-dark".
|
||||||
const auto bundledIconThemes = scanIconThemes(QStringList(QStringLiteral(":/icons")));
|
const auto bundledIconThemes = scanIconThemes(QStringList(QStringLiteral(":/icons")));
|
||||||
if (isPaletteDark() && bundledIconThemes.contains(QStringLiteral("default-dark"))) {
|
if (m_d->isPaletteDark && bundledIconThemes.contains(QStringLiteral("default-dark"))) {
|
||||||
QIcon::setThemeName(QStringLiteral("default-dark"));
|
QIcon::setThemeName(QStringLiteral("default-dark"));
|
||||||
} else if (bundledIconThemes.contains(QStringLiteral("default"))) {
|
} else if (bundledIconThemes.contains(QStringLiteral("default"))) {
|
||||||
QIcon::setThemeName(QStringLiteral("default"));
|
QIcon::setThemeName(QStringLiteral("default"));
|
||||||
|
@ -248,6 +251,39 @@ void QtSettings::apply()
|
||||||
QLocale::setDefault(m_d->customLocale ? QLocale(m_d->localeName) : m_d->defaultLocale);
|
QLocale::setDefault(m_d->customLocale ? QLocale(m_d->localeName) : m_d->defaultLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Re-evaluates whether the palette is dark and re-applies default icon theme.
|
||||||
|
*
|
||||||
|
* Re-assigns the appropriate default icon theme depending on the current palette. Call this function after the palette
|
||||||
|
* has changed.
|
||||||
|
*
|
||||||
|
* \remarks
|
||||||
|
* - The default icon theme must have been assigned before using the apply() function.
|
||||||
|
* - This function has no effect if a custom icon theme is configured.
|
||||||
|
*/
|
||||||
|
void QtSettings::reevaluatePaletteAndDefaultIconTheme()
|
||||||
|
{
|
||||||
|
const auto isPaletteDark = QtUtilities::isPaletteDark();
|
||||||
|
if (isPaletteDark == m_d->isPaletteDark) {
|
||||||
|
return; // no need to do anything if there's no change
|
||||||
|
}
|
||||||
|
m_d->isPaletteDark = isPaletteDark;
|
||||||
|
if (auto iconTheme = QIcon::themeName(); iconTheme == QStringLiteral("default") || iconTheme == QStringLiteral("default-dark")) {
|
||||||
|
QIcon::setThemeName(m_d->isPaletteDark ? QStringLiteral("default-dark") : QStringLiteral("default"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns whether the palette is dark.
|
||||||
|
* \remarks
|
||||||
|
* Changes to the palette since the last call to apply() and reevaluatePaletteAndDefaultIconTheme() are not taken
|
||||||
|
* into account.
|
||||||
|
*/
|
||||||
|
bool QtSettings::isPaletteDark()
|
||||||
|
{
|
||||||
|
return m_d->isPaletteDark;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns a new OptionCatecory containing all Qt related option pages.
|
* \brief Returns a new OptionCatecory containing all Qt related option pages.
|
||||||
* \remarks
|
* \remarks
|
||||||
|
|
|
@ -48,6 +48,8 @@ public:
|
||||||
void restore(QSettings &settings);
|
void restore(QSettings &settings);
|
||||||
void save(QSettings &settings) const;
|
void save(QSettings &settings) const;
|
||||||
void apply();
|
void apply();
|
||||||
|
void reevaluatePaletteAndDefaultIconTheme();
|
||||||
|
bool isPaletteDark();
|
||||||
bool hasCustomFont() const;
|
bool hasCustomFont() const;
|
||||||
|
|
||||||
OptionCategory *category();
|
OptionCategory *category();
|
||||||
|
|
Loading…
Reference in New Issue