Implement Suggestions from flow & Scrumplex

Signed-off-by: Tayou <tayou@gmx.net>
This commit is contained in:
Tayou 2023-01-09 16:58:27 +01:00
parent 49d317b19a
commit 6daa457838
No known key found for this signature in database
GPG Key ID: 02CA43C1CB6E9887
9 changed files with 97 additions and 171 deletions

View File

@ -498,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");
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
// Remembered state
@ -890,8 +890,8 @@ bool Application::createSetupWizard()
return false;
}();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
bool themeInterventionRequired = settings()->get("ApplicationTheme") != "";
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired;
bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
if(wizardRequired)
{
@ -913,6 +913,7 @@ bool Application::createSetupWizard()
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);

View File

@ -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>
@ -1654,20 +1655,7 @@ void MainWindow::onCatToggled(bool state)
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 (std::abs(now.daysTo(xmas)) <= 4) {
cat += "-xmas";
} else if (std::abs(now.daysTo(halloween)) <= 4) {
cat += "-spooky";
} else if (std::abs(now.daysTo(birthday)) <= 12) {
cat += "-bday";
}
if (enabled) {
view->setStyleSheet(QString(R"(
InstanceView
{
@ -1678,10 +1666,8 @@ InstanceView
background-repeat: none;
background-color:palette(base);
})")
.arg(cat));
}
else
{
.arg(ThemeManager::getCatImage()));
} else {
view->setStyleSheet(QString());
}
}

View File

@ -20,6 +20,7 @@
#include "Application.h"
#include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"
#include "ui/widgets/ThemeCustomizationWidget.h"
#include "ui_ThemeCustomizationWidget.h"
@ -27,8 +28,8 @@ ThemeWizardPage::ThemeWizardPage(QWidget* parent) : BaseWizardPage(parent), ui(n
{
ui->setupUi(this);
connect(ui->themeCustomizationWidget, QOverload<int>::of(&ThemeCustomizationWidget::currentIconThemeChanged), this, &ThemeWizardPage::updateIcons);
connect(ui->themeCustomizationWidget, QOverload<int>::of(&ThemeCustomizationWidget::currentCatChanged), this, &ThemeWizardPage::updateCat);
connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentIconThemeChanged, this, &ThemeWizardPage::updateIcons);
connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentCatChanged, this, &ThemeWizardPage::updateCat);
updateIcons();
updateCat();
@ -39,13 +40,6 @@ ThemeWizardPage::~ThemeWizardPage()
delete ui;
}
void ThemeWizardPage::initializePage() {}
bool ThemeWizardPage::validatePage()
{
return true;
}
void ThemeWizardPage::updateIcons()
{
qDebug() << "Setting Icons";
@ -67,20 +61,7 @@ void ThemeWizardPage::updateIcons()
void ThemeWizardPage::updateCat()
{
qDebug() << "Setting Cat";
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 (std::abs(now.daysTo(xmas)) <= 4) {
cat += "-xmas";
} else if (std::abs(now.daysTo(halloween)) <= 4) {
cat += "-spooky";
} else if (std::abs(now.daysTo(birthday)) <= 12) {
cat += "-bday";
}
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(:/backgrounds/%1)").arg(cat)));
ui->catImagePreviewButton->setIcon(QIcon(QString(R"(:/backgrounds/%1)").arg(ThemeManager::getCatImage())));
}
void ThemeWizardPage::retranslate()

View File

@ -24,22 +24,20 @@ namespace Ui {
class ThemeWizardPage;
}
class ThemeWizardPage : public BaseWizardPage
{
class ThemeWizardPage : public BaseWizardPage {
Q_OBJECT
public:
explicit ThemeWizardPage(QWidget *parent = nullptr);
public:
explicit ThemeWizardPage(QWidget* parent = nullptr);
~ThemeWizardPage();
void initializePage() override;
bool validatePage() override;
bool validatePage() override { return true; };
void retranslate() override;
private slots:
private slots:
void updateIcons();
void updateCat();
private:
Ui::ThemeWizardPage *ui;
private:
Ui::ThemeWizardPage* ui;
};

View File

@ -31,13 +31,13 @@
ThemeManager::ThemeManager(MainWindow* mainWindow)
{
m_mainWindow = mainWindow;
InitializeThemes();
initializeThemes();
}
/// @brief Adds the Theme to the list of themes
/// @param theme The Theme to add
/// @return Theme ID
QString ThemeManager::AddTheme(std::unique_ptr<ITheme> theme)
QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
{
QString id = theme->id();
m_themes.emplace(id, std::move(theme));
@ -47,12 +47,12 @@ QString ThemeManager::AddTheme(std::unique_ptr<ITheme> theme)
/// @brief Gets the Theme from the List via ID
/// @param themeId Theme ID of theme to fetch
/// @return Theme at themeId
ITheme* ThemeManager::GetTheme(QString themeId)
ITheme* ThemeManager::getTheme(QString themeId)
{
return m_themes[themeId].get();
}
void ThemeManager::InitializeThemes()
void ThemeManager::initializeThemes()
{
// Icon themes
{
@ -67,10 +67,10 @@ void ThemeManager::InitializeThemes()
// Initialize widget themes
{
themeDebugLog() << "<> Initializing Widget Themes";
themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<SystemTheme>());
auto darkThemeId = AddTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<BrightTheme>());
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
// TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
// dropdown?)
@ -84,7 +84,7 @@ void ThemeManager::InitializeThemes()
if (themeJson.exists()) {
// Load "theme.json" based themes
themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), themeJson, true));
addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
} else {
// Load pure QSS Themes
QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
@ -92,7 +92,7 @@ void ThemeManager::InitializeThemes()
QFile customThemeFile(stylesheetFileIterator.next());
QFileInfo customThemeFileInfo(customThemeFile);
themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), customThemeFileInfo, false));
addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
}
}
}
@ -136,3 +136,20 @@ void ThemeManager::setApplicationTheme(const QString& name)
themeWarningLog() << "Tried to set invalid theme:" << name;
}
}
QString ThemeManager::getCatImage(QString catName)
{
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 = catName == "" ? APPLICATION->settings()->get("BackgroundCat").toString() : catName;
if (std::abs(now.daysTo(xmas)) <= 4) {
cat += "-xmas";
} else if (std::abs(now.daysTo(halloween)) <= 4) {
cat += "-spooky";
} else if (std::abs(now.daysTo(birthday)) <= 12) {
cat += "-bday";
}
return cat;
}

