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.
203 \fn QAbstractEventDispatcher *QPlatformIntegration::guiThreadEventDispatcher() const = 0
205 Accessor function for the event dispatcher. The platform plugin should create
206 an instance of the QAbstractEventDispatcher in its constructor and set it
207 on the application using QGuiApplicationPrivate::instance()->setEventDispatcher().
208 The event dispatcher is owned by QGuiApplication, the accessor should return
210 \sa QGuiApplicationPrivate
213 bool QPlatformIntegration::hasCapability(Capability cap) const
219 QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
221 return new QRasterPlatformPixmap(type);
225 QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
228 qWarning("This plugin does not support createPlatformOpenGLContext!");
234 Factory function for QPlatformSharedGraphicsCache. This function will return 0 if the platform
235 integration does not support any shared graphics cache mechanism for the given \a cacheId.
237 QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const
239 qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!",
245 Factory function for QPaintEngine. This function will return 0 if the platform
246 integration does not support creating any paint engine the given \a paintDevice.
248 QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
250 Q_UNUSED(paintDevice)
255 Returns the platforms input context.
257 The default implementation returns 0, implying no input method support.
259 QPlatformInputContext *QPlatformIntegration::inputContext() const
264 #ifndef QT_NO_ACCESSIBILITY
267 Returns the platforms accessibility.
269 The default implementation returns 0, implying no accessibility support.
271 QPlatformAccessibility *QPlatformIntegration::accessibility() const
278 QVariant QPlatformIntegration::styleHint(StyleHint hint) const
281 case CursorFlashTime:
282 return QPlatformTheme::defaultThemeHint(QPlatformTheme::CursorFlashTime);
283 case KeyboardInputInterval:
284 return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardInputInterval);
285 case KeyboardAutoRepeatRate:
286 return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardAutoRepeatRate);
287 case MouseDoubleClickInterval:
288 return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseDoubleClickInterval);
289 case StartDragDistance:
290 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragDistance);
292 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragTime);
293 case ShowIsFullScreen:
295 case PasswordMaskDelay:
296 return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskDelay);
297 case FontSmoothingGamma:
299 case StartDragVelocity:
300 return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
301 case UseRtlExtensions:
302 return QVariant(false);
303 case SynthesizeMouseFromTouchEvents:
310 Qt::KeyboardModifiers QPlatformIntegration::queryKeyboardModifiers() const
312 return QGuiApplication::keyboardModifiers();
316 Should be used to obtain a list of possible shortcuts for the given key
317 event. As that needs system functionality it cannot be done in qkeymapper.
319 One example for more than 1 possibility is the key combination of Shift+5.
320 That one might trigger a shortcut which is set as "Shift+5" as well as one
321 using %. These combinations depend on the currently set keyboard layout
322 which cannot be obtained by Qt functionality.
324 QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const
330 Should be called by the implementation whenever a new screen is added.
332 The first screen added will be the primary screen, used for default-created
333 windows, GL contexts, and other resources unless otherwise specified.
335 This adds the screen to QGuiApplication::screens(), and emits the
336 QGuiApplication::screenAdded() signal.
338 The screen is automatically removed when the QPlatformScreen is destroyed.
340 void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
342 QScreen *screen = new QScreen(ps);
343 ps->d_func()->screen = screen;
344 QGuiApplicationPrivate::screen_list << screen;
345 emit qGuiApp->screenAdded(screen);
348 QStringList QPlatformIntegration::themeNames() const
350 return QStringList();
353 class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
356 return new QPlatformTheme;