Mercurial > minori
annotate src/gui/theme.cc @ 118:39521c47c7a3
*: another huge megacommit, SORRY
The torrents page works a lot better now
Added the edit option to the anime list right click menu
Vectorized currently playing files
Available player and extensions are now loaded at runtime
from files in (dotpath)/players.json and (dotpath)/extensions.json
These paths are not permanent and will likely be moved to
(dotpath)/recognition
...
...
...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 23:40:54 -0500 |
parents | 2004b41d4a59 |
children | 01d259b9c89f |
rev | line source |
---|---|
102 | 1 #include "core/config.h" |
2 #include "core/session.h" | |
3 #include <QApplication> | |
4 #include <QFile> | |
5 #include <QDebug> | |
6 #include <QTextStream> | |
7 #include <QStyleFactory> | |
8 #ifdef MACOSX | |
9 # include "sys/osx/dark_theme.h" | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
10 #elif WIN32 |
102 | 11 # include "sys/win32/dark_theme.h" |
12 #endif | |
13 | |
14 /* This is, believe it or not, one of the hardest things I've implemented :/ | |
15 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different | |
16 2. Some widgets, i.e. QTabWidget, QTabBar, etc., just completely IGNORE the QPalette setting | |
17 3. I don't want to use the Fusion style on every single platform | |
18 4. Windows dark mode support in Qt 6.5 (with Fusion) is completely unavoidable | |
19 (not a joke btw, it's retarded) | |
20 These three already make it really hard, but along with that, I don't even remember if | |
21 OS X dark mode support even works still; I remember the background of some of the widgets | |
22 would refuse to update for whatever reason. */ | |
23 | |
24 namespace Theme { | |
25 | |
26 Theme::Theme(Themes theme) { | |
27 this->theme = theme; | |
28 } | |
29 | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
30 Themes Theme::GetTheme() const { |
102 | 31 return theme; |
32 } | |
33 | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
34 bool Theme::IsInDarkTheme() const { |
102 | 35 if (theme != Themes::OS) |
36 return (theme == Themes::DARK); | |
37 #ifdef MACOSX | |
38 if (osx::DarkThemeAvailable()) | |
39 return osx::IsInDarkTheme(); | |
40 #elif defined(WIN32) | |
41 if (win32::DarkThemeAvailable()) | |
42 return win32::IsInDarkTheme(); | |
43 #endif | |
44 return (theme == Themes::DARK); | |
45 } | |
46 | |
47 void Theme::SetToDarkTheme() { | |
48 /* macOS >= 10.14 has its own global dark theme, | |
49 use it :) */ | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
50 #ifdef MACOSX |
102 | 51 if (osx::DarkThemeAvailable()) |
52 osx::SetToDarkTheme(); | |
53 else | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
54 #elif defined(WIN32) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
55 if (win32::DarkThemeAvailable()) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
56 win32::SetTitleBarsToBlack(true); |
102 | 57 #endif |
58 SetStyleSheet(Themes::DARK); | |
59 } | |
60 | |
61 void Theme::SetToLightTheme() { | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
62 #ifdef MACOSX |
102 | 63 if (osx::DarkThemeAvailable()) |
64 osx::SetToLightTheme(); | |
65 else | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
66 #elif defined(WIN32) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
67 if (win32::DarkThemeAvailable()) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
68 win32::SetTitleBarsToBlack(false); |
102 | 69 #endif |
70 SetStyleSheet(Themes::LIGHT); | |
71 } | |
72 | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
73 Themes Theme::GetCurrentOSTheme() const { |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
74 #ifdef MACOSX |
102 | 75 if (osx::DarkThemeAvailable()) |
76 return osx::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; | |
77 #elif defined(WIN32) | |
78 if (win32::DarkThemeAvailable()) | |
79 return win32::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; | |
80 #endif | |
81 /* Currently OS detection only supports Windows and macOS. | |
82 Please don't be shy if you're willing to port it to other OSes | |
83 (or desktop environments, or window managers) */ | |
84 return Themes::LIGHT; | |
85 } | |
86 | |
87 /* this function is private, and should stay that way */ | |
88 void Theme::SetStyleSheet(Themes theme) { | |
89 switch (theme) { | |
90 case Themes::DARK: { | |
91 QColor darkGray(53, 53, 53); | |
92 QColor gray(128, 128, 128); | |
93 QColor black(25, 25, 25); | |
94 QColor blue(42, 130, 218); | |
95 | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
96 QPalette pal(QApplication::style()->standardPalette()); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
97 pal.setColor(QPalette::Window, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
98 pal.setColor(QPalette::WindowText, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
99 pal.setColor(QPalette::Base, black); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
100 pal.setColor(QPalette::AlternateBase, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
101 pal.setColor(QPalette::ToolTipBase, blue); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
102 pal.setColor(QPalette::ToolTipText, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
103 pal.setColor(QPalette::Text, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
104 pal.setColor(QPalette::Button, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
105 pal.setColor(QPalette::ButtonText, Qt::white); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
106 pal.setColor(QPalette::Link, blue); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
107 pal.setColor(QPalette::Highlight, blue); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
108 pal.setColor(QPalette::HighlightedText, Qt::black); |
102 | 109 |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
110 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
|
111 pal.setColor(QPalette::Disabled, QPalette::ButtonText, gray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
112 pal.setColor(QPalette::Disabled, QPalette::WindowText, gray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
113 pal.setColor(QPalette::Disabled, QPalette::Text, gray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
114 pal.setColor(QPalette::Disabled, QPalette::Light, darkGray); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
115 qApp->setPalette(pal); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
116 |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
117 QFile f(":dark.qss"); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
118 if (!f.exists()) |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
119 break; // how? |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
120 f.open(QFile::ReadOnly | QFile::Text); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
121 QTextStream ts(&f); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
122 qApp->setStyleSheet(ts.readAll()); |
102 | 123 break; |
124 } | |
125 default: | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
126 QPalette pal(QApplication::style()->standardPalette()); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
127 #ifdef WIN32 /* fuck you Qt 6 */ |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
128 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
|
129 #endif |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
130 pal.setColor(QPalette::WindowText, Qt::black); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
131 pal.setColor(QPalette::ToolTipText, Qt::black); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
132 pal.setColor(QPalette::Text, Qt::black); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
133 pal.setColor(QPalette::ButtonText, Qt::black); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
134 qApp->setPalette(pal); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
135 |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
136 qApp->setStyleSheet(""); |
102 | 137 break; |
138 } | |
139 } | |
140 | |
141 void Theme::SetTheme(Themes theme) { | |
142 switch (theme) { | |
143 case Themes::LIGHT: | |
144 SetToLightTheme(); | |
145 break; | |
146 case Themes::DARK: | |
147 SetToDarkTheme(); | |
148 break; | |
149 case Themes::OS: | |
150 if (GetCurrentOSTheme() == Themes::LIGHT) | |
151 SetToLightTheme(); | |
152 else | |
153 SetToDarkTheme(); | |
154 break; | |
155 } | |
156 this->theme = theme; | |
157 } | |
158 | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
159 void Theme::RepaintCurrentTheme() { |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
160 Theme::SetTheme(theme); |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
161 } |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
102
diff
changeset
|
162 |
102 | 163 } // namespace DarkTheme |