diff src/gui/window.cpp @ 46:d0adc4aedfc8

*: update... this commit: 1. consolidates dark theme stuff to dark_theme.cpp 2. creates a new widgets folder to store all of our custom widgets 3. creates the list settings page in the information dialog, although much of it is nonfunctional: it doesn't save, and the status doesn't even get filled in... we'll fix this later!
author Paper <mrpapersonic@gmail.com>
date Sat, 23 Sep 2023 01:02:15 -0400
parents 619cbd6e69f9
children e613772f41d5
line wrap: on
line diff
--- a/src/gui/window.cpp	Fri Sep 22 15:21:55 2023 -0400
+++ b/src/gui/window.cpp	Sat Sep 23 01:02:15 2023 -0400
@@ -1,12 +1,12 @@
 #include "gui/window.h"
 #include "core/config.h"
 #include "core/session.h"
+#include "gui/dark_theme.h"
 #include "gui/dialog/settings.h"
 #include "gui/pages/anime_list.h"
 #include "gui/pages/now_playing.h"
 #include "gui/pages/statistics.h"
-#include "gui/sidebar.h"
-#include "gui/ui_utils.h"
+#include "gui/widgets/sidebar.h"
 #include "services/services.h"
 #include <QApplication>
 #include <QFile>
@@ -17,7 +17,7 @@
 #include <QTextStream>
 #if MACOSX
 #	include "sys/osx/dark_theme.h"
-#elif WIN32
+#elif defined(WIN32)
 #	include "sys/win32/dark_theme.h"
 #endif
 
@@ -157,9 +157,7 @@
 	});
 
 	menu = menubar->addMenu("&Help");
-	action = menu->addAction("About &Qt", qApp, [this]{
-		qApp->aboutQt();
-	});
+	action = menu->addAction("About &Qt", qApp, [this] { qApp->aboutQt(); });
 	action->setMenuRole(QAction::AboutQtRole);
 
 	setMenuBar(menubar);
@@ -169,67 +167,7 @@
 	layout->addWidget(stack);
 	setCentralWidget(main_widget);
 
-	ThemeChanged();
-}
-
-void MainWindow::SetStyleSheet(enum Themes theme) {
-	switch (theme) {
-		case Themes::DARK: {
-			QFile f(":qdarkstyle/dark/darkstyle.qss");
-			if (!f.exists())
-				return; // fail
-			f.open(QFile::ReadOnly | QFile::Text);
-			QTextStream ts(&f);
-			setStyleSheet(ts.readAll());
-			break;
-		}
-		default: setStyleSheet(""); break;
-	}
-}
-
-void MainWindow::ThemeChanged() {
-	switch (session.config.theme) {
-		case Themes::LIGHT: {
-#if MACOSX
-			if (osx::DarkThemeAvailable())
-				osx::SetToLightTheme();
-			else
-#else
-			SetStyleSheet(Themes::LIGHT);
-#endif
-				break;
-		}
-		case Themes::DARK: {
-#if MACOSX
-			if (osx::DarkThemeAvailable())
-				osx::SetToDarkTheme();
-			else
-#else
-			SetStyleSheet(Themes::DARK);
-#endif
-				break;
-		}
-		case Themes::OS: {
-#if MACOSX
-			if (osx::DarkThemeAvailable())
-				osx::SetToAutoTheme();
-			else
-#elif defined(WIN32)
-			if (win32::DarkThemeAvailable()) {
-				if (win32::IsInDarkTheme()) {
-					SetStyleSheet(Themes::DARK);
-				} else {
-					SetStyleSheet(Themes::LIGHT);
-				}
-			} else
-#endif
-				/* Currently OS detection only supports Windows and macOS.
-				   Please don't be shy if you're willing to port it to other OSes
-				   (or desktop environments, or window managers) */
-				SetStyleSheet(Themes::LIGHT);
-			break;
-		}
-	}
+	DarkTheme::SetTheme(session.config.theme);
 }
 
 void MainWindow::SetActivePage(QWidget* page) {