Fix system theme detection

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2024-08-24 22:50:51 +01:00
parent fac28a81ae
commit cbdacf81ee
No known key found for this signature in database
GPG Key ID: 5E39D70B4C93C38E
4 changed files with 16 additions and 13 deletions

View File

@ -40,11 +40,11 @@
#include "HintOverrideProxyStyle.h"
#include "ThemeManager.h"
SystemTheme::SystemTheme(QString& styleName, bool isSystemTheme)
SystemTheme::SystemTheme(const QString& styleName, const QPalette& palette, bool isDefaultTheme)
{
themeName = isSystemTheme ? "system" : styleName;
themeName = isDefaultTheme ? "system" : styleName;
widgetTheme = styleName;
colorPalette = QApplication::palette();
colorPalette = palette;
}
void SystemTheme::apply(bool initial)

View File

@ -38,7 +38,7 @@
class SystemTheme : public ITheme {
public:
SystemTheme(QString& themeName, bool isSystemTheme = false);
SystemTheme(const QString& styleName, const QPalette& palette, bool isDefaultTheme);
virtual ~SystemTheme() {}
void apply(bool initial) override;

View File

@ -36,6 +36,13 @@
ThemeManager::ThemeManager()
{
themeDebugLog() << "Determining System Widget Theme...";
const auto& style = QApplication::style();
m_defaultStyle = style->objectName();
themeDebugLog() << "System theme seems to be:" << m_defaultStyle;
m_defaultPalette = QApplication::palette();
initializeThemes();
initializeCatPacks();
}
@ -121,13 +128,8 @@ void ThemeManager::initializeIcons()
void ThemeManager::initializeWidgets()
{
themeDebugLog() << "Determining System Widget Theme...";
const auto& style = QApplication::style();
m_currentlySelectedSystemTheme = style->objectName();
themeDebugLog() << "System theme seems to be:" << m_currentlySelectedSystemTheme;
themeDebugLog() << "<> Initializing Widget Themes";
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>(m_currentlySelectedSystemTheme, true));
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>(m_defaultStyle, m_defaultPalette, true));
auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
@ -140,7 +142,7 @@ void ThemeManager::initializeWidgets()
continue;
}
#endif
themeDebugLog() << "Loading System Theme:" << addTheme(std::make_unique<SystemTheme>(st));
themeDebugLog() << "Loading System Theme:" << addTheme(std::make_unique<SystemTheme>(st, m_defaultPalette, false));
}
// TODO: need some way to differentiate same name themes in different subdirectories
@ -260,7 +262,7 @@ void ThemeManager::applyCurrentlySelectedTheme(bool initial)
themeDebugLog() << "<> Icon theme set.";
auto applicationTheme = settings->get("ApplicationTheme").toString();
if (applicationTheme == "") {
applicationTheme = m_currentlySelectedSystemTheme;
applicationTheme = m_defaultStyle;
}
setApplicationTheme(applicationTheme, initial);
themeDebugLog() << "<> Application theme set.";

View File

@ -66,7 +66,8 @@ class ThemeManager {
QDir m_applicationThemeFolder{ "themes" };
QDir m_catPacksFolder{ "catpacks" };
std::map<QString, std::unique_ptr<CatPack>> m_catPacks;
QString m_currentlySelectedSystemTheme;
QString m_defaultStyle;
QPalette m_defaultPalette;
LogColors m_logColors;
void initializeThemes();