diff --git a/gui/spkui_general.cpp b/gui/spkui_general.cpp index 06434d8..78d0b7f 100644 --- a/gui/spkui_general.cpp +++ b/gui/spkui_general.cpp @@ -54,7 +54,7 @@ namespace SpkUi StylesheetBase = ObtainStylesheet.readAll(); ObtainStylesheet.close(); - SetGlobalStyle(Dark); + SetGlobalStyle(Light, false); // Initalize crash handler signal(SIGSEGV, SpkUi::CrashSignalHandler); @@ -138,24 +138,31 @@ namespace SpkUi "with unwanted blue borders.")); } - void SetGlobalStyle(const SpkUiStyle aStyle) + void SetGlobalStyle(const SpkUiStyle aStyle, const bool aPreserveAccentColor) { + if(aStyle == CurrentStyle) // Don't waste precious CPU time parsing new style sheet! + return; CurrentStyle = aStyle; + Qss::ColorSet tempset; switch(aStyle) { case Light: - CurrentStylesheet = StylesheetFromColors(Qss::LightColorSet); - CurrentColorSet = Qss::LightColorSet; - qApp->setStyleSheet(CurrentStylesheet); + tempset = Qss::LightColorSet; ColorLine = Qt::black; break; case Dark: - CurrentStylesheet = StylesheetFromColors(Qss::DarkColorSet); - CurrentColorSet = Qss::DarkColorSet; - qApp->setStyleSheet(CurrentStylesheet); + tempset = Qss::DarkColorSet; ColorLine = Qt::white; break; } + if(aPreserveAccentColor) + { + for(auto i : Qss::AccentColorExceptions) + tempset[i] = CurrentColorSet[i]; + } + CurrentColorSet = tempset; + CurrentStylesheet = StylesheetFromColors(CurrentColorSet); + qApp->setStyleSheet(CurrentStylesheet); } QString WriteStackTrace(const QString &aStackTrace) @@ -259,9 +266,9 @@ namespace SpkUi void UiMetaObject::SetDarkLightTheme(bool isDark) { if(isDark) - SetGlobalStyle(Dark); + SetGlobalStyle(Dark, true); else - SetGlobalStyle(Light); + SetGlobalStyle(Light, true); } } diff --git a/inc/spkqsshelper.h b/inc/spkqsshelper.h index 7f8ab16..7fbd21c 100644 --- a/inc/spkqsshelper.h +++ b/inc/spkqsshelper.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include namespace SpkUi @@ -30,6 +31,13 @@ namespace SpkUi ShadesEdge, }; + const std::list AccentColorExceptions + { + AccentColor, + AccentColorHighlighted, + TextOnAccentColor, + }; + const std::map ColorSet2Token { { GlobalBgnd, "GBG_" }, @@ -87,8 +95,8 @@ namespace SpkUi { TextOnGlobalBgnd, ColorTextOnBackground(0xf8f8f8) }, { TextOnControlsBgnd, ColorTextOnBackground(0xf8f8f8) }, { TextLighter, 0x2a2a2a }, - { GlossyEdge, 0xc5c5c5 }, - { ShadesEdge, 0x9d9d9d } + { GlossyEdge, 0x9d9d9d }, + { ShadesEdge, 0xc5c5c5 } }; using ColorSet = std::map; diff --git a/inc/spkui_general.h b/inc/spkui_general.h index cdb6d93..3fcd0cb 100644 --- a/inc/spkui_general.h +++ b/inc/spkui_general.h @@ -68,5 +68,5 @@ namespace SpkUi void CrashSignalHandler(int); - void SetGlobalStyle(SpkUiStyle); + void SetGlobalStyle(const SpkUiStyle, const bool aPreserveAccentColor); };