Remove QWindowsStylePrivate:isDarkMode

The only usage of that function is to decide whether we should etch
disabled text. That should depend on the actual palette we are using,
not on a system setting (that might be ignored by an application or
style overwriting the palette).

Since styleHint might be called without option and widget, fall back to
the application default palette if needed.

Change-Id: Icf90eb4198890c613dccea6188733e74995962c5
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-12-07 17:39:39 +01:00
parent a2518b4140
commit 13784450d1
2 changed files with 7 additions and 18 deletions

View File

@ -93,21 +93,6 @@ qreal QWindowsStylePrivate::appDevicePixelRatio()
return qApp->devicePixelRatio();
}
bool QWindowsStylePrivate::isDarkMode()
{
bool result = false;
#ifdef Q_OS_WIN
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
// Windows only: Return whether dark mode style support is desired and
// dark mode is in effect.
if (auto windowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration())) {
result = windowsApp->isDarkMode()
&& windowsApp->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle);
}
#endif
return result;
}
// Returns \c true if the toplevel parent of \a widget has seen the Alt-key
bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const
{
@ -514,9 +499,14 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid
int ret = 0;
switch (hint) {
case SH_EtchDisabledText:
ret = d_func()->isDarkMode() ? 0 : 1;
case SH_EtchDisabledText: {
const QPalette pal = opt ? opt->palette
: widget ? widget->palette()
: QPalette();
ret = pal.window().color().lightness() > pal.text().color().lightness()
? 1 : 0;
break;
}
case SH_Slider_SnapToValue:
case SH_PrintDialog_RightAlignButtons:
case SH_FontDialog_SelectAssociatedText:

View File

@ -38,7 +38,6 @@ public:
static qreal devicePixelRatio(const QWidget *widget = nullptr)
{ return widget ? widget->devicePixelRatio() : QWindowsStylePrivate::appDevicePixelRatio(); }
static qreal nativeMetricScaleFactor(const QWidget *widget = nullptr);
static bool isDarkMode();
bool hasSeenAlt(const QWidget *widget) const;
bool altDown() const { return alt_down; }