Qt 6.x
The Qt SDK
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#include "qiosintegration.h"
6#include "qiosglobal.h"
7#include "qioswindow.h"
8#include "qiosscreen.h"
10#ifndef Q_OS_TVOS
11#include "qiosclipboard.h"
12#endif
13#include "qiosinputcontext.h"
14#include "qiostheme.h"
15#include "qiosservices.h"
17
18#include <QtGui/qpointingdevice.h>
19#include <QtGui/private/qguiapplication_p.h>
20#include <QtGui/private/qrhibackingstore_p.h>
21
22#include <qoffscreensurface.h>
23#include <qpa/qplatformoffscreensurface.h>
24
25#include <QtGui/private/qcoretextfontdatabase_p.h>
26#include <QtGui/private/qmacmimeregistry_p.h>
27#include <QtGui/qutimimeconverter.h>
28#include <QDir>
29#include <QOperatingSystemVersion>
30
31#if QT_CONFIG(opengl)
32#include "qioscontext.h"
33#endif
34
35#import <AudioToolbox/AudioServices.h>
36
37#include <QtDebug>
38
40
41using namespace Qt::StringLiterals;
42
44
46{
48}
49
52#if !defined(Q_OS_TVOS) && !defined(QT_NO_CLIPBOARD)
53 , m_clipboard(new QIOSClipboard)
54#endif
55 , m_inputContext(0)
56 , m_platformServices(new QIOSServices)
57 , m_accessibility(0)
58 , m_optionalPlugins(new QFactoryLoader(QIosOptionalPluginInterface_iid, "/platforms/darwin"_L1))
59{
61 qFatal("Error: You are creating QApplication before calling UIApplicationMain.\n" \
62 "If you are writing a native iOS application, and only want to use Qt for\n" \
63 "parts of the application, a good place to create QApplication is from within\n" \
64 "'applicationDidFinishLaunching' inside your UIApplication delegate.\n");
65 }
66
67 // Set current directory to app bundle folder
68 QDir::setCurrent(QString::fromUtf8([[[NSBundle mainBundle] bundlePath] UTF8String]));
69}
70
72{
73 UIScreen *mainScreen = [UIScreen mainScreen];
74 NSMutableArray<UIScreen *> *screens = [[[UIScreen screens] mutableCopy] autorelease];
75 if (![screens containsObject:mainScreen]) {
76 // Fallback for iOS 7.1 (QTBUG-42345)
77 [screens insertObject:mainScreen atIndex:0];
78 }
79
80 for (UIScreen *screen in screens)
82
83 // Depends on a primary screen being present
84 m_inputContext = new QIOSInputContext;
85
86 m_touchDevice = new QPointingDevice;
87 m_touchDevice->setType(QInputDevice::DeviceType::TouchScreen);
88 QPointingDevice::Capabilities touchCapabilities = QPointingDevice::Capability::Position | QPointingDevice::Capability::NormalizedPosition;
89 if (mainScreen.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
90 touchCapabilities |= QPointingDevice::Capability::Pressure;
91 m_touchDevice->setCapabilities(touchCapabilities);
93#if QT_CONFIG(tabletevent)
95#endif
97
99 for (qsizetype i = 0; i < size; ++i)
100 qobject_cast<QIosOptionalPluginInterface *>(m_optionalPlugins->instance(i))->initPlugin();
101}
102
104{
105 delete m_fontDatabase;
106 m_fontDatabase = 0;
107
108#if !defined(Q_OS_TVOS) && !defined(QT_NO_CLIPBOARD)
109 delete m_clipboard;
110 m_clipboard = 0;
111#endif
112
114
115 delete m_inputContext;
116 m_inputContext = 0;
117
120
121 delete m_platformServices;
122 m_platformServices = 0;
123
124 delete m_accessibility;
125 m_accessibility = 0;
126
127 delete m_optionalPlugins;
128 m_optionalPlugins = 0;
129}
130
132{
133 switch (cap) {
134#if QT_CONFIG(opengl)
136 return true;
137 case OpenGL:
138 case ThreadedOpenGL:
139 return true;
140 case RasterGLSurface:
141 return true;
142#endif
143 case ThreadedPixmaps:
144 return true;
145 case MultipleWindows:
146 return true;
147 case WindowManagement:
148 return false;
149 case ApplicationState:
150 return true;
151 default:
153 }
154}
155
157{
158 return new QIOSWindow(window);
159}
160
162{
163 return new QRhiBackingStore(window);
164}
165
166#if QT_CONFIG(opengl)
167// Used when the QWindow's surface type is set by the client to QSurface::OpenGLSurface
169{
170 return new QIOSContext(context);
171}
172#endif
173
175{
176public:
178
179 QSurfaceFormat format() const override
180 {
183 }
184 bool isValid() const override { return true; }
185};
186
188{
189 return new QIOSOffscreenSurface(surface);
190}
191
193{
195}
196
198{
199 return m_fontDatabase;
200}
201
202#ifndef QT_NO_CLIPBOARD
204{
205#ifndef Q_OS_TVOS
206 return m_clipboard;
207#else
209#endif
210}
211#endif
212
214{
215 return m_inputContext;
216}
217
219{
220 return m_platformServices;
221}
222
224{
225 switch (hint) {
226 case StartDragTime:
227 return 300;
229 // this number is based on timing the native delay
230 // since there is no API to get it
231 return 2000;
232 case ShowIsMaximized:
233 return true;
235 return true;
236 default:
238 }
239}
240
242{
244}
245
247{
249 return new QIOSTheme;
250
252}
253
255{
256 return m_touchDevice;
257}
258
259#if QT_CONFIG(accessibility)
260QPlatformAccessibility *QIOSIntegration::accessibility() const
261{
262 if (!m_accessibility)
263 m_accessibility = new QIOSPlatformAccessibility;
264 return m_accessibility;
265}
266#endif
267
269{
270 return const_cast<QIOSIntegration *>(this);
271}
272
274{
275#if !TARGET_IPHONE_SIMULATOR
276 AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
277#endif
278}
279
281{
282 UIApplication.sharedApplication.applicationIconBadgeNumber = number;
283}
284
285// ---------------------------------------------------------
286
288{
289 if (!window || !window->handle())
290 return 0;
291
292 QByteArray lowerCaseResource = resource.toLower();
293
294 QIOSWindow *platformWindow = static_cast<QIOSWindow *>(window->handle());
295
296 if (lowerCaseResource == "uiview")
297 return reinterpret_cast<void *>(platformWindow->winId());
298
299 return 0;
300}
301
302// ---------------------------------------------------------
303
305
306#include "moc_qiosintegration.cpp"
\inmodule QtCore
Definition qbytearray.h:57
QByteArray toLower() const &
Definition qbytearray.h:190
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
Definition qdir.cpp:2027
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()
QPlatformClipboard * clipboard() const override
Accessor for the platform integration's clipboard.
QPlatformOffscreenSurface * createPlatformOffscreenSurface(QOffscreenSurface *surface) const override
Factory function for QOffscreenSurface.
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:34
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
Definition qioswindow.h:51
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
\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:127
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5857
The QSurfaceFormat class represents the format of a QSurface. \inmodule QtGui.
\inmodule QtCore
Definition qvariant.h:64
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)
bool qt_apple_isApplicationExtension()
Definition qcore_mac.mm:423
AppleApplication * qt_apple_sharedApplication()
Definition qcore_mac.mm:430
#define QIosOptionalPluginInterface_iid
#define qFatal
Definition qlogging.h:164
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
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
if(qFloatDistance(a, b)<(1<< 7))
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]