Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/gui/theme.cc Sun Nov 05 02:35:27 2023 -0500 +++ b/src/gui/theme.cc Sun Nov 05 03:54:26 2023 -0500 @@ -7,7 +7,7 @@ #include <QStyleFactory> #ifdef MACOSX # include "sys/osx/dark_theme.h" -#else +#elif WIN32 # include "sys/win32/dark_theme.h" #endif @@ -47,25 +47,31 @@ void Theme::SetToDarkTheme() { /* macOS >= 10.14 has its own global dark theme, use it :) */ -#if MACOSX +#ifdef MACOSX if (osx::DarkThemeAvailable()) osx::SetToDarkTheme(); else +#elif defined(WIN32) + if (win32::DarkThemeAvailable()) + win32::SetTitleBarsToBlack(true); #endif SetStyleSheet(Themes::DARK); } void Theme::SetToLightTheme() { -#if MACOSX +#ifdef MACOSX if (osx::DarkThemeAvailable()) osx::SetToLightTheme(); else +#elif defined(WIN32) + if (win32::DarkThemeAvailable()) + win32::SetTitleBarsToBlack(false); #endif SetStyleSheet(Themes::LIGHT); } Themes Theme::GetCurrentOSTheme() { -#if MACOSX +#ifdef MACOSX if (osx::DarkThemeAvailable()) return osx::IsInDarkTheme() ? Themes::DARK : Themes::LIGHT; #elif defined(WIN32) @@ -87,30 +93,47 @@ QColor black(25, 25, 25); QColor blue(42, 130, 218); - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, darkGray); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, black); - darkPalette.setColor(QPalette::AlternateBase, darkGray); - darkPalette.setColor(QPalette::ToolTipBase, blue); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, darkGray); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, blue); - darkPalette.setColor(QPalette::Highlight, blue); - darkPalette.setColor(QPalette::HighlightedText, Qt::black); + QPalette pal(QApplication::style()->standardPalette()); + pal.setColor(QPalette::Window, darkGray); + pal.setColor(QPalette::WindowText, Qt::white); + pal.setColor(QPalette::Base, black); + pal.setColor(QPalette::AlternateBase, darkGray); + pal.setColor(QPalette::ToolTipBase, blue); + pal.setColor(QPalette::ToolTipText, Qt::white); + pal.setColor(QPalette::Text, Qt::white); + pal.setColor(QPalette::Button, darkGray); + pal.setColor(QPalette::ButtonText, Qt::white); + pal.setColor(QPalette::Link, blue); + pal.setColor(QPalette::Highlight, blue); + pal.setColor(QPalette::HighlightedText, Qt::black); - darkPalette.setColor(QPalette::Active, QPalette::Button, gray.darker()); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); - qApp->setPalette(darkPalette); + pal.setColor(QPalette::Active, QPalette::Button, gray.darker()); + pal.setColor(QPalette::Disabled, QPalette::ButtonText, gray); + pal.setColor(QPalette::Disabled, QPalette::WindowText, gray); + pal.setColor(QPalette::Disabled, QPalette::Text, gray); + pal.setColor(QPalette::Disabled, QPalette::Light, darkGray); + qApp->setPalette(pal); + + QFile f(":dark.qss"); + if (!f.exists()) + break; // how? + f.open(QFile::ReadOnly | QFile::Text); + QTextStream ts(&f); + qApp->setStyleSheet(ts.readAll()); break; } default: - qApp->setPalette(QApplication::style()->standardPalette()); + QPalette pal(QApplication::style()->standardPalette()); +#ifdef WIN32 /* fuck you Qt 6 */ + pal.setColor(QPalette::Window, QColor(0xF0, 0xF0, 0xF0)); +#endif + pal.setColor(QPalette::WindowText, Qt::black); + pal.setColor(QPalette::ToolTipText, Qt::black); + pal.setColor(QPalette::Text, Qt::black); + pal.setColor(QPalette::ButtonText, Qt::black); + qApp->setPalette(pal); + + qApp->setStyleSheet(""); break; } } @@ -133,4 +156,8 @@ this->theme = theme; } +void Theme::RepaintCurrentTheme() { + Theme::SetTheme(theme); +} + } // namespace DarkTheme