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();
const bool darkAppearance = theme
? theme->appearance() == QPlatformTheme::Appearance::Dark
? theme->appearance() == Qt::Appearance::Dark
: false;
const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black;
const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239);
@ -426,9 +426,9 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType typ
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

View File

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

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)));
}
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)
return;

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ public:
const QPalette *palette(Palette type = SystemPalette) const override;
QVariant themeHint(ThemeHint hint) const override;
Appearance appearance() const override;
Qt::Appearance appearance() const override;
QPlatformMenuItem* createPlatformMenuItem() 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) {
return window.rootViewController.traitCollection.userInterfaceStyle
== UIUserInterfaceStyleDark
? QPlatformTheme::Appearance::Dark
: QPlatformTheme::Appearance::Light;
? Qt::Appearance::Dark
: Qt::Appearance::Light;
}
return QPlatformTheme::Appearance::Unknown;
return Qt::Appearance::Unknown;
}
const QFont *QIOSTheme::font(Font type) const

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ public:
virtual QVariant themeHint(ThemeHint hint) const override;
virtual QString gtkFontName() const override;
Appearance appearance() const override;
Qt::Appearance appearance() 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 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
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 QPlatformTheme::Appearance appearanceFromXdgPref(const XdgColorschemePref colorschemePref)
static Qt::Appearance appearanceFromXdgPref(const XdgColorschemePref colorschemePref)
{
switch (colorschemePref) {
case PreferDark: return QPlatformTheme::Appearance::Dark;
case PreferLight: return QPlatformTheme::Appearance::Light;
default: return QPlatformTheme::Appearance::Unknown;
case PreferDark: return Qt::Appearance::Dark;
case PreferLight: return Qt::Appearance::Light;
default: return Qt::Appearance::Unknown;
}
}
QPlatformTheme *baseTheme = nullptr;
uint fileChooserPortalVersion = 0;
QPlatformTheme::Appearance appearance = QPlatformTheme::Appearance::Unknown;
Qt::Appearance appearance = Qt::Appearance::Unknown;
};
QXdgDesktopPortalTheme::QXdgDesktopPortalTheme()
@ -205,7 +205,7 @@ QVariant QXdgDesktopPortalTheme::themeHint(ThemeHint hint) const
return d->baseTheme->themeHint(hint);
}
QPlatformTheme::Appearance QXdgDesktopPortalTheme::appearance() const
Qt::Appearance QXdgDesktopPortalTheme::appearance() const
{
Q_D(const QXdgDesktopPortalTheme);
return d->appearance;

View File

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