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>bb10
parent
25c02ae5bf
commit
aae9638951
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue