Rename Qt::Appearance to Qt::ColorScheme

Based on discussions in the 6.5 API review, where we concluded that
'appearance' is too general. Instead, we follow the CSS standard
and use the term 'color scheme'.

Change-Id: I8ceaf4138ecadff5ccd962480e8e5beb39b556ec
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Jonas Kvinge <jonas@jkvinge.net>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 32749c913b32e89e2027227233794f2296166cc6)
This commit is contained in:
Tor Arne Vestbø 2023-02-09 14:16:05 +01:00 committed by Axel Spoerl
parent 9a7a12692f
commit c22cf6dc07
35 changed files with 164 additions and 193 deletions

View File

@ -46,12 +46,6 @@ namespace Qt {
transparent transparent
}; };
enum class Appearance {
Unknown,
Light,
Dark,
};
enum class ColorScheme { enum class ColorScheme {
Unknown, Unknown,
Light, Light,
@ -1763,7 +1757,6 @@ namespace Qt {
Q_ENUM_NS(DayOfWeek) Q_ENUM_NS(DayOfWeek)
Q_ENUM_NS(CursorShape) Q_ENUM_NS(CursorShape)
Q_ENUM_NS(GlobalColor) Q_ENUM_NS(GlobalColor)
Q_ENUM_NS(Appearance)
Q_ENUM_NS(ColorScheme) Q_ENUM_NS(ColorScheme)
Q_ENUM_NS(AspectRatioMode) Q_ENUM_NS(AspectRatioMode)
Q_ENUM_NS(TransformationMode) Q_ENUM_NS(TransformationMode)

View File

@ -799,7 +799,7 @@
*/ */
/*! /*!
\enum Qt::Appearance \enum Qt::ColorScheme
Represents the appearance of an application's theme, Represents the appearance of an application's theme,
defined by QGuiApplication::palette(). defined by QGuiApplication::palette().

View File

@ -1496,7 +1496,7 @@ void QGuiApplicationPrivate::createPlatformIntegration()
init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv); init_platform(QLatin1StringView(platformName), platformPluginPath, platformThemeName, argc, argv);
if (const QPlatformTheme *theme = platformTheme()) if (const QPlatformTheme *theme = platformTheme())
QStyleHintsPrivate::get(QGuiApplication::styleHints())->setAppearance(theme->appearance()); QStyleHintsPrivate::get(QGuiApplication::styleHints())->setColorScheme(theme->colorScheme());
if (!icon.isEmpty()) if (!icon.isEmpty())
forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon); forcedWindowIcon = QDir::isAbsolutePath(icon) ? QIcon(icon) : QIcon::fromTheme(icon);
@ -2595,22 +2595,15 @@ void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::
for (auto *window : windows) for (auto *window : windows)
QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent); QGuiApplication::sendSpontaneousEvent(window, &themeChangeEvent);
QStyleHintsPrivate::get(QGuiApplication::styleHints())->setAppearance(appearance()); QStyleHintsPrivate::get(QGuiApplication::styleHints())->setColorScheme(colorScheme());
} }
/*! /*!
\internal \internal
\brief QGuiApplicationPrivate::appearance \brief QGuiApplicationPrivate::colorScheme
\return the platform theme's appearance \return the platform theme's color scheme
or Qt::Appearance::Unknown if a platform theme cannot be established or Qt::ColorScheme::Unknown if a platform theme cannot be established
Qt::Appearance.
*/ */
Qt::Appearance QGuiApplicationPrivate::appearance()
{
return platformTheme() ? platformTheme()->appearance()
: Qt::Appearance::Unknown;
}
Qt::ColorScheme QGuiApplicationPrivate::colorScheme() Qt::ColorScheme QGuiApplicationPrivate::colorScheme()
{ {
return platformTheme() ? platformTheme()->colorScheme() return platformTheme() ? platformTheme()->colorScheme()

View File

@ -313,7 +313,6 @@ private:
friend class QDragManager; friend class QDragManager;
static Qt::Appearance appearance();
static Qt::ColorScheme colorScheme(); static Qt::ColorScheme colorScheme();
static QGuiApplicationPrivate *self; static QGuiApplicationPrivate *self;

View File

@ -356,7 +356,7 @@ Q_GUI_EXPORT QPalette qt_fusionPalette()
{ {
auto theme = QGuiApplicationPrivate::platformTheme(); auto theme = QGuiApplicationPrivate::platformTheme();
const bool darkAppearance = theme const bool darkAppearance = theme
? theme->appearance() == Qt::Appearance::Dark ? theme->colorScheme() == Qt::ColorScheme::Dark
: false; : false;
const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black; const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black;
const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239); const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239);
@ -436,14 +436,9 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType typ
return nullptr; return nullptr;
} }
Qt::Appearance QPlatformTheme::appearance() const
{
return Qt::Appearance::Unknown;
}
Qt::ColorScheme QPlatformTheme::colorScheme() const Qt::ColorScheme QPlatformTheme::colorScheme() const
{ {
return Qt::ColorScheme(appearance()); return Qt::ColorScheme::Unknown;
} }
const QPalette *QPlatformTheme::palette(Palette type) const const QPalette *QPlatformTheme::palette(Palette type) const

View File

@ -293,7 +293,6 @@ public:
virtual QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const; virtual QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const;
#endif #endif
virtual Qt::Appearance appearance() const;
virtual Qt::ColorScheme colorScheme() const; virtual Qt::ColorScheme colorScheme() const;
virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QPalette *palette(Palette type = SystemPalette) const;

View File

@ -122,20 +122,15 @@ int QStyleHints::touchDoubleTapDistance() const
} }
/*! /*!
\property QStyleHints::appearance \property QStyleHints::colorScheme
\brief the appearance of the platform theme \brief the color scheme of the platform theme.
\sa Qt::Appearance \sa Qt::ColorScheme
\since 6.5 \since 6.5
*/ */
Qt::Appearance QStyleHints::appearance() const
{
Q_D(const QStyleHints);
return d->appearance();
}
Qt::ColorScheme QStyleHints::colorScheme() const Qt::ColorScheme QStyleHints::colorScheme() const
{ {
return Qt::ColorScheme(appearance()); Q_D(const QStyleHints);
return d->colorScheme();
} }
/*! /*!
@ -597,17 +592,17 @@ int QStyleHints::mouseQuickSelectionThreshold() const
/*! /*!
\internal \internal
QStyleHintsPrivate::setAppearance - set a new appearance. QStyleHintsPrivate::setColorScheme - set a new color scheme.
Set \a appearance as the new appearance of the QStyleHints. Set \a colorScheme as the new color scheme of the QStyleHints.
The appearanceChanged signal will be emitted if present and new appearance differ. The colorSchemeChanged signal will be emitted if present and new color scheme differ.
*/ */
void QStyleHintsPrivate::setAppearance(Qt::Appearance appearance) void QStyleHintsPrivate::setColorScheme(Qt::ColorScheme colorScheme)
{ {
if (m_appearance == appearance) if (m_colorScheme == colorScheme)
return; return;
m_appearance = appearance; m_colorScheme = colorScheme;
Q_Q(QStyleHints); Q_Q(QStyleHints);
emit q->appearanceChanged(appearance); emit q->colorSchemeChanged(colorScheme);
} }
QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q) QStyleHintsPrivate *QStyleHintsPrivate::get(QStyleHints *q)

View File

