Replace QPlatformTheme::Appearance by Qt:Appearance

With the introduction of Qt:Appearance, its predecessor in
QPlatformTheme has become redundant.

This patch replaces all occurrences of QPlatformTheme::Appearance with
the new enum class.

Task-number: QTBUG-106381
Change-Id: I5406f1b7c19f68571f074617c681318c96a6517e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Axel Spoerl 2022-09-20 14:06:40 +02:00
parent feed452a99
commit 4973155512
18 changed files with 38 additions and 44 deletions

View File

@ -346,7 +346,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() == QPlatformTheme::Appearance::Dark ? theme->appearance() == Qt::Appearance::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);
@ -426,9 +426,9 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType typ
return nullptr; return nullptr;
} }
QPlatformTheme::Appearance QPlatformTheme::appearance() const Qt::Appearance QPlatformTheme::appearance() const
{ {
return Appearance::Unknown; return Qt::Appearance::Unknown;
} }
const QPalette *QPlatformTheme::palette(Palette type) const const QPalette *QPlatformTheme::palette(Palette type) const

View File

@ -98,12 +98,6 @@ public:
MessageDialog MessageDialog
}; };
enum class Appearance {
Unknown = 0x0000,
Light = 0x0001,
Dark = 0x0002
};
enum Palette { enum Palette {
SystemPalette, SystemPalette,
ToolTipPalette, ToolTipPalette,
@ -286,7 +280,7 @@ public:
virtual QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const; virtual QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const;
#endif #endif
virtual Appearance appearance() const; virtual Qt::Appearance appearance() const;
virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QPalette *palette(Palette type = SystemPalette) const;

View File

@ -758,7 +758,7 @@ static void handleRefreshRateChanged(JNIEnv */*env*/, jclass /*cls*/, jfloat ref
static void handleUiDarkModeChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newUiMode) static void handleUiDarkModeChanged(JNIEnv */*env*/, jobject /*thiz*/, jint newUiMode)
{ {
QAndroidPlatformIntegration::setAppearance( QAndroidPlatformIntegration::setAppearance(
(newUiMode == 1 ) ? QPlatformTheme::Appearance::Dark : QPlatformTheme::Appearance::Light); (newUiMode == 1 ) ? Qt::Appearance::Dark : Qt::Appearance::Light);
} }
static void onActivityResult(JNIEnv */*env*/, jclass /*cls*/, static void onActivityResult(JNIEnv */*env*/, jclass /*cls*/,

View File

@ -488,9 +488,9 @@ 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)));
} }
QPlatformTheme::Appearance QAndroidPlatformIntegration::m_appearance = QPlatformTheme::Appearance::Light; Qt::Appearance QAndroidPlatformIntegration::m_appearance = Qt::Appearance::Light;
void QAndroidPlatformIntegration::setAppearance(QPlatformTheme::Appearance newAppearance) void QAndroidPlatformIntegration::setAppearance(Qt::Appearance newAppearance)
{ {
if (m_appearance == newAppearance) if (m_appearance == newAppearance)
return; return;

View File

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

View File

@ -358,7 +358,7 @@ void QAndroidPlatformTheme::showPlatformMenuBar()
QtAndroidMenu::openOptionsMenu(); QtAndroidMenu::openOptionsMenu();
} }
QPlatformTheme::Appearance QAndroidPlatformTheme::appearance() const Qt::Appearance QAndroidPlatformTheme::appearance() const
{ {
return QAndroidPlatformIntegration::appearance(); return QAndroidPlatformIntegration::appearance();
} }

View File

@ -35,7 +35,7 @@ public:
QPlatformMenu *createPlatformMenu() const override; QPlatformMenu *createPlatformMenu() const override;
QPlatformMenuItem *createPlatformMenuItem() const override; QPlatformMenuItem *createPlatformMenuItem() const override;
void showPlatformMenuBar() override; void showPlatformMenuBar() override;
Appearance appearance() const override; Qt::Appearance appearance() 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;
Appearance appearance() const override; Qt::Appearance appearance() 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

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

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;
Appearance appearance() const override; Qt::Appearance appearance() const override;
QPlatformMenuItem* createPlatformMenuItem() const override; QPlatformMenuItem* createPlatformMenuItem() const override;
QPlatformMenu* createPlatformMenu() const override; QPlatformMenu* createPlatformMenu() const override;

View File

@ -132,15 +132,15 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const
} }
} }
QPlatformTheme::Appearance QIOSTheme::appearance() const Qt::Appearance QIOSTheme::appearance() const
{ {
if (UIWindow *window = qt_apple_sharedApplication().windows.lastObject) { if (UIWindow *window = qt_apple_sharedApplication().windows.lastObject) {
return window.rootViewController.traitCollection.userInterfaceStyle return window.rootViewController.traitCollection.userInterfaceStyle
== UIUserInterfaceStyleDark == UIUserInterfaceStyleDark
? QPlatformTheme::Appearance::Dark ? Qt::Appearance::Dark
: QPlatformTheme::Appearance::Light; : Qt::Appearance::Light;
} }
return QPlatformTheme::Appearance::Unknown; return Qt::Appearance::Unknown;
} }
const QFont *QIOSTheme::font(Font type) const const QFont *QIOSTheme::font(Font type) const

View File

