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));
|
m_settings.reset(new INISettingsObject({ BuildConfig.LAUNCHER_CONFIGFILE, "polymc.cfg", "multimc.cfg" }, this));
|
||||||
|
|
||||||
// Theming
|
// Theming
|
||||||
m_settings->registerSetting("IconTheme", QString("pe_colored"));
|
m_settings->registerSetting("IconTheme", QString());
|
||||||
m_settings->registerSetting("ApplicationTheme", QString());
|
m_settings->registerSetting("ApplicationTheme", QString());
|
||||||
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
|
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
|
||||||
|
|
||||||
@ -801,7 +801,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Themes
|
// Themes
|
||||||
m_themeManager = std::make_unique<ThemeManager>(m_mainWindow);
|
m_themeManager = std::make_unique<ThemeManager>();
|
||||||
|
|
||||||
// initialize and load all instances
|
// initialize and load all instances
|
||||||
{
|
{
|
||||||
@ -893,8 +893,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
applyCurrentlySelectedTheme(true);
|
|
||||||
|
|
||||||
updateCapabilities();
|
updateCapabilities();
|
||||||
|
|
||||||
if(createSetupWizard())
|
if(createSetupWizard())
|
||||||
@ -902,6 +900,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyCurrentlySelectedTheme(true);
|
||||||
performMainStartupAction();
|
performMainStartupAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,11 +929,21 @@ bool Application::createSetupWizard()
|
|||||||
}();
|
}();
|
||||||
bool languageRequired = settings()->get("Language").toString().isEmpty();
|
bool languageRequired = settings()->get("Language").toString().isEmpty();
|
||||||
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
|
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;
|
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
|
||||||
|
|
||||||
if(wizardRequired)
|
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);
|
m_setupWizard = new SetupWizard(nullptr);
|
||||||
if (languageRequired)
|
if (languageRequired)
|
||||||
{
|
{
|
||||||
@ -953,9 +962,9 @@ bool Application::createSetupWizard()
|
|||||||
|
|
||||||
if (themeInterventionRequired)
|
if (themeInterventionRequired)
|
||||||
{
|
{
|
||||||
settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
|
|
||||||
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
|
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
|
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
|
||||||
m_setupWizard->show();
|
m_setupWizard->show();
|
||||||
return true;
|
return true;
|
||||||
|
@ -29,9 +29,8 @@
|
|||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
ThemeManager::ThemeManager(MainWindow* mainWindow)
|
ThemeManager::ThemeManager()
|
||||||
{
|
{
|
||||||
m_mainWindow = mainWindow;
|
|
||||||
initializeThemes();
|
initializeThemes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,33 +168,27 @@ QList<IconTheme*> ThemeManager::getValidIconThemes()
|
|||||||
return ret;
|
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()) {
|
if (m_icons.find(name) == m_icons.end()) {
|
||||||
themeWarningLog() << "Tried to set invalid icon theme:" << name;
|
themeWarningLog() << "Tried to set invalid icon theme:" << name;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon::setThemeName(name);
|
QIcon::setThemeName(name);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeManager::applyCurrentlySelectedTheme(bool initial)
|
void ThemeManager::setApplicationTheme(const QString& name, 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)
|
|
||||||
{
|
{
|
||||||
auto systemPalette = qApp->palette();
|
auto systemPalette = qApp->palette();
|
||||||
auto themeIter = m_themes.find(name);
|
auto themeIter = m_themes.find(name);
|
||||||
@ -203,13 +196,20 @@ bool ThemeManager::setApplicationTheme(const QString& name, bool initial)
|
|||||||
auto& theme = themeIter->second;
|
auto& theme = themeIter->second;
|
||||||
themeDebugLog() << "applying theme" << theme->name();
|
themeDebugLog() << "applying theme" << theme->name();
|
||||||
theme->apply(initial);
|
theme->apply(initial);
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
themeWarningLog() << "Tried to set invalid theme:" << name;
|
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)
|
QString ThemeManager::getCatImage(QString catName)
|
||||||
{
|
{
|
||||||
QDateTime now = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
|
@ -35,13 +35,15 @@ inline auto themeWarningLog()
|
|||||||
|
|
||||||
class ThemeManager {
|
class ThemeManager {
|
||||||
public:
|
public:
|
||||||
ThemeManager(MainWindow* mainWindow);
|
ThemeManager();
|
||||||
|
|
||||||
QList<ITheme*> getValidApplicationThemes();
|
QList<ITheme*> getValidApplicationThemes();
|
||||||
QList<IconTheme*> getValidIconThemes();
|
QList<IconTheme*> getValidIconThemes();
|
||||||
bool setIconTheme(const QString& name);
|
bool isValidApplicationTheme(const QString& id);
|
||||||
|
bool isValidIconTheme(const QString& id);
|
||||||
void applyCurrentlySelectedTheme(bool initial = false);
|
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>
|
/// <summary>
|
||||||
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
|
||||||
@ -53,7 +55,6 @@ class ThemeManager {
|
|||||||
private:
|
private:
|
||||||
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
std::map<QString, std::unique_ptr<ITheme>> m_themes;
|
||||||
std::map<QString, IconTheme> m_icons;
|
std::map<QString, IconTheme> m_icons;
|
||||||
MainWindow* m_mainWindow;
|
|
||||||
|
|
||||||
void initializeThemes();
|
void initializeThemes();
|
||||||
QString addTheme(std::unique_ptr<ITheme> theme);
|
QString addTheme(std::unique_ptr<ITheme> theme);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user