diff src/gui/theme.cc @ 279:657fda1b9cac

*: clean up enums
author Paper <paper@paper.us.eu.org>
date Fri, 19 Apr 2024 13:24:06 -0400
parents 862d0d8619f6
children 9a88e1725fd2
line wrap: on
line diff
--- a/src/gui/theme.cc	Thu Apr 18 17:24:42 2024 -0400
+++ b/src/gui/theme.cc	Fri Apr 19 13:24:06 2024 -0400
@@ -1,13 +1,15 @@
 #include "core/config.h"
 #include "core/session.h"
+#include "gui/theme.h"
 #include <QApplication>
 #include <QDebug>
 #include <QFile>
 #include <QStyleFactory>
 #include <QTextStream>
+#include <QStyle>
 #ifdef MACOSX
 #	include "sys/osx/dark_theme.h"
-#elif WIN32
+#elif defined(WIN32)
 #	include "sys/win32/dark_theme.h"
 #else
 #	ifdef GLIB
@@ -24,32 +26,34 @@
 
 namespace Theme {
 
-Theme::Theme(Themes theme) {
+ThemeManager::ThemeManager(Theme theme) {
 	this->theme = theme;
 }
 
-Themes Theme::GetTheme() const {
+Theme ThemeManager::GetTheme() const {
 	return theme;
 }
 
-bool Theme::IsInDarkTheme() const {
-	if (theme != Themes::OS)
-		return (theme == Themes::DARK);
+bool ThemeManager::IsInDarkTheme() const {
+	switch (theme) {
+		case Theme::Default:
 #ifdef MACOSX
-	if (osx::DarkThemeAvailable())
-		return osx::IsInDarkTheme();
+			if (osx::DarkThemeAvailable())
+				return osx::IsInDarkTheme();
 #elif defined(WIN32)
-	if (win32::DarkThemeAvailable())
-		return win32::IsInDarkTheme();
+			if (win32::DarkThemeAvailable())
+				return win32::IsInDarkTheme();
 #else
 #	ifdef GLIB
-	return glib::IsInDarkTheme();
+			return glib::IsInDarkTheme();
 #	endif
 #endif
-	return (theme == Themes::DARK);
+		default: break;
+	}
+	return (theme == Theme::Dark);
 }
 
-void Theme::SetToDarkTheme() {
+void ThemeManager::SetToDarkTheme() {
 	/* macOS >= 10.14 has its own global dark theme,
 	   use it :) */
 #ifdef MACOSX
@@ -60,10 +64,10 @@
 	if (win32::DarkThemeAvailable())
 		win32::SetTitleBarsToBlack(true);
 #endif
-		SetStyleSheet(Themes::DARK);
+		SetStyleSheet(Theme::Dark);
 }
 
-void Theme::SetToLightTheme() {
+void ThemeManager::SetToLightTheme() {
 #ifdef MACOSX
 	if (osx::DarkThemeAvailable())
 		osx::SetToLightTheme();
@@ -72,22 +76,17 @@
 	if (win32::DarkThemeAvailable())
 		win32::SetTitleBarsToBlack(false);
 #endif
-		SetStyleSheet(Themes::LIGHT);
+		SetStyleSheet(Theme::Light);
 }
 
-Themes Theme::GetCurrentOSTheme() const {
-	return IsInDarkTheme() ? Themes::DARK : Themes::LIGHT;
-
-	/* 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) */
-	return Themes::LIGHT;
+Theme ThemeManager::GetCurrentOSTheme() const {
+	return IsInDarkTheme() ? Theme::Dark : Theme::Light;
 }
 
 /* this function is private, and should stay that way */
-void Theme::SetStyleSheet(Themes theme) {
+void ThemeManager::SetStyleSheet(Theme theme) {
 	switch (theme) {
-		case Themes::DARK: {
+		case Theme::Dark: {
 			const QColor darkGray(53, 53, 53);
 			const QColor gray(128, 128, 128);
 			const QColor black(25, 25, 25);
@@ -127,8 +126,7 @@
 			break;
 		}
 		default:
-			/* this sucks, it relies on the standard palette which
-			 * may or may not be a dark style itself. */
+			/* this sucks. */
 			QPalette pal(QApplication::style()->standardPalette());
 #ifdef WIN32 /* fuck you Qt 6 */
 			pal.setColor(QPalette::Window, QColor(0xF0, 0xF0, 0xF0));
@@ -140,12 +138,12 @@
 	}
 }
 
-void Theme::SetTheme(Themes theme) {
+void ThemeManager::SetTheme(Theme theme) {
 	switch (theme) {
-		case Themes::LIGHT: SetToLightTheme(); break;
-		case Themes::DARK: SetToDarkTheme(); break;
-		case Themes::OS:
-			if (GetCurrentOSTheme() == Themes::LIGHT)
+		case Theme::Light: SetToLightTheme(); break;
+		case Theme::Dark: SetToDarkTheme(); break;
+		case Theme::Default:
+			if (GetCurrentOSTheme() == Theme::Light)
 				SetToLightTheme();
 			else
 				SetToDarkTheme();
@@ -154,8 +152,8 @@
 	this->theme = theme;
 }
 
-void Theme::RepaintCurrentTheme() {
-	Theme::SetTheme(theme);
+void ThemeManager::RepaintCurrentTheme() {
+	SetTheme(theme);
 }
 
 } // namespace Theme