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'.

Pick-to: 6.5
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>
This commit is contained in:
Tor Arne Vestbø 2023-02-09 14:16:05 +01:00
parent 0c6aa4c8c2
commit 32749c913b
35 changed files with 164 additions and 193 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -122,20 +122,15 @@ int QStyleHints::touchDoubleTapDistance() const
}
/*!
\property QStyleHints::appearance
\brief the appearance of the platform theme.
\sa Qt::Appearance
\property QStyleHints::colorScheme
\brief the color scheme of the platform theme.
\sa Qt::ColorScheme
\since 6.5
*/
Qt::Appearance QStyleHints::appearance() const
{
Q_D(const QStyleHints);
return d->appearance();
}
Qt::ColorScheme QStyleHints::colorScheme() const
{
return Qt::ColorScheme(appearance());
Q_D(const QStyleHints);
return d->colorScheme();
}
/*!
@ -600,17 +595,17 @@ int QStyleHints::mouseQuickSelectionThreshold() const
/*!
\internal
QStyleHintsPrivate::setAppearance - set a new appearance.
Set \a appearance as the new appearance of the QStyleHints.
The appearanceChanged signal will be emitted if present and new appearance differ.
QStyleHintsPrivate::setColorScheme - set a new color scheme.
Set \a colorScheme as the new color scheme of the QStyleHints.
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;
m_appearance = appearance;
m_colorScheme = colorScheme;
Q_Q(QStyleHints);
emit q->appearanceChanged(appearance);
emit q->colorSchemeChanged(colorScheme);
}
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
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)
public:
@ -94,7 +93,6 @@ public:
void setWheelScrollLines(int scrollLines);
void setMouseQuickSelectionThreshold(int threshold);
int mouseQuickSelectionThreshold() const;
Qt::Appearance appearance() const;
Qt::ColorScheme colorScheme() const;
Q_SIGNALS:
@ -109,7 +107,6 @@ Q_SIGNALS:
void showShortcutsInContextMenusChanged(bool);
void wheelScrollLinesChanged(int scrollLines);
void mouseQuickSelectionThresholdChanged(int threshold);
void appearanceChanged(Qt::Appearance appearance);
void colorSchemeChanged(Qt::ColorScheme colorScheme);
private:

View File

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

View File

@ -374,8 +374,8 @@ public:
int startDragDist = 10;
int startDragTime = 500;
int cursorBlinkRate = 1000;
Qt::Appearance m_appearance = Qt::Appearance::Unknown;
void updateAppearance(const QString &themeName);
Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
void updateColorScheme(const QString &themeName);
#ifndef QT_NO_DBUS
private:
@ -464,9 +464,9 @@ void QKdeThemePrivate::refresh()
kdeVersion, kdeSettings);
if (colorScheme.isValid())
updateAppearance(colorScheme.toString());
updateColorScheme(colorScheme.toString());
else
m_appearance = Qt::Appearance::Unknown;
m_colorScheme = Qt::ColorScheme::Unknown;
const QVariant singleClickValue = readKdeSetting(QStringLiteral("KDE/SingleClick"), kdeDirs, kdeVersion, kdeSettings);
if (singleClickValue.isValid())
@ -749,14 +749,14 @@ QIcon QKdeTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions
#endif
}
Qt::Appearance QKdeTheme::appearance() const
Qt::ColorScheme QKdeTheme::colorScheme() const
{
return d_func()->m_appearance;
return d_func()->m_colorScheme;
}
/*!
\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.
The key words "dark" or "light" should be part of the theme name.
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
of the system palette.
*/
void QKdeThemePrivate::updateAppearance(const QString &themeName)
void QKdeThemePrivate::updateColorScheme(const QString &themeName)
{
if (themeName.contains(QLatin1StringView("light"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Light;
m_colorScheme = Qt::ColorScheme::Light;
return;
}
if (themeName.contains(QLatin1StringView("dark"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Dark;
m_colorScheme = Qt::ColorScheme::Dark;
return;
}
if (systemPalette) {
if (systemPalette->text().color().lightness() < systemPalette->base().color().lightness()) {
m_appearance = Qt::Appearance::Light;
m_colorScheme = Qt::ColorScheme::Light;
return;
}
if (systemPalette->text().color().lightness() > systemPalette->base().color().lightness()) {
m_appearance = Qt::Appearance::Dark;
m_colorScheme = Qt::ColorScheme::Dark;
return;
}
}
m_appearance = Qt::Appearance::Unknown;
m_colorScheme = Qt::ColorScheme::Unknown;
}
@ -911,11 +911,11 @@ public:
mutable QFont *fixedFont = nullptr;
#ifndef QT_NO_DBUS
Qt::Appearance m_appearance = Qt::Appearance::Unknown;
Qt::ColorScheme m_colorScheme = Qt::ColorScheme::Unknown;
private:
std::unique_ptr<QGenericUnixThemeDBusListener> dbus;
bool initDbus();
void updateAppearance(const QString &themeName);
void updateColorScheme(const QString &themeName);
#endif // QT_NO_DBUS
};
@ -946,25 +946,25 @@ bool QGnomeThemePrivate::initDbus()
// Wrap slot in a lambda to avoid inheriting QGnomeThemePrivate from QObject
auto wrapper = [this](QGenericUnixThemeDBusListener::SettingType type, const QString &value) {
if (type == QGenericUnixThemeDBusListener::SettingType::GtkTheme)
updateAppearance(value);
updateColorScheme(value);
};
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)) {
m_appearance = Qt::Appearance::Light;
m_colorScheme = Qt::ColorScheme::Light;
} else if (themeName.contains(QLatin1StringView("dark"), Qt::CaseInsensitive)) {
m_appearance = Qt::Appearance::Dark;
m_colorScheme = Qt::ColorScheme::Dark;
} else {
m_appearance = Qt::Appearance::Unknown;
m_colorScheme = Qt::ColorScheme::Unknown;
}
if (oldAppearance != m_appearance)
if (oldColorScheme != m_colorScheme)
QWindowSystemInterface::handleThemeChange();
}
#endif // QT_NO_DBUS
@ -1053,9 +1053,9 @@ QPlatformMenuBar *QGnomeTheme::createPlatformMenuBar() const
return nullptr;
}
Qt::Appearance QGnomeTheme::appearance() const
Qt::ColorScheme QGnomeTheme::colorScheme() const
{
return d_func()->m_appearance;
return d_func()->m_colorScheme;
}
#endif

