diff options
author | TheKodeToad <TheKodeToad@proton.me> | 2023-07-19 20:57:08 +0100 |
---|---|---|
committer | TheKodeToad <TheKodeToad@proton.me> | 2023-07-19 20:57:08 +0100 |
commit | 960093700a9daa4e2115d4663ab486a5dd1a4757 (patch) | |
tree | 0d943e8a26655da5fe81a9ef2671db4b23fb38c7 /launcher/ui/themes | |
parent | 54d393632d5c964f0c30ca9bc816853b92552c9c (diff) | |
download | PrismLauncher-960093700a9daa4e2115d4663ab486a5dd1a4757.tar.gz PrismLauncher-960093700a9daa4e2115d4663ab486a5dd1a4757.tar.bz2 PrismLauncher-960093700a9daa4e2115d4663ab486a5dd1a4757.zip |
Better theme reset
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Diffstat (limited to 'launcher/ui/themes')
-rw-r--r-- | launcher/ui/themes/ThemeManager.cpp | 46 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.h | 9 |
2 files changed, 28 insertions, 27 deletions
diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 525201be..a9fae589 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -29,9 +29,8 @@ #include "Application.h" -ThemeManager::ThemeManager(MainWindow* mainWindow) +ThemeManager::ThemeManager() { - m_mainWindow = mainWindow; initializeThemes(); } @@ -169,33 +168,27 @@ QList<IconTheme*> ThemeManager::getValidIconThemes() return ret; } -bool ThemeManager::setIconTheme(const QString& name) +bool ThemeManager::isValidApplicationTheme(const QString& id) { - if (m_icons.find(name) == m_icons.end()) { - themeWarningLog() << "Tried to set invalid icon theme:" << name; - return false; - } + return !id.isEmpty() && m_themes.find(id) != m_themes.end(); +} - QIcon::setThemeName(name); - return true; +bool ThemeManager::isValidIconTheme(const QString& id) +{ + return !id.isEmpty() && m_icons.find(id) != m_icons.end(); } -void ThemeManager::applyCurrentlySelectedTheme(bool initial) +void ThemeManager::setIconTheme(const QString& name) { - auto settings = APPLICATION->settings(); - if (!setIconTheme(settings->get("IconTheme").toString())) { - APPLICATION->settings()->reset("IconTheme"); - setIconTheme(settings->get("IconTheme").toString()); - } - themeDebugLog() << "<> Icon theme set."; - if (!setApplicationTheme(settings->get("ApplicationTheme").toString(), initial)) { - APPLICATION->settings()->reset("ApplicationTheme"); - setApplicationTheme(settings->get("ApplicationTheme").toString(), initial); + if (m_icons.find(name) == m_icons.end()) { + themeWarningLog() << "Tried to set invalid icon theme:" << name; + return; } - themeDebugLog() << "<> Application theme set."; + + QIcon::setThemeName(name); } -bool ThemeManager::setApplicationTheme(const QString& name, bool initial) +void ThemeManager::setApplicationTheme(const QString& name, bool initial) { auto systemPalette = qApp->palette(); auto themeIter = m_themes.find(name); @@ -203,13 +196,20 @@ bool ThemeManager::setApplicationTheme(const QString& name, bool initial) auto& theme = themeIter->second; themeDebugLog() << "applying theme" << theme->name(); theme->apply(initial); - return true; } else { themeWarningLog() << "Tried to set invalid theme:" << name; - return false; } } +void ThemeManager::applyCurrentlySelectedTheme(bool initial) +{ + auto settings = APPLICATION->settings(); + setIconTheme(settings->get("IconTheme").toString()); + themeDebugLog() << "<> Icon theme set."; + setApplicationTheme(settings->get("ApplicationTheme").toString(), initial); + themeDebugLog() << "<> Application theme set."; +} + QString ThemeManager::getCatImage(QString catName) { QDateTime now = QDateTime::currentDateTime(); diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index 2b6c57e9..627fdc75 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -35,13 +35,15 @@ inline auto themeWarningLog() class ThemeManager { public: - ThemeManager(MainWindow* mainWindow); + ThemeManager(); QList<ITheme*> getValidApplicationThemes(); QList<IconTheme*> getValidIconThemes(); - bool setIconTheme(const QString& name); + bool isValidApplicationTheme(const QString& id); + bool isValidIconTheme(const QString& id); void applyCurrentlySelectedTheme(bool initial = false); - bool setApplicationTheme(const QString& name, bool initial = false); + void setIconTheme(const QString& name); + void setApplicationTheme(const QString& name, bool initial = false); /// <summary> /// Returns the cat based on selected cat and with events (Birthday, XMas, etc.) @@ -53,7 +55,6 @@ class ThemeManager { private: std::map<QString, std::unique_ptr<ITheme>> m_themes; std::map<QString, IconTheme> m_icons; - MainWindow* m_mainWindow; void initializeThemes(); QString addTheme(std::unique_ptr<ITheme> theme); |