Better theme reset
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
54d393632d
commit
960093700a
@ -526,7 +526,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
m_settings.reset(new INISettingsObject({ BuildConfig.LAUNCHER_CONFIGFILE, "polymc.cfg", "multimc.cfg" }, this));
|
||||
|
||||
// Theming
|
||||
m_settings->registerSetting("IconTheme", QString("pe_colored"));
|
||||
m_settings->registerSetting("IconTheme", QString());
|
||||
m_settings->registerSetting("ApplicationTheme", QString());
|
||||
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
|
||||
|
||||
@ -801,7 +801,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
}
|
||||
|
||||
// Themes
|
||||
m_themeManager = std::make_unique<ThemeManager>(m_mainWindow);
|
||||
m_themeManager = std::make_unique<ThemeManager>();
|
||||
|
||||
// initialize and load all instances
|
||||
{
|
||||
@ -893,8 +893,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
}
|
||||
});
|
||||
|
||||
applyCurrentlySelectedTheme(true);
|
||||
|
||||
updateCapabilities();
|
||||
|
||||
if(createSetupWizard())
|
||||
@ -902,6 +900,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
||||
return;
|
||||
}
|
||||
|
||||
applyCurrentlySelectedTheme(true);
|
||||
performMainStartupAction();
|
||||
}
|
||||
|
||||
@ -930,11 +929,21 @@ bool Application::createSetupWizard()
|
||||
}();
|
||||
bool languageRequired = settings()->get("Language").toString().isEmpty();
|
||||
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
|
||||
bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
|
||||
bool validWidgets = m_themeManager->isValidApplicationTheme(settings()->get("ApplicationTheme").toString());
|
||||
bool validIcons = m_themeManager->isValidIconTheme(settings()->get("IconTheme").toString());
|
||||
bool themeInterventionRequired = !validWidgets || !validIcons;
|
||||
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
|
||||
|
||||
if(wizardRequired)
|
||||
{
|
||||
// set default theme after going into theme wizard
|
||||
if (!validIcons)
|
||||
settings()->set("IconTheme", QString("pe_colored"));
|
||||
if (!validWidgets)
|
||||
settings()->set("ApplicationTheme", QString("system"));
|
||||
|
||||
applyCurrentlySelectedTheme(true);
|
||||
|
||||
m_setupWizard = new SetupWizard(nullptr);
|
||||
if (languageRequired)
|
||||
{
|
||||
@ -953,9 +962,9 @@ bool Application::createSetupWizard()
|
||||
|
||||
if (themeInterventionRequired)
|
||||
{
|
||||
settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
|
||||
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
|
||||
}
|
||||
|
||||
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
|
||||
m_setupWizard->show();
|
||||
return true;
|
||||
|
@ -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)
|
||||
{
|
||||
return !id.isEmpty() && m_themes.find(id) != m_themes.end();
|
||||
}
|
||||
|
||||
bool ThemeManager::isValidIconTheme(const QString& id)
|
||||
{
|
||||
return !id.isEmpty() && m_icons.find(id) != m_icons.end();
|
||||
}
|
||||
|
||||
void ThemeManager::setIconTheme(const QString& name)
|
||||
{
|
||||
if (m_icons.find(name) == m_icons.end()) {
|
||||
themeWarningLog() << "Tried to set invalid icon theme:" << name;
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
QIcon::setThemeName(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ThemeManager::applyCurrentlySelectedTheme(bool initial)
|
||||
{
|
||||
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);
|
||||
}
|
||||
themeDebugLog() << "<> Application theme set.";
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user