From 96fb877ede3f4fb1f746a939d89050eddba5ff1b 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 | 17 ++++++++++++++---
 src/VivyApplication.hh |  7 +++++--
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/VivyApplication.cc b/src/VivyApplication.cc
index d474fca4..08f2b2ac 100644
--- a/src/VivyApplication.cc
+++ b/src/VivyApplication.cc
@@ -1,6 +1,7 @@
 #include "VivyApplication.hh"
 #include "UI/MainWindow.hh"
 #include "UI/DockWidgetTitleBar.hh"
+#include "UI/Theme/Theme.hh"
 #include "Lib/Document/VivyDocumentStore.hh"
 #include "Lib/Document/VivyDocument.hh"
 #include "Lib/Script/ScriptStore.hh"
@@ -40,6 +41,8 @@ VivyApplication::VivyApplication(int &argc, char **argv)
     }
 }
 
+VivyApplication::~VivyApplication() noexcept {}
+
 void
 VivyApplication::setTheme(Theme theme) noexcept
 {
@@ -48,6 +51,14 @@ VivyApplication::setTheme(Theme theme) noexcept
         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");
 
@@ -82,8 +93,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);
@@ -105,7 +116,7 @@ VivyApplication::exec() noexcept
 
     case ApplicationType::GUI: {
         // Show the main window, also set up the log console
-        mainWindowPtr               = std::make_shared<MainWindow>();
+        mainWindowPtr               = std::make_unique<MainWindow>();
         QDockWidget *logConsoleDock = new QDockWidget("Console", mainWindowPtr.get());
         LogConsole *logConsole      = new LogConsole(mainWindowPtr.get());
         std::shared_ptr<ConsoleLogSinkDispatcher> consoleLogSinkDispatcher =
diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh
index 654989b1..1d416441 100644
--- a/src/VivyApplication.hh
+++ b/src/VivyApplication.hh
@@ -50,6 +50,7 @@ class VivyDocumentStore;
 class AbstractDocument;
 class ScriptDocument;
 class VivyDocument;
+class Theme;
 
 // Vivy application class
 class VivyApplication : public QApplication {
@@ -73,7 +74,7 @@ public:
         DefaultBoldItalic
     };
 
-    enum class Theme { System, Dark, Light };
+    enum class Theme { System, Dark, Light, QtCreator };
 
 private:
     int fontIdMonospace;
@@ -83,7 +84,8 @@ private:
     int fontIdBold;
     int fontIdBoldItalic;
 
-    std::shared_ptr<MainWindow> mainWindowPtr{ nullptr };
+    std::unique_ptr<Vivy::Theme> qtCreatorThemePtr{ nullptr };
+    std::unique_ptr<MainWindow> mainWindowPtr{ nullptr };
     bool useFakeVim{ false };
     ApplicationType selectedType{ ApplicationType::GUI };
 
@@ -93,6 +95,7 @@ private:
 
 public:
     VivyApplication(int &argc, char **argv);
+    ~VivyApplication() noexcept override;
 
     int exec() noexcept;
 
-- 
GitLab