Windows QPA plugin: Move palette helper function to qwindowstheme.h
This avoids the duplication of helper functions. Amends a2518b4140ed88a674bf4a4fcf4576e35c698bb9. Task-number: QTBUG-109394 Change-Id: If969a6497aed3b3662621cf723772c87eb66fd23 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 9ac0742d3699bdce7015abeecec8aa23abea47d6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
efe740e03b
commit
db6b607cae
@ -9,17 +9,13 @@
|
||||
#include "qwindowsopengltester.h"
|
||||
#include "qwindowswindow.h"
|
||||
#include "qwindowsintegration.h"
|
||||
#include "qwindowstheme.h"
|
||||
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QtCore/private/qfunctions_win_p.h>
|
||||
|
||||
#include <QtGui/qpalette.h>
|
||||
|
||||
#if QT_CONFIG(cpp_winrt)
|
||||
# include <QtCore/private/qt_winrtbase_p.h>
|
||||
# include <winrt/Windows.UI.ViewManagement.h>
|
||||
#endif // QT_CONFIG(cpp_winrt)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
void QWindowsApplication::setTouchWindowTouchType(QWindowsApplication::TouchWindowTouchTypes type)
|
||||
@ -147,67 +143,9 @@ QVariant QWindowsApplication::gpuList() const
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline QColor getSysColor(int index)
|
||||
{
|
||||
COLORREF cr = GetSysColor(index);
|
||||
return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr));
|
||||
}
|
||||
|
||||
#if QT_CONFIG(cpp_winrt)
|
||||
static constexpr QColor getSysColor(winrt::Windows::UI::Color &&color)
|
||||
{
|
||||
return QColor(color.R, color.G, color.B, color.A);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline QColor placeHolderColor(QColor textColor)
|
||||
{
|
||||
textColor.setAlpha(128);
|
||||
return textColor;
|
||||
}
|
||||
|
||||
void QWindowsApplication::lightSystemPalette(QPalette &result) const
|
||||
{
|
||||
QColor background = getSysColor(COLOR_BTNFACE);
|
||||
QColor textColor = getSysColor(COLOR_WINDOWTEXT);
|
||||
QColor accent = getSysColor(COLOR_HIGHLIGHT);
|
||||
|
||||
#if QT_CONFIG(cpp_winrt)
|
||||
// respect the Windows 11 accent color
|
||||
using namespace winrt::Windows::UI::ViewManagement;
|
||||
const auto settings = UISettings();
|
||||
|
||||
accent = getSysColor(settings.GetColorValue(UIColorType::Accent));
|
||||
#endif
|
||||
|
||||
const QColor btnFace = background;
|
||||
const QColor btnHighlight = getSysColor(COLOR_BTNHIGHLIGHT);
|
||||
|
||||
result.setColor(QPalette::Highlight, accent);
|
||||
result.setColor(QPalette::WindowText, getSysColor(COLOR_WINDOWTEXT));
|
||||
result.setColor(QPalette::Button, btnFace);
|
||||
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_WINDOW));
|
||||
result.setColor(QPalette::Window, btnFace);
|
||||
result.setColor(QPalette::ButtonText, getSysColor(COLOR_BTNTEXT));
|
||||
result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT));
|
||||
result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW));
|
||||
result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT));
|
||||
|
||||
result.setColor(QPalette::Link, Qt::blue);
|
||||
result.setColor(QPalette::LinkVisited, Qt::magenta);
|
||||
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));
|
||||
QWindowsTheme::populateLightSystemBasePalette(result);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -225,11 +225,48 @@ 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)
|
||||
{
|
||||
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
|
||||
if (auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()))
|
||||
nativeWindowsApp->lightSystemPalette(result);
|
||||
QColor background = getSysColor(COLOR_BTNFACE);
|
||||
QColor textColor = getSysColor(COLOR_WINDOWTEXT);
|
||||
QColor accent = getSysColor(COLOR_HIGHLIGHT);
|
||||
|
||||
#if QT_CONFIG(cpp_winrt)
|
||||
// respect the Windows 11 accent color
|
||||
using namespace winrt::Windows::UI::ViewManagement;
|
||||
const auto settings = UISettings();
|
||||
|
||||
accent = getSysColor(settings.GetColorValue(UIColorType::Accent));
|
||||
#endif
|
||||
|
||||
const QColor btnFace = background;
|
||||
const QColor btnHighlight = getSysColor(COLOR_BTNHIGHLIGHT);
|
||||
|
||||
result.setColor(QPalette::Highlight, accent);
|
||||
result.setColor(QPalette::WindowText, getSysColor(COLOR_WINDOWTEXT));
|
||||
result.setColor(QPalette::Button, btnFace);
|
||||
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_WINDOW));
|
||||
result.setColor(QPalette::Window, btnFace);
|
||||
result.setColor(QPalette::ButtonText, getSysColor(COLOR_BTNTEXT));
|
||||
result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT));
|
||||
result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW));
|
||||
result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT));
|
||||
|
||||
result.setColor(QPalette::Link, Qt::blue);
|
||||
result.setColor(QPalette::LinkVisited, Qt::magenta);
|
||||
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));
|
||||
}
|
||||
|
||||
static void populateDarkSystemBasePalette(QPalette &result)
|
||||
@ -300,7 +337,7 @@ static QPalette systemPalette(bool light)
|
||||
{
|
||||
QPalette result = standardPalette();
|
||||
if (light)
|
||||
populateLightSystemBasePalette(result);
|
||||
QWindowsTheme::populateLightSystemBasePalette(result);
|
||||
else
|
||||
populateDarkSystemBasePalette(result);
|
||||
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
|
||||
static const char *name;
|
||||
|
||||
static void populateLightSystemBasePalette(QPalette &result);
|
||||
|
||||
private:
|
||||
void clearPalettes();
|
||||
void refreshPalettes();
|
||||
|
Loading…
x
Reference in New Issue
Block a user