Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qiostheme.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qiostheme.h"
5
6#include <QtCore/QStringList>
7#include <QtCore/QVariant>
8#include <QtCore/private/qcore_mac_p.h>
9
10#include <QtGui/QFont>
11#include <QtGui/private/qcoregraphics_p.h>
12
13#include <QtGui/private/qcoretextfontdatabase_p.h>
14#include <QtGui/private/qguiapplication_p.h>
15#include <qpa/qplatformintegration.h>
16
17#include <UIKit/UIFont.h>
18#include <UIKit/UIInterface.h>
19
20#ifndef Q_OS_TVOS
21#include "qiosmenu.h"
22#include "qiosfiledialog.h"
23#include "qiosmessagedialog.h"
24#include "qioscolordialog.h"
25#include "qiosfontdialog.h"
26#include "qiosscreen.h"
27#endif
28
30
31const char *QIOSTheme::name = "ios";
32
34{
36
37 m_contentSizeCategoryObserver = QMacNotificationObserver(nil,
38 UIContentSizeCategoryDidChangeNotification, [] {
39 qCDebug(lcQpaFonts) << "Contents size category changed to" << UIApplication.sharedApplication.preferredContentSizeCategory;
41 });
42}
43
45{
46}
47
48QPalette QIOSTheme::s_systemPalette;
49
51{
53 s_systemPalette = qt_fusionPalette();
54
55 s_systemPalette.setBrush(QPalette::Window, qt_mac_toQBrush(UIColor.systemGroupedBackgroundColor.CGColor));
56 s_systemPalette.setBrush(QPalette::Active, QPalette::WindowText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
57
58 s_systemPalette.setBrush(QPalette::Base, qt_mac_toQBrush(UIColor.secondarySystemGroupedBackgroundColor.CGColor));
59 s_systemPalette.setBrush(QPalette::Active, QPalette::Text, qt_mac_toQBrush(UIColor.labelColor.CGColor));
60
61 s_systemPalette.setBrush(QPalette::Button, qt_mac_toQBrush(UIColor.secondarySystemBackgroundColor.CGColor));
62 s_systemPalette.setBrush(QPalette::Active, QPalette::ButtonText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
63
64 s_systemPalette.setBrush(QPalette::Active, QPalette::BrightText, qt_mac_toQBrush(UIColor.lightTextColor.CGColor));
65 s_systemPalette.setBrush(QPalette::Active, QPalette::PlaceholderText, qt_mac_toQBrush(UIColor.placeholderTextColor.CGColor));
66
67 s_systemPalette.setBrush(QPalette::Active, QPalette::Link, qt_mac_toQBrush(UIColor.linkColor.CGColor));
68 s_systemPalette.setBrush(QPalette::Active, QPalette::LinkVisited, qt_mac_toQBrush(UIColor.linkColor.CGColor));
69
70 s_systemPalette.setBrush(QPalette::Highlight, QColor(11, 70, 150, 60));
71 s_systemPalette.setBrush(QPalette::HighlightedText, qt_mac_toQBrush(UIColor.labelColor.CGColor));
72
73 if (@available(ios 15.0, *))
74 s_systemPalette.setBrush(QPalette::AccentColor, qt_mac_toQBrush(UIColor.tintColor.CGColor));
75}
76
78{
80 return &s_systemPalette;
81 return 0;
82}
83
85{
86#ifdef Q_OS_TVOS
87 return 0;
88#else
89 return new QIOSMenuItem();
90#endif
91}
92
94{
95#ifdef Q_OS_TVOS
96 return 0;
97#else
98 return new QIOSMenu();
99#endif
100}
101
103{
104 switch (type) {
105 case FileDialog:
106 case MessageDialog:
107 case ColorDialog:
108 case FontDialog:
110 default:
111 return false;
112 }
113}
114
116{
117 switch (type) {
118#ifndef Q_OS_TVOS
119 case FileDialog:
120 return new QIOSFileDialog();
121 break;
122 case MessageDialog:
123 return new QIOSMessageDialog();
124 break;
125 case ColorDialog:
126 return new QIOSColorDialog();
127 break;
128 case FontDialog:
129 return new QIOSFontDialog();
130 break;
131#endif
132 default:
133 return 0;
134 }
135}
136
138{
139 switch (hint) {
141 return QStringList(QStringLiteral("Fusion"));
142 case KeyboardScheme:
143 return QVariant(int(MacKeyboardScheme));
144 default:
146 }
147}
148
150{
151 // Set the appearance based on the QUIWindow
152 // Fallback to the UIScreen if no window is created yet
153 UIUserInterfaceStyle appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle;
154 NSArray<UIWindow *> *windows = qt_apple_sharedApplication().windows;
155 for (UIWindow *window in windows) {
156 if ([window isKindOfClass:[QUIWindow class]]) {
157 appearance = static_cast<QUIWindow*>(window).traitCollection.userInterfaceStyle;
158 break;
159 }
160 }
161
162 return appearance == UIUserInterfaceStyleDark
165}
166
168{
169 const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
170 const auto *coreTextFontDatabase = static_cast<QCoreTextFontDatabase *>(platformIntegration->fontDatabase());
171 return coreTextFontDatabase->themeFont(type);
172}
173
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QFont * themeFont(QPlatformTheme::Font) const
\reentrant
Definition qfont.h:20
static QPlatformIntegration * platformIntegration()
QPlatformMenu * createPlatformMenu() const override
Definition qiostheme.mm:93
const QFont * font(Font type=SystemFont) const override
Definition qiostheme.mm:167
static const char * name
Definition qiostheme.h:34
QVariant themeHint(ThemeHint hint) const override
Definition qiostheme.mm:137
static void initializeSystemPalette()
Definition qiostheme.mm:50
Qt::ColorScheme colorScheme() const override
Definition qiostheme.mm:149
bool usePlatformNativeDialog(DialogType type) const override
Definition qiostheme.mm:102
QPlatformMenuItem * createPlatformMenuItem() const override
Definition qiostheme.mm:84
const QPalette * palette(Palette type=SystemPalette) const override
Definition qiostheme.mm:77
QPlatformDialogHelper * createPlatformDialogHelper(DialogType type) const override
Definition qiostheme.mm:115
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette.
Definition qpalette.h:150
@ HighlightedText
Definition qpalette.h:52
@ BrightText
Definition qpalette.h:51
@ ButtonText
Definition qpalette.h:51
@ WindowText
Definition qpalette.h:50
@ Highlight
Definition qpalette.h:52
@ AccentColor
Definition qpalette.h:58
@ PlaceholderText
Definition qpalette.h:57
@ LinkVisited
Definition qpalette.h:53
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
static void repopulateFontDatabase()
Requests that the platform font database should be repopulated.
virtual QVariant themeHint(ThemeHint hint) const
ThemeHint
This enum describes the available theme hints.
\inmodule QtCore
\inmodule QtCore
Definition qvariant.h:64
Combined button and popup list for selecting options.
ColorScheme
Definition qnamespace.h:49
#define Q_DECL_IMPORT
bool qt_apple_isApplicationExtension()
Definition qcore_mac.mm:423
AppleApplication * qt_apple_sharedApplication()
Definition qcore_mac.mm:430
QBrush qt_mac_toQBrush(CGColorRef color)
#define qCDebug(category,...)
GLenum type
GLuint in
Q_GUI_EXPORT QPalette qt_fusionPalette()
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
aWidget window() -> setWindowTitle("New Window Title")
[2]