From 872cfe036d9472739939ad401dbe9511193d62ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 21 Oct 2016 09:07:26 +0200 Subject: GH-903 simple theme switching and dark theme --- application/MultiMC.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'application/MultiMC.cpp') diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index f53d05e1..093d03b4 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -9,6 +9,10 @@ #include "pages/global/AccountListPage.h" #include "pages/global/PasteEEPage.h" +#include "themes/ITheme.h" +#include "themes/SystemTheme.h" +#include "themes/DarkTheme.h" + #include #include #include @@ -241,6 +245,9 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar // load icons initIcons(); + // load themes + initThemes(); + // and instances auto InstDirSetting = m_settings->getSetting("InstanceDir"); // instance path: check for problems with '!' in instance path and warn the user in the log @@ -442,7 +449,10 @@ void MultiMC::initGlobalSettings(bool test_mode) // Updates m_settings->registerSetting("UpdateChannel", BuildConfig.VERSION_CHANNEL); m_settings->registerSetting("AutoUpdate", true); + + // Theming m_settings->registerSetting("IconTheme", QString("multimc")); + m_settings->registerSetting("ApplicationTheme", QString("system")); // Notifications m_settings->registerSetting("ShownNotifications", QString()); @@ -943,6 +953,45 @@ FAILED: QMessageBox::critical(nullptr, tr("Update failed!"), msg); } +std::vector MultiMC::getValidApplicationThemes() +{ + std::vector ret; + auto iter = m_themes.cbegin(); + while (iter != m_themes.cend()) + { + ret.push_back((*iter).second.get()); + iter++; + } + return ret; +} + +void MultiMC::initThemes() +{ + auto insertTheme = [this](ITheme * theme) + { + m_themes.insert(std::make_pair(theme->id(), std::unique_ptr(theme))); + }; + insertTheme(new SystemTheme()); + insertTheme(new DarkTheme()); +} + +void MultiMC::setApplicationTheme(const QString& name) +{ + auto systemPalette = qApp->palette(); + auto themeIter = m_themes.find(name); + if(themeIter != m_themes.end()) + { + auto & theme = (*themeIter).second; + setPalette(theme->colorScheme()); + setStyleSheet(theme->appStyleSheet()); + //setStyle(QStyleFactory::create("Fusion")); + } + else + { + qWarning() << "Tried to set invalid theme:" << name; + } +} + void MultiMC::setIconTheme(const QString& name) { XdgIcon::setThemeName(name); -- cgit v1.2.3