Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add theme selection to setup wizard #249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "ui/setupwizard/LanguageWizardPage.h"
#include "ui/setupwizard/JavaWizardPage.h"
#include "ui/setupwizard/PasteWizardPage.h"
#include "ui/setupwizard/ThemeWizardPage.h"

#include "ui/dialogs/CustomMessageBox.h"

Expand Down Expand Up @@ -497,7 +498,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)

// Theming
m_settings->registerSetting("IconTheme", QString("pe_colored"));
m_settings->registerSetting("ApplicationTheme", QString("system"));
m_settings->registerSetting("ApplicationTheme", QString());
m_settings->registerSetting("BackgroundCat", QString("kitteh"));

// Remembered state
Expand Down Expand Up @@ -846,10 +847,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
});

{
setIconTheme(settings()->get("IconTheme").toString());
qDebug() << "<> Icon theme set.";
setApplicationTheme(settings()->get("ApplicationTheme").toString(), true);
qDebug() << "<> Application theme set.";
applyCurrentlySelectedTheme();
}

updateCapabilities();
Expand Down Expand Up @@ -892,7 +890,8 @@ bool Application::createSetupWizard()
return false;
}();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired;
bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;

if(wizardRequired)
{
Expand All @@ -911,6 +910,12 @@ bool Application::createSetupWizard()
{
m_setupWizard->addPage(new PasteWizardPage(m_setupWizard));
}

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;
Expand Down Expand Up @@ -1118,9 +1123,14 @@ QList<ITheme*> Application::getValidApplicationThemes()
return m_themeManager->getValidApplicationThemes();
}

void Application::setApplicationTheme(const QString& name, bool initial)
void Application::applyCurrentlySelectedTheme()
{
m_themeManager->applyCurrentlySelectedTheme();
}

void Application::setApplicationTheme(const QString& name)
{
m_themeManager->setApplicationTheme(name, initial);
m_themeManager->setApplicationTheme(name);
}

void Application::setIconTheme(const QString& name)
Expand Down
4 changes: 3 additions & 1 deletion launcher/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ class Application : public QApplication

void setIconTheme(const QString& name);

void applyCurrentlySelectedTheme();

QList<ITheme*> getValidApplicationThemes();

void setApplicationTheme(const QString& name, bool initial);
void setApplicationTheme(const QString& name);

