From 367920ef80b48a5aa52480a571c5a587668b1422 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Wed, 8 Sep 2021 11:49:30 +0200 Subject: [PATCH] UI: Use the new theming system to set Vivy's theme --- src/VivyApplication.cc | 15 +++++++++++++-- src/VivyApplication.hh | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/VivyApplication.cc b/src/VivyApplication.cc index efb10c01..15be1249 100644 --- a/src/VivyApplication.cc +++ b/src/VivyApplication.cc @@ -1,5 +1,6 @@ #include "VivyApplication.hh" #include "UI/MainWindow.hh" +#include "UI/Theme/Theme.hh" using namespace Vivy; @@ -8,12 +9,22 @@ VivyApplication::VivyApplication(int &argc, char **argv) { } +VivyApplication::~VivyApplication() noexcept {} + void VivyApplication::setTheme(Theme theme) noexcept { if (theme == Theme::System) return; + else if (theme == Theme::QtCreator) { + qtCreatorThemePtr.reset(new Vivy::Theme("QtCreator")); + QSettings settings(QStringLiteral(":theme/design.creatortheme"), QSettings::IniFormat); + qtCreatorThemePtr->readSettings(&settings); + qtCreatorThemePtr->applyToApplication(); + return; + } + const QString sheet = theme == Theme::Dark ? QStringLiteral(":qdarkstyle/dark/style.qss") : QStringLiteral(":qdarkstyle/light/style.qss"); @@ -46,8 +57,8 @@ VivyApplication::exec() noexcept setAttribute(Qt::AA_DontShowIconsInMenus, false); setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false); setFont(getApplicationFont(Font::Default)); - setTheme(Theme::Dark); // TODO: Set system theme for now (because we - // don't have a central theme provider). + setTheme(Theme::QtCreator); // TODO: Set system theme for now (because we + // don't have a central theme provider). // Cursor blinking setCursorFlashTime(0); diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh index 0bfa830a..f9e24ec6 100644 --- a/src/VivyApplication.hh +++ b/src/VivyApplication.hh @@ -36,6 +36,7 @@ namespace Vivy { class MainWindow; +class Theme; // Vivy application class class VivyApplication : public QApplication { @@ -54,7 +55,7 @@ public: DefaultBoldItalic }; - enum class Theme { System, Dark, Light }; + enum class Theme { System, Dark, Light, QtCreator }; private: int fontIdMonospace; @@ -64,11 +65,13 @@ private: int fontIdBold; int fontIdBoldItalic; + std::unique_ptr<Vivy::Theme> qtCreatorThemePtr{ nullptr }; std::unique_ptr<MainWindow> mainWindowPtr{ nullptr }; bool useFakeVim{ false }; public: VivyApplication(int &argc, char **argv); + ~VivyApplication() noexcept override; int exec() noexcept; -- GitLab