aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/fluentwinui3
diff options
context:
space:
mode:
authorDoris Verria <[email protected]>2024-08-09 11:13:20 +0200
committerDoris Verria <[email protected]>2024-08-23 15:44:58 +0200
commit15e63383bcc0bba21f8c71c720fec4cf4ea5ab9f (patch)
treed2b0190db8cb804ea29239762219236db95c55e8 /src/quickcontrols/fluentwinui3
parentff074177c1066ac4b1859e1989d7a6a50d275857 (diff)
FluentWinUI3 Style: Override platform theme's palette with style's one
On Windows platforms we were using the platform theme's palette to construct the FluentWinUI3 style's palette with the motivation that the colors as gotten from the system's APIs in qwindowstheme would be the correct ones for the style. This is not the case as these APIs represent the colors for old Windows10 platforms and do not correspond with the modern WinUI3 colors. That is why we need to override many of these palette roles in the FluentWinUI3's style palette. These colors need to be hardcoded even for Windows platforms as there are no APIs that we can use to retrieve them. The color entries are taken from the official Figma files for the style. The accent color is an exception and that we can safely retrieve from the system APIs. As a drive-by, resolve the style's palette based on the platform theme for all platforms, not only on Windows, as we want to use the system's accent color no matter the platform. Partially reverts 8516ddf690440cd33e3332e8cb2d049ed0032954. Pick-to: 6.8 Change-Id: I360fc30bd04fac9b04a8ffe0e99791349ad365a6 Reviewed-by: Mitch Curtis <[email protected]>
Diffstat (limited to 'src/quickcontrols/fluentwinui3')
-rw-r--r--src/quickcontrols/fluentwinui3/qquickfluentwinui3theme.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/quickcontrols/fluentwinui3/qquickfluentwinui3theme.cpp b/src/quickcontrols/fluentwinui3/qquickfluentwinui3theme.cpp
index 126bdfa6ee..75bc07bc14 100644
--- a/src/quickcontrols/fluentwinui3/qquickfluentwinui3theme.cpp
+++ b/src/quickcontrols/fluentwinui3/qquickfluentwinui3theme.cpp
@@ -96,10 +96,8 @@ static void populateSystemPalette(QPalette &palette)
palette.setColor(QPalette::All, QPalette::ButtonText, WINUI3Colors[colorSchemeIndex][textPrimary]);
palette.setColor(QPalette::Disabled, QPalette::ButtonText, WINUI3Colors[colorSchemeIndex][textDisabled]);
- palette.setColor(QPalette::All, QPalette::Highlight, WINUI3Colors[colorSchemeIndex][accentDefault]);
- palette.setColor(QPalette::Disabled, QPalette::Highlight, WINUI3Colors[colorSchemeIndex][accentDisabled]);
- palette.setColor(QPalette::All, QPalette::Accent, WINUI3Colors[colorSchemeIndex][accentDefault]);
palette.setColor(QPalette::Disabled, QPalette::Accent, WINUI3Colors[colorSchemeIndex][accentDisabled]);
+ palette.setColor(QPalette::Disabled, QPalette::Highlight, WINUI3Colors[colorSchemeIndex][accentDisabled]);
palette.setColor(QPalette::All, QPalette::HighlightedText, Qt::white);
}
@@ -136,13 +134,26 @@ void QQuickFluentWinUI3Theme::initialize(QQuickTheme *theme)
populateThemeFont(theme);
QPalette systemPalette;
updatePalette(systemPalette);
-#ifdef Q_OS_WIN
+
if (auto platformTheme = QGuiApplicationPrivate::platformTheme()) {
const auto platformPalette = platformTheme->palette();
if (platformPalette)
- systemPalette = platformPalette->resolve(systemPalette);
+ // style palette takes precedence over platform's theme
+ systemPalette = systemPalette.resolve(*platformPalette);
}
-#endif
+
+ {
+ const auto colorSchemeIndex = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Light ? 0 : 1;
+ if (!systemPalette.isBrushSet(QPalette::Active, QPalette::Accent))
+ systemPalette.setColor(QPalette::Active, QPalette::Accent, WINUI3Colors[colorSchemeIndex][accentDefault]);
+
+ systemPalette.setColor(QPalette::Active, QPalette::Highlight, systemPalette.accent().color());
+ systemPalette.setColor(QPalette::Inactive, QPalette::Accent, systemPalette.accent().color());
+ systemPalette.setColor(QPalette::Inactive, QPalette::Highlight, systemPalette.highlight().color());
+ }
+
+ // Finally QGuiApp::palette() should take precedence over style palette
+ systemPalette = QGuiApplication::palette().resolve(systemPalette);
theme->setPalette(QQuickTheme::System, systemPalette);
}