aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/widgets
diff options
context:
space:
mode:
authorAaron Sonin <10217842+byteduck@users.noreply.github.com>2023-01-12 20:11:46 -0800
committerGitHub <noreply@github.com>2023-01-12 20:11:46 -0800
commitb2f48eaeb8cd6dbdf9b8bbbf1a163339c88173a7 (patch)
tree80773415691e538d437bc03c42f73a8abd01f126 /launcher/ui/widgets
parent160dd09fc2788fea17c8e9e332c2877586640971 (diff)
parent5e89ba70797df863c7eeae9b147080e7dbdf6d3b (diff)
downloadPrismLauncher-b2f48eaeb8cd6dbdf9b8bbbf1a163339c88173a7.tar.gz
PrismLauncher-b2f48eaeb8cd6dbdf9b8bbbf1a163339c88173a7.tar.bz2
PrismLauncher-b2f48eaeb8cd6dbdf9b8bbbf1a163339c88173a7.zip
Merge branch 'PrismLauncher:develop' into instance-accounts
Diffstat (limited to 'launcher/ui/widgets')
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.cpp150
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.h77
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.ui132
3 files changed, 359 insertions, 0 deletions
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
new file mode 100644
index 00000000..dcf13303
--- /dev/null
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
@@ -0,0 +1,150 @@
+// 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"
+#include "ui/themes/ThemeManager.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;
+}
+
+/// <summary>
+/// The layout was not quite right, so currently this just disables the UI elements, which should be hidden instead
+/// TODO FIXME
+///
+/// Original Method One:
+/// 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);
+///
+/// original Method Two:
+/// if (!(features & ThemeFields::ICONS)) {
+/// ui->formLayout->setRowVisible(0, false);
+/// }
+/// if (!(features & ThemeFields::WIDGETS)) {
+/// ui->formLayout->setRowVisible(1, false);
+/// }
+/// if (!(features & ThemeFields::CAT)) {
+/// ui->formLayout->setRowVisible(2, false);
+/// }
+/// </summary>
+/// <param name="features"></param>
+void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
+ ui->iconsComboBox->setEnabled(features & ThemeFields::ICONS);
+ ui->iconsLabel->setEnabled(features & ThemeFields::ICONS);
+ ui->widgetStyleComboBox->setEnabled(features & ThemeFields::WIDGETS);
+ ui->widgetThemeLabel->setEnabled(features & ThemeFields::WIDGETS);
+ ui->backgroundCatComboBox->setEnabled(features & ThemeFields::CAT);
+ ui->backgroundCatLabel->setEnabled(features & ThemeFields::CAT);
+}
+
+void ThemeCustomizationWidget::applyIconTheme(int index) {
+ auto settings = APPLICATION->settings();
+ auto originalIconTheme = settings->get("IconTheme").toString();
+ auto& newIconTheme = m_iconThemeOptions[index].first;
+ settings->set("IconTheme", newIconTheme);
+
+ if (originalIconTheme != newIconTheme) {
+ APPLICATION->applyCurrentlySelectedTheme();
+ }
+
+ emit currentIconThemeChanged(index);
+}
+
+void ThemeCustomizationWidget::applyWidgetTheme(int 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();
+ }
+
+ emit currentWidgetThemeChanged(index);
+}
+
+void ThemeCustomizationWidget::applyCatTheme(int index) {
+ auto settings = APPLICATION->settings();
+ settings->set("BackgroundCat", m_catOptions[index].first);
+
+ emit currentCatChanged(index);
+}
+
+void ThemeCustomizationWidget::applySettings()
+{
+ applyIconTheme(ui->iconsComboBox->currentIndex());
+ applyWidgetTheme(ui->widgetStyleComboBox->currentIndex());
+ applyCatTheme(ui->backgroundCatComboBox->currentIndex());
+}
+void ThemeCustomizationWidget::loadSettings()
+{
+ auto settings = APPLICATION->settings();
+
+ auto iconTheme = settings->get("IconTheme").toString();
+ for (auto& iconThemeFromList : m_iconThemeOptions) {
+ QIcon iconForComboBox = QIcon(QString(":/icons/%1/scalable/settings").arg(iconThemeFromList.first));
+ ui->iconsComboBox->addItem(iconForComboBox, iconThemeFromList.second);
+ if (iconTheme == iconThemeFromList.first) {
+ ui->iconsComboBox->setCurrentIndex(ui->iconsComboBox->count() - 1);
+ }
+ }
+
+ {
+ 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();
+ for (auto& catFromList : m_catOptions) {
+ QIcon catIcon = QIcon(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage(catFromList.first)));
+ ui->backgroundCatComboBox->addItem(catIcon, catFromList.second);
+ if (cat == catFromList.first) {
+ ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
+ }
+ }
+}
+
+void ThemeCustomizationWidget::retranslate()
+{
+ ui->retranslateUi(this);
+}
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.h b/launcher/ui/widgets/ThemeCustomizationWidget.h
new file mode 100644
index 00000000..d955a266
--- /dev/null
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.h
@@ -0,0 +1,77 @@
+// 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();
+
+ 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:
+ Ui::ThemeCustomizationWidget* ui;
+
+ //TODO finish implementing
+ QList<std::pair<QString, QString>> m_iconThemeOptions{
+ { "pe_colored", QObject::tr("Simple (Colored Icons)") },
+ { "pe_light", QObject::tr("Simple (Light Icons)") },
+ { "pe_dark", QObject::tr("Simple (Dark Icons)") },
+ { "pe_blue", QObject::tr("Simple (Blue Icons)") },
+ { "breeze_light", QObject::tr("Breeze Light") },
+ { "breeze_dark", QObject::tr("Breeze Dark") },
+ { "OSX", QObject::tr("OSX") },
+ { "iOS", QObject::tr("iOS") },
+ { "flat", QObject::tr("Flat") },
+ { "flat_white", QObject::tr("Flat (White)") },
+ { "multimc", QObject::tr("Legacy") },
+ { "custom", QObject::tr("Custom") }
+ };
+ QList<std::pair<QString, QString>> m_catOptions{
+ { "kitteh", QObject::tr("Background Cat (from MultiMC)") },
+ { "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
+ { "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
+ { "teawie", QObject::tr("Teawie (drawn by SympathyTea)") }
+ };
+};
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.ui b/launcher/ui/widgets/ThemeCustomizationWidget.ui
new file mode 100644
index 00000000..f216a610
--- /dev/null
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.ui
@@ -0,0 +1,132 @@
+<?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>191</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string notr="true">Form</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <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>
+ </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="toolTip">
+ <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ <property name="text">
+ <string>C&amp;at</string>
+ </property>
+ <property name="buddy">
+ <cstring>backgroundCatComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <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>
+ <property name="toolTip">
+ <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="catInfoLabel">
+ <property name="toolTip">
+ <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset theme="about">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>