@ -52,7 +52,6 @@ class Q_GUI_EXPORT QStyleHints : public QObject
Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT Q_PROPERTY(int mouseDoubleClickDistance READ mouseDoubleClickDistance STORED false CONSTANT
FINAL) FINAL)
Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL) Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL)
Q_PROPERTY(Qt::Appearance appearance READ appearance NOTIFY appearanceChanged FINAL)
Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme NOTIFY colorSchemeChanged FINAL) Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme NOTIFY colorSchemeChanged FINAL)
public: public:
@ -94,7 +93,6 @@ public:
void setWheelScrollLines(int scrollLines); void setWheelScrollLines(int scrollLines);
void setMouseQuickSelectionThreshold(int threshold); void setMouseQuickSelectionThreshold(int threshold);
int mouseQuickSelectionThreshold() const; int mouseQuickSelectionThreshold() const;
Qt::Appearance appearance() const;
Qt::ColorScheme colorScheme() const; Qt::ColorScheme colorScheme() const;
Q_SIGNALS: Q_SIGNALS:
@ -109,7 +107,6 @@ Q_SIGNALS:
void showShortcutsInContextMenusChanged(bool); void showShortcutsInContextMenusChanged(bool);
void wheelScrollLinesChanged(int scrollLines); void wheelScrollLinesChanged(int scrollLines);
void mouseQuickSelectionThresholdChanged(int threshold); void mouseQuickSelectionThresholdChanged(int threshold);
void appearanceChanged(Qt::Appearance appearance);
void colorSchemeChanged(Qt::ColorScheme colorScheme); void colorSchemeChanged(Qt::ColorScheme colorScheme);
private: private:

View File

@ -40,13 +40,13 @@ public:
int m_mouseDoubleClickDistance = -1; int m_mouseDoubleClickDistance = -1;
int m_touchDoubleTapDistance = -1; int m_touchDoubleTapDistance = -1;
Qt::Appearance appearance() const { return m_appearance; } Qt::ColorScheme colorScheme() const { return m_colorScheme; }
void setAppearance(Qt::Appearance appearance); void setColorScheme(Qt::ColorScheme colorScheme);
static QStyleHintsPrivate *get(QStyleHints *q); static QStyleHintsPrivate *get(QStyleHints *q);
private: private:
Qt::Appearance m_appearance = Qt::Appearance::Unknown; Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -374,8 +374,8 @@ public:
int startDragDist = 10; int startDragDist = 10;
int startDragTime = 500; int startDragTime = 500;
int cursorBlinkRate = 1000; int cursorBlinkRate = 1000;
Qt::Appearance m_appearance = Qt::Appearance::Unknown; Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
void updateAppearance(const QString &themeName); void updateColorScheme(const QString &themeName);
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
private: private:
@ -464,9 +464,9 @@ void QKdeThemePrivate::refresh()
kdeVersion, kdeSettings); kdeVersion, kdeSettings);
if (colorScheme.isValid()) if (colorScheme.isValid())
updateAppearance(colorScheme.toString()); updateColorScheme(colorScheme.toString());
else else
m_appearance = Qt::Appearance::Unknown; m_colorScheme = Qt::ColorScheme::Unknown;
const QVariant singleClickValue = readKdeSetting(QStringLiteral("KDE/SingleClick"), kdeDirs, kdeVersion, kdeSettings); const QVariant singleClickValue = readKdeSetting(QStringLiteral("KDE/SingleClick"), kdeDirs, kdeVersion, kdeSettings);
if (singleClickValue.isValid()) if (singleClickValue.isValid())
@ -749,14 +749,14 @@ QIcon QKdeTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions
#endif #endif
} }
Qt::Appearance QKdeTheme::appearance() const Qt::ColorScheme QKdeTheme::colorScheme() const
{ {
return d_func()->m_appearance; return d_func()->m_colorScheme;
} }
/*! /*!
\internal \internal
\brief QKdeTheme::setAppearance - guess and set appearance for unix themes. \brief QKdeTheme::setColorScheme - guess and set appearance for unix themes.
KDE themes do not have an appearance property. KDE themes do not have an appearance property.
The key words "dark" or "light" should be part of the theme name. The key words "dark" or "light" should be part of the theme name.
This is, however, not a mandatory convention. This is, however, not a mandatory convention.
@ -765,29 +765,29 @@ Qt::Appearance QKdeTheme::appearance() const
If it doesn't, the appearance is heuristically determined by comparing text and base color If it doesn't, the appearance is heuristically determined by comparing text and base color
of the system palette. of the system palette.
*/ */
void QKdeThemePrivate::updateAppearance(const QString &themeName) void QKdeThemePrivate::updateColorScheme(const QString &themeName)
{ {
if (themeName.contains(QLatin1StringView("light"), Qt::CaseInsensitive)) { if (themeName.contains(QLatin1StringView("light"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Light; m_colorScheme = Qt::ColorScheme::Light;
return; return;
} }
if (themeName.contains(QLatin1StringView("dark"), Qt::CaseInsensitive)) { if (themeName.contains(QLatin1StringView("dark"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Dark; m_colorScheme = Qt::ColorScheme::Dark;
return; return;
} }
if (systemPalette) { if (systemPalette) {
if (systemPalette->text().color().lightness() < systemPalette->base().color().lightness()) { if (systemPalette->text().color().lightness() < systemPalette->base().color().lightness()) {
m_appearance = Qt::Appearance::Light; m_colorScheme = Qt::ColorScheme::Light;
return; return;
} }
if (systemPalette->text().color().lightness() > systemPalette->base().color().lightness()) { if (systemPalette->text().color().lightness() > systemPalette->base().color().lightness()) {
m_appearance = Qt::Appearance::Dark; m_colorScheme = Qt::ColorScheme::Dark;
return; return;
} }
} }
m_appearance = Qt::Appearance::Unknown; m_colorScheme = Qt::ColorScheme::Unknown;
} }
@ -911,11 +911,11 @@ public:
mutable QFont *fixedFont = nullptr; mutable QFont *fixedFont = nullptr;
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
Qt::Appearance m_appearance = Qt::Appearance::Unknown; Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
private: private:
std::unique_ptr<QGenericUnixThemeDBusListener> dbus; std::unique_ptr<QGenericUnixThemeDBusListener> dbus;
bool initDbus(); bool initDbus();
void updateAppearance(const QString &themeName); void updateColorScheme(const QString &themeName);
#endif // QT_NO_DBUS #endif // QT_NO_DBUS
}; };
@ -946,25 +946,25 @@ bool QGnomeThemePrivate::initDbus()
// Wrap slot in a lambda to avoid inheriting QGnomeThemePrivate from QObject // Wrap slot in a lambda to avoid inheriting QGnomeThemePrivate from QObject
auto wrapper = [this](QGenericUnixThemeDBusListener::SettingType type, const QString &value) { auto wrapper = [this](QGenericUnixThemeDBusListener::SettingType type, const QString &value) {
if (type == QGenericUnixThemeDBusListener::SettingType::GtkTheme) if (type == QGenericUnixThemeDBusListener::SettingType::GtkTheme)
updateAppearance(value); updateColorScheme(value);
}; };
return QObject::connect(dbus.get(), &QGenericUnixThemeDBusListener::settingChanged, wrapper); return QObject::connect(dbus.get(), &QGenericUnixThemeDBusListener::settingChanged, wrapper);
} }
void QGnomeThemePrivate::updateAppearance(const QString &themeName) void QGnomeThemePrivate::updateColorScheme(const QString &themeName)
{ {
const auto oldAppearance = m_appearance; const auto oldColorScheme = m_colorScheme;
if (themeName.contains(QLatin1StringView("light"), Qt::CaseInsensitive)) { if (themeName.contains(QLatin1StringView("light"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Light; m_colorScheme = Qt::ColorScheme::Light;
} else if (themeName.contains(QLatin1StringView("dark"), Qt::CaseInsensitive)) { } else if (themeName.contains(QLatin1StringView("dark"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Dark; m_colorScheme = Qt::ColorScheme::Dark;
} else { } else {
m_appearance = Qt::Appearance::Unknown; m_colorScheme = Qt::ColorScheme::Unknown;
} }
if (oldAppearance != m_appearance) if (oldColorScheme != m_colorScheme)
QWindowSystemInterface::handleThemeChange(); QWindowSystemInterface::handleThemeChange();
} }
#endif // QT_NO_DBUS #endif // QT_NO_DBUS
@ -1053,9 +1053,9 @@ QPlatformMenuBar *QGnomeTheme::createPlatformMenuBar() const
return nullptr; return nullptr;
} }
Qt::Appearance QGnomeTheme::appearance() const Qt::ColorScheme QGnomeTheme::colorScheme() const
{ {
return d_func()->m_appearance; return d_func()->m_colorScheme;
} }
#endif #endif

View File

@ -77,7 +77,7 @@ public:
QPlatformTheme::IconOptions iconOptions = { }) const override; QPlatformTheme::IconOptions iconOptions = { }) const override;
const QPalette *palette(Palette type = SystemPalette) const override; const QPalette *palette(Palette type = SystemPalette) const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
const QFont *font(Font type) const override; const QFont *font(Font type) const override;
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
@ -107,7 +107,7 @@ public:
virtual QString gtkFontName() const; virtual QString gtkFontName() const;
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
QPlatformMenuBar *createPlatformMenuBar() const override; QPlatformMenuBar *createPlatformMenuBar() const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
#endif #endif
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON) #if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override; QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override;