shared_qobject_ptr<UpdateChecker> updateChecker() {
return m_updateChecker;
Expand Down
6 changes: 6 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ SET(LAUNCHER_SOURCES
ui/setupwizard/LanguageWizardPage.h
ui/setupwizard/PasteWizardPage.cpp
ui/setupwizard/PasteWizardPage.h
ui/setupwizard/ThemeWizardPage.cpp
ui/setupwizard/ThemeWizardPage.h

# GUI - themes
ui/themes/FusionTheme.cpp
Expand Down Expand Up @@ -922,6 +924,8 @@ SET(LAUNCHER_SOURCES
ui/widgets/ProgressWidget.cpp
ui/widgets/WideBar.h
ui/widgets/WideBar.cpp
ui/widgets/ThemeCustomizationWidget.h
ui/widgets/ThemeCustomizationWidget.cpp

# GUI - instance group view
ui/instanceview/InstanceProxyModel.cpp
Expand All @@ -939,6 +943,7 @@ SET(LAUNCHER_SOURCES

qt_wrap_ui(LAUNCHER_UI
ui/setupwizard/PasteWizardPage.ui
ui/setupwizard/ThemeWizardPage.ui
ui/pages/global/AccountListPage.ui
ui/pages/global/JavaPage.ui
ui/pages/global/LauncherPage.ui
Expand Down Expand Up @@ -971,6 +976,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/widgets/CustomCommands.ui
ui/widgets/InfoFrame.ui
ui/widgets/ModFilterWidget.ui
ui/widgets/ThemeCustomizationWidget.ui
ui/dialogs/CopyInstanceDialog.ui
ui/dialogs/ProfileSetupDialog.ui
ui/dialogs/ProgressDialog.ui
Expand Down
34 changes: 5 additions & 29 deletions launcher/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#include "ui/dialogs/ExportInstanceDialog.h"
#include "ui/dialogs/ImportResourcePackDialog.h"
#include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"

#include <minecraft/mod/ResourcePackFolderModel.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
Expand Down Expand Up @@ -1346,7 +1347,7 @@ void MainWindow::updateThemeMenu()
themeAction->setActionGroup(themesGroup);

connect(themeAction, &QAction::triggered, [theme]() {
APPLICATION->setApplicationTheme(theme->id(),false);
APPLICATION->setApplicationTheme(theme->id());
APPLICATION->settings()->set("ApplicationTheme", theme->id());
});
}
Expand Down Expand Up @@ -1652,32 +1653,9 @@ void MainWindow::onCatToggled(bool state)
APPLICATION->settings()->set("TheCat", state);
}

namespace {
template <typename T>
T non_stupid_abs(T in)
{
if (in < 0)
return -in;
return in;
}
}

void MainWindow::setCatBackground(bool enabled)
{
if (enabled)
{
QDateTime now = QDateTime::currentDateTime();
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
QString cat = APPLICATION->settings()->get("BackgroundCat").toString();
if (non_stupid_abs(now.daysTo(xmas)) <= 4) {
cat += "-xmas";
} else if (non_stupid_abs(now.daysTo(halloween)) <= 4) {
cat += "-spooky";
} else if (non_stupid_abs(now.daysTo(birthday)) <= 12) {
cat += "-bday";
}
if (enabled) {
view->setStyleSheet(QString(R"(
InstanceView
{
Expand All @@ -1688,10 +1666,8 @@ InstanceView
background-repeat: none;
background-color:palette(base);
})")
.arg(cat));
}
else
{
.arg(ThemeManager::getCatImage()));
} else {
view->setStyleSheet(QString());
}
}
Expand Down
110 changes: 0 additions & 110 deletions launcher/ui/pages/global/LauncherPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,75 +286,6 @@ void LauncherPage::applySettings()
}

s->set("UpdateChannel", m_currentUpdateChannel);
auto original = s->get("IconTheme").toString();
//FIXME: make generic
switch (ui->themeComboBox->currentIndex())
{
case 0:
s->set("IconTheme", "pe_colored");
break;
case 1:
s->set("IconTheme", "pe_light");
break;
case 2:
s->set("IconTheme", "pe_dark");
break;
case 3:
s->set("IconTheme", "pe_blue");
break;
case 4:
s->set("IconTheme", "breeze_light");
break;
case 5:
s->set("IconTheme", "breeze_dark");
break;
case 6:
s->set("IconTheme", "OSX");
break;
case 7:
s->set("IconTheme", "iOS");
break;
case 8:
s->set("IconTheme", "flat");
break;
case 9:
s->set("IconTheme", "flat_white");
break;
case 10:
s->set("IconTheme", "multimc");
break;
case 11:
s->set("IconTheme", "custom");
break;
}

if(original != s->get("IconTheme"))
{
APPLICATION->setIconTheme(s->get("IconTheme").toString());
}

auto originalAppTheme = s->get("ApplicationTheme").toString();
auto newAppTheme = ui->themeComboBoxColors->currentData().toString();
if(originalAppTheme != newAppTheme)
{
s->set("ApplicationTheme", newAppTheme);
APPLICATION->setApplicationTheme(newAppTheme, false);
}

switch (ui->themeBackgroundCat->currentIndex()) {
case 0: // original cat
s->set("BackgroundCat", "kitteh");
break;
case 1: // rory the cat
s->set("BackgroundCat", "rory");
break;
case 2: // rory the cat flat edition
s->set("BackgroundCat", "rory-flat");
break;
case 3: // teawie
s->set("BackgroundCat", "teawie");
break;
}

s->set("MenuBarInsteadOfToolBar", ui->preferMenuBarCheckBox->isChecked());

Expand Down Expand Up @@ -404,47 +335,6 @@ void LauncherPage::loadSettings()
}

m_currentUpdateChannel = s->get("UpdateChannel").toString();
//FIXME: make generic
auto theme = s->get("IconTheme").toString();
QStringList iconThemeOptions{"pe_colored",
"pe_light",
"pe_dark",
"pe_blue",
"breeze_light",
"breeze_dark",
"OSX",
"iOS",
"flat",
"flat_white",
"multimc",
"custom"};
ui->themeComboBox->setCurrentIndex(iconThemeOptions.indexOf(theme));

auto cat = s->get("BackgroundCat").toString();
if (cat == "kitteh") {
ui->themeBackgroundCat->setCurrentIndex(0);
} else if (cat == "rory") {
ui->themeBackgroundCat->setCurrentIndex(1);
} else if (cat == "rory-flat") {
ui->themeBackgroundCat->setCurrentIndex(2);
} else if (cat == "teawie") {
ui->themeBackgroundCat->setCurrentIndex(3);
}

{
auto currentTheme = s->get("ApplicationTheme").toString();
auto themes = APPLICATION->getValidApplicationThemes();
int idx = 0;
for(auto &theme: themes)
{
ui->themeComboBoxColors->addItem(theme->name(), theme->id());
if(currentTheme == theme->id())
{
ui->themeComboBoxColors->setCurrentIndex(idx);
}
idx++;
}
}

// Toolbar/menu bar settings (not applicable if native menu bar is present)
ui->toolsBox->setEnabled(!QMenuBar().isNativeMenuBar());
Expand Down