View File

@ -40,12 +40,13 @@ class ThemeManager {
void applyCurrentlySelectedTheme();
void setApplicationTheme(const QString& name);
static QString getCatImage(QString catName = "");
private:
std::map<QString, std::unique_ptr<ITheme>> m_themes;
MainWindow* m_mainWindow;
bool m_firstThemeInitialized;
void InitializeThemes();
QString AddTheme(std::unique_ptr<ITheme> theme);
ITheme* GetTheme(QString themeId);
void initializeThemes();
QString addTheme(std::unique_ptr<ITheme> theme);
ITheme* getTheme(QString themeId);
};

View File

@ -20,6 +20,7 @@
#include "Application.h"
#include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"
ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget)
{
@ -72,8 +73,7 @@ void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
void ThemeCustomizationWidget::applyIconTheme(int index) {
auto settings = APPLICATION->settings();
auto original = settings->get("IconTheme").toString();
// FIXME: make generic
settings->set("IconTheme", m_iconThemeOptions[index]);
settings->set("IconTheme", m_iconThemeOptions[index].first);
if (original != settings->get("IconTheme")) {
APPLICATION->applyCurrentlySelectedTheme();
@ -96,7 +96,7 @@ void ThemeCustomizationWidget::applyWidgetTheme(int index) {
void ThemeCustomizationWidget::applyCatTheme(int index) {
auto settings = APPLICATION->settings();
settings->set("BackgroundCat", m_catOptions[index]);
settings->set("BackgroundCat", m_catOptions[index].first);
emit currentCatChanged(index);
}
@ -111,9 +111,13 @@ void ThemeCustomizationWidget::loadSettings()
{
auto settings = APPLICATION->settings();
// FIXME: make generic
auto iconTheme = settings->get("IconTheme").toString();
ui->iconsComboBox->setCurrentIndex(m_iconThemeOptions.indexOf(iconTheme));
for (auto& iconThemeFromList : m_iconThemeOptions) {
ui->iconsComboBox->addItem(QIcon(QString(":/icons/%1/scalable/settings").arg(iconThemeFromList.first)), iconThemeFromList.second);
if (iconTheme == iconThemeFromList.first) {
ui->iconsComboBox->setCurrentIndex(ui->iconsComboBox->count() - 1);
}
}
{
auto currentTheme = settings->get("ApplicationTheme").toString();
@ -129,7 +133,13 @@ void ThemeCustomizationWidget::loadSettings()
}
auto cat = settings->get("BackgroundCat").toString();
ui->backgroundCatComboBox->setCurrentIndex(m_catOptions.indexOf(cat));
for (auto& catFromList : m_catOptions) {
ui->backgroundCatComboBox->addItem(QIcon(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage(catFromList.first))),
catFromList.second);
if (cat == catFromList.first) {
ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
}
}
}
void ThemeCustomizationWidget::retranslate()

View File

@ -18,25 +18,19 @@
#pragma once
#include <QWidget>
#include <translations/TranslationsModel.h>
#include "translations/TranslationsModel.h"
enum ThemeFields {
NONE = 0b0000,
ICONS = 0b0001,
WIDGETS = 0b0010,
CAT = 0b0100
};
enum ThemeFields { NONE = 0b0000, ICONS = 0b0001, WIDGETS = 0b0010, CAT = 0b0100 };
namespace Ui {
class ThemeCustomizationWidget;
}
class ThemeCustomizationWidget : public QWidget
{
class ThemeCustomizationWidget : public QWidget {
Q_OBJECT
public:
explicit ThemeCustomizationWidget(QWidget *parent = nullptr);
public:
explicit ThemeCustomizationWidget(QWidget* parent = nullptr);
~ThemeCustomizationWidget();
void showFeatures(ThemeFields features);
@ -45,21 +39,39 @@ public:
void loadSettings();
void retranslate();
Ui::ThemeCustomizationWidget *ui;
private slots:
private slots:
void applyIconTheme(int index);
void applyWidgetTheme(int index);
void applyCatTheme(int index);
signals:
signals:
int currentIconThemeChanged(int index);
int currentWidgetThemeChanged(int index);
int currentCatChanged(int index);
private:
private:
Ui::ThemeCustomizationWidget* ui;
QStringList m_iconThemeOptions{ "pe_colored", "pe_light", "pe_dark", "pe_blue", "breeze_light", "breeze_dark", "OSX", "iOS", "flat", "flat_white", "multimc", "custom" };
QStringList m_catOptions{ "kitteh", "rory", "rory-flat" };
};
//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)") }
};
};

View File

@ -50,66 +50,6 @@
<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">
@ -156,26 +96,6 @@
<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>