View File

@ -775,8 +775,8 @@ static void handleScreenRemoved(JNIEnv */*env*/, jclass /*cls*/, jint displayId)
static void handleUiDarkModeChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newUiMode) static void handleUiDarkModeChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newUiMode)
{ {
QAndroidPlatformIntegration::setAppearance( QAndroidPlatformIntegration::setColorScheme(
(newUiMode == 1 ) ? Qt::Appearance::Dark : Qt::Appearance::Light); (newUiMode == 1 ) ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light);
} }
static void onActivityResult(JNIEnv */*env*/, jclass /*cls*/, static void onActivityResult(JNIEnv */*env*/, jclass /*cls*/,

View File

@ -532,16 +532,16 @@ void QAndroidPlatformIntegration::setScreenSize(int width, int height)
QMetaObject::invokeMethod(m_primaryScreen, "setSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height))); QMetaObject::invokeMethod(m_primaryScreen, "setSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height)));
} }
Qt::Appearance QAndroidPlatformIntegration::m_appearance = Qt::Appearance::Light; Qt::ColorScheme QAndroidPlatformIntegration::m_colorScheme = Qt::ColorScheme::Light;
void QAndroidPlatformIntegration::setAppearance(Qt::Appearance newAppearance) void QAndroidPlatformIntegration::setColorScheme(Qt::ColorScheme colorScheme)
{ {
if (m_appearance == newAppearance) if (m_colorScheme == colorScheme)
return; return;
m_appearance = newAppearance; m_colorScheme = colorScheme;
QMetaObject::invokeMethod(qGuiApp, QMetaObject::invokeMethod(qGuiApp,
[] () { QAndroidPlatformTheme::instance()->updateAppearance();}); [] () { QAndroidPlatformTheme::instance()->updateColorScheme();});
} }
void QAndroidPlatformIntegration::setScreenSizeParameters(const QSize &physicalSize, void QAndroidPlatformIntegration::setScreenSizeParameters(const QSize &physicalSize,

View File

@ -110,8 +110,8 @@ public:
void flushPendingUpdates(); void flushPendingUpdates();
static void setAppearance(Qt::Appearance newAppearance); static void setColorScheme(Qt::ColorScheme colorScheme);
static Qt::Appearance appearance() { return m_appearance; } static Qt::ColorScheme colorScheme() { return m_colorScheme; }
#if QT_CONFIG(vulkan) #if QT_CONFIG(vulkan)
QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const override; QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const override;
#endif #endif
@ -124,7 +124,7 @@ private:
QThread *m_mainThread; QThread *m_mainThread;
static Qt::Appearance m_appearance; static Qt::ColorScheme m_colorScheme;
static QRect m_defaultAvailableGeometry; static QRect m_defaultAvailableGeometry;
static QSize m_defaultPhysicalSize; static QSize m_defaultPhysicalSize;

View File

@ -158,7 +158,7 @@ QJsonObject AndroidStyle::loadStyleData()
if (!stylePath.isEmpty() && !stylePath.endsWith(slashChar)) if (!stylePath.isEmpty() && !stylePath.endsWith(slashChar))
stylePath += slashChar; stylePath += slashChar;
if (QAndroidPlatformIntegration::appearance() == Qt::Appearance::Dark) if (QAndroidPlatformIntegration::colorScheme() == Qt::ColorScheme::Dark)
stylePath += "darkUiMode/"_L1; stylePath += "darkUiMode/"_L1;
Q_ASSERT(!stylePath.isEmpty()); Q_ASSERT(!stylePath.isEmpty());
@ -333,7 +333,7 @@ QAndroidPlatformTheme::~QAndroidPlatformTheme()
m_instance = nullptr; m_instance = nullptr;
} }
void QAndroidPlatformTheme::updateAppearance() void QAndroidPlatformTheme::updateColorScheme()
{ {
updateStyle(); updateStyle();
QWindowSystemInterface::handleThemeChange(); QWindowSystemInterface::handleThemeChange();
@ -358,7 +358,7 @@ void QAndroidPlatformTheme::updateStyle()
QColor highlight(148, 210, 231); QColor highlight(148, 210, 231);
QColor disabledShadow = shadow.lighter(150); QColor disabledShadow = shadow.lighter(150);
if (appearance() == Qt::Appearance::Dark) { if (colorScheme() == Qt::ColorScheme::Dark) {
// Colors were prepared based on Theme.DeviceDefault.DayNight // Colors were prepared based on Theme.DeviceDefault.DayNight
windowText = QColor(250, 250, 250); windowText = QColor(250, 250, 250);
background = QColor(48, 48, 48); background = QColor(48, 48, 48);
@ -418,9 +418,9 @@ void QAndroidPlatformTheme::showPlatformMenuBar()
QtAndroidMenu::openOptionsMenu(); QtAndroidMenu::openOptionsMenu();
} }
Qt::Appearance QAndroidPlatformTheme::appearance() const Qt::ColorScheme QAndroidPlatformTheme::colorScheme() const
{ {
return QAndroidPlatformIntegration::appearance(); return QAndroidPlatformIntegration::colorScheme();
} }
static inline int paletteType(QPlatformTheme::Palette type) static inline int paletteType(QPlatformTheme::Palette type)

View File

@ -31,13 +31,13 @@ class QAndroidPlatformTheme: public QPlatformTheme
{ {
public: public:
~QAndroidPlatformTheme(); ~QAndroidPlatformTheme();
void updateAppearance(); void updateColorScheme();
void updateStyle(); void updateStyle();
QPlatformMenuBar *createPlatformMenuBar() const override; QPlatformMenuBar *createPlatformMenuBar() const override;
QPlatformMenu *createPlatformMenu() const override; QPlatformMenu *createPlatformMenu() const override;
QPlatformMenuItem *createPlatformMenuItem() const override; QPlatformMenuItem *createPlatformMenuItem() const override;
void showPlatformMenuBar() override; void showPlatformMenuBar() override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
const QPalette *palette(Palette type = SystemPalette) const override; const QPalette *palette(Palette type = SystemPalette) const override;
const QFont *font(Font type = SystemFont) const override; const QFont *font(Font type = SystemFont) const override;
QVariant themeHint(ThemeHint hint) const override; QVariant themeHint(ThemeHint hint) const override;

View File

@ -37,7 +37,7 @@ public:
QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = {}) const override; QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = {}) const override;
QVariant themeHint(ThemeHint hint) const override; QVariant themeHint(ThemeHint hint) const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
QString standardButtonText(int button) const override; QString standardButtonText(int button) const override;
QKeySequence standardButtonShortcut(int button) const override; QKeySequence standardButtonShortcut(int button) const override;

View File

@ -470,9 +470,9 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const
return QPlatformTheme::themeHint(hint); return QPlatformTheme::themeHint(hint);
} }
Qt::Appearance QCocoaTheme::appearance() const Qt::ColorScheme QCocoaTheme::colorScheme() const
{ {
return qt_mac_applicationIsInDarkMode() ? Qt::Appearance::Dark : Qt::Appearance::Light; return qt_mac_applicationIsInDarkMode() ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
} }
QString QCocoaTheme::standardButtonText(int button) const QString QCocoaTheme::standardButtonText(int button) const

