1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qplatformintegration.h"
41
42#include <qpa/qplatformfontdatabase.h>
43#include <qpa/qplatformclipboard.h>
44#include <qpa/qplatformaccessibility.h>
45#include <qpa/qplatformtheme.h>
46#include <QtGui/private/qguiapplication_p.h>
47#include <QtGui/private/qpixmap_raster_p.h>
48
49#if QT_CONFIG(draganddrop)
50#include <private/qdnd_p.h>
51#include <private/qsimpledrag_p.h>
52#endif
53
54#ifndef QT_NO_SESSIONMANAGER
55# include <qpa/qplatformsessionmanager.h>
56#endif
57
58QT_BEGIN_NAMESPACE
59
60/*!
61 Accessor for the platform integration's fontdatabase.
62
63 Default implementation returns a default QPlatformFontDatabase.
64
65 \sa QPlatformFontDatabase
66*/
67QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
68{
69 static QPlatformFontDatabase *db = 0;
70 if (!db) {
71 db = new QPlatformFontDatabase;
72 }
73 return db;
74}
75
76/*!
77 Accessor for the platform integration's clipboard.
78
79 Default implementation returns a default QPlatformClipboard.
80
81 \sa QPlatformClipboard
82
83*/
84
85#ifndef QT_NO_CLIPBOARD
86
87QPlatformClipboard *QPlatformIntegration::clipboard() const
88{
89 static QPlatformClipboard *clipboard = 0;
90 if (!clipboard) {
91 clipboard = new QPlatformClipboard;
92 }
93 return clipboard;
94}
95
96#endif
97
98#if QT_CONFIG(draganddrop)
99/*!
100 Accessor for the platform integration's drag object.
101
102 Default implementation returns QSimpleDrag. This class supports only drag
103 and drop operations within the same Qt application.
104*/
105QPlatformDrag *QPlatformIntegration::drag() const
106{
107 static QSimpleDrag *drag = 0;
108 if (!drag) {
109 drag = new QSimpleDrag;
110 }
111 return drag;
112}
113#endif // QT_CONFIG(draganddrop)
114
115QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
116{
117 return 0;
118}
119
120QPlatformServices *QPlatformIntegration::services() const
121{
122 return 0;
123}
124
125/*!
126 \class QPlatformIntegration
127 \since 4.8
128 \internal
129 \preliminary
130 \ingroup qpa
131 \brief The QPlatformIntegration class is the entry for WindowSystem specific functionality.
132
133 QPlatformIntegration is the single entry point for windowsystem specific functionality when
134 using the QPA platform. It has factory functions for creating platform specific pixmaps and
135 windows. The class also controls the font subsystem.
136
137 QPlatformIntegration is a singleton class which gets instantiated in the QGuiApplication
138 constructor. The QPlatformIntegration instance do not have ownership of objects it creates in
139 functions where the name starts with create. However, functions which don't have a name
140 starting with create acts as accessors to member variables.
141
142 It is not trivial to create or build a platform plugin outside of the Qt source tree. Therefore
143 the recommended approach for making new platform plugin is to copy an existing plugin inside
144 the QTSRCTREE/src/plugins/platform and develop the plugin inside the source tree.
145
146 The minimal platform integration is the smallest platform integration it is possible to make,
147 which makes it an ideal starting point for new plugins. For a slightly more advanced plugin,
148 consider reviewing the directfb plugin, or the testlite plugin.
149*/
150
151/*!
152 \fn QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
153
154 Factory function for QPlatformPixmap. PixelType can be either PixmapType or BitmapType.
155 \sa QPlatformPixmap
156*/
157
158/*!
159 \fn QPlatformWindow *QPlatformIntegration::createPlatformWindow(QWindow *window) const
160
161 Factory function for QPlatformWindow. The \a window parameter is a pointer to the window
162 which the QPlatformWindow is supposed to be created for.
163
164 All windows have to have a QPlatformWindow, and it will be created on-demand when the
165 QWindow is made visible for the first time, or explicitly through calling QWindow::create().
166
167 In the constructor, of the QPlatformWindow, the window flags, state, title and geometry
168 of the \a window should be applied to the underlying window. If the resulting flags or state
169 differs, the resulting values should be set on the \a window using QWindow::setWindowFlags()
170 or QWindow::setWindowState(), respectively.
171
172 \sa QPlatformWindow, QPlatformWindowFormat
173 \sa createPlatformBackingStore()
174*/
175
176/*!
177 \fn QPlatformBackingStore *QPlatformIntegration::createPlatformBackingStore(QWindow *window) const
178
179 Factory function for QPlatformBackingStore. The QWindow parameter is a pointer to the
180 top level widget(tlw) the window surface is created for. A QPlatformWindow is always created
181 before the QPlatformBackingStore for tlw where the widget also requires a backing store.
182
183 \sa QBackingStore
184 \sa createPlatformWindow()
185*/
186
187/*!
188 \enum QPlatformIntegration::Capability
189
190 Capabilities are used to determing specific features of a platform integration
191
192 \value ThreadedPixmaps The platform uses a pixmap implementation that is reentrant
193 and can be used from multiple threads, like the raster paint engine and QImage based
194 pixmaps.
195
196 \value OpenGL The platform supports OpenGL
197
198 \value ThreadedOpenGL The platform supports using OpenGL outside the GUI thread.
199
200 \value SharedGraphicsCache The platform supports a shared graphics cache
201
202 \value BufferQueueingOpenGL The OpenGL implementation on the platform will queue
203 up buffers when swapBuffers() is called and block only when its buffer pipeline
204 is full, rather than block immediately.
205
206 \value MultipleWindows The platform supports multiple QWindows, i.e. does some kind
207 of compositing either client or server side. Some platforms might only support a
208 single fullscreen window.
209
210 \value ApplicationState The platform handles the application state explicitly.
211 This means that QEvent::ApplicationActivate and QEvent::ApplicationDeativate
212 will not be posted automatically. Instead, the platform must handle application
213 state explicitly by using QWindowSystemInterface::handleApplicationStateChanged().
214 If not set, application state will follow window activation, which is the normal
215 behavior for desktop platforms.
216
217 \value ForeignWindows The platform allows creating QWindows which represent
218 native windows created by other processes or by using native libraries.
219
220 \value NonFullScreenWindows The platform supports top-level windows which do not
221 fill the screen. The default implementation returns \c true. Returning false for
222 this will cause all windows, including dialogs and popups, to be resized to fill the
223 screen.
224
225 \value WindowManagement The platform is based on a system that performs window
226 management. This includes the typical desktop platforms. Can be set to false on
227 platforms where no window management is available, meaning for example that windows
228 are never repositioned by the window manager. The default implementation returns \c true.
229
230 \value AllGLFunctionsQueryable Deprecated. Used to indicate whether the QOpenGLContext
231 backend provided by the platform is
232 able to return function pointers from getProcAddress() even for standard OpenGL
233 functions, for example OpenGL 1 functions like glClear() or glDrawArrays(). This is
234 important because the OpenGL specifications do not require this ability from the
235 getProcAddress implementations of the windowing system interfaces (EGL, WGL, GLX). The
236 platform plugins may however choose to enhance the behavior in the backend
237 implementation for QOpenGLContext::getProcAddress() and support returning a function
238 pointer also for the standard, non-extension functions. This capability is a
239 prerequisite for dynamic OpenGL loading. Starting with Qt 5.7, the platform plugin
240 is required to have this capability.
241
242 \value ApplicationIcon The platform supports setting the application icon. (since 5.5)
243
244 \value TopStackedNativeChildWindows The platform supports native child windows via
245 QWindowContainer without having to punch a transparent hole in the
246 backingstore. (since 5.10)
247 */
248
249/*!
250
251 \fn QAbstractEventDispatcher *QPlatformIntegration::createEventDispatcher() const = 0
252
253 Factory function for the GUI event dispatcher. The platform plugin should create
254 and return a QAbstractEventDispatcher subclass when this function is called.
255
256 If the platform plugin for some reason creates the event dispatcher outside of
257 this function (for example in the constructor), it needs to handle the case
258 where this function is never called, ensuring that the event dispatcher is
259 still deleted at some point (typically in the destructor).
260
261 Note that the platform plugin should never explicitly set the event dispatcher
262 itself, using QCoreApplication::setEventDispatcher(), but let QCoreApplication
263 decide when and which event dispatcher to create.
264
265 \since 5.2
266*/
267
268bool QPlatformIntegration::hasCapability(Capability cap) const
269{
270 return cap == NonFullScreenWindows || cap == NativeWidgets || cap == WindowManagement
271 || cap == TopStackedNativeChildWindows || cap == WindowActivation;
272}
273
274QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
275{
276 return new QRasterPlatformPixmap(type);
277}
278
279#ifndef QT_NO_OPENGL
280/*!
281 Factory function for QPlatformOpenGLContext. The \a context parameter is a pointer to
282 the context for which a platform-specific context backend needs to be
283 created. Configuration settings like the format, share context and screen have to be
284 taken from this QOpenGLContext and the resulting platform context is expected to be
285 backed by a native context that fulfills these criteria.
286
287 If the context has native handles set, no new native context is expected to be created.
288 Instead, the provided handles have to be used. In this case the ownership of the handle
289 must not be taken and the platform implementation is not allowed to destroy the native
290 context. Configuration parameters like the format are also to be ignored. Instead, the
291 platform implementation is responsible for querying the configuriation from the provided
292 native context.
293
294 Returns a pointer to a QPlatformOpenGLContext instance or \nullptr if the context could
295 not be created.
296
297 \sa QOpenGLContext
298*/
299QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
300{
301 Q_UNUSED(context);
302 qWarning("This plugin does not support createPlatformOpenGLContext!");
303 return 0;
304}
305#endif // QT_NO_OPENGL
306
307/*!
308 Factory function for QPlatformSharedGraphicsCache. This function will return 0 if the platform
309 integration does not support any shared graphics cache mechanism for the given \a cacheId.
310*/
311QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const
312{
313 qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!",
314 cacheId);
315 return 0;
316}
317
318/*!
319 Factory function for QPaintEngine. This function will return 0 if the platform
320 integration does not support creating any paint engine the given \a paintDevice.
321*/
322QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
323{
324 Q_UNUSED(paintDevice)
325 return 0;
326}
327
328/*!
329 Performs initialization steps that depend on having an event dispatcher
330 available. Called after the event dispatcher has been created.
331
332 Tasks that require an event dispatcher, for example creating socket notifiers, cannot be
333 performed in the constructor. Instead, they should be performed here. The default
334 implementation does nothing.
335*/
336void QPlatformIntegration::initialize()
337{
338}
339
340/*!
341 Called before the platform integration is deleted. Useful when cleanup relies on virtual
342 functions.
343
344 \since 5.5
345*/
346void QPlatformIntegration::destroy()
347{
348}
349
350/*!
351 Returns the platforms input context.
352
353 The default implementation returns \nullptr, implying no input method support.
354*/
355QPlatformInputContext *QPlatformIntegration::inputContext() const
356{
357 return 0;
358}
359
360#ifndef QT_NO_ACCESSIBILITY
361
362/*!
363 Returns the platforms accessibility.
364
365 The default implementation returns QPlatformAccessibility which
366 delegates handling of accessibility to accessiblebridge plugins.
367*/
368QPlatformAccessibility *QPlatformIntegration::accessibility() const
369{
370 static QPlatformAccessibility *accessibility = 0;
371 if (Q_UNLIKELY(!accessibility)) {
372 accessibility = new QPlatformAccessibility;
373 }
374 return accessibility;
375}
376
377#endif
378
379QVariant QPlatformIntegration::styleHint(StyleHint hint) const
380{
381 switch (hint) {
382 case CursorFlashTime:
383 return QPlatformTheme::defaultThemeHint(QPlatformTheme::CursorFlashTime);
384 case KeyboardInputInterval:
385 return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardInputInterval);
386 case KeyboardAutoRepeatRate:
387 return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardAutoRepeatRate);
388 case MouseDoubleClickInterval:
389 return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseDoubleClickInterval);
390 case StartDragDistance:
391 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragDistance);
392 case StartDragTime:
393 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragTime);
394 case ShowIsFullScreen:
395 return false;
396 case ShowIsMaximized:
397 return false;
398 case ShowShortcutsInContextMenus:
399 return QPlatformTheme::defaultThemeHint(QPlatformTheme::ShowShortcutsInContextMenus);
400 case PasswordMaskDelay:
401 return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskDelay);
402 case PasswordMaskCharacter:
403 return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskCharacter);
404 case FontSmoothingGamma:
405 return qreal(1.7);
406 case StartDragVelocity:
407 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
408 case UseRtlExtensions:
409 return QVariant(false);
410 case SetFocusOnTouchRelease:
411 return QVariant(false);
412 case MousePressAndHoldInterval:
413 return QPlatformTheme::defaultThemeHint(QPlatformTheme::MousePressAndHoldInterval);
414 case TabFocusBehavior:
415 return QPlatformTheme::defaultThemeHint(QPlatformTheme::TabFocusBehavior);
416 case ReplayMousePressOutsidePopup:
417 return true;
418 case ItemViewActivateItemOnSingleClick:
419 return QPlatformTheme::defaultThemeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick);
420 case UiEffects:
421 return QPlatformTheme::defaultThemeHint(QPlatformTheme::UiEffects);
422 case WheelScrollLines:
423 return QPlatformTheme::defaultThemeHint(QPlatformTheme::WheelScrollLines);
424 case MouseQuickSelectionThreshold:
425 return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseQuickSelectionThreshold);
426 }
427
428 return 0;
429}
430
431Qt::WindowState QPlatformIntegration::defaultWindowState(Qt::WindowFlags flags) const
432{
433 // Leave popup-windows as is
434 if (flags & Qt::Popup & ~Qt::Window)
435 return Qt::WindowNoState;
436
437 if (styleHint(QPlatformIntegration::ShowIsFullScreen).toBool())
438 return Qt::WindowFullScreen;
439 else if (styleHint(QPlatformIntegration::ShowIsMaximized).toBool())
440 return Qt::WindowMaximized;
441
442 return Qt::WindowNoState;
443}
444
445Qt::KeyboardModifiers QPlatformIntegration::queryKeyboardModifiers() const
446{
447 return QGuiApplication::keyboardModifiers();
448}
449
450/*!
451 Should be used to obtain a list of possible shortcuts for the given key
452 event. Shortcuts should be encoded as int(Qt::Key + Qt::KeyboardModifiers).
453
454 One example for more than one possibility is the key combination of Shift+5.
455 That one might trigger a shortcut which is set as "Shift+5" as well as one
456 using %. These combinations depend on the currently set keyboard layout.
457
458 \note This function should be called only from key event handlers.
459*/
460QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const
461{
462 return QList<int>();
463}
464
465QStringList QPlatformIntegration::themeNames() const
466{
467 return QStringList();
468}
469
470class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
471{
472 Q_UNUSED(name)
473 return new QPlatformTheme;
474}
475
476/*!
477 Factory function for QOffscreenSurface. An offscreen surface will typically be implemented with a
478 pixel buffer (pbuffer). If the platform doesn't support offscreen surfaces, an invisible window
479 will be used by QOffscreenSurface instead.
480*/
481QPlatformOffscreenSurface *QPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
482{
483 Q_UNUSED(surface)
484 return 0;
485}
486
487#ifndef QT_NO_SESSIONMANAGER
488/*!
489 \since 5.2
490
491 Factory function for QPlatformSessionManager. The default QPlatformSessionManager provides the same
492 functionality as the QSessionManager.
493*/
494QPlatformSessionManager *QPlatformIntegration::createPlatformSessionManager(const QString &id, const QString &key) const
495{
496 return new QPlatformSessionManager(id, key);
497}
498#endif
499
500/*!
501 \since 5.2
502
503 Function to sync the platform integrations state with the window system.
504
505 This is often implemented as a roundtrip from the platformintegration to the window system.
506
507 This function should not call QWindowSystemInterface::flushWindowSystemEvents() or
508 QCoreApplication::processEvents()
509*/
510void QPlatformIntegration::sync()
511{
512}
513
514/*!
515 \since 5.7
516
517 Should sound a bell, using the default volume and sound.
518
519 \sa QApplication::beep()
520*/
521void QPlatformIntegration::beep() const
522{
523}
524
525#ifndef QT_NO_OPENGL
526/*!
527 Platform integration function for querying the OpenGL implementation type.
528
529 Used only when dynamic OpenGL implementation loading is enabled.
530
531 Subclasses should reimplement this function and return a value based on
532 the OpenGL implementation they have chosen to load.
533
534 \note The return value does not indicate or limit the types of
535 contexts that can be created by a given implementation. For example
536 a desktop OpenGL implementation may be capable of creating OpenGL
537 ES-compatible contexts too.
538
539 \sa QOpenGLContext::openGLModuleType(), QOpenGLContext::isOpenGLES()
540
541 \since 5.3
542 */
543QOpenGLContext::OpenGLModuleType QPlatformIntegration::openGLModuleType()
544{
545 qWarning("This plugin does not support dynamic OpenGL loading!");
546 return QOpenGLContext::LibGL;
547}
548#endif
549
550/*!
551 \since 5.5
552
553 Platform integration function for setting the application icon.
554
555 \sa QGuiApplication::setWindowIcon()
556*/
557void QPlatformIntegration::setApplicationIcon(const QIcon &icon) const
558{
559 Q_UNUSED(icon);
560}
561
562#if QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
563
564/*!
565 Factory function for QPlatformVulkanInstance. The \a instance parameter is a
566 pointer to the instance for which a platform-specific backend needs to be
567 created.
568
569 Returns a pointer to a QPlatformOpenGLContext instance or \nullptr if the context could
570 not be created.
571
572 \sa QVulkanInstance
573 \since 5.10
574*/
575QPlatformVulkanInstance *QPlatformIntegration::createPlatformVulkanInstance(QVulkanInstance *instance) const
576{
577 Q_UNUSED(instance);
578 qWarning("This plugin does not support createPlatformVulkanInstance");
579 return nullptr;
580}
581
582#endif // QT_CONFIG(vulkan)
583
584QT_END_NAMESPACE
585