Mercurial > minori
annotate src/gui/theme.cc @ 337:a7d4e5107531
dep/animone: REFACTOR ALL THE THINGS
1: animone now has its own syntax divergent from anisthesia,
making different platforms actually have their own sections
2: process names in animone are now called `comm' (this will
probably break things). this is what its called in bsd/linux
so I'm just going to use it everywhere
3: the X11 code now checks for the existence of a UTF-8 window title
and passes it if available
4: ANYTHING THATS NOT LINUX IS 100% UNTESTED AND CAN AND WILL BREAK!
I still actually need to test the bsd code. to be honest I'm probably
going to move all of the bsds into separate files because they're
all essentially different operating systems at this point
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 19 Jun 2024 12:51:15 -0400 |
parents | 91ac90a34003 |
children | c844f8bb87ce |
rev | line source |
---|---|
102 | 1 #include "core/config.h" |
2 #include "core/session.h" | |
279 | 3 #include "gui/theme.h" |
102 | 4 #include <QApplication> |
258 | 5 #include <QDebug> |
102 | 6 #include <QFile> |
258 | 7 #include <QStyleFactory> |
102 | 8 #include <QTextStream> |
279 | 9 #include <QStyle> |
291 | 10 #include <QtGlobal> |
102 | 11 #ifdef MACOSX |
12 # include "sys/osx/dark_theme.h" | |
279 | 13 #elif defined(WIN32) |
102 | 14 # include "sys/win32/dark_theme.h" |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
15 #else |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
16 # ifdef GLIB |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
17 # include "sys/glib/dark_theme.h" |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
18 # endif |
102 | 19 #endif |
20 | |
229
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
21 /* Weird quirks of this implementation: |
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
22 * 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different |
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
23 * 2. Some widgets, i.e. QTabWidget, QTabBar, etc., just completely IGNORE the QPalette setting |
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
24 * on different platforms and the only way to fix it is by using Fusion |
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
25 * 3. Windows dark mode support in Qt 6.5 (with Fusion) is completely unavoidable |
258 | 26 */ |
102 | 27 |
28 namespace Theme { | |
29 | |
279 | 30 ThemeManager::ThemeManager(Theme theme) { |
102 | 31 this->theme = theme; |
32 } | |
33 | |
279 | 34 Theme ThemeManager::GetTheme() const { |
102 | 35 return theme; |
36 } | |
37 | |
279 | 38 bool ThemeManager::IsInDarkTheme() const { |
39 switch (theme) { | |
40 case Theme::Default: | |
102 | 41 #ifdef MACOSX |
279 | 42 if (osx::DarkThemeAvailable()) |
43 return osx::IsInDarkTheme(); | |
102 | 44 #elif defined(WIN32) |
279 | 45 if (win32::DarkThemeAvailable()) |
46 return win32::IsInDarkTheme(); | |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
47 #else |
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
48 # ifdef GLIB |
279 | 49 return glib::IsInDarkTheme(); |
232
ff0061e75f0f
theme: add OS detection with glib
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
50 # endif |
102 | 51 #endif |
279 | 52 default: break; |
53 } | |
54 return (theme == Theme::Dark); | |
102 | 55 } |
56 | |
279 | 57 void ThemeManager::SetToDarkTheme() { |
102 | 58 /* macOS >= 10.14 has its own global dark theme, |
59 use it :) */ | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
60 #ifdef MACOSX |
102 | 61 if (osx::DarkThemeAvailable()) |
62 osx::SetToDarkTheme(); | |
63 else | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
64 #elif defined(WIN32) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
65 if (win32::DarkThemeAvailable()) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
66 win32::SetTitleBarsToBlack(true); |
102 | 67 #endif |
279 | 68 SetStyleSheet(Theme::Dark); |
102 | 69 } |
70 | |
279 | 71 void ThemeManager::SetToLightTheme() { |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
72 #ifdef MACOSX |
102 | 73 if (osx::DarkThemeAvailable()) |
74 osx::SetToLightTheme(); | |
75 else | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
76 #elif defined(WIN32) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
77 if (win32::DarkThemeAvailable()) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
78 win32::SetTitleBarsToBlack(false); |
102 | 79 #endif |
279 | 80 SetStyleSheet(Theme::Light); |
102 | 81 } |
82 | |
279 | 83 Theme ThemeManager::GetCurrentOSTheme() const { |
84 return IsInDarkTheme() ? Theme::Dark : Theme::Light; | |
102 | 85 } |
86 | |
87 /* this function is private, and should stay that way */ | |
279 | 88 void ThemeManager::SetStyleSheet(Theme theme) { |
102 | 89 switch (theme) { |
279 | 90 case Theme::Dark: { |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
91 const QColor darkGray(53, 53, 53); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
92 const QColor gray(128, 128, 128); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
93 const QColor black(25, 25, 25); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
94 const QColor blue(42, 130, 218); |
102 | 95 |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
96 QPalette pal; |
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
97 |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
98 pal.setColor(QPalette::Window, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
99 pal.setColor(QPalette::WindowText, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
100 pal.setColor(QPalette::Base, black); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
101 pal.setColor(QPalette::AlternateBase, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
102 pal.setColor(QPalette::ToolTipBase, blue); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
103 pal.setColor(QPalette::ToolTipText, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
104 pal.setColor(QPalette::Text, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
105 pal.setColor(QPalette::Button, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
106 pal.setColor(QPalette::ButtonText, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
107 pal.setColor(QPalette::Link, blue); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
108 pal.setColor(QPalette::Highlight, blue); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
109 pal.setColor(QPalette::HighlightedText, Qt::black); |
102 | 110 |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
111 pal.setColor(QPalette::Active, QPalette::Button, gray.darker()); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
112 pal.setColor(QPalette::Disabled, QPalette::ButtonText, gray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
113 pal.setColor(QPalette::Disabled, QPalette::WindowText, gray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
114 pal.setColor(QPalette::Disabled, QPalette::Text, gray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
115 pal.setColor(QPalette::Disabled, QPalette::Light, darkGray); |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
116 |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
117 qApp->setPalette(pal); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
118 |
229
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
119 #ifdef WIN32 |
258 | 120 qApp->setStyleSheet([] { |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
121 QFile f(":/dark.qss"); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
122 if (!f.exists()) |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
123 return QStringLiteral(""); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
124 f.open(QFile::ReadOnly | QFile::Text); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
125 QTextStream ts(&f); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
126 return ts.readAll(); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
229
diff
changeset
|
127 }()); |
229
adc20fa321c1
theme: force Fusion style on platforms other than Win32 or OS X
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
128 #endif |
102 | 129 break; |
130 } | |
131 default: | |
305
91ac90a34003
core/time: remove Duration class, use regular functions instead
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
132 /* this sucks */ |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
133 QPalette pal(QApplication::style()->standardPalette()); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
134 #ifdef WIN32 /* fuck you Qt 6 */ |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
135 pal.setColor(QPalette::Window, QColor(0xF0, 0xF0, 0xF0)); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
136 #endif |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
137 qApp->setPalette(pal); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
138 |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
139 qApp->setStyleSheet(""); |
102 | 140 break; |
141 } | |
142 } | |
143 | |
279 | 144 void ThemeManager::SetTheme(Theme theme) { |
102 | 145 switch (theme) { |
279 | 146 case Theme::Light: SetToLightTheme(); break; |
147 case Theme::Dark: SetToDarkTheme(); break; | |
148 case Theme::Default: | |
149 if (GetCurrentOSTheme() == Theme::Light) | |
102 | 150 SetToLightTheme(); |
151 else | |
152 SetToDarkTheme(); | |
153 break; | |
154 } | |
155 this->theme = theme; | |
156 } | |
157 | |
279 | 158 void ThemeManager::RepaintCurrentTheme() { |
159 SetTheme(theme); | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
160 } |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
161 |
258 | 162 } // namespace Theme |