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 // Theming
m_settings->registerSetting("IconTheme", QString("pe_colored")); m_settings->registerSetting("IconTheme", QString("pe_colored"));
m_settings->registerSetting("ApplicationTheme", QString("system")); m_settings->registerSetting("ApplicationTheme");
m_settings->registerSetting("BackgroundCat", QString("kitteh")); m_settings->registerSetting("BackgroundCat", QString("kitteh"));
// Remembered state // Remembered state
@ -890,8 +890,8 @@ bool Application::createSetupWizard()
return false; return false;
}(); }();
bool pasteInterventionRequired = settings()->get("PastebinURL") != ""; bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
bool themeInterventionRequired = settings()->get("ApplicationTheme") != ""; bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired; bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
if(wizardRequired) if(wizardRequired)
{ {
@ -913,6 +913,7 @@ bool Application::createSetupWizard()
if (themeInterventionRequired) if (themeInterventionRequired)
{ {
settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard)); m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
} }
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished); connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);

View File

@ -111,6 +111,7 @@
#include "ui/dialogs/ExportInstanceDialog.h" #include "ui/dialogs/ExportInstanceDialog.h"
#include "ui/dialogs/ImportResourcePackDialog.h" #include "ui/dialogs/ImportResourcePackDialog.h"
#include "ui/themes/ITheme.h" #include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"
#include <minecraft/mod/ResourcePackFolderModel.h> #include <minecraft/mod/ResourcePackFolderModel.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h> #include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
@ -1654,20 +1655,7 @@ void MainWindow::onCatToggled(bool state)
void MainWindow::setCatBackground(bool enabled) void MainWindow::setCatBackground(bool enabled)
{ {
if (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";
}
view->setStyleSheet(QString(R"( view->setStyleSheet(QString(R"(
InstanceView InstanceView
{ {
@ -1678,10 +1666,8 @@ InstanceView
background-repeat: none; background-repeat: none;
background-color:palette(base); background-color:palette(base);
})") })")
.arg(cat)); .arg(ThemeManager::getCatImage()));
} } else {
else
{
view->setStyleSheet(QString()); view->setStyleSheet(QString());
} }
} }

View File

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

View File

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

View File

