add theme setup wizard

Signed-off-by: Tayou <tayou@gmx.net>
This commit is contained in:
Tayou
2022-10-22 19:43:04 +02:00
parent 61144f7a21
commit 1b80ae0fca
18 changed files with 982 additions and 288 deletions

View File

@ -0,0 +1,135 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <tayou@gmx.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ThemeCustomizationWidget.h"
#include "ui_ThemeCustomizationWidget.h"
#include "Application.h"
#include "ui/themes/ITheme.h"
ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget)
{
ui->setupUi(this);
loadSettings();
connect(ui->iconsComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyIconTheme);
connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyWidgetTheme);
connect(ui->backgroundCatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyCatTheme);
}
ThemeCustomizationWidget::~ThemeCustomizationWidget()
{
delete ui;
}
void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
ui->iconsComboBox->setVisible(features & ThemeFields::ICONS);
ui->iconsLabel->setVisible(features & ThemeFields::ICONS);
ui->widgetStyleComboBox->setVisible(features & ThemeFields::WIDGETS);
ui->widgetThemeLabel->setVisible(features & ThemeFields::WIDGETS);
ui->backgroundCatComboBox->setVisible(features & ThemeFields::CAT);
ui->backgroundCatLabel->setVisible(features & ThemeFields::CAT);
}
void ThemeCustomizationWidget::applyIconTheme(int index) {
emit currentIconThemeChanged(index);
auto settings = APPLICATION->settings();
auto original = settings->get("IconTheme").toString();
// FIXME: make generic
settings->set("IconTheme", m_iconThemeOptions[index]);
if (original != settings->get("IconTheme")) {
APPLICATION->applyCurrentlySelectedTheme();
}
}
void ThemeCustomizationWidget::applyWidgetTheme(int index) {
emit currentWidgetThemeChanged(index);
auto settings = APPLICATION->settings();
auto originalAppTheme = settings->get("ApplicationTheme").toString();
auto newAppTheme = ui->widgetStyleComboBox->currentData().toString();
if (originalAppTheme != newAppTheme) {
settings->set("ApplicationTheme", newAppTheme);
APPLICATION->applyCurrentlySelectedTheme();
}
}
void ThemeCustomizationWidget::applyCatTheme(int index) {
emit currentCatChanged(index);
auto settings = APPLICATION->settings();
switch (index) {
case 0: // original cat
settings->set("BackgroundCat", "kitteh");
break;
case 1: // rory the cat
settings->set("BackgroundCat", "rory");
break;
case 2: // rory the cat flat edition
settings->set("BackgroundCat", "rory-flat");
break;
case 3: // teawie
settings->set("BackgroundCat", "teawie");
break;
}
}
void ThemeCustomizationWidget::applySettings()
{
applyIconTheme(ui->iconsComboBox->currentIndex());
applyWidgetTheme(ui->widgetStyleComboBox->currentIndex());
applyCatTheme(ui->backgroundCatComboBox->currentIndex());
}
void ThemeCustomizationWidget::loadSettings()
{
auto settings = APPLICATION->settings();
// FIXME: make generic
auto theme = settings->get("IconTheme").toString();
ui->iconsComboBox->setCurrentIndex(m_iconThemeOptions.indexOf(theme));
{
auto currentTheme = settings->get("ApplicationTheme").toString();
auto themes = APPLICATION->getValidApplicationThemes();
int idx = 0;
for (auto& theme : themes) {
ui->widgetStyleComboBox->addItem(theme->name(), theme->id());
if (currentTheme == theme->id()) {
ui->widgetStyleComboBox->setCurrentIndex(idx);
}
idx++;
}
}
auto cat = settings->get("BackgroundCat").toString();
if (cat == "kitteh") {
ui->backgroundCatComboBox->setCurrentIndex(0);
} else if (cat == "rory") {
ui->backgroundCatComboBox->setCurrentIndex(1);
} else if (cat == "rory-flat") {
ui->backgroundCatComboBox->setCurrentIndex(2);
} else if (cat == "teawie") {
ui->backgroundCatComboBox->setCurrentIndex(3);
}
}
void ThemeCustomizationWidget::retranslate()
{
ui->retranslateUi(this);
}

View File

@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Tayou <tayou@gmx.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <QWidget>
#include <translations/TranslationsModel.h>
enum ThemeFields {
NONE = 0b0000,
ICONS = 0b0001,
WIDGETS = 0b0010,
CAT = 0b0100
};
namespace Ui {
class ThemeCustomizationWidget;
}
class ThemeCustomizationWidget : public QWidget
{
Q_OBJECT
public:
explicit ThemeCustomizationWidget(QWidget *parent = nullptr);
~ThemeCustomizationWidget();
void showFeatures(ThemeFields features);
void applySettings();
void loadSettings();
void retranslate();
Ui::ThemeCustomizationWidget *ui;
private slots:
void applyIconTheme(int index);
void applyWidgetTheme(int index);
void applyCatTheme(int index);
signals:
int currentIconThemeChanged(int index);
int currentWidgetThemeChanged(int index);
int currentCatChanged(int index);
private:
QStringList m_iconThemeOptions{ "pe_colored", "pe_light", "pe_dark", "pe_blue", "breeze_light", "breeze_dark", "OSX", "iOS", "flat", "flat_white", "multimc", "custom" };
};

View File

@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ThemeCustomizationWidget</class>
<widget class="QWidget" name="ThemeCustomizationWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>311</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="iconsLabel">
<property name="text">
<string>&amp;Icons</string>
</property>
<property name="buddy">
<cstring>iconsComboBox</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="iconsComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<item>
<property name="text">
<string>Simple (Colored Icons)</string>
</property>
</item>
<item>
<property name="text">
<string>Simple (Light Icons)</string>
</property>
</item>
<item>
<property name="text">
<string>Simple (Dark Icons)</string>
</property>
</item>
<item>
<property name="text">
<string>Simple (Blue Icons)</string>
</property>
</item>
<item>
<property name="text">
<string>Breeze Light</string>
</property>
</item>
<item>
<property name="text">
<string>Breeze Dark</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">OSX</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">iOS</string>
</property>
</item>
<item>
<property name="text">
<string>Flat</string>
</property>
</item>
<item>
<property name="text">
<string>Flat (White)</string>
</property>
</item>
<item>
<property name="text">
<string>Legacy</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="widgetThemeLabel">
<property name="text">
<string>&amp;Colors</string>
</property>
<property name="buddy">
<cstring>widgetStyleComboBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="widgetStyleComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="backgroundCatLabel">
<property name="text">
<string>C&amp;at</string>
</property>
<property name="buddy">
<cstring>backgroundCatComboBox</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="backgroundCatComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<item>
<property name="text">
<string>Background Cat (from MultiMC)</string>
</property>
</item>
<item>
<property name="text">
<string>Rory ID 11 (drawn by Ashtaka)</string>
</property>
</item>
<item>
<property name="text">
<string>Rory ID 11 (flat edition, drawn by Ashtaka)</string>
</property>
</item>
<item>
<property name="text">
<string>Teawie (drawn by SympathyTea)</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>