View File

@ -77,7 +77,7 @@ public:
QPlatformTheme::IconOptions iconOptions = { }) 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;
#ifndef QT_NO_DBUS
@ -107,7 +107,7 @@ public:
virtual QString gtkFontName() const;
#ifndef QT_NO_DBUS
QPlatformMenuBar *createPlatformMenuBar() const override;
Qt::Appearance appearance() const override;
Qt::ColorScheme colorScheme() const override;
#endif
#if !defined(QT_NO_DBUS) && !defined(QT_NO_SYSTEMTRAYICON)
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)
{
QAndroidPlatformIntegration::setAppearance(
(newUiMode == 1 ) ? Qt::Appearance::Dark : Qt::Appearance::Light);
QAndroidPlatformIntegration::setColorScheme(
(newUiMode == 1 ) ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light);
}
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)));
}
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;
m_appearance = newAppearance;
m_colorScheme = colorScheme;
QMetaObject::invokeMethod(qGuiApp,
[] () { QAndroidPlatformTheme::instance()->updateAppearance();});
[] () { QAndroidPlatformTheme::instance()->updateColorScheme();});
}
void QAndroidPlatformIntegration::setScreenSizeParameters(const QSize &physicalSize,

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ public:
const QPalette *palette(Palette type = SystemPalette) const override;
QVariant themeHint(ThemeHint hint) const override;
Qt::Appearance appearance() const override;
Qt::ColorScheme colorScheme() const override;
QPlatformMenuItem* createPlatformMenuItem() 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;
// Set the appearance based on the UIWindow
@ -153,8 +153,8 @@ Qt::Appearance QIOSTheme::appearance() const
appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle;
}
return appearance == UIUserInterfaceStyleDark
? Qt::Appearance::Dark
: Qt::Appearance::Light;
? Qt::ColorScheme::Dark
: Qt::ColorScheme::Light;
}
const QFont *QIOSTheme::font(Font type) const

