diff options
author | Tayou <tayou@gmx.net> | 2023-01-09 16:54:10 +0100 |
---|---|---|
committer | Tayou <tayou@gmx.net> | 2023-01-10 16:06:24 +0100 |
commit | 49d317b19aa61fed056e0f14c12eb1997f68982d (patch) | |
tree | 0a6f62b069814138160f40508630edafd9b9763a /launcher/ui | |
parent | 1b80ae0fca5e41d8caaa7d77d19faa9826752143 (diff) | |
download | PrismLauncher-49d317b19aa61fed056e0f14c12eb1997f68982d.tar.gz PrismLauncher-49d317b19aa61fed056e0f14c12eb1997f68982d.tar.bz2 PrismLauncher-49d317b19aa61fed056e0f14c12eb1997f68982d.zip |
UX tweak + formatting + added cat to wizard
Signed-off-by: Tayou <tayou@gmx.net>
Diffstat (limited to 'launcher/ui')
-rw-r--r-- | launcher/ui/MainWindow.cpp | 16 | ||||
-rw-r--r-- | launcher/ui/setupwizard/ThemeWizardPage.cpp | 39 | ||||
-rw-r--r-- | launcher/ui/setupwizard/ThemeWizardPage.h | 1 | ||||
-rw-r--r-- | launcher/ui/setupwizard/ThemeWizardPage.ui | 26 | ||||
-rw-r--r-- | launcher/ui/themes/CustomTheme.cpp | 31 | ||||
-rw-r--r-- | launcher/ui/themes/ITheme.h | 12 | ||||
-rw-r--r-- | launcher/ui/themes/SystemTheme.cpp | 12 | ||||
-rw-r--r-- | launcher/ui/themes/SystemTheme.h | 8 | ||||
-rw-r--r-- | launcher/ui/themes/ThemeManager.h | 4 | ||||
-rw-r--r-- | launcher/ui/widgets/ThemeCustomizationWidget.cpp | 79 | ||||
-rw-r--r-- | launcher/ui/widgets/ThemeCustomizationWidget.h | 1 | ||||
-rw-r--r-- | launcher/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 <typename T> -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<int>::of(&ThemeCustomizationWidget::currentIconThemeChanged), this, &ThemeWizardPage::updateIcons);
+ connect(ui->themeCustomizationWidget, QOverload<int>::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 @@ <rect>
<x>0</x>
<y>0</y>
- <width>400</width>
- <height>300</height>
+ <width>510</width>
+ <height>552</height>
</rect>
</property>
<property name="windowTitle">
@@ -310,6 +310,28 @@ </layout>
</item>
<item>
+ <widget class="QPushButton" name="catImagePreviewButton">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>256</height>
+ </size>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>256</width>
+ <height>256</height>
+ </size>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
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 <QString> #include <QPalette> +#include <QString> 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 <QApplication> +#include <QDebug> #include <QStyle> #include <QStyleFactory> -#include <QDebug> #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<ITheme*> 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<ITheme> 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;
}
+/// <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->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 @@ </rect>
</property>
<property name="windowTitle">
- <string>Form</string>
+ <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>
|