From 827e3b734cbfe30d6f9aae63d7df67a333d38a94 Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Sun, 24 Feb 2019 16:22:59 +0200 Subject: [PATCH] refactor: edit variables for themes --- src/widget/style.cpp | 34 ++++++++++++++++++++++++---------- src/widget/style.h | 14 +++++++++++++- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/widget/style.cpp b/src/widget/style.cpp index 69fe0a830..85c27ff0a 100644 --- a/src/widget/style.cpp +++ b/src/widget/style.cpp @@ -89,11 +89,28 @@ static QMap dictColor; static QMap dictFont; static QMap dictTheme; +QList Style::themeNameColors = { + {Style::Light, QObject::tr("Default"), QColor()}, + {Style::Light, QObject::tr("Blue"), QColor("#004aa4")}, + {Style::Light, QObject::tr("Olive"), QColor("#97ba00")}, + {Style::Light, QObject::tr("Red"), QColor("#c23716")}, + {Style::Light, QObject::tr("Violet"), QColor("#4617b5")}, + {Style::Dark, QObject::tr("Dark"), QColor()}, + {Style::Dark, QObject::tr("Dark blue"), QColor("#00336d")}, + {Style::Dark, QObject::tr("Dark olive"), QColor("#4d5f00")}, + {Style::Dark, QObject::tr("Dark red"), QColor("#7a210d")}, + {Style::Dark, QObject::tr("Dark violet"), QColor("#280d6c")} +}; + QStringList Style::getThemeColorNames() { - return {QObject::tr("Default"), QObject::tr("Blue"), QObject::tr("Olive"), QObject::tr("Red"), - QObject::tr("Violet"), QObject::tr("Dark"), QObject::tr("Dark blue"), QObject::tr("Dark olive"), - QObject::tr("Dark red"), QObject::tr("Dark violet")}; + QStringList l; + + for (auto t : themeNameColors) { + l << t.name; + } + + return l; } QString Style::getThemeName() @@ -118,10 +135,6 @@ QString Style::getThemeFolder() return fullPath % QDir::separator(); } -QList Style::themeColorColors = {QColor(), QColor("#004aa4"), QColor("#97ba00"), - QColor("#c23716"), QColor("#4617b5"), - QColor(), QColor("#00336d"), QColor("#4d5f00"), - QColor("#7a210d"), QColor("#280d6c")}; QMap Style::aliasColors = {{Green, "green"}, {Yellow, "yellow"}, @@ -318,10 +331,10 @@ void Style::setThemeColor(int color) dictColor.clear(); initPalette(); initDictColor(); - if (color < 0 || color >= themeColorColors.size()) + if (color < 0 || color >= themeNameColors.size()) setThemeColor(QColor()); else - setThemeColor(themeColorColors[color]); + setThemeColor(themeNameColors[color].color); } /** @@ -404,7 +417,8 @@ void Style::initDictColor() QString Style::getThemePath() { - if (Settings::getInstance().getThemeColor() > 4) { + const int num = Settings::getInstance().getThemeColor(); + if (themeNameColors[num].type == Dark) { return BuiltinThemeDarkPath; } diff --git a/src/widget/style.h b/src/widget/style.h index 0c3eb50fd..b41ba8cd1 100644 --- a/src/widget/style.h +++ b/src/widget/style.h @@ -59,6 +59,18 @@ public: SmallLight }; + enum MainTheme + { + Light, + Dark + }; + + struct ThemeNameColor { + MainTheme type; + QString name; + QColor color; + }; + static QStringList getThemeColorNames(); static const QString getStylesheet(const QString& filename, const QFont& baseFont = QFont()); static const QString getImagePath(const QString& filename); @@ -83,7 +95,7 @@ private: Style(); private: - static QList themeColorColors; + static QList themeNameColors; static std::map, const QString> stylesheetsCache; static QMap aliasColors; };