View File

@ -178,16 +178,16 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen)
{ {
[super traitCollectionDidChange:previousTraitCollection]; [super traitCollectionDidChange:previousTraitCollection];
Qt::Appearance appearance = self.traitCollection.userInterfaceStyle Qt::ColorScheme colorScheme = self.traitCollection.userInterfaceStyle
== UIUserInterfaceStyleDark == UIUserInterfaceStyleDark
? Qt::Appearance::Dark ? Qt::ColorScheme::Dark
: Qt::Appearance::Light; : Qt::ColorScheme::Light;
if (self.screen == UIScreen.mainScreen) { if (self.screen == UIScreen.mainScreen) {
// Check if the current userInterfaceStyle reports a different appearance than // Check if the current userInterfaceStyle reports a different appearance than
// the platformTheme's appearance. We might have set that one based on the UIScreen // the platformTheme's appearance. We might have set that one based on the UIScreen
if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle
|| QGuiApplicationPrivate::platformTheme()->appearance() != appearance) { || QGuiApplicationPrivate::platformTheme()->colorScheme() != colorScheme) {
QIOSTheme::initializeSystemPalette(); QIOSTheme::initializeSystemPalette();
QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>(); QWindowSystemInterface::handleThemeChange<QWindowSystemInterface::SynchronousDelivery>();
} }

View File

@ -21,7 +21,7 @@ public:
const QPalette *palette(Palette type = SystemPalette) const override; const QPalette *palette(Palette type = SystemPalette) const override;
QVariant themeHint(ThemeHint hint) const override; QVariant themeHint(ThemeHint hint) const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
QPlatformMenuItem* createPlatformMenuItem() const override; QPlatformMenuItem* createPlatformMenuItem() const override;
QPlatformMenu* createPlatformMenu() const override; QPlatformMenu* createPlatformMenu() const override;

View File

@ -142,7 +142,7 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const
} }
} }
Qt::Appearance QIOSTheme::appearance() const Qt::ColorScheme QIOSTheme::colorScheme() const
{ {
UIUserInterfaceStyle appearance = UIUserInterfaceStyleUnspecified; UIUserInterfaceStyle appearance = UIUserInterfaceStyleUnspecified;
// Set the appearance based on the UIWindow // Set the appearance based on the UIWindow
@ -153,8 +153,8 @@ Qt::Appearance QIOSTheme::appearance() const
appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle; appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle;
} }
return appearance == UIUserInterfaceStyleDark return appearance == UIUserInterfaceStyleDark
? Qt::Appearance::Dark ? Qt::ColorScheme::Dark
: Qt::Appearance::Light; : Qt::ColorScheme::Light;
} }
const QFont *QIOSTheme::font(Font type) const const QFont *QIOSTheme::font(Font type) const

View File

@ -499,9 +499,9 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const
return QPlatformTheme::themeHint(hint); return QPlatformTheme::themeHint(hint);
} }
Qt::Appearance QWindowsTheme::appearance() const Qt::ColorScheme QWindowsTheme::colorScheme() const
{ {
return QWindowsContext::isDarkMode() ? Qt::Appearance::Dark : Qt::Appearance::Light; return QWindowsContext::isDarkMode() ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
} }
void QWindowsTheme::clearPalettes() void QWindowsTheme::clearPalettes()

View File

@ -31,7 +31,7 @@ public:
#endif #endif
QVariant themeHint(ThemeHint) const override; QVariant themeHint(ThemeHint) const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
const QPalette *palette(Palette type = SystemPalette) const override const QPalette *palette(Palette type = SystemPalette) const override
{ return m_palettes[type]; } { return m_palettes[type]; }

View File

