diff options
author | Tayou <tayou@gmx.net> | 2022-10-22 19:43:04 +0200 |
---|---|---|
committer | Tayou <tayou@gmx.net> | 2023-01-10 16:06:01 +0100 |
commit | 1b80ae0fca5e41d8caaa7d77d19faa9826752143 (patch) | |
tree | fcdc7c2a84261a8ff90af6222b37b8ee4c64bb1b /launcher/ui/widgets/ThemeCustomizationWidget.cpp | |
parent | 61144f7a219995fa29531683ed36e8e4002848b5 (diff) | |
download | PrismLauncher-1b80ae0fca5e41d8caaa7d77d19faa9826752143.tar.gz PrismLauncher-1b80ae0fca5e41d8caaa7d77d19faa9826752143.tar.bz2 PrismLauncher-1b80ae0fca5e41d8caaa7d77d19faa9826752143.zip |
add theme setup wizard
Signed-off-by: Tayou <tayou@gmx.net>
Diffstat (limited to 'launcher/ui/widgets/ThemeCustomizationWidget.cpp')
-rw-r--r-- | launcher/ui/widgets/ThemeCustomizationWidget.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp new file mode 100644 index 00000000..0830a030 --- /dev/null +++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp @@ -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);
+}
\ No newline at end of file |