comparison src/gui/theme.cc @ 393:963047512d34

*: clang-format
author Paper <paper@tflc.us>
date Fri, 07 Nov 2025 07:16:15 -0500
parents 47c9f8502269
children
comparison
equal deleted inserted replaced
392:a72d6d7b3568 393:963047512d34
41 } 41 }
42 42
43 bool ThemeManager::IsInDarkTheme() const 43 bool ThemeManager::IsInDarkTheme() const
44 { 44 {
45 switch (theme) { 45 switch (theme) {
46 case Theme::Default: 46 case Theme::Default:
47 #ifdef MACOSX 47 #ifdef MACOSX
48 if (osx::DarkThemeAvailable()) 48 if (osx::DarkThemeAvailable())
49 return osx::IsInDarkTheme(); 49 return osx::IsInDarkTheme();
50 #elif defined(WIN32) 50 #elif defined(WIN32)
51 if (win32::DarkThemeAvailable()) 51 if (win32::DarkThemeAvailable())
52 return win32::IsInDarkTheme(); 52 return win32::IsInDarkTheme();
53 #else 53 #else
54 # ifdef HAVE_XCB 54 # ifdef HAVE_XCB
55 if (x11::IsInDarkTheme()) 55 if (x11::IsInDarkTheme())
56 return true; 56 return true;
57 # endif 57 # endif
58 # ifdef GLIB 58 # ifdef GLIB
59 if (glib::IsInDarkTheme()) 59 if (glib::IsInDarkTheme())
60 return true; 60 return true;
61 # endif 61 # endif
62 break; 62 break;
63 #endif 63 #endif
64 default: break; 64 default:
65 break;
65 } 66 }
66 return (theme == Theme::Dark); 67 return (theme == Theme::Dark);
67 } 68 }
68 69
69 void ThemeManager::SetToDarkTheme() 70 void ThemeManager::SetToDarkTheme()
101 102
102 /* this function is private, and should stay that way */ 103 /* this function is private, and should stay that way */
103 void ThemeManager::SetStyleSheet(Theme theme) 104 void ThemeManager::SetStyleSheet(Theme theme)
104 { 105 {
105 switch (theme) { 106 switch (theme) {
106 case Theme::Dark: { 107 case Theme::Dark: {
107 const QColor darkGray(53, 53, 53); 108 const QColor darkGray(53, 53, 53);
108 const QColor gray(128, 128, 128); 109 const QColor gray(128, 128, 128);
109 const QColor black(25, 25, 25); 110 const QColor black(25, 25, 25);
110 const QColor blue(42, 130, 218); 111 const QColor blue(42, 130, 218);
111 112
112 QPalette pal; 113 QPalette pal;
113 114
114 pal.setColor(QPalette::Window, darkGray); 115 pal.setColor(QPalette::Window, darkGray);
115 pal.setColor(QPalette::WindowText, Qt::white); 116 pal.setColor(QPalette::WindowText, Qt::white);
116 pal.setColor(QPalette::Base, black); 117 pal.setColor(QPalette::Base, black);
117 pal.setColor(QPalette::AlternateBase, darkGray); 118 pal.setColor(QPalette::AlternateBase, darkGray);
118 pal.setColor(QPalette::ToolTipBase, blue); 119 pal.setColor(QPalette::ToolTipBase, blue);
119 pal.setColor(QPalette::ToolTipText, Qt::white); 120 pal.setColor(QPalette::ToolTipText, Qt::white);
120 pal.setColor(QPalette::Text, Qt::white); 121 pal.setColor(QPalette::Text, Qt::white);
121 pal.setColor(QPalette::Button, darkGray); 122 pal.setColor(QPalette::Button, darkGray);
122 pal.setColor(QPalette::ButtonText, Qt::white); 123 pal.setColor(QPalette::ButtonText, Qt::white);
123 pal.setColor(QPalette::Link, blue); 124 pal.setColor(QPalette::Link, blue);
124 pal.setColor(QPalette::Highlight, blue); 125 pal.setColor(QPalette::Highlight, blue);
125 pal.setColor(QPalette::HighlightedText, Qt::black); 126 pal.setColor(QPalette::HighlightedText, Qt::black);
126 127
127 pal.setColor(QPalette::Active, QPalette::Button, gray.darker()); 128 pal.setColor(QPalette::Active, QPalette::Button, gray.darker());
128 pal.setColor(QPalette::Disabled, QPalette::ButtonText, gray); 129 pal.setColor(QPalette::Disabled, QPalette::ButtonText, gray);
129 pal.setColor(QPalette::Disabled, QPalette::WindowText, gray); 130 pal.setColor(QPalette::Disabled, QPalette::WindowText, gray);
130 pal.setColor(QPalette::Disabled, QPalette::Text, gray); 131 pal.setColor(QPalette::Disabled, QPalette::Text, gray);
131 pal.setColor(QPalette::Disabled, QPalette::Light, darkGray); 132 pal.setColor(QPalette::Disabled, QPalette::Light, darkGray);
132 133
133 qApp->setPalette(pal); 134 qApp->setPalette(pal);
134 135
135 #ifdef WIN32 136 #ifdef WIN32
136 qApp->setStyleSheet([] { 137 qApp->setStyleSheet([] {
137 QFile f(":/dark.qss"); 138 QFile f(":/dark.qss");
138 if (!f.exists()) 139 if (!f.exists())
139 return QStringLiteral(""); 140 return QStringLiteral("");
140 f.open(QFile::ReadOnly | QFile::Text); 141 f.open(QFile::ReadOnly | QFile::Text);
141 QTextStream ts(&f); 142 QTextStream ts(&f);
142 return ts.readAll(); 143 return ts.readAll();
143 }()); 144 }());
144 #endif 145 #endif
145 break; 146 break;
146 } 147 }
147 default: 148 default:
148 /* this sucks */ 149 /* this sucks */
149 QPalette pal(QApplication::style()->standardPalette()); 150 QPalette pal(QApplication::style()->standardPalette());
150 #ifdef WIN32 /* fuck you Qt 6 */ 151 #ifdef WIN32 /* fuck you Qt 6 */
151 pal.setColor(QPalette::Window, QColor(0xF0, 0xF0, 0xF0)); 152 pal.setColor(QPalette::Window, QColor(0xF0, 0xF0, 0xF0));
152 #endif 153 #endif
153 qApp->setPalette(pal); 154 qApp->setPalette(pal);
154 155
155 qApp->setStyleSheet(""); 156 qApp->setStyleSheet("");
156 break; 157 break;
157 } 158 }
158 } 159 }
159 160
160 void ThemeManager::SetTheme(Theme theme) 161 void ThemeManager::SetTheme(Theme theme)
161 { 162 {
162 switch (theme) { 163 switch (theme) {
163 case Theme::Light: SetToLightTheme(); break; 164 case Theme::Light:
164 case Theme::Dark: SetToDarkTheme(); break; 165 SetToLightTheme();
165 case Theme::Default: 166 break;
166 if (GetCurrentOSTheme() == Theme::Light) 167 case Theme::Dark:
167 SetToLightTheme(); 168 SetToDarkTheme();
168 else 169 break;
169 SetToDarkTheme(); 170 case Theme::Default:
170 break; 171 if (GetCurrentOSTheme() == Theme::Light)
172 SetToLightTheme();
173 else
174 SetToDarkTheme();
175 break;
171 } 176 }
172 this->theme = theme; 177 this->theme = theme;
173 } 178 }
174 179
175 void ThemeManager::RepaintCurrentTheme() 180 void ThemeManager::RepaintCurrentTheme()