@ -488,14 +488,14 @@ const QString QGtk3Interface::themeName() const
/*! /*!
\internal \internal
\brief Determine appearance by colors. \brief Determine color scheme by colors.
Returns the appearance of the current GTK theme, heuristically determined by the Returns the color scheme of the current GTK theme, heuristically determined by the
lightness difference between default background and foreground colors. lightness difference between default background and foreground colors.
\note Returns Unknown in the unlikely case that both colors have the same lightness. \note Returns Unknown in the unlikely case that both colors have the same lightness.
*/ */
Qt::Appearance QGtk3Interface::appearanceByColors() const Qt::ColorScheme QGtk3Interface::colorSchemeByColors() const
{ {
const QColor background = color(widget(QGtkWidget::gtk_Default), const QColor background = color(widget(QGtkWidget::gtk_Default),
QGtkColorSource::Background, QGtkColorSource::Background,
@ -505,10 +505,10 @@ Qt::Appearance QGtk3Interface::appearanceByColors() const
GTK_STATE_FLAG_ACTIVE); GTK_STATE_FLAG_ACTIVE);
if (foreground.lightness() > background.lightness()) if (foreground.lightness() > background.lightness())
return Qt::Appearance::Dark; return Qt::ColorScheme::Dark;
if (foreground.lightness() < background.lightness()) if (foreground.lightness() < background.lightness())
return Qt::Appearance::Light; return Qt::ColorScheme::Light;
return Qt::Appearance::Unknown; return Qt::ColorScheme::Unknown;
} }
/*! /*!

View File

@ -137,8 +137,8 @@ public:
// Return current GTK theme name // Return current GTK theme name
const QString themeName() const; const QString themeName() const;
// Derive appearance from default colors // Derive color scheme from default colors
Qt::Appearance appearanceByColors() const; Qt::ColorScheme colorSchemeByColors() const;
// Convert GTK state to/from string // Convert GTK state to/from string
static int toGtkState(const QString &state); static int toGtkState(const QString &state);

View File

@ -53,9 +53,9 @@ QLatin1String QGtk3Json::fromWidgetType(QGtk3Interface::QGtkWidget widgetType)
return QLatin1String(QMetaEnum::fromType<QGtk3Interface::QGtkWidget>().valueToKey(static_cast<int>(widgetType))); return QLatin1String(QMetaEnum::fromType<QGtk3Interface::QGtkWidget>().valueToKey(static_cast<int>(widgetType)));
} }
QLatin1String QGtk3Json::fromAppearance(Qt::Appearance app) QLatin1String QGtk3Json::fromColorScheme(Qt::ColorScheme app)
{ {
return QLatin1String(QMetaEnum::fromType<Qt::Appearance>().valueToKey(static_cast<int>(app))); return QLatin1String(QMetaEnum::fromType<Qt::ColorScheme>().valueToKey(static_cast<int>(app)));
} }
#define CONVERT(type, key, def)\ #define CONVERT(type, key, def)\
@ -63,9 +63,9 @@ QLatin1String QGtk3Json::fromAppearance(Qt::Appearance app)
const int intVal = QMetaEnum::fromType<type>().keyToValue(key.toLatin1().constData(), &ok);\ const int intVal = QMetaEnum::fromType<type>().keyToValue(key.toLatin1().constData(), &ok);\
return ok ? static_cast<type>(intVal) : type::def return ok ? static_cast<type>(intVal) : type::def
Qt::Appearance QGtk3Json::toAppearance(const QString &appearance) Qt::ColorScheme QGtk3Json::toColorScheme(const QString &colorScheme)
{ {
CONVERT(Qt::Appearance, appearance, Unknown); CONVERT(Qt::ColorScheme, colorScheme, Unknown);
} }
QPlatformTheme::Palette QGtk3Json::toPalette(const QString &palette) QPlatformTheme::Palette QGtk3Json::toPalette(const QString &palette)
@ -175,7 +175,7 @@ const QJsonDocument QGtk3Json::save(const QGtk3Storage::PaletteMap &map)
const QGtk3Storage::TargetBrush tb = brushIterator.key(); const QGtk3Storage::TargetBrush tb = brushIterator.key();
QGtk3Storage::Source s = brushIterator.value(); QGtk3Storage::Source s = brushIterator.value();
brushObject.insert(ceColorGroup, fromColorGroup(tb.colorGroup)); brushObject.insert(ceColorGroup, fromColorGroup(tb.colorGroup));
brushObject.insert(ceAppearance, fromAppearance(tb.appearance)); brushObject.insert(ceColorScheme, fromColorScheme(tb.colorScheme));
brushObject.insert(ceSourceType, fromSourceType(s.sourceType)); brushObject.insert(ceSourceType, fromSourceType(s.sourceType));
QJsonObject sourceObject; QJsonObject sourceObject;
@ -201,7 +201,7 @@ const QJsonDocument QGtk3Json::save(const QGtk3Storage::PaletteMap &map)
case QGtk3Storage::SourceType::Modified:{ case QGtk3Storage::SourceType::Modified:{
sourceObject.insert(ceColorGroup, fromColorGroup(s.rec.colorGroup)); sourceObject.insert(ceColorGroup, fromColorGroup(s.rec.colorGroup));
sourceObject.insert(ceColorRole, fromColorRole(s.rec.colorRole)); sourceObject.insert(ceColorRole, fromColorRole(s.rec.colorRole));
sourceObject.insert(ceAppearance, fromAppearance(s.rec.appearance)); sourceObject.insert(ceColorScheme, fromColorScheme(s.rec.colorScheme));
sourceObject.insert(ceRed, s.rec.deltaRed); sourceObject.insert(ceRed, s.rec.deltaRed);
sourceObject.insert(ceGreen, s.rec.deltaGreen); sourceObject.insert(ceGreen, s.rec.deltaGreen);
sourceObject.insert(ceBlue, s.rec.deltaBlue); sourceObject.insert(ceBlue, s.rec.deltaBlue);
@ -322,9 +322,9 @@ bool QGtk3Json::load(QGtk3Storage::PaletteMap &map, const QJsonDocument &doc)
const QGtk3Storage::SourceType sourceType = toSourceType(value); const QGtk3Storage::SourceType sourceType = toSourceType(value);
GETSTR(brushObject, ceColorGroup); GETSTR(brushObject, ceColorGroup);
const QPalette::ColorGroup colorGroup = toColorGroup(value); const QPalette::ColorGroup colorGroup = toColorGroup(value);
GETSTR(brushObject, ceAppearance); GETSTR(brushObject, ceColorScheme);
const Qt::Appearance appearance = toAppearance(value); const Qt::ColorScheme colorScheme = toColorScheme(value);
QGtk3Storage::TargetBrush tb(colorGroup, colorRole, appearance); QGtk3Storage::TargetBrush tb(colorGroup, colorRole, colorScheme);
QGtk3Storage::Source s; QGtk3Storage::Source s;
if (!brushObject.contains(ceData) || !brushObject[ceData].isObject()) { if (!brushObject.contains(ceData) || !brushObject[ceData].isObject()) {
@ -376,13 +376,13 @@ bool QGtk3Json::load(QGtk3Storage::PaletteMap &map, const QJsonDocument &doc)
const QPalette::ColorGroup colorGroup = toColorGroup(value); const QPalette::ColorGroup colorGroup = toColorGroup(value);
GETSTR(sourceObject, ceColorRole); GETSTR(sourceObject, ceColorRole);
const QPalette::ColorRole colorRole = toColorRole(value); const QPalette::ColorRole colorRole = toColorRole(value);
GETSTR(sourceObject, ceAppearance); GETSTR(sourceObject, ceColorScheme);
const Qt::Appearance appearance = toAppearance(value); const Qt::ColorScheme colorScheme = toColorScheme(value);
GETINT(sourceObject, ceLighter, lighter); GETINT(sourceObject, ceLighter, lighter);
GETINT(sourceObject, ceRed, red); GETINT(sourceObject, ceRed, red);
GETINT(sourceObject, ceBlue, blue); GETINT(sourceObject, ceBlue, blue);
GETINT(sourceObject, ceGreen, green); GETINT(sourceObject, ceGreen, green);
s = QGtk3Storage::Source(colorGroup, colorRole, appearance, s = QGtk3Storage::Source(colorGroup, colorRole, colorScheme,
lighter, red, green, blue); lighter, red, green, blue);
} }
break; break;

View File

@ -50,7 +50,7 @@ public:
static QLatin1String fromGdkSource(QGtk3Interface::QGtkColorSource source); static QLatin1String fromGdkSource(QGtk3Interface::QGtkColorSource source);
static QLatin1String fromSourceType(QGtk3Storage::SourceType sourceType); static QLatin1String fromSourceType(QGtk3Storage::SourceType sourceType);
static QLatin1String fromWidgetType(QGtk3Interface::QGtkWidget widgetType); static QLatin1String fromWidgetType(QGtk3Interface::QGtkWidget widgetType);
static QLatin1String fromAppearance(Qt::Appearance app); static QLatin1String fromColorScheme(Qt::ColorScheme colorScheme);
// Convert strings to enums // Convert strings to enums
static QPlatformTheme::Palette toPalette(const QString &palette); static QPlatformTheme::Palette toPalette(const QString &palette);
@ -61,7 +61,7 @@ public:
static QGtk3Interface::QGtkColorSource toGdkSource(const QString &source); static QGtk3Interface::QGtkColorSource toGdkSource(const QString &source);
static QGtk3Storage::SourceType toSourceType(const QString &sourceType); static QGtk3Storage::SourceType toSourceType(const QString &sourceType);
static QGtk3Interface::QGtkWidget toWidgetType(const QString &widgetType); static QGtk3Interface::QGtkWidget toWidgetType(const QString &widgetType);
static Qt::Appearance toAppearance(const QString &appearance); static Qt::ColorScheme toColorScheme(const QString &colorScheme);
// Json keys // Json keys
static constexpr QLatin1StringView cePalettes = "QtGtk3Palettes"_L1; static constexpr QLatin1StringView cePalettes = "QtGtk3Palettes"_L1;
@ -82,7 +82,7 @@ public:
static constexpr QLatin1StringView ceBrush = "FixedBrush"_L1; static constexpr QLatin1StringView ceBrush = "FixedBrush"_L1;
static constexpr QLatin1StringView ceData = "SourceData"_L1; static constexpr QLatin1StringView ceData = "SourceData"_L1;
static constexpr QLatin1StringView ceBrushes = "Brushes"_L1; static constexpr QLatin1StringView ceBrushes = "Brushes"_L1;
static constexpr QLatin1StringView ceAppearance = "Appearance"_L1; static constexpr QLatin1StringView ceColorScheme = "ColorScheme"_L1;
// Save to a file // Save to a file
static bool save(const QGtk3Storage::PaletteMap &map, const QString &fileName, static bool save(const QGtk3Storage::PaletteMap &map, const QString &fileName,

View File

@ -55,7 +55,7 @@ QBrush QGtk3Storage::brush(const Source &source, const BrushMap &map) const
case SourceType::Modified: { case SourceType::Modified: {
// don't loop through modified sources, break if modified source not found // don't loop through modified sources, break if modified source not found
Source recSource = brush(TargetBrush(source.rec.colorGroup, source.rec.colorRole, Source recSource = brush(TargetBrush(source.rec.colorGroup, source.rec.colorRole,
source.rec.appearance), map); source.rec.colorScheme), map);
if (!recSource.isValid() || (recSource.sourceType == SourceType::Modified)) if (!recSource.isValid() || (recSource.sourceType == SourceType::Modified))
return QBrush(); return QBrush();
@ -99,15 +99,15 @@ QGtk3Storage::Source QGtk3Storage::brush(const TargetBrush &b, const BrushMap &m
// Return exact match // Return exact match
FIND(b); FIND(b);
// unknown appearance can find anything // unknown color scheme can find anything
if (b.appearance == Qt::Appearance::Unknown) { if (b.colorScheme == Qt::ColorScheme::Unknown) {
FIND(TargetBrush(b, Qt::Appearance::Dark)); FIND(TargetBrush(b, Qt::ColorScheme::Dark));
FIND(TargetBrush(b, Qt::Appearance::Light)); FIND(TargetBrush(b, Qt::ColorScheme::Light));
} }
// Color group All can always be found // Color group All can always be found
if (b.colorGroup != QPalette::All) if (b.colorGroup != QPalette::All)
return brush(TargetBrush(QPalette::All, b.colorRole, b.appearance), map); return brush(TargetBrush(QPalette::All, b.colorRole, b.colorScheme), map);
// Brush not found // Brush not found
return Source(); return Source();
@ -181,13 +181,13 @@ const QPalette *QGtk3Storage::palette(QPlatformTheme::Palette type) const
Source source = i.value(); Source source = i.value();
// Brush is set if // Brush is set if
// - theme and source appearance match // - theme and source color scheme match
// - or either of them is unknown // - or either of them is unknown
const auto appSource = i.key().appearance; const auto appSource = i.key().colorScheme;
const auto appTheme = appearance(); const auto appTheme = colorScheme();
const bool setBrush = (appSource == appTheme) || const bool setBrush = (appSource == appTheme) ||
(appSource == Qt::Appearance::Unknown) || (appSource == Qt::ColorScheme::Unknown) ||
(appTheme == Qt::Appearance::Unknown); (appTheme == Qt::ColorScheme::Unknown);
if (setBrush) { if (setBrush) {
p.setBrush(i.key().colorGroup, i.key().colorRole, brush(source, brushes)); p.setBrush(i.key().colorGroup, i.key().colorRole, brush(source, brushes));
@ -196,7 +196,7 @@ const QPalette *QGtk3Storage::palette(QPlatformTheme::Palette type) const
m_paletteCache[type].emplace(p); m_paletteCache[type].emplace(p);
if (type == QPlatformTheme::SystemPalette) if (type == QPlatformTheme::SystemPalette)
qCDebug(lcQGtk3Interface) << "System Palette defined" << themeName() << appearance() << p; qCDebug(lcQGtk3Interface) << "System Palette defined" << themeName() << colorScheme() << p;
return &m_paletteCache[type].value(); return &m_paletteCache[type].value();
} }
@ -255,7 +255,7 @@ QIcon QGtk3Storage::fileIcon(const QFileInfo &fileInfo) const
*/ */
void QGtk3Storage::clear() void QGtk3Storage::clear()
{ {
m_appearance = Qt::Appearance::Unknown; m_colorScheme = Qt::ColorScheme::Unknown;
m_palettes.clear(); m_palettes.clear();
for (auto &cache : m_paletteCache) for (auto &cache : m_paletteCache)
cache.reset(); cache.reset();
@ -307,7 +307,7 @@ void QGtk3Storage::handleThemeChange()
- "QGtk3Palettes" (top level value) - "QGtk3Palettes" (top level value)
- QPlatformTheme::Palette - QPlatformTheme::Palette
- QPalette::ColorRole - QPalette::ColorRole
- Qt::Appearance - Qt::ColorScheme
- Qt::ColorGroup - Qt::ColorGroup
- Source data - Source data
- Source Type - Source Type
@ -337,14 +337,14 @@ void QGtk3Storage::populateMap()
clear(); clear();
// Derive appearance from theme name // Derive color scheme from theme name
m_appearance = newThemeName.contains("dark"_L1, Qt::CaseInsensitive) m_colorScheme = newThemeName.contains("dark"_L1, Qt::CaseInsensitive)
? Qt::Appearance::Dark : m_interface->appearanceByColors(); ? Qt::ColorScheme::Dark : m_interface->colorSchemeByColors();
if (m_themeName.isEmpty()) { if (m_themeName.isEmpty()) {
qCDebug(lcQGtk3Interface) << "GTK theme initialized:" << newThemeName << m_appearance; qCDebug(lcQGtk3Interface) << "GTK theme initialized:" << newThemeName << m_colorScheme;
} else { } else {
qCDebug(lcQGtk3Interface) << "GTK theme changed to:" << newThemeName << m_appearance; qCDebug(lcQGtk3Interface) << "GTK theme changed to:" << newThemeName << m_colorScheme;
} }
m_themeName = newThemeName; m_themeName = newThemeName;
@ -466,19 +466,19 @@ void QGtk3Storage::createMapping()
// Define a modified source // Define a modified source
#define LIGHTER(group, role, lighter)\ #define LIGHTER(group, role, lighter)\
source = Source(QPalette::group, QPalette::role,\ source = Source(QPalette::group, QPalette::role,\
Qt::Appearance::Unknown, lighter) Qt::ColorScheme::Unknown, lighter)
#define MODIFY(group, role, red, green, blue)\ #define MODIFY(group, role, red, green, blue)\
source = Source(QPalette::group, QPalette::role,\ source = Source(QPalette::group, QPalette::role,\
Qt::Appearance::Unknown, red, green, blue) Qt::ColorScheme::Unknown, red, green, blue)
// Define fixed source // Define fixed source
#define FIX(color) source = FixedSource(color); #define FIX(color) source = FixedSource(color);
// Add the source to a target brush // Add the source to a target brush
// Use default Qt::Appearance::Unknown, if no appearance was specified // Use default Qt::ColorScheme::Unknown, if no color scheme was specified
#define ADD_2(group, role) map.insert(TargetBrush(QPalette::group, QPalette::role), source); #define ADD_2(group, role) map.insert(TargetBrush(QPalette::group, QPalette::role), source);
#define ADD_3(group, role, app) map.insert(TargetBrush(QPalette::group, QPalette::role,\ #define ADD_3(group, role, app) map.insert(TargetBrush(QPalette::group, QPalette::role,\
Qt::Appearance::app), source); Qt::ColorScheme::app), source);
#define ADD_X(x, group, role, app, FUNC, ...) FUNC #define ADD_X(x, group, role, app, FUNC, ...) FUNC
#define ADD(...) ADD_X(,##__VA_ARGS__, ADD_3(__VA_ARGS__), ADD_2(__VA_ARGS__)) #define ADD(...) ADD_X(,##__VA_ARGS__, ADD_3(__VA_ARGS__), ADD_2(__VA_ARGS__))
// Save target brushes to a palette type // Save target brushes to a palette type
@ -508,8 +508,8 @@ void QGtk3Storage::createMapping()
Use ADD(ColorGroup, ColorRole) to use the defined source for the Use ADD(ColorGroup, ColorRole) to use the defined source for the
color group / role in the current palette. color group / role in the current palette.
Use ADD(ColorGroup, ColorRole, Appearance) to use the defined source Use ADD(ColorGroup, ColorRole, ColorScheme) to use the defined source
only for a specific appearance only for a specific color scheme
3. Save mapping 3. Save mapping
Save the defined mappings for a specific palette. Save the defined mappings for a specific palette.

