Mercurial > minori
comparison src/gui/theme.cc @ 105:6d8da6e64d61
theme: add dark stylesheet, make it actually usable
win32: make the titlebar black where available
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 05 Nov 2023 03:54:26 -0500 |
parents | b315f3759c56 |
children | 2004b41d4a59 |
comparison
equal
deleted
inserted
replaced
104:27455104ea37 | 105:6d8da6e64d61 |
---|---|
5 #include <QDebug> | 5 #include <QDebug> |
6 #include <QTextStream> | 6 #include <QTextStream> |
7 #include <QStyleFactory> | 7 #include <QStyleFactory> |
8 #ifdef MACOSX | 8 #ifdef MACOSX |
9 # include "sys/osx/dark_theme.h" | 9 # include "sys/osx/dark_theme.h" |
10 #else | 10 #elif WIN32 |
11 # include "sys/win32/dark_theme.h" | 11 # include "sys/win32/dark_theme.h" |
12 #endif | 12 #endif |
13 | 13 |
14 /* This is, believe it or not, one of the hardest things I've implemented :/ | 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 | 15 1. Dark mode stuff in Qt changes a lot and Qt 5 and Qt 6 are massively different |
45 } | 45 } |
46 | 46 |
47 void Theme::SetToDarkTheme() { | 47 void Theme::SetToDarkTheme() { |
48 /* macOS >= 10.14 has its own global dark theme, | 48 /* macOS >= 10.14 has its own global dark theme, |
49 use it :) */ | 49 use it :) */ |
50 #if MACOSX | 50 #ifdef MACOSX |
51 if (osx::DarkThemeAvailable()) | 51 if (osx::DarkThemeAvailable()) |
52 osx::SetToDarkTheme(); | 52 osx::SetToDarkTheme(); |
53 else | 53 else |
54 #elif defined(WIN32) | |
55 if (win32::DarkThemeAvailable()) | |
56 win32::SetTitleBarsToBlack(true); | |
54 #endif | 57 #endif |
55 SetStyleSheet(Themes::DARK); | 58 SetStyleSheet(Themes::DARK); |
56 } | 59 } |
57 | 60 |
58 void Theme::SetToLightTheme() { | 61 void Theme::SetToLightTheme() { |
59 #if MACOSX | 62 #ifdef MACOSX |
60 if (osx::DarkThemeAvailable()) | 63 if (osx::DarkThemeAvailable()) |
61 osx::SetToLightTheme(); | 64 osx::SetToLightTheme(); |
62 else | 65 else |
66 #elif defined(WIN32) | |
67 if (win32::DarkThemeAvailable()) | |
68 win32::SetTitleBarsToBlack(false); | |
63 #endif | 69 #endif |
64 SetStyleSheet(Themes::LIGHT); | 70 SetStyleSheet(Themes::LIGHT); |
65 } | 71 } |
66 | 72 |
67 Themes Theme::GetCurrentOSTheme() { | 73 Themes Theme::GetCurrentOSTheme() { |
68 #if MACOSX | 74 #ifdef MACOSX |
69 if (osx::DarkThemeAvailable()) | 75 if (osx::DarkThemeAvailable()) |
70 return osx::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; | 76 return osx::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; |
71 #elif defined(WIN32) | 77 #elif defined(WIN32) |
72 if (win32::DarkThemeAvailable()) | 78 if (win32::DarkThemeAvailable()) |
73 return win32::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; | 79 return win32::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; |
85 QColor darkGray(53, 53, 53); | 91 QColor darkGray(53, 53, 53); |
86 QColor gray(128, 128, 128); | 92 QColor gray(128, 128, 128); |
87 QColor black(25, 25, 25); | 93 QColor black(25, 25, 25); |
88 QColor blue(42, 130, 218); | 94 QColor blue(42, 130, 218); |
89 | 95 |
90 QPalette darkPalette; | 96 QPalette pal(QApplication::style()->standardPalette()); |
91 darkPalette.setColor(QPalette::Window, darkGray); | 97 pal.setColor(QPalette::Window, darkGray); |
92 darkPalette.setColor(QPalette::WindowText, Qt::white); | 98 pal.setColor(QPalette::WindowText, Qt::white); |
93 darkPalette.setColor(QPalette::Base, black); | 99 pal.setColor(QPalette::Base, black); |
94 darkPalette.setColor(QPalette::AlternateBase, darkGray); | 100 pal.setColor(QPalette::AlternateBase, darkGray); |
95 darkPalette.setColor(QPalette::ToolTipBase, blue); | 101 pal.setColor(QPalette::ToolTipBase, blue); |
96 darkPalette.setColor(QPalette::ToolTipText, Qt::white); | 102 pal.setColor(QPalette::ToolTipText, Qt::white); |
97 darkPalette.setColor(QPalette::Text, Qt::white); | 103 pal.setColor(QPalette::Text, Qt::white); |
98 darkPalette.setColor(QPalette::Button, darkGray); | 104 pal.setColor(QPalette::Button, darkGray); |
99 darkPalette.setColor(QPalette::ButtonText, Qt::white); | 105 pal.setColor(QPalette::ButtonText, Qt::white); |
100 darkPalette.setColor(QPalette::Link, blue); | 106 pal.setColor(QPalette::Link, blue); |
101 darkPalette.setColor(QPalette::Highlight, blue); | 107 pal.setColor(QPalette::Highlight, blue); |
102 darkPalette.setColor(QPalette::HighlightedText, Qt::black); | 108 pal.setColor(QPalette::HighlightedText, Qt::black); |
103 | 109 |
104 darkPalette.setColor(QPalette::Active, QPalette::Button, gray.darker()); | 110 pal.setColor(QPalette::Active, QPalette::Button, gray.darker()); |
105 darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); | 111 pal.setColor(QPalette::Disabled, QPalette::ButtonText, gray); |
106 darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); | 112 pal.setColor(QPalette::Disabled, QPalette::WindowText, gray); |
107 darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); | 113 pal.setColor(QPalette::Disabled, QPalette::Text, gray); |
108 darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); | 114 pal.setColor(QPalette::Disabled, QPalette::Light, darkGray); |
109 qApp->setPalette(darkPalette); | 115 qApp->setPalette(pal); |
116 | |
117 QFile f(":dark.qss"); | |
118 if (!f.exists()) | |
119 break; // how? | |
120 f.open(QFile::ReadOnly | QFile::Text); | |
121 QTextStream ts(&f); | |
122 qApp->setStyleSheet(ts.readAll()); | |
110 break; | 123 break; |
111 } | 124 } |
112 default: | 125 default: |
113 qApp->setPalette(QApplication::style()->standardPalette()); | 126 QPalette pal(QApplication::style()->standardPalette()); |
127 #ifdef WIN32 /* fuck you Qt 6 */ | |
128 pal.setColor(QPalette::Window, QColor(0xF0, 0xF0, 0xF0)); | |
129 #endif | |
130 pal.setColor(QPalette::WindowText, Qt::black); | |
131 pal.setColor(QPalette::ToolTipText, Qt::black); | |
132 pal.setColor(QPalette::Text, Qt::black); | |
133 pal.setColor(QPalette::ButtonText, Qt::black); | |
134 qApp->setPalette(pal); | |
135 | |
136 qApp->setStyleSheet(""); | |
114 break; | 137 break; |
115 } | 138 } |
116 } | 139 } |
117 | 140 |
118 void Theme::SetTheme(Themes theme) { | 141 void Theme::SetTheme(Themes theme) { |
131 break; | 154 break; |
132 } | 155 } |
133 this->theme = theme; | 156 this->theme = theme; |
134 } | 157 } |
135 | 158 |
159 void Theme::RepaintCurrentTheme() { | |
160 Theme::SetTheme(theme); | |
161 } | |
162 | |
136 } // namespace DarkTheme | 163 } // namespace DarkTheme |