From aae96389516645f8067a5173ab436ae27462ddd3 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 30 Apr 2024 15:15:08 +0200 Subject: Windows: refactor theme's handling of color scheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø Reviewed-by: Santhosh Kumar Reviewed-by: Wladimir Leuschner --- src/plugins/platforms/windows/qwindowstheme.cpp | 11 ++++++++--- src/plugins/platforms/windows/qwindowstheme.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms') 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; @@ -541,6 +541,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; @@ -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; -- cgit v1.2.3