View File

@ -61,7 +61,7 @@ public:
struct RecursiveSource { struct RecursiveSource {
QPalette::ColorGroup colorGroup; QPalette::ColorGroup colorGroup;
QPalette::ColorRole colorRole; QPalette::ColorRole colorRole;
Qt::Appearance appearance; Qt::ColorScheme colorScheme;
int lighter = 100; int lighter = 100;
int deltaRed = 0; int deltaRed = 0;
int deltaGreen = 0; int deltaGreen = 0;
@ -71,7 +71,7 @@ public:
QDebug operator<<(QDebug dbg) QDebug operator<<(QDebug dbg)
{ {
return dbg << "QGtkStorage::RecursiceSource(colorGroup=" << colorGroup << ", colorRole=" return dbg << "QGtkStorage::RecursiceSource(colorGroup=" << colorGroup << ", colorRole="
<< colorRole << ", appearance=" << appearance << ", lighter=" << lighter << colorRole << ", colorScheme=" << colorScheme << ", lighter=" << lighter
<< ", deltaRed="<< deltaRed << "deltaBlue =" << deltaBlue << "deltaGreen=" << ", deltaRed="<< deltaRed << "deltaBlue =" << deltaBlue << "deltaGreen="
<< deltaGreen << ", width=" << width << ", height=" << height << ")"; << deltaGreen << ", width=" << width << ", height=" << height << ")";
} }
@ -106,23 +106,23 @@ public:
// Recursive constructor for darker/lighter colors // Recursive constructor for darker/lighter colors
Source(QPalette::ColorGroup group, QPalette::ColorRole role, Source(QPalette::ColorGroup group, QPalette::ColorRole role,
Qt::Appearance app, int p_lighter = 100) Qt::ColorScheme scheme, int p_lighter = 100)
: sourceType(SourceType::Modified) : sourceType(SourceType::Modified)
{ {
rec.colorGroup = group; rec.colorGroup = group;
rec.colorRole = role; rec.colorRole = role;
rec.appearance = app; rec.colorScheme = scheme;
rec.lighter = p_lighter; rec.lighter = p_lighter;
} }
// Recursive ocnstructor for color modification // Recursive ocnstructor for color modification
Source(QPalette::ColorGroup group, QPalette::ColorRole role, Source(QPalette::ColorGroup group, QPalette::ColorRole role,
Qt::Appearance app, int p_red, int p_green, int p_blue) Qt::ColorScheme scheme, int p_red, int p_green, int p_blue)
: sourceType(SourceType::Modified) : sourceType(SourceType::Modified)
{ {
rec.colorGroup = group; rec.colorGroup = group;
rec.colorRole = role; rec.colorRole = role;
rec.appearance = app; rec.colorScheme = scheme;
rec.deltaRed = p_red; rec.deltaRed = p_red;
rec.deltaGreen = p_green; rec.deltaGreen = p_green;
rec.deltaBlue = p_blue; rec.deltaBlue = p_blue;
@ -130,12 +130,12 @@ public:
// Recursive constructor for all: color modification and darker/lighter // Recursive constructor for all: color modification and darker/lighter
Source(QPalette::ColorGroup group, QPalette::ColorRole role, Source(QPalette::ColorGroup group, QPalette::ColorRole role,
Qt::Appearance app, int p_lighter, Qt::ColorScheme scheme, int p_lighter,
int p_red, int p_green, int p_blue) : sourceType(SourceType::Modified) int p_red, int p_green, int p_blue) : sourceType(SourceType::Modified)
{ {
rec.colorGroup = group; rec.colorGroup = group;
rec.colorRole = role; rec.colorRole = role;
rec.appearance = app; rec.colorScheme = scheme;
rec.lighter = p_lighter; rec.lighter = p_lighter;
rec.deltaRed = p_red; rec.deltaRed = p_red;
rec.deltaGreen = p_green; rec.deltaGreen = p_green;
@ -159,25 +159,25 @@ public:
} }
}; };
// Struct with key attributes to identify a brush: color group, color role and appearance // Struct with key attributes to identify a brush: color group, color role and color scheme
struct TargetBrush { struct TargetBrush {
QPalette::ColorGroup colorGroup; QPalette::ColorGroup colorGroup;
QPalette::ColorRole colorRole; QPalette::ColorRole colorRole;
Qt::Appearance appearance; Qt::ColorScheme colorScheme;
// Generic constructor // Generic constructor
TargetBrush(QPalette::ColorGroup group, QPalette::ColorRole role, TargetBrush(QPalette::ColorGroup group, QPalette::ColorRole role,
Qt::Appearance app = Qt::Appearance::Unknown) : Qt::ColorScheme scheme = Qt::ColorScheme::Unknown) :
colorGroup(group), colorRole(role), appearance(app) {}; colorGroup(group), colorRole(role), colorScheme(scheme) {};
// Copy constructor with appearance modifier for dark/light aware search // Copy constructor with color scheme modifier for dark/light aware search
TargetBrush(const TargetBrush &other, Qt::Appearance app) : TargetBrush(const TargetBrush &other, Qt::ColorScheme scheme) :
colorGroup(other.colorGroup), colorRole(other.colorRole), appearance(app) {}; colorGroup(other.colorGroup), colorRole(other.colorRole), colorScheme(scheme) {};
// struct becomes key of a map, so operator< is needed // struct becomes key of a map, so operator< is needed
bool operator<(const TargetBrush& other) const { bool operator<(const TargetBrush& other) const {
return std::tie(colorGroup, colorRole, appearance) < return std::tie(colorGroup, colorRole, colorScheme) <
std::tie(other.colorGroup, other.colorRole, other.appearance); std::tie(other.colorGroup, other.colorRole, other.colorScheme);
} }
}; };
@ -190,7 +190,7 @@ public:
// Public getters // Public getters
const QPalette *palette(QPlatformTheme::Palette = QPlatformTheme::SystemPalette) const; const QPalette *palette(QPlatformTheme::Palette = QPlatformTheme::SystemPalette) const;
QPixmap standardPixmap(QPlatformTheme::StandardPixmap standardPixmap, const QSizeF &size) const; QPixmap standardPixmap(QPlatformTheme::StandardPixmap standardPixmap, const QSizeF &size) const;
Qt::Appearance appearance() const { return m_appearance; }; Qt::ColorScheme colorScheme() const { return m_colorScheme; };
static QPalette standardPalette(); static QPalette standardPalette();
const QString themeName() const { return m_interface ? m_interface->themeName() : QString(); }; const QString themeName() const { return m_interface ? m_interface->themeName() : QString(); };
const QFont *font(QPlatformTheme::Font type) const; const QFont *font(QPlatformTheme::Font type) const;
@ -207,7 +207,7 @@ private:
std::unique_ptr<QGtk3Interface> m_interface; std::unique_ptr<QGtk3Interface> m_interface;
Qt::Appearance m_appearance = Qt::Appearance::Unknown; Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
// Caches for Pixmaps, fonts and palettes // Caches for Pixmaps, fonts and palettes
mutable QCache<QPlatformTheme::StandardPixmap, QImage> m_pixmapCache; mutable QCache<QPlatformTheme::StandardPixmap, QImage> m_pixmapCache;
@ -220,7 +220,7 @@ private:
// Get GTK3 source for a target brush // Get GTK3 source for a target brush
Source brush (const TargetBrush &brush, const BrushMap &map) const; Source brush (const TargetBrush &brush, const BrushMap &map) const;
// clear cache, palettes and appearance // clear cache, palettes and color scheme
void clear(); void clear();
// Data creation, import & export // Data creation, import & export

View File

@ -174,10 +174,10 @@ QString QGtk3Theme::gtkFontName() const
return QGnomeTheme::gtkFontName(); return QGnomeTheme::gtkFontName();
} }
Qt::Appearance QGtk3Theme::appearance() const Qt::ColorScheme QGtk3Theme::colorScheme() const
{ {
Q_ASSERT(m_storage); Q_ASSERT(m_storage);
return m_storage->appearance(); return m_storage->colorScheme();
} }
bool QGtk3Theme::usePlatformNativeDialog(DialogType type) const bool QGtk3Theme::usePlatformNativeDialog(DialogType type) const

