Implement QPlatformTheme::appearance() for iOS

Implement support for detecting Light/Dark mode on iOS. This is needed
by the QQuickIOSStyle in order to display the proper image assets
according to the theme.

A further improvement would be to react to theme changes dynamically.

Change-Id: I95e11c4a4b647614bdd78d734941d2b11546687a
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Doris Verria 2022-03-24 16:21:49 +01:00 committed by Tor Arne Vestbø
parent a86ee60887
commit 1b6874034a
2 changed files with 15 additions and 0 deletions

View File

@ -55,6 +55,8 @@ public:
const QPalette *palette(Palette type = SystemPalette) const override;
QVariant themeHint(ThemeHint hint) const override;
Appearance appearance() const override;
QPlatformMenuItem* createPlatformMenuItem() const override;
QPlatformMenu* createPlatformMenu() const override;

View File

@ -167,6 +167,19 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const
}
}
QPlatformTheme::Appearance QIOSTheme::appearance() const
{
if (@available(ios 12, *)) {
if (UIWindow *window = qt_apple_sharedApplication().keyWindow) {
return window.rootViewController.traitCollection.userInterfaceStyle
== UIUserInterfaceStyleDark
? QPlatformTheme::Appearance::Dark
: QPlatformTheme::Appearance::Light;
}
}
return QPlatformTheme::Appearance::Unknown;
}
const QFont *QIOSTheme::font(Font type) const
{
const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();