1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qplatformintegration.h"
44 #include <qpa/qplatformfontdatabase.h>
45 #include <qpa/qplatformclipboard.h>
46 #include <qpa/qplatformaccessibility.h>
47 #include <qpa/qplatformtheme.h>
48 #include <QtGui/private/qguiapplication_p.h>
49 #include <QtGui/private/qpixmap_raster_p.h>
50 #include <qpa/qplatformscreen_p.h>
51 #include <private/qdnd_p.h>
56 Accessor for the platform integration's fontdatabase.
58 Default implementation returns a default QPlatformFontDatabase.
60 \sa QPlatformFontDatabase
62 QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
64 static QPlatformFontDatabase *db = 0;
66 db = new QPlatformFontDatabase;
72 Accessor for the platform integration's clipboard.
74 Default implementation returns a default QPlatformClipboard.
76 \sa QPlatformClipboard
80 #ifndef QT_NO_CLIPBOARD
82 QPlatformClipboard *QPlatformIntegration::clipboard() const
84 static QPlatformClipboard *clipboard = 0;
86 clipboard = new QPlatformClipboard;
93 #ifndef QT_NO_DRAGANDDROP
95 Accessor for the platform integration's drag object.
97 Default implementation returns 0, implying no drag and drop support.
100 QPlatformDrag *QPlatformIntegration::drag() const
106 QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
111 QPlatformServices *QPlatformIntegration::services() const
117 \class QPlatformIntegration
122 \brief The QPlatformIntegration class is the entry for WindowSystem specific functionality.
124 QPlatformIntegration is the single entry point for windowsystem specific functionality when
125 using the QPA platform. It has factory functions for creating platform specific pixmaps and
126 windows. The class also controls the font subsystem.
128 QPlatformIntegration is a singleton class which gets instantiated in the QGuiApplication
129 constructor. The QPlatformIntegration instance do not have ownership of objects it creates in
130 functions where the name starts with create. However, functions which don't have a name
131 starting with create acts as accessors to member variables.
133 It is not trivial to create or build a platform plugin outside of the Qt source tree. Therefore
134 the recommended approach for making new platform plugin is to copy an existing plugin inside
135 the QTSRCTREE/src/plugins/platform and develop the plugin inside the source tree.
137 The minimal platform integration is the smallest platform integration it is possible to make,
138 which makes it an ideal starting point for new plugins. For a slightly more advanced plugin,
139 consider reviewing the directfb plugin, or the testlite plugin.
143 \fn QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
145 Factory function for QPlatformPixmap. PixelType can be either PixmapType or BitmapType.
150 \fn QPlatformWindow *QPlatformIntegration::createPlatformWindow(QWindow *window) const
152 Factory function for QPlatformWindow. The \a window parameter is a pointer to the top level
153 window which the QPlatformWindow is supposed to be created for.
155 All top level windows have to have a QPlatformWindow, and it will be created when the
156 QPlatformWindow is set to be visible for the first time. If the top level window's flags are
157 changed, or if the top level window's QPlatformWindowFormat is changed, then the top level
158 window's QPlatformWindow is deleted and a new one is created.
160 In the constructor, of the QPlatformWindow, the window flags, state, title and geometry
161 of the \a window should be applied to the underlying window. If the resulting flags or state
162 differs, the resulting values should be set on the \a window using QWindow::setWindowFlags()
163 or QWindow::setWindowState(), respectively.
165 \sa QPlatformWindow, QPlatformWindowFormat
166 \sa createPlatformBackingStore()
170 \fn QPlatformBackingStore *QPlatformIntegration::createPlatformBackingStore(QWindow *window) const
172 Factory function for QPlatformBackingStore. The QWindow parameter is a pointer to the
173 top level widget(tlw) the window surface is created for. A QPlatformWindow is always created
174 before the QPlatformBackingStore for tlw where the widget also requires a backing store.
177 \sa createPlatformWindow()
181 \enum QPlatformIntegration::Capability
183 Capabilities are used to determing specific features of a platform integration
185 \value ThreadedPixmaps The platform uses a pixmap implementation that is reentrant
186 and can be used from multiple threads, like the raster paint engine and QImage based
189 \value OpenGL The platform supports OpenGL
191 \value ThreadedOpenGL The platform supports using OpenGL outside the GUI thread.
193 \value SharedGraphicsCache The platform supports a shared graphics cache
195 \value BufferQueueingOpenGL The OpenGL implementation on the platform will queue
196 up buffers when swapBuffers() is called and block only when its buffer pipeline
197 is full, rather than block immediately.
199 \value MultipleWindows The platform supports multiple QWindows, i.e. does some kind
200 of compositing either client or server side. Some platforms might only support a
201 single fullscreen window.
207 \fn QAbstractEventDispatcher *QPlatformIntegration::guiThreadEventDispatcher() const = 0
209 Accessor function for the event dispatcher. The platform plugin should create
210 an instance of the QAbstractEventDispatcher in its constructor and set it
211 on the application using QGuiApplicationPrivate::instance()->setEventDispatcher().
212 The event dispatcher is owned by QGuiApplication, the accessor should return
214 \sa QGuiApplicationPrivate
217 bool QPlatformIntegration::hasCapability(Capability cap) const
223 QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
225 return new QRasterPlatformPixmap(type);
229 QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
232 qWarning("This plugin does not support createPlatformOpenGLContext!");
238 Factory function for QPlatformSharedGraphicsCache. This function will return 0 if the platform
239 integration does not support any shared graphics cache mechanism for the given \a cacheId.
241 QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const
243 qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!",
249 Factory function for QPaintEngine. This function will return 0 if the platform
250 integration does not support creating any paint engine the given \a paintDevice.
252 QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
254 Q_UNUSED(paintDevice)
259 Returns the platforms input context.
261 The default implementation returns 0, implying no input method support.
263 QPlatformInputContext *QPlatformIntegration::inputContext() const
268 #ifndef QT_NO_ACCESSIBILITY
271 Returns the platforms accessibility.
273 The default implementation returns 0, implying no accessibility support.
275 QPlatformAccessibility *QPlatformIntegration::accessibility() const
282 QVariant QPlatformIntegration::styleHint(StyleHint hint) const
285 case CursorFlashTime:
286 return QPlatformTheme::defaultThemeHint(QPlatformTheme::CursorFlashTime);
287 case KeyboardInputInterval:
288 return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardInputInterval);
289 case KeyboardAutoRepeatRate:
290 return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardAutoRepeatRate);
291 case MouseDoubleClickInterval:
292 return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseDoubleClickInterval);
293 case StartDragDistance:
294 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragDistance);
296 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragTime);
297 case ShowIsFullScreen:
299 case PasswordMaskDelay:
300 return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskDelay);
301 case FontSmoothingGamma:
303 case StartDragVelocity:
304 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
305 case UseRtlExtensions:
306 return QVariant(false);
307 case SynthesizeMouseFromTouchEvents:
314 Qt::KeyboardModifiers QPlatformIntegration::queryKeyboardModifiers() const
316 return QGuiApplication::keyboardModifiers();
320 Should be used to obtain a list of possible shortcuts for the given key
321 event. As that needs system functionality it cannot be done in qkeymapper.
323 One example for more than 1 possibility is the key combination of Shift+5.
324 That one might trigger a shortcut which is set as "Shift+5" as well as one
325 using %. These combinations depend on the currently set keyboard layout
326 which cannot be obtained by Qt functionality.
328 QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const
334 Should be called by the implementation whenever a new screen is added.
336 The first screen added will be the primary screen, used for default-created
337 windows, GL contexts, and other resources unless otherwise specified.
339 This adds the screen to QGuiApplication::screens(), and emits the
340 QGuiApplication::screenAdded() signal.
342 The screen is automatically removed when the QPlatformScreen is destroyed.
344 void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
346 QScreen *screen = new QScreen(ps);
347 ps->d_func()->screen = screen;
348 QGuiApplicationPrivate::screen_list << screen;
349 emit qGuiApp->screenAdded(screen);
352 QStringList QPlatformIntegration::themeNames() const
354 return QStringList();
357 class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
360 return new QPlatformTheme;