@ -31,13 +31,13 @@
ThemeManager::ThemeManager(MainWindow* mainWindow) ThemeManager::ThemeManager(MainWindow* mainWindow)
{ {
m_mainWindow = mainWindow; m_mainWindow = mainWindow;
InitializeThemes(); initializeThemes();
} }
/// @brief Adds the Theme to the list of themes /// @brief Adds the Theme to the list of themes
/// @param theme The Theme to add /// @param theme The Theme to add
/// @return Theme ID /// @return Theme ID
QString ThemeManager::AddTheme(std::unique_ptr<ITheme> theme) QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
{ {
QString id = theme->id(); QString id = theme->id();
m_themes.emplace(id, std::move(theme)); 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 /// @brief Gets the Theme from the List via ID
/// @param themeId Theme ID of theme to fetch /// @param themeId Theme ID of theme to fetch
/// @return Theme at themeId /// @return Theme at themeId
ITheme* ThemeManager::GetTheme(QString themeId) ITheme* ThemeManager::getTheme(QString themeId)
{ {
return m_themes[themeId].get(); return m_themes[themeId].get();
} }
void ThemeManager::InitializeThemes() void ThemeManager::initializeThemes()
{ {
// Icon themes // Icon themes
{ {
@ -67,10 +67,10 @@ void ThemeManager::InitializeThemes()
// Initialize widget themes // Initialize widget themes
{ {
themeDebugLog() << "<> Initializing Widget Themes"; themeDebugLog() << "<> Initializing Widget Themes";
themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<SystemTheme>()); themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
auto darkThemeId = AddTheme(std::make_unique<DarkTheme>()); auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; 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 // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
// dropdown?) // dropdown?)
@ -84,7 +84,7 @@ void ThemeManager::InitializeThemes()
if (themeJson.exists()) { if (themeJson.exists()) {
// Load "theme.json" based themes // Load "theme.json" based themes
themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath(); 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 { } else {
// Load pure QSS Themes // Load pure QSS Themes
QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files); QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
@ -92,7 +92,7 @@ void ThemeManager::InitializeThemes()
QFile customThemeFile(stylesheetFileIterator.next()); QFile customThemeFile(stylesheetFileIterator.next());
QFileInfo customThemeFileInfo(customThemeFile); QFileInfo customThemeFileInfo(customThemeFile);
themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath(); 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; 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 applyCurrentlySelectedTheme();
void setApplicationTheme(const QString& name); void setApplicationTheme(const QString& name);
static QString getCatImage(QString catName = "");
private: private:
std::map<QString, std::unique_ptr<ITheme>> m_themes; std::map<QString, std::unique_ptr<ITheme>> m_themes;
MainWindow* m_mainWindow; MainWindow* m_mainWindow;
bool m_firstThemeInitialized;
void InitializeThemes(); void initializeThemes();
QString AddTheme(std::unique_ptr<ITheme> theme); QString addTheme(std::unique_ptr<ITheme> theme);
ITheme* GetTheme(QString themeId); ITheme* getTheme(QString themeId);
}; };

View File

@ -20,6 +20,7 @@
#include "Application.h" #include "Application.h"
#include "ui/themes/ITheme.h" #include "ui/themes/ITheme.h"
#include "ui/themes/ThemeManager.h"
ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget) ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget)
{ {
@ -72,8 +73,7 @@ void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
void ThemeCustomizationWidget::applyIconTheme(int index) { void ThemeCustomizationWidget::applyIconTheme(int index) {
auto settings = APPLICATION->settings(); auto settings = APPLICATION->settings();
auto original = settings->get("IconTheme").toString(); auto original = settings->get("IconTheme").toString();
// FIXME: make generic settings->set("IconTheme", m_iconThemeOptions[index].first);
settings->set("IconTheme", m_iconThemeOptions[index]);
if (original != settings->get("IconTheme")) { if (original != settings->get("IconTheme")) {
APPLICATION->applyCurrentlySelectedTheme(); APPLICATION->applyCurrentlySelectedTheme();
@ -96,7 +96,7 @@ void ThemeCustomizationWidget::applyWidgetTheme(int index) {
void ThemeCustomizationWidget::applyCatTheme(int index) { void ThemeCustomizationWidget::applyCatTheme(int index) {
auto settings = APPLICATION->settings(); auto settings = APPLICATION->settings();
settings->set("BackgroundCat", m_catOptions[index]); settings->set("BackgroundCat", m_catOptions[index].first);
emit currentCatChanged(index); emit currentCatChanged(index);
} }
@ -111,9 +111,13 @@ void ThemeCustomizationWidget::loadSettings()
{ {
auto settings = APPLICATION->settings(); auto settings = APPLICATION->settings();
// FIXME: make generic
auto iconTheme = settings->get("IconTheme").toString(); 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(); auto currentTheme = settings->get("ApplicationTheme").toString();
@ -129,7 +133,13 @@ void ThemeCustomizationWidget::loadSettings()
} }
auto cat = settings->get("BackgroundCat").toString(); 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() void ThemeCustomizationWidget::retranslate()

View File

@ -18,25 +18,19 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <translations/TranslationsModel.h> #include "translations/TranslationsModel.h"
enum ThemeFields { enum ThemeFields { NONE = 0b0000, ICONS = 0b0001, WIDGETS = 0b0010, CAT = 0b0100 };
NONE = 0b0000,
ICONS = 0b0001,
WIDGETS = 0b0010,
CAT = 0b0100
};
namespace Ui { namespace Ui {
class ThemeCustomizationWidget; class ThemeCustomizationWidget;
} }
class ThemeCustomizationWidget : public QWidget class ThemeCustomizationWidget : public QWidget {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ThemeCustomizationWidget(QWidget *parent = nullptr); explicit ThemeCustomizationWidget(QWidget* parent = nullptr);
~ThemeCustomizationWidget(); ~ThemeCustomizationWidget();
void showFeatures(ThemeFields features); void showFeatures(ThemeFields features);
@ -45,21 +39,39 @@ public:
void loadSettings(); void loadSettings();
void retranslate(); void retranslate();
Ui::ThemeCustomizationWidget *ui;
private slots: private slots:
void applyIconTheme(int index); void applyIconTheme(int index);
void applyWidgetTheme(int index); void applyWidgetTheme(int index);
void applyCatTheme(int index); void applyCatTheme(int index);
signals: signals:
int currentIconThemeChanged(int index); int currentIconThemeChanged(int index);
int currentWidgetThemeChanged(int index); int currentWidgetThemeChanged(int index);
int currentCatChanged(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" }; //TODO finish implementing
QStringList m_catOptions{ "kitteh", "rory", "rory-flat" }; 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"> <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </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> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
@ -156,26 +96,6 @@
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </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> </widget>
</item> </item>
</layout> </layout>