@ -564,9 +564,9 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const
return QPlatformTheme::themeHint(hint); return QPlatformTheme::themeHint(hint);
} }
QPlatformTheme::Appearance QWindowsTheme::appearance() const Qt::Appearance QWindowsTheme::appearance() const
{ {
return QWindowsContext::isDarkMode() ? Appearance::Dark : Appearance::Light; return QWindowsContext::isDarkMode() ? Qt::Appearance::Dark : Qt::Appearance::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;
Appearance appearance() const override; Qt::Appearance appearance() 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

@ -149,7 +149,7 @@ QString QGtk3Theme::gtkFontName() const
return QGnomeTheme::gtkFontName(); return QGnomeTheme::gtkFontName();
} }
QPlatformTheme::Appearance QGtk3Theme::appearance() const Qt::Appearance QGtk3Theme::appearance() const
{ {
/* /*
https://docs.gtk.org/gtk3/running.html https://docs.gtk.org/gtk3/running.html
@ -167,7 +167,7 @@ QPlatformTheme::Appearance QGtk3Theme::appearance() const
QString themeName = qEnvironmentVariable("GTK_THEME"); QString themeName = qEnvironmentVariable("GTK_THEME");
const QRegularExpression darkRegex(QStringLiteral("[:-]dark"), QRegularExpression::CaseInsensitiveOption); const QRegularExpression darkRegex(QStringLiteral("[:-]dark"), QRegularExpression::CaseInsensitiveOption);
if (!themeName.isEmpty()) if (!themeName.isEmpty())
return darkRegex.match(themeName).hasMatch() ? Appearance::Dark : Appearance::Light; return darkRegex.match(themeName).hasMatch() ? Qt::Appearance::Dark : Qt::Appearance::Light;
/* /*
https://docs.gtk.org/gtk3/property.Settings.gtk-application-prefer-dark-theme.html https://docs.gtk.org/gtk3/property.Settings.gtk-application-prefer-dark-theme.html
@ -178,16 +178,16 @@ QPlatformTheme::Appearance QGtk3Theme::appearance() const
*/ */
const auto preferDark = gtkSetting<bool>("gtk-application-prefer-dark-theme"); const auto preferDark = gtkSetting<bool>("gtk-application-prefer-dark-theme");
if (preferDark) if (preferDark)
return Appearance::Dark; return Qt::Appearance::Dark;
/* /*
https://docs.gtk.org/gtk3/property.Settings.gtk-theme-name.html https://docs.gtk.org/gtk3/property.Settings.gtk-theme-name.html
*/ */
themeName = gtkSetting("gtk-theme-name"); themeName = gtkSetting("gtk-theme-name");
if (!themeName.isEmpty()) if (!themeName.isEmpty())
return darkRegex.match(themeName).hasMatch() ? Appearance::Dark : Appearance::Light; return darkRegex.match(themeName).hasMatch() ? Qt::Appearance::Dark : Qt::Appearance::Light;
return Appearance::Unknown; return Qt::Appearance::Unknown;
} }
bool QGtk3Theme::usePlatformNativeDialog(DialogType type) const bool QGtk3Theme::usePlatformNativeDialog(DialogType type) const

View File

@ -17,7 +17,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;
Appearance appearance() const override; Qt::Appearance appearance() 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 QPlatformTheme::Appearance value. Converts the given Freedesktop color scheme setting \a colorschemePref to a Qt::Appearance 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 QPlatformTheme::Appearance appearanceFromXdgPref(const XdgColorschemePref colorschemePref) static Qt::Appearance appearanceFromXdgPref(const XdgColorschemePref colorschemePref)
{ {
switch (colorschemePref) { switch (colorschemePref) {
case PreferDark: return QPlatformTheme::Appearance::Dark; case PreferDark: return Qt::Appearance::Dark;
case PreferLight: return QPlatformTheme::Appearance::Light; case PreferLight: return Qt::Appearance::Light;
default: return QPlatformTheme::Appearance::Unknown; default: return Qt::Appearance::Unknown;
} }
} }
QPlatformTheme *baseTheme = nullptr; QPlatformTheme *baseTheme = nullptr;
uint fileChooserPortalVersion = 0; uint fileChooserPortalVersion = 0;
QPlatformTheme::Appearance appearance = QPlatformTheme::Appearance::Unknown; Qt::Appearance appearance = Qt::Appearance::Unknown;
}; };
QXdgDesktopPortalTheme::QXdgDesktopPortalTheme() QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
@ -205,7 +205,7 @@ QVariant QXdgDesktopPortalTheme::themeHint(ThemeHint hint) const
return d->baseTheme->themeHint(hint); return d->baseTheme->themeHint(hint);
} }
QPlatformTheme::Appearance QXdgDesktopPortalTheme::appearance() const Qt::Appearance QXdgDesktopPortalTheme::appearance() const
{ {
Q_D(const QXdgDesktopPortalTheme); Q_D(const QXdgDesktopPortalTheme);
return d->appearance; return d->appearance;

View File

@ -34,7 +34,7 @@ public:
QVariant themeHint(ThemeHint hint) const override; QVariant themeHint(ThemeHint hint) const override;
Appearance appearance() const override; Qt::Appearance appearance() 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() == QPlatformTheme::Appearance::Dark; } bool isDarkMode() { return QGuiApplicationPrivate::platformTheme()->appearance() == Qt::Appearance::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