View File

@ -18,7 +18,7 @@ public:
virtual QVariant themeHint(ThemeHint hint) const override; virtual QVariant themeHint(ThemeHint hint) const override;
virtual QString gtkFontName() const override; virtual QString gtkFontName() const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
bool usePlatformNativeDialog(DialogType type) const override; bool usePlatformNativeDialog(DialogType type) const override;
QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override; QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override;

View File

@ -40,7 +40,7 @@ public:
/*! \internal /*! \internal
Converts the given Freedesktop color scheme setting \a colorschemePref to a Qt::Appearance value. Converts the given Freedesktop color scheme setting \a colorschemePref to a Qt::ColorScheme value.
Specification: https://github.com/flatpak/xdg-desktop-portal/blob/d7a304a00697d7d608821253cd013f3b97ac0fb6/data/org.freedesktop.impl.portal.Settings.xml#L33-L45 Specification: https://github.com/flatpak/xdg-desktop-portal/blob/d7a304a00697d7d608821253cd013f3b97ac0fb6/data/org.freedesktop.impl.portal.Settings.xml#L33-L45
Unfortunately the enum numerical values are not defined identically, so we have to convert them. Unfortunately the enum numerical values are not defined identically, so we have to convert them.
@ -53,18 +53,18 @@ public:
1: Prefer dark appearance | 2: Dark 1: Prefer dark appearance | 2: Dark
2: Prefer light appearance | 1: Light 2: Prefer light appearance | 1: Light
*/ */
static Qt::Appearance appearanceFromXdgPref(const XdgColorschemePref colorschemePref) static Qt::ColorScheme colorSchemeFromXdgPref(const XdgColorschemePref colorschemePref)
{ {
switch (colorschemePref) { switch (colorschemePref) {
case PreferDark: return Qt::Appearance::Dark; case PreferDark: return Qt::ColorScheme::Dark;
case PreferLight: return Qt::Appearance::Light; case PreferLight: return Qt::ColorScheme::Light;
default: return Qt::Appearance::Unknown; default: return Qt::ColorScheme::Unknown;
} }
} }
QPlatformTheme *baseTheme = nullptr; QPlatformTheme *baseTheme = nullptr;
uint fileChooserPortalVersion = 0; uint fileChooserPortalVersion = 0;
Qt::Appearance appearance = Qt::Appearance::Unknown; Qt::ColorScheme colorScheme = Qt::ColorScheme::Unknown;
}; };
QXdgDesktopPortalTheme::QXdgDesktopPortalTheme() QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
@ -124,7 +124,7 @@ QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
if (reply.isValid()) { if (reply.isValid()) {
const QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(reply.value()); const QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(reply.value());
const QXdgDesktopPortalThemePrivate::XdgColorschemePref xdgPref = static_cast<QXdgDesktopPortalThemePrivate::XdgColorschemePref>(dbusVariant.variant().toUInt()); const QXdgDesktopPortalThemePrivate::XdgColorschemePref xdgPref = static_cast<QXdgDesktopPortalThemePrivate::XdgColorschemePref>(dbusVariant.variant().toUInt());
d->appearance = QXdgDesktopPortalThemePrivate::appearanceFromXdgPref(xdgPref); d->colorScheme = QXdgDesktopPortalThemePrivate::colorSchemeFromXdgPref(xdgPref);
} }
} }
@ -205,10 +205,10 @@ QVariant QXdgDesktopPortalTheme::themeHint(ThemeHint hint) const
return d->baseTheme->themeHint(hint); return d->baseTheme->themeHint(hint);
} }
Qt::Appearance QXdgDesktopPortalTheme::appearance() const Qt::ColorScheme QXdgDesktopPortalTheme::colorScheme() const
{ {
Q_D(const QXdgDesktopPortalTheme); Q_D(const QXdgDesktopPortalTheme);
return d->appearance; return d->colorScheme;
} }
QPixmap QXdgDesktopPortalTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const QPixmap QXdgDesktopPortalTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const

