diff --git a/src/Lib/Utils.hh b/src/Lib/Utils.hh index c2ac33642dbf2cb15e435f2105bf0c19ff726369..8e954575fcd7b01d65a082640949be6cc5f1dd99 100644 --- a/src/Lib/Utils.hh +++ b/src/Lib/Utils.hh @@ -103,6 +103,12 @@ concept StringType = requires(T str) { str[0] } -> std::same_as<typename T::const_reference>; // clang-format on }; + +// Theme type +enum class ThemeType { QtCreator, System, QssFile }; + +// Prefered collor for a given type +enum class VivyThemeType { Dark, Light, ___COUNT }; } namespace Vivy::Utils diff --git a/src/UI/Theme/Theme.cc b/src/UI/Theme/Theme.cc index 31c53f16d5c53f74915227b758329ce52fa42f3c..6b2abeebddccaf0dfb6b737eb9daceb336548304 100644 --- a/src/UI/Theme/Theme.cc +++ b/src/UI/Theme/Theme.cc @@ -10,8 +10,8 @@ namespace Vivy struct Theme::Private { Private() noexcept; - Theme::Type classType{ Theme::Type::System }; - Theme::VivyTheme preferedColor{ Theme::VivyTheme::Dark }; + ThemeType classType{ ThemeType::System }; + VivyThemeType preferedColor{ VivyThemeType::Dark }; QString id; QString fileName; @@ -80,7 +80,7 @@ Theme::Private::Private() noexcept void Theme::applyToApplication() const noexcept { - if (d->classType == Type::QssFile) { + if (d->classType == ThemeType::QssFile) { QFile stylesheet(d->fileName); if (!stylesheet.exists()) { qFatal("Missing stylesheet"); @@ -193,7 +193,7 @@ Theme::fromQssFile(const QString &id, const QString &file) noexcept { Theme *ret = new Theme(id); ret->d->fileName = file; - ret->d->classType = Type::QssFile; + ret->d->classType = ThemeType::QssFile; ret->setDisplayName(QFileInfo(file).baseName()); return ret; } @@ -207,11 +207,11 @@ Theme::fromSettings(const QString &id, QSettings *const settings) noexcept } Theme * -Theme::fromVivyTheme(const QString &id, const VivyTheme which) noexcept +Theme::fromVivyTheme(const QString &id, const VivyThemeType which) noexcept { - Theme *ret = - fromQssFile(id, which == VivyTheme::Dark ? QStringLiteral(":qdarkstyle/dark/style.qss") - : QStringLiteral(":qdarkstyle/light/style.qss")); + Theme *ret = fromQssFile(id, which == VivyThemeType::Dark + ? QStringLiteral(":qdarkstyle/dark/style.qss") + : QStringLiteral(":qdarkstyle/light/style.qss")); ret->setDisplayName(QStringLiteral("Vivy Theme")); return ret; } @@ -226,7 +226,7 @@ void Theme::readSettings(QSettings *const settings) noexcept { d->fileName = settings->fileName(); - d->classType = Type::QtCreator; + d->classType = ThemeType::QtCreator; const QMetaObject &m = *metaObject(); { diff --git a/src/UI/Theme/Theme.hh b/src/UI/Theme/Theme.hh index d2adc518e0498e09423311741856ab5aff30baad..532bcb6795f658e1049738e53c64adf6ae1e0afd 100644 --- a/src/UI/Theme/Theme.hh +++ b/src/UI/Theme/Theme.hh @@ -1,8 +1,8 @@ #pragma once +#include "../../VivyApplication.hh" #include "../../Lib/Utils.hh" - -// #include "../../Lib/Log.hh" +#include "../../Lib/Log.hh" namespace Vivy { @@ -11,11 +11,9 @@ class Theme; class Theme final : public QObject { Q_OBJECT + VIVY_APP_LOGGABLE_OBJECT(Theme, logger) public: - enum class Type { QtCreator, System, QssFile }; - enum class VivyTheme { Dark, Light, ___COUNT }; - struct HighlightingTheme final { const QBrush functionForeground; const QBrush keywordForeground; @@ -36,7 +34,8 @@ public: [[nodiscard("free")]] static Theme *fromQssFile(const QString &, const QString &) noexcept; [[nodiscard("free")]] static Theme *fromSettings(const QString &, QSettings *const) noexcept; - [[nodiscard("free")]] static Theme *fromVivyTheme(const QString &, const VivyTheme) noexcept; + [[nodiscard("free")]] static Theme *fromVivyTheme(const QString &, + const VivyThemeType) noexcept; void applyToApplication() const noexcept; [[nodiscard]] const HighlightingTheme &getHighlightingTheme() const noexcept; @@ -495,7 +494,7 @@ private: .enumForeground = Qt::darkMagenta, }; - const Theme::HighlightingTheme highlightingTheme[Utils::toUnderlying(VivyTheme::___COUNT)] = { + const Theme::HighlightingTheme highlightingTheme[Utils::toUnderlying(VivyThemeType::___COUNT)] = { darkHighlightingTheme, lightHighlightingTheme, }; diff --git a/src/VivyApplication.cc b/src/VivyApplication.cc index 907e02c0dca08eca00a0d7bcafee3acece9b304b..3be55a7da0ea7b285d699476804fb4e43b44bfdf 100644 --- a/src/VivyApplication.cc +++ b/src/VivyApplication.cc @@ -45,20 +45,20 @@ VivyApplication::VivyApplication(int &argc, char **argv) VivyApplication::~VivyApplication() noexcept {} void -VivyApplication::setTheme(Theme::Type theme, Theme::VivyTheme preferedColor) noexcept +VivyApplication::setTheme(ThemeType theme, VivyThemeType preferedColor) noexcept { - if (theme == Theme::Type::System) { + if (theme == ThemeType::System) { return; } - else if (theme == Theme::Type::QtCreator) { + else if (theme == ThemeType::QtCreator) { QSettings settings(QStringLiteral(":theme/design.creatortheme"), QSettings::IniFormat); qtCreatorThemePtr.reset(Vivy::Theme::fromSettings("QtCreator", &settings)); qtCreatorThemePtr->applyToApplication(); return; } - if (theme != Theme::Type::QssFile) { + if (theme != ThemeType::QssFile) { qFatal("Unknown Theme type"); } @@ -85,7 +85,7 @@ VivyApplication::exec() noexcept setAttribute(Qt::AA_DontShowIconsInMenus, false); setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false); setFont(getApplicationFont(Font::Default)); - setTheme(Theme::Type::QtCreator, Theme::VivyTheme::Dark); + setTheme(ThemeType::QtCreator, VivyThemeType::Dark); // Cursor blinking setCursorFlashTime(0); diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh index 4d67f0ec94850af9a26ec6b319108f0c6a3ef614..1546392992bb3ab29383f3c76fdf7ab79b8503e6 100644 --- a/src/VivyApplication.hh +++ b/src/VivyApplication.hh @@ -41,9 +41,9 @@ #define VIVY_MACOS 0 #endif +#include "Lib/Utils.hh" #include "Lib/Log.hh" #include "Lib/HostOsInfo.hh" -#include "UI/Theme/Theme.hh" namespace Vivy { @@ -108,7 +108,7 @@ public: [[nodiscard]] std::shared_ptr<LogSink> getLogSink() noexcept { return logSink; } void setUseFakeVimEditor(bool) noexcept; - void setTheme(Theme::Type, Theme::VivyTheme) noexcept; + void setTheme(ThemeType, VivyThemeType) noexcept; }; }