View File

@ -499,9 +499,9 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const
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()

View File

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

View File

@ -488,14 +488,14 @@ const QString QGtk3Interface::themeName() const
/*!
\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.
\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),
QGtkColorSource::Background,
@ -505,10 +505,10 @@ Qt::Appearance QGtk3Interface::appearanceByColors() const
GTK_STATE_FLAG_ACTIVE);
if (foreground.lightness() > background.lightness())
return Qt::Appearance::Dark;
return Qt::ColorScheme::Dark;
if (foreground.lightness() < background.lightness())
return Qt::Appearance::Light;
return Qt::Appearance::Unknown;
return Qt::ColorScheme::Light;
return Qt::ColorScheme::Unknown;
}
/*!

View File

@ -136,8 +136,8 @@ public:
// Return current GTK theme name
const QString themeName() const;
// Derive appearance from default colors
Qt::Appearance appearanceByColors() const;
// Derive color scheme from default colors
Qt::ColorScheme colorSchemeByColors() const;
// Convert GTK state to/from string
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)));
}
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)\
@ -63,9 +63,9 @@ QLatin1String QGtk3Json::fromAppearance(Qt::Appearance app)
const int intVal = QMetaEnum::fromType<type>().keyToValue(key.toLatin1().constData(), &ok);\
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)
@ -175,7 +175,7 @@ const QJsonDocument QGtk3Json::save(const QGtk3Storage::PaletteMap &map)
const QGtk3Storage::TargetBrush tb = brushIterator.key();
QGtk3Storage::Source s = brushIterator.value();
brushObject.insert(ceColorGroup, fromColorGroup(tb.colorGroup));
brushObject.insert(ceAppearance, fromAppearance(tb.appearance));
brushObject.insert(ceColorScheme, fromColorScheme(tb.colorScheme));
brushObject.insert(ceSourceType, fromSourceType(s.sourceType));
QJsonObject sourceObject;
@ -201,7 +201,7 @@ const QJsonDocument QGtk3Json::save(const QGtk3Storage::PaletteMap &map)
case QGtk3Storage::SourceType::Modified:{
sourceObject.insert(ceColorGroup, fromColorGroup(s.rec.colorGroup));
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(ceGreen, s.rec.deltaGreen);
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);
GETSTR(brushObject, ceColorGroup);
const QPalette::ColorGroup colorGroup = toColorGroup(value);
GETSTR(brushObject, ceAppearance);
const Qt::Appearance appearance = toAppearance(value);
QGtk3Storage::TargetBrush tb(colorGroup, colorRole, appearance);
GETSTR(brushObject, ceColorScheme);
const Qt::ColorScheme colorScheme = toColorScheme(value);
QGtk3Storage::TargetBrush tb(colorGroup, colorRole, colorScheme);
QGtk3Storage::Source s;
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);
GETSTR(sourceObject, ceColorRole);
const QPalette::ColorRole colorRole = toColorRole(value);
GETSTR(sourceObject, ceAppearance);
const Qt::Appearance appearance = toAppearance(value);
GETSTR(sourceObject, ceColorScheme);
const Qt::ColorScheme colorScheme = toColorScheme(value);
GETINT(sourceObject, ceLighter, lighter);
GETINT(sourceObject, ceRed, red);
GETINT(sourceObject, ceBlue, blue);
GETINT(sourceObject, ceGreen, green);
s = QGtk3Storage::Source(colorGroup, colorRole, appearance,
s = QGtk3Storage::Source(colorGroup, colorRole, colorScheme,
lighter, red, green, blue);
}
break;

View File

@ -50,7 +50,7 @@ public:
static QLatin1String fromGdkSource(QGtk3Interface::QGtkColorSource source);
static QLatin1String fromSourceType(QGtk3Storage::SourceType sourceType);
static QLatin1String fromWidgetType(QGtk3Interface::QGtkWidget widgetType);
static QLatin1String fromAppearance(Qt::Appearance app);
static QLatin1String fromColorScheme(Qt::ColorScheme colorScheme);
// Convert strings to enums
static QPlatformTheme::Palette toPalette(const QString &palette);
@ -61,7 +61,7 @@ public:
static QGtk3Interface::QGtkColorSource toGdkSource(const QString &source);
static QGtk3Storage::SourceType toSourceType(const QString &sourceType);
static QGtk3Interface::QGtkWidget toWidgetType(const QString &widgetType);
static Qt::Appearance toAppearance(const QString &appearance);
static Qt::ColorScheme toColorScheme(const QString &colorScheme);
// Json keys
static constexpr QLatin1StringView cePalettes = "QtGtk3Palettes"_L1;
@ -82,7 +82,7 @@ public:
static constexpr QLatin1StringView ceBrush = "FixedBrush"_L1;
static constexpr QLatin1StringView ceData = "SourceData"_L1;
static constexpr QLatin1StringView ceBrushes = "Brushes"_L1;
static constexpr QLatin1StringView ceAppearance = "Appearance"_L1;
static constexpr QLatin1StringView ceColorScheme = "ColorScheme"_L1;
// Save to a file
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: {
// don't loop through modified sources, break if modified source not found
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))
return QBrush();
@ -99,15 +99,15 @@ QGtk3Storage::Source QGtk3Storage::brush(const TargetBrush &b, const BrushMap &m
// Return exact match
FIND(b);
// unknown appearance can find anything
if (b.appearance == Qt::Appearance::Unknown) {
FIND(TargetBrush(b, Qt::Appearance::Dark));
FIND(TargetBrush(b, Qt::Appearance::Light));
// unknown color scheme can find anything
if (b.colorScheme == Qt::ColorScheme::Unknown) {
FIND(TargetBrush(b, Qt::ColorScheme::Dark));
FIND(TargetBrush(b, Qt::ColorScheme::Light));
}
// Color group All can always be found
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
return Source();
@ -181,13 +181,13 @@ const QPalette *QGtk3Storage::palette(QPlatformTheme::Palette type) const
Source source = i.value();
// Brush is set if
// - theme and source appearance match
// - theme and source color scheme match
// - or either of them is unknown
const auto appSource = i.key().appearance;
const auto appTheme = appearance();
const auto appSource = i.key().colorScheme;
const auto appTheme = colorScheme();
const bool setBrush = (appSource == appTheme) ||
(appSource == Qt::Appearance::Unknown) ||
(appTheme == Qt::Appearance::Unknown);
(appSource == Qt::ColorScheme::Unknown) ||
(appTheme == Qt::ColorScheme::Unknown);
if (setBrush) {
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);
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();
}
@ -255,7 +255,7 @@ QIcon QGtk3Storage::fileIcon(const QFileInfo &fileInfo) const
*/
void QGtk3Storage::clear()
{
m_appearance = Qt::Appearance::Unknown;
m_colorScheme = Qt::ColorScheme::Unknown;
m_palettes.clear();
for (auto &cache : m_paletteCache)
cache.reset();
@ -307,7 +307,7 @@ void QGtk3Storage::handleThemeChange()
- "QGtk3Palettes" (top level value)
- QPlatformTheme::Palette
- QPalette::ColorRole
- Qt::Appearance
- Qt::ColorScheme
- Qt::ColorGroup
- Source data
- Source Type
@ -337,14 +337,14 @@ void QGtk3Storage::populateMap()
clear();
// Derive appearance from theme name
m_appearance = newThemeName.contains("dark"_L1, Qt::CaseInsensitive)
? Qt::Appearance::Dark : m_interface->appearanceByColors();
// Derive color scheme from theme name
m_colorScheme = newThemeName.contains("dark"_L1, Qt::CaseInsensitive)
? Qt::ColorScheme::Dark : m_interface->colorSchemeByColors();
if (m_themeName.isEmpty()) {
qCDebug(lcQGtk3Interface) << "GTK theme initialized:" << newThemeName << m_appearance;
qCDebug(lcQGtk3Interface) << "GTK theme initialized:" << newThemeName << m_colorScheme;
} else {
qCDebug(lcQGtk3Interface) << "GTK theme changed to:" << newThemeName << m_appearance;
qCDebug(lcQGtk3Interface) << "GTK theme changed to:" << newThemeName << m_colorScheme;
}
m_themeName = newThemeName;
@ -466,19 +466,19 @@ void QGtk3Storage::createMapping()
// Define a modified source
#define LIGHTER(group, role, lighter)\
source = Source(QPalette::group, QPalette::role,\
Qt::Appearance::Unknown, lighter)
Qt::ColorScheme::Unknown, lighter)
#define MODIFY(group, role, red, green, blue)\
source = Source(QPalette::group, QPalette::role,\
Qt::Appearance::Unknown, red, green, blue)
Qt::ColorScheme::Unknown, red, green, blue)
// Define fixed source
#define FIX(color) source = FixedSource(color);
// 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_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(...) ADD_X(,##__VA_ARGS__, ADD_3(__VA_ARGS__), ADD_2(__VA_ARGS__))
// 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
color group / role in the current palette.
Use ADD(ColorGroup, ColorRole, Appearance) to use the defined source
only for a specific appearance
Use ADD(ColorGroup, ColorRole, ColorScheme) to use the defined source
only for a specific color scheme
3. Save mapping
Save the defined mappings for a specific palette.

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ public:
/*! \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
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
2: Prefer light appearance | 1: Light
*/
static Qt::Appearance appearanceFromXdgPref(const XdgColorschemePref colorschemePref)
static Qt::ColorScheme colorSchemeFromXdgPref(const XdgColorschemePref colorschemePref)
{
switch (colorschemePref) {
case PreferDark: return Qt::Appearance::Dark;
case PreferLight: return Qt::Appearance::Light;
default: return Qt::Appearance::Unknown;
case PreferDark: return Qt::ColorScheme::Dark;
case PreferLight: return Qt::ColorScheme::Light;
default: return Qt::ColorScheme::Unknown;
}
}
QPlatformTheme *baseTheme = nullptr;
uint fileChooserPortalVersion = 0;
Qt::Appearance appearance = Qt::Appearance::Unknown;
Qt::ColorScheme colorScheme = Qt::ColorScheme::Unknown;
};
QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
@ -124,7 +124,7 @@ QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
if (reply.isValid()) {
const QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(reply.value());
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);
}
Qt::Appearance QXdgDesktopPortalTheme::appearance() const
Qt::ColorScheme QXdgDesktopPortalTheme::colorScheme() const
{
Q_D(const QXdgDesktopPortalTheme);
return d->appearance;
return d->colorScheme;
}
QPixmap QXdgDesktopPortalTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const

View File

@ -34,7 +34,7 @@ public:
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;
QIcon fileIcon(const QFileInfo &fileInfo,

View File

@ -160,7 +160,7 @@ const int pushButtonBevelRectOffsets[3] = {
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
// using CoreUI's CoreThemeDocument; there is no public API to retrieve them

View File

@ -4781,7 +4781,7 @@ void QWindowsVistaStyle::polish(QPalette &pal)
{
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.
// Overwrite with the light system palette.
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
@ -4817,7 +4817,7 @@ void QWindowsVistaStyle::polish(QPalette &pal)
void QWindowsVistaStyle::polish(QApplication *app)
{
// Override windows theme palettes to light
if (qApp->styleHints()->appearance() == Qt::Appearance::Dark) {
if (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
static const char* themedWidgets[] = {
"QToolButton",
"QAbstractButton",