2023-01-09 16:01:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
2023-06-28 22:02:34 +01:00
|
|
|
* Copyright (C) 2022 Tayou <git@tayou.org>
|
2023-01-09 16:01:33 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2023-07-20 11:51:44 +01:00
|
|
|
#include "DesktopServices.h"
|
2023-01-09 16:01:33 +00:00
|
|
|
#include "ui/themes/ITheme.h"
|
|
|
|
#include "ui/themes/ThemeManager.h"
|
|
|
|
|
2023-07-20 11:51:44 +01:00
|
|
|
ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget* parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget)
|
2023-01-09 16:01:33 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
loadSettings();
|
|
|
|
|
|
|
|
connect(ui->iconsComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyIconTheme);
|
2023-07-20 11:51:44 +01:00
|
|
|
connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
&ThemeCustomizationWidget::applyWidgetTheme);
|
2023-01-09 16:01:33 +00:00
|
|
|
connect(ui->backgroundCatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyCatTheme);
|
2023-07-20 11:51:44 +01:00
|
|
|
|
2023-08-07 12:10:21 +01:00
|
|
|
connect(ui->iconsFolder, &QPushButton::clicked, this,
|
|
|
|
[] { DesktopServices::openDirectory(APPLICATION->themeManager()->getIconThemesFolder().path()); });
|
|
|
|
connect(ui->widgetStyleFolder, &QPushButton::clicked, this,
|
|
|
|
[] { DesktopServices::openDirectory(APPLICATION->themeManager()->getApplicationThemesFolder().path()); });
|
|
|
|
connect(ui->catPackFolder, &QPushButton::clicked, this,
|
|
|
|
[] { DesktopServices::openDirectory(APPLICATION->themeManager()->getCatPacksFolder().path()); });
|
2023-01-09 16:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2023-07-20 11:51:44 +01:00
|
|
|
///
|
2023-01-09 16:01:33 +00:00
|
|
|
/// 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);
|
2023-07-20 11:51:44 +01:00
|
|
|
///
|
2023-01-09 16:01:33 +00:00
|
|
|
/// 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>
|
2023-07-20 11:51:44 +01:00
|
|
|
void ThemeCustomizationWidget::showFeatures(ThemeFields features)
|
|
|
|
{
|
2023-01-09 16:01:33 +00:00
|
|
|
ui->iconsComboBox->setEnabled(features & ThemeFields::ICONS);
|
|
|
|
ui->iconsLabel->setEnabled(features & ThemeFields::ICONS);
|
|
|
|
ui->widgetStyleComboBox->setEnabled(features & ThemeFields::WIDGETS);
|
2023-07-20 11:51:44 +01:00
|
|
|
ui->widgetStyleLabel->setEnabled(features & ThemeFields::WIDGETS);
|
2023-01-09 16:01:33 +00:00
|
|
|
ui->backgroundCatComboBox->setEnabled(features & ThemeFields::CAT);
|
|
|
|
ui->backgroundCatLabel->setEnabled(features & ThemeFields::CAT);
|
|
|
|
}
|
|
|
|
|
2023-07-20 11:51:44 +01:00
|
|
|
void ThemeCustomizationWidget::applyIconTheme(int index)
|
|
|
|
{
|
2023-01-09 16:01:33 +00:00
|
|
|
auto settings = APPLICATION->settings();
|
2023-01-09 17:40:58 +00:00
|
|
|
auto originalIconTheme = settings->get("IconTheme").toString();
|
2023-07-18 22:50:43 +01:00
|
|
|
auto newIconTheme = ui->iconsComboBox->currentData().toString();
|
2023-01-09 17:40:58 +00:00
|
|
|
if (originalIconTheme != newIconTheme) {
|
2023-07-18 22:50:43 +01:00
|
|
|
settings->set("IconTheme", newIconTheme);
|
2023-07-20 11:51:44 +01:00
|
|
|
APPLICATION->themeManager()->applyCurrentlySelectedTheme();
|
2023-01-09 16:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit currentIconThemeChanged(index);
|
|
|
|
}
|
|
|
|
|
2023-07-20 11:51:44 +01:00
|
|
|
void ThemeCustomizationWidget::applyWidgetTheme(int index)
|
|
|
|
{
|
2023-01-09 16:01:33 +00:00
|
|
|
auto settings = APPLICATION->settings();
|
|
|
|
auto originalAppTheme = settings->get("ApplicationTheme").toString();
|
|
|
|
auto newAppTheme = ui->widgetStyleComboBox->currentData().toString();
|
|
|
|
if (originalAppTheme != newAppTheme) {
|
|
|
|
settings->set("ApplicationTheme", newAppTheme);
|
2023-07-20 11:51:44 +01:00
|
|
|
APPLICATION->themeManager()->applyCurrentlySelectedTheme();
|
2023-01-09 16:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit currentWidgetThemeChanged(index);
|
|
|
|
}
|
|
|
|
|
2023-07-20 11:51:44 +01:00
|
|
|
void ThemeCustomizationWidget::applyCatTheme(int index)
|
|
|
|
{
|
2023-01-09 16:01:33 +00:00
|
|
|
auto settings = APPLICATION->settings();
|
2023-06-22 23:37:28 +01:00
|
|
|
auto originalCat = settings->get("BackgroundCat").toString();
|
|
|
|
auto newCat = ui->backgroundCatComboBox->currentData().toString();
|
|
|
|
if (originalCat != newCat) {
|
|
|
|
settings->set("BackgroundCat", newCat);
|
|
|
|
}
|
2023-01-09 16:01:33 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2023-07-18 22:50:43 +01:00
|
|
|
{
|
|
|
|
auto currentIconTheme = settings->get("IconTheme").toString();
|
2023-07-20 11:51:44 +01:00
|
|
|
auto iconThemes = APPLICATION->themeManager()->getValidIconThemes();
|
2023-07-18 22:50:43 +01:00
|
|
|
int idx = 0;
|
|
|
|
for (auto iconTheme : iconThemes) {
|
|
|
|
QIcon iconForComboBox = QIcon(iconTheme->path() + "/scalable/settings");
|
|
|
|
ui->iconsComboBox->addItem(iconForComboBox, iconTheme->name(), iconTheme->id());
|
|
|
|
if (currentIconTheme == iconTheme->id()) {
|
|
|
|
ui->iconsComboBox->setCurrentIndex(idx);
|
|
|
|
}
|
|
|
|
idx++;
|
2023-01-09 16:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto currentTheme = settings->get("ApplicationTheme").toString();
|
2023-07-20 11:51:44 +01:00
|
|
|
auto themes = APPLICATION->themeManager()->getValidApplicationThemes();
|
2023-01-09 16:01:33 +00:00
|
|
|
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();
|
2023-07-21 13:01:01 +01:00
|
|
|
for (auto& catFromList : APPLICATION->themeManager()->getValidCatPacks()) {
|
2023-06-22 23:37:28 +01:00
|
|
|
QIcon catIcon = QIcon(QString("%1").arg(catFromList->path()));
|
|
|
|
ui->backgroundCatComboBox->addItem(catIcon, catFromList->name(), catFromList->id());
|
|
|
|
if (cat == catFromList->id()) {
|
2023-01-09 16:01:33 +00:00
|
|
|
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeCustomizationWidget::retranslate()
|
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|