Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qiosintegration.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#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
6#include "qiosintegration.h"
8#include "qiosglobal.h"
9#include "qioswindow.h"
10#include "qiosscreen.h"
12#if QT_CONFIG(clipboard)
13#include "qiosclipboard.h"
14#endif
15#include "qiosinputcontext.h"
16#include "qiostheme.h"
17#include "qiosservices.h"
19
20#if defined(Q_OS_VISIONOS)
21#include "qiosswiftintegration.h"
22#endif
23
24#include <QtGui/qpointingdevice.h>
25#include <QtGui/private/qguiapplication_p.h>
26#include <QtGui/private/qrhibackingstore_p.h>
27
28#include <qoffscreensurface.h>
29#include <qpa/qplatformoffscreensurface.h>
30
31#include <QtGui/private/qcoretextfontdatabase_p.h>
32#include <QtGui/private/qmacmimeregistry_p.h>
33#include <QtGui/qutimimeconverter.h>
34#include <QDir>
35#include <QOperatingSystemVersion>
36
37#if QT_CONFIG(opengl)
38#include "qioscontext.h"
39#endif
40
41#import <AudioToolbox/AudioServices.h>
42
43#include <QtDebug>
44
46
47using namespace Qt::StringLiterals;
48
50
55
58#if QT_CONFIG(clipboard)
59 , m_clipboard(new QIOSClipboard)
60#endif
61 , m_inputContext(0)
62 , m_platformServices(new QIOSServices)
63 , m_accessibility(0)
64 , m_optionalPlugins(new QFactoryLoader(QIosOptionalPluginInterface_iid, "/platforms/darwin"_L1))
65{
67 qFatal("Error: You are creating QApplication before calling UIApplicationMain.\n" \
68 "If you are writing a native iOS application, and only want to use Qt for\n" \
69 "parts of the application, a good place to create QApplication is from within\n" \
70 "'applicationDidFinishLaunching' inside your UIApplication delegate.\n");
71 }
72
73 // Set current directory to app bundle folder
74 QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String]));
75}
76
78{
79#if defined(Q_OS_VISIONOS)
80 // Qt requires a screen, so let's give it a dummy one
82#else
83 UIScreen *mainScreen = [UIScreen mainScreen];
84 NSMutableArray<UIScreen *> *screens = [[[UIScreen screens] mutableCopy] autorelease];
85 if (![screens containsObject:mainScreen]) {
86 // Fallback for iOS 7.1 (QTBUG-42345)
87 [screens insertObject:mainScreen atIndex:0];
88 }
89
90 for (UIScreen *screen in screens)
92#endif
93
94 // Depends on a primary screen being present
95 m_inputContext = new QIOSInputContext;
96
97 m_touchDevice = new QPointingDevice;
98 m_touchDevice->setType(QInputDevice::DeviceType::TouchScreen);
99 QPointingDevice::Capabilities touchCapabilities = QPointingDevice::Capability::Position | QPointingDevice::Capability::NormalizedPosition;
100#if !defined(Q_OS_VISIONOS)
101 if (mainScreen.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
102 touchCapabilities |= QPointingDevice::Capability::Pressure;
103#endif
104 m_touchDevice->setCapabilities(touchCapabilities);
106#if QT_CONFIG(tabletevent)
108#endif
110
111 qsizetype size = QList<QPluginParsedMetaData>(m_optionalPlugins->metaData()).size();
112 for (qsizetype i = 0; i < size; ++i)
113 qobject_cast<QIosOptionalPluginInterface *>(m_optionalPlugins->instance(i))->initPlugin();
114}
115
117{
118 delete m_fontDatabase;
119 m_fontDatabase = 0;
120
121#if QT_CONFIG(clipboard)
122 delete m_clipboard;
123 m_clipboard = 0;
124#endif
125
127
128 delete m_inputContext;
129 m_inputContext = 0;
130
133
134 delete m_platformServices;
135 m_platformServices = 0;
136
137 delete m_accessibility;
138 m_accessibility = 0;
139
140 delete m_optionalPlugins;
141 m_optionalPlugins = 0;
142}
143
145{
146 switch (cap) {
147#if QT_CONFIG(opengl)
149 return true;
150 case OpenGL:
151 case ThreadedOpenGL:
152 return true;
153 case RasterGLSurface:
154 return true;
155#endif
156 case ThreadedPixmaps:
157 return true;
158 case MultipleWindows:
159 return true;
160 case WindowManagement:
161 return false;
162 case ApplicationState:
163 return true;
164 case ForeignWindows:
165 return true;
166 default:
168 }
169}
170
175
177{
178 return new QIOSWindow(window, nativeHandle);
179}
180
185
186#if QT_CONFIG(opengl)
187// Used when the QWindow's surface type is set by the client to QSurface::OpenGLSurface
189{
190 return new QIOSContext(context);
191}
192#endif
193
206
211
216
218{
219 return m_fontDatabase;
220}
221
222#if QT_CONFIG(clipboard)
224{
225 return m_clipboard;
226}
227#endif
228
230{
231 return m_inputContext;
232}
233
235{
236 return m_platformServices;
237}
238
240{
241 switch (hint) {
242 case StartDragTime:
243 return 300;
245 // this number is based on timing the native delay
246 // since there is no API to get it
247 return 2000;
248 case ShowIsMaximized:
249 return true;
251 return true;
252 default:
254 }
255}
256
261
269
271{
272 return m_touchDevice;
273}
274
275#if QT_CONFIG(accessibility)
276QPlatformAccessibility *QIOSIntegration::accessibility() const
277{
278 if (!m_accessibility)
279 m_accessibility = new QIOSPlatformAccessibility;
280 return m_accessibility;
281}
282#endif
283
285{
286 return const_cast<QIOSIntegration *>(this);
287}
288
290{
291#if !TARGET_IPHONE_SIMULATOR
292 AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
293#endif
294}
295
297{
298 UIApplication.sharedApplication.applicationIconBadgeNumber = number;
299}
300
301// ---------------------------------------------------------
302
303#if defined(Q_OS_VISIONOS)
304void QIOSIntegration::openImmersiveSpace()
305{
306 [ImmersiveSpaceManager openImmersiveSpace];
307}
308
309void QIOSIntegration::dismissImmersiveSpace()
310{
311 [ImmersiveSpaceManager dismissImmersiveSpace];
312}
313
314void QIOSIntegration::setImmersiveSpaceCompositorLayer(CompositorLayer *layer)
315{
316 m_immersiveSpaceCompositorLayer = layer;
317}
318
319void QIOSIntegration::configureCompositorLayer(cp_layer_renderer_capabilities_t capabilities,
320 cp_layer_renderer_configuration_t configuration)
321{
322 if (m_immersiveSpaceCompositorLayer)
323 m_immersiveSpaceCompositorLayer->configure(capabilities, configuration);
324}
325
326void QIOSIntegration::renderCompositorLayer(cp_layer_renderer_t renderer)
327{
328 if (m_immersiveSpaceCompositorLayer)
329 m_immersiveSpaceCompositorLayer->render(renderer);
330}
331
332#endif
333
334// ---------------------------------------------------------
335
337{
338 if (!window || !window->handle())
339 return 0;
340
341 QByteArray lowerCaseResource = resource.toLower();
342
343 QIOSWindow *platformWindow = static_cast<QIOSWindow *>(window->handle());
344
345 if (lowerCaseResource == "uiview")
346 return reinterpret_cast<void *>(platformWindow->winId());
347
348 return 0;
349}
350
351// ---------------------------------------------------------
352
354
355#include "moc_qiosintegration.cpp"
\inmodule QtCore
Definition qbytearray.h:57
QByteArray toLower() const &
Definition qbytearray.h:254
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
Definition qdir.cpp:2030
MetaDataList metaData() const
QObject * instance(int index) const
static QPlatformIntegration * platformIntegration()
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
static QIOSEventDispatcher * create()
void initialize() override
Performs initialization steps that depend on having an event dispatcher available.
QVariant styleHint(StyleHint hint) const override
QPlatformTheme * createPlatformTheme(const QString &name) const override
void * nativeResourceForWindow(const QByteArray &resource, QWindow *window) override
void beep() const override
static QIOSIntegration * instance()
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
Factory function for QOffscreenSurface.
QPlatformWindow * createForeignWindow(QWindow *window, WId nativeHandle) const override
void setApplicationBadge(qint64 number) override
QPointingDevice * touchDevice()
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QStringList themeNames() const override
QPlatformNativeInterface * nativeInterface() const override
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
QPlatformServices * services() const override
bool hasCapability(Capability cap) const override
QPlatformInputContext * inputContext() const override
Returns the platforms input context.
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
bool isValid() const override
Returns true if the platform offscreen surface has been allocated.
QIOSOffscreenSurface(QOffscreenSurface *offscreenSurface)
QSurfaceFormat format() const override
Returns the actual surface format of the offscreen surface.
static const char * name
Definition qiostheme.h:40
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
Definition qioswindow.h:50
\inmodule QtGui
QSurfaceFormat requestedFormat() const
Returns the requested surfaceformat of this offscreen surface.
\inmodule QtGui
The QPlatformBackingStore class provides the drawing area for top-level windows.
The QPlatformClipboard class provides an abstraction for the system clipboard.
The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they ...
The QPlatformInputContext class abstracts the input method dependent data and composing state.
virtual QVariant styleHint(StyleHint hint) const
virtual bool hasCapability(Capability cap) const
virtual QPlatformOpenGLContext * createPlatformOpenGLContext(QOpenGLContext *context) const
Factory function for QPlatformOpenGLContext.
virtual QPlatformClipboard * clipboard() const
Accessor for the platform integration's clipboard.
virtual QPlatformTheme * createPlatformTheme(const QString &name) const
Capability
Capabilities are used to determine specific features of a platform integration.
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
QOffscreenSurface * offscreenSurface() const
The QPlatformOpenGLContext class provides an abstraction for native GL contexts.
The QPlatformServices provides the backend for desktop-related functionality.
The QPlatformTheme class allows customizing the UI based on themes.
The QPlatformWindow class provides an abstraction for top-level windows.
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
\inmodule QtCore
Definition qvariant.h:65
static void registerInputDevice(const QInputDevice *device)
static void handleScreenAdded(QPlatformScreen *screen, bool isPrimary=false)
Should be called by the implementation whenever a new screen is added.
static void handleScreenRemoved(QPlatformScreen *screen)
Should be called by the implementation whenever a screen is removed.
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
static void * context
#define Q_UNLIKELY(x)
QList< QString > QStringList
Constructs a string list that contains the given string, str.
bool qt_apple_isApplicationExtension()
Definition qcore_mac.mm:424
AppleApplication * qt_apple_sharedApplication()
Definition qcore_mac.mm:431
EGLOutputLayerEXT layer
#define QIosOptionalPluginInterface_iid
#define qFatal
Definition qlogging.h:168
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint name
GLuint in
GLenum cap
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QScreen * screen
[1]
Definition main.cpp:29
#define QT_CONFIG(feature)
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
if(qFloatDistance(a, b)<(1<< 7))
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QSvgRenderer * renderer
[0]