View File

@ -34,7 +34,7 @@ public:
QVariant themeHint(ThemeHint hint) const override; QVariant themeHint(ThemeHint hint) const override;
Qt::Appearance appearance() const override; Qt::ColorScheme colorScheme() const override;
QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override; QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override;
QIcon fileIcon(const QFileInfo &fileInfo, QIcon fileIcon(const QFileInfo &fileInfo,

View File

@ -160,7 +160,7 @@ const int pushButtonBevelRectOffsets[3] = {
QVector<QPointer<QObject> > QMacStylePrivate::scrollBars; QVector<QPointer<QObject> > QMacStylePrivate::scrollBars;
bool isDarkMode() { return QGuiApplicationPrivate::platformTheme()->appearance() == Qt::Appearance::Dark; } bool isDarkMode() { return QGuiApplicationPrivate::platformTheme()->colorScheme() == Qt::ColorScheme::Dark; }
// Title bar gradient colors for Lion were determined by inspecting PSDs exported // Title bar gradient colors for Lion were determined by inspecting PSDs exported
// using CoreUI's CoreThemeDocument; there is no public API to retrieve them // using CoreUI's CoreThemeDocument; there is no public API to retrieve them

View File

@ -4789,7 +4789,7 @@ void QWindowsVistaStyle::polish(QPalette &pal)
{ {
Q_D(QWindowsVistaStyle); Q_D(QWindowsVistaStyle);
if (qApp->styleHints()->appearance() == Qt::Appearance::Dark) { if (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
// System runs in dark mode, but the Vista style cannot use a dark palette. // System runs in dark mode, but the Vista style cannot use a dark palette.
// Overwrite with the light system palette. // Overwrite with the light system palette.
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication; using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
@ -4825,7 +4825,7 @@ void QWindowsVistaStyle::polish(QPalette &pal)
void QWindowsVistaStyle::polish(QApplication *app) void QWindowsVistaStyle::polish(QApplication *app)
{ {
// Override windows theme palettes to light // Override windows theme palettes to light
if (qApp->styleHints()->appearance() == Qt::Appearance::Dark) { if (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
static const char* themedWidgets[] = { static const char* themedWidgets[] = {
"QToolButton", "QToolButton",
"QAbstractButton", "QAbstractButton",