UX tweak + formatting + added cat to wizard
Signed-off-by: Tayou <tayou@gmx.net>
This commit is contained in:
parent
1b80ae0fca
commit
49d317b19a
@ -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"(
|
||||
|
@ -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);
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void updateIcons();
|
||||
void updateCat();
|
||||
|
||||
private:
|
||||
Ui::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">
|
||||
@ -309,6 +309,28 @@
|
||||
</item>
|
||||
</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">
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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" };
|
||||
};
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user