From 49d317b19aa61fed056e0f14c12eb1997f68982d Mon Sep 17 00:00:00 2001 From: Tayou Date: Mon, 9 Jan 2023 16:54:10 +0100 Subject: [PATCH] UX tweak + formatting + added cat to wizard Signed-off-by: Tayou --- launcher/ui/MainWindow.cpp | 16 +--- launcher/ui/setupwizard/ThemeWizardPage.cpp | 39 ++++++--- launcher/ui/setupwizard/ThemeWizardPage.h | 1 + launcher/ui/setupwizard/ThemeWizardPage.ui | 26 +++++- launcher/ui/themes/CustomTheme.cpp | 31 +++----- launcher/ui/themes/ITheme.h | 12 +-- launcher/ui/themes/SystemTheme.cpp | 12 ++- launcher/ui/themes/SystemTheme.h | 8 +- launcher/ui/themes/ThemeManager.h | 4 +- .../ui/widgets/ThemeCustomizationWidget.cpp | 79 ++++++++++--------- .../ui/widgets/ThemeCustomizationWidget.h | 1 + .../ui/widgets/ThemeCustomizationWidget.ui | 5 +- 12 files changed, 127 insertions(+), 107 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 331ca0e1..a921e378 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1652,16 +1652,6 @@ void MainWindow::onCatToggled(bool state) APPLICATION->settings()->set("TheCat", state); } -namespace { -template -T non_stupid_abs(T in) -{ - if (in < 0) - return -in; - return in; -} -} - void MainWindow::setCatBackground(bool enabled) { if (enabled) @@ -1671,11 +1661,11 @@ void MainWindow::setCatBackground(bool enabled) 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 (non_stupid_abs(now.daysTo(xmas)) <= 4) { + if (std::abs(now.daysTo(xmas)) <= 4) { cat += "-xmas"; - } else if (non_stupid_abs(now.daysTo(halloween)) <= 4) { + } else if (std::abs(now.daysTo(halloween)) <= 4) { cat += "-spooky"; - } else if (non_stupid_abs(now.daysTo(birthday)) <= 12) { + } else if (std::abs(now.daysTo(birthday)) <= 12) { cat += "-bday"; } view->setStyleSheet(QString(R"( diff --git a/launcher/ui/setupwizard/ThemeWizardPage.cpp b/launcher/ui/setupwizard/ThemeWizardPage.cpp index 6f041134..4e1eb488 100644 --- a/launcher/ui/setupwizard/ThemeWizardPage.cpp +++ b/launcher/ui/setupwizard/ThemeWizardPage.cpp @@ -23,31 +23,31 @@ #include "ui/widgets/ThemeCustomizationWidget.h" #include "ui_ThemeCustomizationWidget.h" -ThemeWizardPage::ThemeWizardPage(QWidget *parent) : -BaseWizardPage(parent), -ui(new Ui::ThemeWizardPage) { +ThemeWizardPage::ThemeWizardPage(QWidget* parent) : BaseWizardPage(parent), ui(new Ui::ThemeWizardPage) +{ ui->setupUi(this); - ui->themeCustomizationWidget->showFeatures((ThemeFields)(ThemeFields::ICONS | ThemeFields::WIDGETS)); connect(ui->themeCustomizationWidget, QOverload::of(&ThemeCustomizationWidget::currentIconThemeChanged), this, &ThemeWizardPage::updateIcons); + connect(ui->themeCustomizationWidget, QOverload::of(&ThemeCustomizationWidget::currentCatChanged), this, &ThemeWizardPage::updateCat); updateIcons(); + updateCat(); } -ThemeWizardPage::~ThemeWizardPage() { -delete ui; -} - -void ThemeWizardPage::initializePage() +ThemeWizardPage::~ThemeWizardPage() { + delete ui; } +void ThemeWizardPage::initializePage() {} + bool ThemeWizardPage::validatePage() { return true; } -void ThemeWizardPage::updateIcons() { +void ThemeWizardPage::updateIcons() +{ qDebug() << "Setting Icons"; ui->previewIconButton0->setIcon(APPLICATION->getThemedIcon("new")); ui->previewIconButton1->setIcon(APPLICATION->getThemedIcon("centralmods")); @@ -64,6 +64,25 @@ void ThemeWizardPage::updateIcons() { parentWidget()->update(); } +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))); +} + void ThemeWizardPage::retranslate() { ui->retranslateUi(this); diff --git a/launcher/ui/setupwizard/ThemeWizardPage.h b/launcher/ui/setupwizard/ThemeWizardPage.h index 10913d1b..6562ad2e 100644 --- a/launcher/ui/setupwizard/ThemeWizardPage.h +++ b/launcher/ui/setupwizard/ThemeWizardPage.h @@ -38,6 +38,7 @@ public: private slots: void updateIcons(); + void updateCat(); private: Ui::ThemeWizardPage *ui; diff --git a/launcher/ui/setupwizard/ThemeWizardPage.ui b/launcher/ui/setupwizard/ThemeWizardPage.ui index b743644f..95b0f805 100644 --- a/launcher/ui/setupwizard/ThemeWizardPage.ui +++ b/launcher/ui/setupwizard/ThemeWizardPage.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 510 + 552 @@ -309,6 +309,28 @@ + + + + + 0 + 256 + + + + + + + + 256 + 256 + + + + true + + + diff --git a/launcher/ui/themes/CustomTheme.cpp b/launcher/ui/themes/CustomTheme.cpp index 3ad61668..198e76ba 100644 --- a/launcher/ui/themes/CustomTheme.cpp +++ b/launcher/ui/themes/CustomTheme.cpp @@ -167,8 +167,6 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest if (!FS::ensureFolderPathExists(path) || !FS::ensureFolderPathExists(pathResources)) { themeWarningLog() << "couldn't create folder for theme!"; - m_palette = baseTheme->colorScheme(); - m_styleSheet = baseTheme->appStyleSheet(); return; } @@ -177,18 +175,15 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest bool jsonDataIncomplete = false; m_palette = baseTheme->colorScheme(); - if (!readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) { - themeDebugLog() << "Did not read theme json file correctly, writing new one to: " << themeFilePath; - m_name = "Custom"; - m_palette = baseTheme->colorScheme(); - m_fadeColor = baseTheme->fadeColor(); - m_fadeAmount = baseTheme->fadeAmount(); - m_widgets = baseTheme->qtTheme(); - m_qssFilePath = "themeStyle.css"; - } else { + if (readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) { + // If theme data was found, fade "Disabled" color of each role according to FadeAmount m_palette = fadeInactive(m_palette, m_fadeAmount, m_fadeColor); + } else { + themeDebugLog() << "Did not read theme json file correctly, not changing theme, keeping previous."; + return; } + // FIXME: This is kinda jank, it only actually checks if the qss file path is not present. It should actually check for any relevant missing data (e.g. name, colors) if (jsonDataIncomplete) { writeThemeJson(fileInfo.absoluteFilePath(), m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath); } @@ -197,20 +192,14 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest QFileInfo info(qssFilePath); if (info.isFile()) { try { - // TODO: validate css? + // TODO: validate qss? m_styleSheet = QString::fromUtf8(FS::read(qssFilePath)); } catch (const Exception& e) { - themeWarningLog() << "Couldn't load css:" << e.cause() << "from" << qssFilePath; - m_styleSheet = baseTheme->appStyleSheet(); + themeWarningLog() << "Couldn't load qss:" << e.cause() << "from" << qssFilePath; + return; } } else { - themeDebugLog() << "No theme css present."; - m_styleSheet = baseTheme->appStyleSheet(); - try { - FS::write(qssFilePath, m_styleSheet.toUtf8()); - } catch (const Exception& e) { - themeWarningLog() << "Couldn't write css:" << e.cause() << "to" << qssFilePath; - } + themeDebugLog() << "No theme qss present."; } } else { m_id = fileInfo.fileName(); diff --git a/launcher/ui/themes/ITheme.h b/launcher/ui/themes/ITheme.h index bb5c8afe..2e5b7f25 100644 --- a/launcher/ui/themes/ITheme.h +++ b/launcher/ui/themes/ITheme.h @@ -33,14 +33,13 @@ * limitations under the License. */ #pragma once -#include #include +#include class QStyle; -class ITheme -{ -public: +class ITheme { + public: virtual ~ITheme() {} virtual void apply(); virtual QString id() = 0; @@ -52,10 +51,7 @@ public: virtual QPalette colorScheme() = 0; virtual QColor fadeColor() = 0; virtual double fadeAmount() = 0; - virtual QStringList searchPaths() - { - return {}; - } + virtual QStringList searchPaths() { return {}; } static QPalette fadeInactive(QPalette in, qreal bias, QColor color); }; diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index d6ef442b..24875e33 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -34,24 +34,22 @@ */ #include "SystemTheme.h" #include +#include #include #include -#include #include "ThemeManager.h" SystemTheme::SystemTheme() { themeDebugLog() << "Determining System Theme..."; - const auto & style = QApplication::style(); + const auto& style = QApplication::style(); systemPalette = style->standardPalette(); QString lowerThemeName = style->objectName(); themeDebugLog() << "System theme seems to be:" << lowerThemeName; QStringList styles = QStyleFactory::keys(); - for(auto &st: styles) - { + for (auto& st : styles) { themeDebugLog() << "Considering theme from theme factory:" << st.toLower(); - if(st.toLower() == lowerThemeName) - { + if (st.toLower() == lowerThemeName) { systemTheme = st; themeDebugLog() << "System theme has been determined to be:" << systemTheme; return; @@ -99,7 +97,7 @@ double SystemTheme::fadeAmount() QColor SystemTheme::fadeColor() { - return QColor(128,128,128); + return QColor(128, 128, 128); } bool SystemTheme::hasStyleSheet() diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h index 5c9216eb..b5c03def 100644 --- a/launcher/ui/themes/SystemTheme.h +++ b/launcher/ui/themes/SystemTheme.h @@ -36,9 +36,8 @@ #include "ITheme.h" -class SystemTheme: public ITheme -{ -public: +class SystemTheme : public ITheme { + public: SystemTheme(); virtual ~SystemTheme() {} void apply() override; @@ -52,7 +51,8 @@ public: QPalette colorScheme() override; double fadeAmount() override; QColor fadeColor() override; -private: + + private: QPalette systemPalette; QString systemTheme; }; diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index 0a70ddfc..bb10cd48 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -35,9 +35,6 @@ class ThemeManager { public: ThemeManager(MainWindow* mainWindow); - // maybe make private? Or put in ctor? - void InitializeThemes(); - QList getValidApplicationThemes(); void setIconTheme(const QString& name); void applyCurrentlySelectedTheme(); @@ -48,6 +45,7 @@ class ThemeManager { MainWindow* m_mainWindow; bool m_firstThemeInitialized; + void InitializeThemes(); QString AddTheme(std::unique_ptr theme); ITheme* GetTheme(QString themeId); }; diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp index 0830a030..eafcf482 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.cpp +++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp @@ -36,18 +36,40 @@ ThemeCustomizationWidget::~ThemeCustomizationWidget() delete ui; } +/// +/// 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); +/// } +/// +/// 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); + 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) { - emit currentIconThemeChanged(index); - auto settings = APPLICATION->settings(); auto original = settings->get("IconTheme").toString(); // FIXME: make generic @@ -56,11 +78,11 @@ void ThemeCustomizationWidget::applyIconTheme(int index) { if (original != settings->get("IconTheme")) { APPLICATION->applyCurrentlySelectedTheme(); } + + emit currentIconThemeChanged(index); } void ThemeCustomizationWidget::applyWidgetTheme(int index) { - emit currentWidgetThemeChanged(index); - auto settings = APPLICATION->settings(); auto originalAppTheme = settings->get("ApplicationTheme").toString(); auto newAppTheme = ui->widgetStyleComboBox->currentData().toString(); @@ -68,26 +90,15 @@ void ThemeCustomizationWidget::applyWidgetTheme(int index) { settings->set("ApplicationTheme", newAppTheme); APPLICATION->applyCurrentlySelectedTheme(); } + + emit currentWidgetThemeChanged(index); } 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; - } + settings->set("BackgroundCat", m_catOptions[index]); + + emit currentCatChanged(index); } void ThemeCustomizationWidget::applySettings() @@ -101,8 +112,8 @@ void ThemeCustomizationWidget::loadSettings() auto settings = APPLICATION->settings(); // FIXME: make generic - auto theme = settings->get("IconTheme").toString(); - ui->iconsComboBox->setCurrentIndex(m_iconThemeOptions.indexOf(theme)); + auto iconTheme = settings->get("IconTheme").toString(); + ui->iconsComboBox->setCurrentIndex(m_iconThemeOptions.indexOf(iconTheme)); { auto currentTheme = settings->get("ApplicationTheme").toString(); @@ -118,18 +129,10 @@ void ThemeCustomizationWidget::loadSettings() } 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); - } + ui->backgroundCatComboBox->setCurrentIndex(m_catOptions.indexOf(cat)); } void ThemeCustomizationWidget::retranslate() { ui->retranslateUi(this); -} \ No newline at end of file +} diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.h b/launcher/ui/widgets/ThemeCustomizationWidget.h index e17286e1..653e89e7 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.h +++ b/launcher/ui/widgets/ThemeCustomizationWidget.h @@ -61,4 +61,5 @@ signals: private: 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" }; }; diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.ui b/launcher/ui/widgets/ThemeCustomizationWidget.ui index c184b8f3..9cc5cc76 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.ui +++ b/launcher/ui/widgets/ThemeCustomizationWidget.ui @@ -11,9 +11,12 @@ - Form + Form + + QLayout::SetMinimumSize + 0