diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-04-30 15:15:08 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-05-02 19:03:42 +0200 |
commit | aae96389516645f8067a5173ab436ae27462ddd3 (patch) | |
tree | 46734f5fd33f1e06ec01de0cb7d826b7098fac06 /src/plugins/platforms | |
parent | 25c02ae5bf308c905dee580c6a4c6569d70e2cdc (diff) |
Windows: refactor theme's handling of color scheme
Make the functions populating the palette static class members so
that they can access private helpers.
Encapsulate logic that overrides the system or (later) explicitly set
color scheme into a helper that always respects the presence of a
high-contrast theme.
Task-number: QTBUG-124490
Change-Id: I7ad09596bb308b17b4c6ec34bb02cb6cf4b8c1bb
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.cpp | 11 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.h | 4 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 77c018bd9a..fb5874fd8b 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -259,7 +259,7 @@ static QColor placeHolderColor(QColor textColor) This is used when the theme is light mode, and when the theme is dark but the application doesn't support dark mode. In the latter case, we need to check. */ -static void populateLightSystemBasePalette(QPalette &result) +void QWindowsTheme::populateLightSystemBasePalette(QPalette &result) { const QColor background = getSysColor(COLOR_BTNFACE); const QColor textColor = getSysColor(COLOR_WINDOWTEXT); @@ -299,7 +299,7 @@ static void populateLightSystemBasePalette(QPalette &result) result.setColor(QPalette::Midlight, result.button().color().lighter(110)); } -static void populateDarkSystemBasePalette(QPalette &result) +void QWindowsTheme::populateDarkSystemBasePalette(QPalette &result) { #if QT_CONFIG(cpp_winrt) using namespace winrt::Windows::UI::ViewManagement; @@ -542,6 +542,11 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const Qt::ColorScheme QWindowsTheme::colorScheme() const { + return QWindowsTheme::effectiveColorScheme(); +} + +Qt::ColorScheme QWindowsTheme::effectiveColorScheme() +{ if (queryHighContrast()) return Qt::ColorScheme::Unknown; return s_colorScheme; @@ -577,7 +582,7 @@ void QWindowsTheme::refreshPalettes() if (!QGuiApplication::desktopSettingsAware()) return; const bool light = - s_colorScheme != Qt::ColorScheme::Dark + effectiveColorScheme() != Qt::ColorScheme::Dark || !QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle); clearPalettes(); m_palettes[SystemPalette] = new QPalette(QWindowsTheme::systemPalette(s_colorScheme)); diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index 2716769aff..6109122944 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -70,7 +70,11 @@ private: void clearFonts(); void refreshIconPixmapSizes(); + static void populateLightSystemBasePalette(QPalette &result); + static void populateDarkSystemBasePalette(QPalette &result); + static Qt::ColorScheme queryColorScheme(); + static Qt::ColorScheme effectiveColorScheme(); static bool queryHighContrast(); static QWindowsTheme *m_instance; |