Mercurial > minori
comparison src/gui/theme.cc @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 25 Jul 2025 10:16:02 -0400 |
| parents | c844f8bb87ce |
| children | 963047512d34 |
comparison
equal
deleted
inserted
replaced
| 368:6d37a998cf91 | 369:47c9f8502269 |
|---|---|
| 1 #include "gui/theme.h" | |
| 1 #include "core/config.h" | 2 #include "core/config.h" |
| 2 #include "core/session.h" | 3 #include "core/session.h" |
| 3 #include "gui/theme.h" | |
| 4 #include <QApplication> | 4 #include <QApplication> |
| 5 #include <QDebug> | 5 #include <QDebug> |
| 6 #include <QFile> | 6 #include <QFile> |
| 7 #include <QStyle> | |
| 7 #include <QStyleFactory> | 8 #include <QStyleFactory> |
| 8 #include <QTextStream> | 9 #include <QTextStream> |
| 9 #include <QStyle> | |
| 10 #include <QtGlobal> | 10 #include <QtGlobal> |
| 11 #ifdef MACOSX | 11 #ifdef MACOSX |
| 12 # include "sys/osx/dark_theme.h" | 12 # include "sys/osx/dark_theme.h" |
| 13 #elif defined(WIN32) | 13 #elif defined(WIN32) |
| 14 # include "sys/win32/dark_theme.h" | 14 # include "sys/win32/dark_theme.h" |
| 15 #else | 15 #else |
| 16 # ifdef GLIB | 16 # ifdef GLIB |
| 17 # include "sys/glib/dark_theme.h" | 17 # include "sys/glib/dark_theme.h" |
| 18 # endif | 18 # endif |
| 19 # ifdef HAVE_XCB | 19 # ifdef HAVE_XCB |
| 20 # include "sys/x11/dark_theme.h" | 20 # include "sys/x11/dark_theme.h" |
| 21 # endif | 21 # endif |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 /* Weird quirks of this implementation: | 24 /* Weird quirks of this implementation: |
| 25 * 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different | 25 * 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different |
| 26 * 2. Some widgets, i.e. QTabWidget, QTabBar, etc., just completely IGNORE the QPalette setting | 26 * 2. Some widgets, i.e. QTabWidget, QTabBar, etc., just completely IGNORE the QPalette setting |
| 28 * 3. Windows dark mode support in Qt 6.5 (with Fusion) is completely unavoidable | 28 * 3. Windows dark mode support in Qt 6.5 (with Fusion) is completely unavoidable |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 namespace Theme { | 31 namespace Theme { |
| 32 | 32 |
| 33 ThemeManager::ThemeManager(Theme theme) { | 33 ThemeManager::ThemeManager(Theme theme) |
| 34 { | |
| 34 this->theme = theme; | 35 this->theme = theme; |
| 35 } | 36 } |
| 36 | 37 |
| 37 Theme ThemeManager::GetTheme() const { | 38 Theme ThemeManager::GetTheme() const |
| 39 { | |
| 38 return theme; | 40 return theme; |
| 39 } | 41 } |
| 40 | 42 |
| 41 bool ThemeManager::IsInDarkTheme() const { | 43 bool ThemeManager::IsInDarkTheme() const |
| 44 { | |
| 42 switch (theme) { | 45 switch (theme) { |
| 43 case Theme::Default: | 46 case Theme::Default: |
| 44 #ifdef MACOSX | 47 #ifdef MACOSX |
| 45 if (osx::DarkThemeAvailable()) | 48 if (osx::DarkThemeAvailable()) |
| 46 return osx::IsInDarkTheme(); | 49 return osx::IsInDarkTheme(); |
| 47 #elif defined(WIN32) | 50 #elif defined(WIN32) |
| 48 if (win32::DarkThemeAvailable()) | 51 if (win32::DarkThemeAvailable()) |
| 49 return win32::IsInDarkTheme(); | 52 return win32::IsInDarkTheme(); |
| 50 #else | 53 #else |
| 51 # ifdef HAVE_XCB | 54 # ifdef HAVE_XCB |
| 52 if (x11::IsInDarkTheme()) | 55 if (x11::IsInDarkTheme()) |
| 53 return true; | 56 return true; |
| 54 # endif | 57 # endif |
| 55 # ifdef GLIB | 58 # ifdef GLIB |
| 56 if (glib::IsInDarkTheme()) | 59 if (glib::IsInDarkTheme()) |
| 57 return true; | 60 return true; |
| 58 # endif | 61 # endif |
| 59 break; | 62 break; |
| 60 #endif | 63 #endif |
| 61 default: | 64 default: break; |
| 62 break; | |
| 63 } | 65 } |
| 64 return (theme == Theme::Dark); | 66 return (theme == Theme::Dark); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void ThemeManager::SetToDarkTheme() { | 69 void ThemeManager::SetToDarkTheme() |
| 70 { | |
| 68 /* macOS >= 10.14 has its own global dark theme, | 71 /* macOS >= 10.14 has its own global dark theme, |
| 69 use it :) */ | 72 use it :) */ |
| 70 #ifdef MACOSX | 73 #ifdef MACOSX |
| 71 if (osx::DarkThemeAvailable()) | 74 if (osx::DarkThemeAvailable()) |
| 72 osx::SetToDarkTheme(); | 75 osx::SetToDarkTheme(); |
| 76 win32::SetTitleBarsToBlack(true); | 79 win32::SetTitleBarsToBlack(true); |
| 77 #endif | 80 #endif |
| 78 SetStyleSheet(Theme::Dark); | 81 SetStyleSheet(Theme::Dark); |
| 79 } | 82 } |
| 80 | 83 |
| 81 void ThemeManager::SetToLightTheme() { | 84 void ThemeManager::SetToLightTheme() |
| 85 { | |
| 82 #ifdef MACOSX | 86 #ifdef MACOSX |
| 83 if (osx::DarkThemeAvailable()) | 87 if (osx::DarkThemeAvailable()) |
| 84 osx::SetToLightTheme(); | 88 osx::SetToLightTheme(); |
| 85 else | 89 else |
| 86 #elif defined(WIN32) | 90 #elif defined(WIN32) |
| 88 win32::SetTitleBarsToBlack(false); | 92 win32::SetTitleBarsToBlack(false); |
| 89 #endif | 93 #endif |
| 90 SetStyleSheet(Theme::Light); | 94 SetStyleSheet(Theme::Light); |
| 91 } | 95 } |
| 92 | 96 |
| 93 Theme ThemeManager::GetCurrentOSTheme() const { | 97 Theme ThemeManager::GetCurrentOSTheme() const |
| 98 { | |
| 94 return IsInDarkTheme() ? Theme::Dark : Theme::Light; | 99 return IsInDarkTheme() ? Theme::Dark : Theme::Light; |
| 95 } | 100 } |
| 96 | 101 |
| 97 /* this function is private, and should stay that way */ | 102 /* this function is private, and should stay that way */ |
| 98 void ThemeManager::SetStyleSheet(Theme theme) { | 103 void ThemeManager::SetStyleSheet(Theme theme) |
| 104 { | |
| 99 switch (theme) { | 105 switch (theme) { |
| 100 case Theme::Dark: { | 106 case Theme::Dark: { |
| 101 const QColor darkGray(53, 53, 53); | 107 const QColor darkGray(53, 53, 53); |
| 102 const QColor gray(128, 128, 128); | 108 const QColor gray(128, 128, 128); |
| 103 const QColor black(25, 25, 25); | 109 const QColor black(25, 25, 25); |
| 149 qApp->setStyleSheet(""); | 155 qApp->setStyleSheet(""); |
| 150 break; | 156 break; |
| 151 } | 157 } |
| 152 } | 158 } |
| 153 | 159 |
| 154 void ThemeManager::SetTheme(Theme theme) { | 160 void ThemeManager::SetTheme(Theme theme) |
| 161 { | |
| 155 switch (theme) { | 162 switch (theme) { |
| 156 case Theme::Light: SetToLightTheme(); break; | 163 case Theme::Light: SetToLightTheme(); break; |
| 157 case Theme::Dark: SetToDarkTheme(); break; | 164 case Theme::Dark: SetToDarkTheme(); break; |
| 158 case Theme::Default: | 165 case Theme::Default: |
| 159 if (GetCurrentOSTheme() == Theme::Light) | 166 if (GetCurrentOSTheme() == Theme::Light) |
| 163 break; | 170 break; |
| 164 } | 171 } |
| 165 this->theme = theme; | 172 this->theme = theme; |
| 166 } | 173 } |
| 167 | 174 |
| 168 void ThemeManager::RepaintCurrentTheme() { | 175 void ThemeManager::RepaintCurrentTheme() |
| 176 { | |
| 169 SetTheme(theme); | 177 SetTheme(theme); |
| 170 } | 178 } |
| 171 | 179 |
| 172 } // namespace Theme | 180 } // namespace Theme |
