diff options
author | Wladimir Leuschner <wladimir.leuschner@qt.io> | 2024-01-17 14:39:01 +0100 |
---|---|---|
committer | Wladimir Leuschner <wladimir.leuschner@qt.io> | 2024-02-29 22:15:24 +0100 |
commit | 41854cfaac0fcd2c8f4386a46955716e652c4edc (patch) | |
tree | d8b91856b4d10f027c4674f7be9b663088423430 | |
parent | 2d1db53f9c0eceb5196cd2fc571b3b48c706a70e (diff) |
QWindows11Style: Revert Windows global palette changes
Revert Windows global palette changes and set the QPalette for
QWindows11Style in QWindows11Style::polish
Fixes: QTBUG-120571
Pick-to: 6.7
Change-Id: Iad4eb699c2dbfed38a917e6c9bc378c4262dc66e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
-rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.cpp | 174 | ||||
-rw-r--r-- | src/plugins/styles/modernwindows/qwindows11style.cpp | 79 |
2 files changed, 117 insertions, 136 deletions
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index a61caae1b1..b0b6672487 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -28,12 +28,12 @@ #include <QtCore/qqueue.h> #include <QtCore/qmutex.h> #include <QtCore/qwaitcondition.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtGui/qcolor.h> #include <QtGui/qpalette.h> #include <QtGui/qguiapplication.h> #include <QtGui/qpainter.h> #include <QtGui/qpixmapcache.h> -#include <QtCore/qoperatingsystemversion.h> #include <qpa/qwindowsysteminterface.h> #include <QtGui/private/qabstractfileiconengine_p.h> #include <QtGui/private/qwindowsfontdatabase_p.h> @@ -123,24 +123,6 @@ static constexpr QColor getSysColor(winrt::Windows::UI::Color &&color) static inline QColor getSysColor(int index) { - static const bool isWin11OrUpward = QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11; - static const bool highContrastMode = QWindowsTheme::queryHighContrast(); - - if (isWin11OrUpward && !highContrastMode) { - switch (index) { - case COLOR_WINDOW: - return QColor(0xF3,0xF3,0xF3,0xFF); - case COLOR_3DFACE: - return QColor(0xFF,0xFF,0xFF,0xB3); - case COLOR_WINDOWTEXT: - case COLOR_BTNTEXT: - return QColor(0x00,0x00,0x00,0xE4); - case COLOR_HIGHLIGHT: - return qt_accentColor(AccentColorNormal); - default: - break; - } - } COLORREF cr = GetSysColor(index); return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); } @@ -275,87 +257,35 @@ 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. - - The colors for Windows 11 are taken from the official WinUI3 Figma style at - https://www.figma.com/community/file/1159947337437047524 */ static void populateLightSystemBasePalette(QPalette &result) { - const QColor textColor = QColor(0x00,0x00,0x00,0xE4); - - const QColor accent = qt_accentColor(AccentColorNormal); - const QColor accentDarkest = qt_accentColor(AccentColorDarkest); - - const QColor linkColor = accent; - const QColor btnFace = QColor(0xFF,0xFF,0xFF,0xB3); - const QColor btnHighlight = getSysColor(COLOR_HIGHLIGHT); - - result.setColor(QPalette::Highlight, getSysColor(COLOR_HIGHLIGHT)); - result.setColor(QPalette::WindowText, textColor); - result.setColor(QPalette::Button, btnFace); - result.setColor(QPalette::Light, result.button().color().lighter(150)); - result.setColor(QPalette::Dark, result.button().color().darker(200)); - result.setColor(QPalette::Mid, result.button().color().darker(150)); - result.setColor(QPalette::Text, textColor); - result.setColor(QPalette::PlaceholderText, placeHolderColor(textColor)); - result.setColor(QPalette::BrightText, btnHighlight); - result.setColor(QPalette::Base, btnFace); - result.setColor(QPalette::Window, QColor(0xF3,0xF3,0xF3,0xFF)); - result.setColor(QPalette::ButtonText, textColor); - result.setColor(QPalette::Midlight, result.button().color().lighter(125)); - result.setColor(QPalette::Shadow, Qt::black); - result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT)); - result.setColor(QPalette::Accent, accent); - result.setColor(QPalette::ToolTipBase, getSysColor(COLOR_WINDOW)); - result.setColor(QPalette::ToolTipText, getSysColor(COLOR_WINDOWTEXT)); - - result.setColor(QPalette::Link, linkColor); - result.setColor(QPalette::LinkVisited, accentDarkest); - result.setColor(QPalette::Inactive, QPalette::Button, result.button().color()); - result.setColor(QPalette::Inactive, QPalette::Window, result.window().color()); - result.setColor(QPalette::Inactive, QPalette::Light, result.light().color()); - result.setColor(QPalette::Inactive, QPalette::Dark, result.dark().color()); - - if (result.midlight() == result.button()) - result.setColor(QPalette::Midlight, result.button().color().lighter(110)); -} - -/* - 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. - -The colors for Windows 11 are taken from the official WinUI3 Figma style at -https://www.figma.com/community/file/1159947337437047524 -*/ -static void populateHighContrastSystemBasePalette(QPalette &result) -{ + const QColor background = getSysColor(COLOR_BTNFACE); const QColor textColor = getSysColor(COLOR_WINDOWTEXT); const QColor accent = qt_accentColor(AccentColorNormal); const QColor accentDarkest = qt_accentColor(AccentColorDarkest); const QColor linkColor = accent; - const QColor btnFace = getSysColor(COLOR_3DFACE); - const QColor btnHighlight = getSysColor(COLOR_HIGHLIGHT); + const QColor btnFace = background; + const QColor btnHighlight = getSysColor(COLOR_BTNHIGHLIGHT); result.setColor(QPalette::Highlight, getSysColor(COLOR_HIGHLIGHT)); result.setColor(QPalette::WindowText, getSysColor(COLOR_WINDOWTEXT)); result.setColor(QPalette::Button, btnFace); - result.setColor(QPalette::Light, result.button().color().lighter(150)); - result.setColor(QPalette::Dark, result.button().color().darker(200)); + result.setColor(QPalette::Light, btnHighlight); + result.setColor(QPalette::Dark, getSysColor(COLOR_BTNSHADOW)); result.setColor(QPalette::Mid, result.button().color().darker(150)); result.setColor(QPalette::Text, textColor); result.setColor(QPalette::PlaceholderText, placeHolderColor(textColor)); result.setColor(QPalette::BrightText, btnHighlight); - result.setColor(QPalette::Base, getSysColor(COLOR_3DFACE)); - result.setColor(QPalette::Window, getSysColor(COLOR_WINDOW)); + result.setColor(QPalette::Base, getSysColor(COLOR_WINDOW)); + result.setColor(QPalette::Window, btnFace); result.setColor(QPalette::ButtonText, getSysColor(COLOR_BTNTEXT)); - result.setColor(QPalette::Midlight, result.button().color().lighter(125)); - result.setColor(QPalette::Shadow, Qt::black); + result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT)); + result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW)); result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT)); result.setColor(QPalette::Accent, accent); - result.setColor(QPalette::ToolTipBase, getSysColor(COLOR_WINDOW)); - result.setColor(QPalette::ToolTipText, getSysColor(COLOR_WINDOWTEXT)); result.setColor(QPalette::Link, linkColor); result.setColor(QPalette::LinkVisited, accentDarkest); @@ -404,7 +334,8 @@ static void populateDarkSystemBasePalette(QPalette &result) const QColor accentLightest = accentLighter.lighter(120); #endif const QColor linkColor = accent; - const QColor buttonColor = background.lighter(); + const QColor buttonColor = background.lighter(200); + result.setColor(QPalette::All, QPalette::WindowText, foreground); result.setColor(QPalette::All, QPalette::Text, foreground); result.setColor(QPalette::All, QPalette::BrightText, accentLightest); @@ -429,25 +360,14 @@ static void populateDarkSystemBasePalette(QPalette &result) result.setColor(QPalette::All, QPalette::ToolTipText, foreground.darker(120)); result.setColor(QPalette::All, QPalette::PlaceholderText, placeHolderColor(foreground)); result.setColor(QPalette::All, QPalette::Accent, accent); - - result.setColor(QPalette::Inactive, QPalette::Button, result.button().color()); - result.setColor(QPalette::Inactive, QPalette::Window, result.window().color()); - result.setColor(QPalette::Inactive, QPalette::Light, result.light().color()); - result.setColor(QPalette::Inactive, QPalette::Dark, result.dark().color()); - result.setColor(QPalette::Disabled, QPalette::Text, result.text().color().darker()); - result.setColor(QPalette::Disabled, QPalette::WindowText, result.windowText().color().darker()); - - - if (result.midlight() == result.button()) - result.setColor(QPalette::Midlight, result.button().color().lighter(110)); } static inline QPalette toolTipPalette(const QPalette &systemPalette, bool light) { QPalette result(systemPalette); - const QColor tipBgColor = light ? getSysColor(COLOR_WINDOW) + const QColor tipBgColor = light ? getSysColor(COLOR_INFOBK) : systemPalette.button().color(); - const QColor tipTextColor = light ? getSysColor(COLOR_WINDOWTEXT) + const QColor tipTextColor = light ? getSysColor(COLOR_INFOTEXT) : systemPalette.buttonText().color().darker(120); result.setColor(QPalette::All, QPalette::Button, tipBgColor); @@ -472,16 +392,15 @@ static inline QPalette toolTipPalette(const QPalette &systemPalette, bool light) return result; } -/* - The colors for Windows 11 are taken from the official WinUI3 Figma style at - https://www.figma.com/community/file/1159947337437047524 -*/ static inline QPalette menuPalette(const QPalette &systemPalette, bool light) { + if (!light) + return systemPalette; + QPalette result(systemPalette); - const QColor menuColor = light ? getSysColor(COLOR_3DFACE) : QColor(0x00,0x00,0x00,0xFF); - const QColor menuTextColor = light ? getSysColor(COLOR_WINDOWTEXT) : QColor(0xFF,0xFF,0xFF,0xFF); - const QColor disabled = light ? getSysColor(COLOR_GRAYTEXT) : menuTextColor.darker(); + const QColor menuColor = getSysColor(COLOR_MENU); + const QColor menuTextColor = getSysColor(COLOR_MENUTEXT); + const QColor disabled = getSysColor(COLOR_GRAYTEXT); // we might need a special color group for the result. result.setColor(QPalette::Active, QPalette::Button, menuColor); result.setColor(QPalette::Active, QPalette::Text, menuTextColor); @@ -489,10 +408,9 @@ static inline QPalette menuPalette(const QPalette &systemPalette, bool light) result.setColor(QPalette::Active, QPalette::ButtonText, menuTextColor); result.setColor(QPalette::Disabled, QPalette::WindowText, disabled); result.setColor(QPalette::Disabled, QPalette::Text, disabled); - const QColor highlightColor = getSysColor(COLOR_HIGHLIGHT); - result.setColor(QPalette::Active, QPalette::Highlight, highlightColor); - - result.setColor(QPalette::Active, QPalette::HighlightedText, menuTextColor); + const bool isFlat = booleanSystemParametersInfo(SPI_GETFLATMENU, false); + const QColor highlightColor = getSysColor(isFlat ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT); + result.setColor(QPalette::Disabled, QPalette::Highlight, highlightColor); result.setColor(QPalette::Disabled, QPalette::HighlightedText, disabled); result.setColor(QPalette::Disabled, QPalette::Button, result.color(QPalette::Active, QPalette::Button)); @@ -513,18 +431,14 @@ static inline QPalette menuPalette(const QPalette &systemPalette, bool light) return result; } -/* - The colors for Windows 11 are taken from the official WinUI3 Figma style at - https://www.figma.com/community/file/1159947337437047524 -*/ static inline QPalette *menuBarPalette(const QPalette &menuPalette, bool light) { QPalette *result = nullptr; - if (!booleanSystemParametersInfo(SPI_GETFLATMENU, false)) + if (!light || !booleanSystemParametersInfo(SPI_GETFLATMENU, false)) return result; result = new QPalette(menuPalette); - const QColor menubar = light ? getSysColor(COLOR_WINDOW) : QColor(0x00,0x00,0x00,0x00); + const QColor menubar(getSysColor(COLOR_MENUBAR)); result->setColor(QPalette::Active, QPalette::Button, menubar); result->setColor(QPalette::Disabled, QPalette::Button, menubar); result->setColor(QPalette::Inactive, QPalette::Button, menubar); @@ -660,40 +574,30 @@ void QWindowsTheme::refreshPalettes() QPalette QWindowsTheme::systemPalette(Qt::ColorScheme colorScheme) { - static const bool isWin11OrUpward = QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11; - static const bool highContrastMode = QWindowsTheme::queryHighContrast(); - QPalette result = standardPalette(); + switch (colorScheme) { - case Qt::ColorScheme::Light: - populateLightSystemBasePalette(result); - break; - case Qt::ColorScheme::Dark: - populateDarkSystemBasePalette(result); - break; - default: - qFatal("Unknown color scheme"); - break; - } - if (highContrastMode) { - populateHighContrastSystemBasePalette(result); + case Qt::ColorScheme::Light: + populateLightSystemBasePalette(result); + break; + case Qt::ColorScheme::Dark: + populateDarkSystemBasePalette(result); + break; + default: + qFatal("Unknown color scheme"); + break; } - if (result.window() != result.base() && (!isWin11OrUpward || highContrastMode)) { + if (result.window() != result.base()) { result.setColor(QPalette::Inactive, QPalette::Highlight, result.color(QPalette::Inactive, QPalette::Window)); result.setColor(QPalette::Inactive, QPalette::HighlightedText, result.color(QPalette::Inactive, QPalette::Text)); - // Only set this if it hasn't been set. - if (!result.isBrushSet(QPalette::Inactive, QPalette::Accent)) { - // We set Accent to Window to match the behavior of Windows 11. - result.setColor(QPalette::Inactive, QPalette::Accent, - result.color(QPalette::Inactive, QPalette::Window)); - } + result.setColor(QPalette::Inactive, QPalette::Accent, + result.color(QPalette::Inactive, QPalette::Window)); } - const QColor disabled = (isWin11OrUpward && !highContrastMode) ? result.text().color().darker() - : mixColors(result.windowText().color(), result.button().color()); + const QColor disabled = mixColors(result.windowText().color(), result.button().color()); result.setColorGroup(QPalette::Disabled, result.windowText(), result.button(), result.light(), result.dark(), result.mid(), diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index 6da6460536..7291723fec 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -1872,13 +1872,90 @@ void QWindows11Style::polish(QWidget* widget) } +/* +The colors for Windows 11 are taken from the official WinUI3 Figma style at +https://www.figma.com/community/file/1159947337437047524 +*/ +static void populateLightSystemBasePalette(QPalette &result) +{ + static QString oldStyleSheet; + const bool styleSheetChanged = oldStyleSheet != qApp->styleSheet(); + + QPalette standardPalette = QApplication::palette(); + const QColor textColor = QColor(0x00,0x00,0x00,0xE4); + + const QColor btnFace = QColor(0xFF,0xFF,0xFF,0xB3); + const QColor btnHighlight = result.accent().color(); + const QColor btnColor = result.button().color(); + + if (standardPalette.color(QPalette::Highlight) == result.color(QPalette::Highlight) || styleSheetChanged) + result.setColor(QPalette::Highlight, btnHighlight); + if (standardPalette.color(QPalette::WindowText) == result.color(QPalette::WindowText) || styleSheetChanged) + result.setColor(QPalette::WindowText, textColor); + if (standardPalette.color(QPalette::Button) == result.color(QPalette::Button) || styleSheetChanged) + result.setColor(QPalette::Button, btnFace); + if (standardPalette.color(QPalette::Light) == result.color(QPalette::Light) || styleSheetChanged) + result.setColor(QPalette::Light, btnColor.lighter(150)); + if (standardPalette.color(QPalette::Dark) == result.color(QPalette::Dark) || styleSheetChanged) + result.setColor(QPalette::Dark, btnColor.darker(200)); + if (standardPalette.color(QPalette::Mid) == result.color(QPalette::Mid) || styleSheetChanged) + result.setColor(QPalette::Mid, btnColor.darker(150)); + if (standardPalette.color(QPalette::Text) == result.color(QPalette::Text) || styleSheetChanged) + result.setColor(QPalette::Text, textColor); + if (standardPalette.color(QPalette::BrightText) != result.color(QPalette::BrightText) || styleSheetChanged) + result.setColor(QPalette::BrightText, btnHighlight); + if (standardPalette.color(QPalette::Base) == result.color(QPalette::Base) || styleSheetChanged) + result.setColor(QPalette::Base, btnFace); + if (standardPalette.color(QPalette::Window) == result.color(QPalette::Window) || styleSheetChanged) + result.setColor(QPalette::Window, QColor(0xF3,0xF3,0xF3,0xFF)); + if (standardPalette.color(QPalette::ButtonText) == result.color(QPalette::ButtonText) || styleSheetChanged) + result.setColor(QPalette::ButtonText, textColor); + if (standardPalette.color(QPalette::Midlight) == result.color(QPalette::Midlight) || styleSheetChanged) + result.setColor(QPalette::Midlight, btnColor.lighter(125)); + if (standardPalette.color(QPalette::Shadow) == result.color(QPalette::Shadow) || styleSheetChanged) + result.setColor(QPalette::Shadow, Qt::black); + if (standardPalette.color(QPalette::ToolTipBase) == result.color(QPalette::ToolTipBase) || styleSheetChanged) + result.setColor(QPalette::ToolTipBase, result.window().color()); + if (standardPalette.color(QPalette::ToolTipText) == result.color(QPalette::ToolTipText) || styleSheetChanged) + result.setColor(QPalette::ToolTipText, result.windowText().color()); + + if (result.midlight() == result.button()) + result.setColor(QPalette::Midlight, btnColor.lighter(110)); + oldStyleSheet = qApp->styleSheet(); +} + /*! \internal */ -void QWindows11Style::polish(QPalette& /*pal*/) +void QWindows11Style::polish(QPalette& pal) { highContrastTheme = QGuiApplicationPrivate::colorScheme() == Qt::ColorScheme::Unknown; colorSchemeIndex = QGuiApplicationPrivate::colorScheme() == Qt::ColorScheme::Light ? 0 : 1; + + if (!highContrastTheme && colorSchemeIndex == 0) + populateLightSystemBasePalette(pal); + + if (standardPalette().color(QPalette::Inactive, QPalette::Button) == pal.color(QPalette::Inactive, QPalette::Button)) + pal.setColor(QPalette::Inactive, QPalette::Button, pal.button().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::Window) == pal.color(QPalette::Inactive, QPalette::Window)) + pal.setColor(QPalette::Inactive, QPalette::Window, pal.window().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::Light) == pal.color(QPalette::Inactive, QPalette::Light)) + pal.setColor(QPalette::Inactive, QPalette::Light, pal.light().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::Dark) == pal.color(QPalette::Inactive, QPalette::Dark)) + pal.setColor(QPalette::Inactive, QPalette::Dark, pal.dark().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::Accent) == pal.color(QPalette::Inactive, QPalette::Accent)) + pal.setColor(QPalette::Inactive, QPalette::Accent, pal.accent().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::Highlight) == pal.color(QPalette::Inactive, QPalette::Highlight)) + pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.highlight().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::HighlightedText) == pal.color(QPalette::Inactive, QPalette::HighlightedText)) + pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.highlightedText().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::Text) == pal.color(QPalette::Inactive, QPalette::Text)) + pal.setColor(QPalette::Inactive, QPalette::Text, pal.text().color()); + if (standardPalette().color(QPalette::Inactive, QPalette::WindowText) == pal.color(QPalette::Inactive, QPalette::WindowText)) + pal.setColor(QPalette::Inactive, QPalette::WindowText, pal.windowText().color()); + + if (highContrastTheme) + pal.setColor(QPalette::Active, QPalette::HighlightedText, pal.windowText().color()); } QT_END_NAMESPACE |