cf55c59bab2d4814ba717abce80340d85a9633ef
[profile/ivi/qtbase.git] / src / gui / kernel / qplatformintegration.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qplatformintegration.h"
43
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>
52
53 QT_BEGIN_NAMESPACE
54
55 /*!
56     Accessor for the platform integration's fontdatabase.
57
58     Default implementation returns a default QPlatformFontDatabase.
59
60     \sa QPlatformFontDatabase
61 */
62 QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
63 {
64     static QPlatformFontDatabase *db = 0;
65     if (!db) {
66         db = new QPlatformFontDatabase;
67     }
68     return db;
69 }
70
71 /*!
72     Accessor for the platform integration's clipboard.
73
74     Default implementation returns a default QPlatformClipboard.
75
76     \sa QPlatformClipboard
77
78 */
79
80 #ifndef QT_NO_CLIPBOARD
81
82 QPlatformClipboard *QPlatformIntegration::clipboard() const
83 {
84     static QPlatformClipboard *clipboard = 0;
85     if (!clipboard) {
86         clipboard = new QPlatformClipboard;
87     }
88     return clipboard;
89 }
90
91 #endif
92
93 #ifndef QT_NO_DRAGANDDROP
94 /*!
95     Accessor for the platform integration's drag object.
96
97     Default implementation returns 0, implying no drag and drop support.
98
99 */
100 QPlatformDrag *QPlatformIntegration::drag() const
101 {
102     return 0;
103 }
104 #endif
105
106 QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
107 {
108     return 0;
109 }
110
111 QPlatformServices *QPlatformIntegration::services() const
112 {
113     return 0;
114 }
115
116 /*!
117     \class QPlatformIntegration
118     \since 4.8
119     \internal
120     \preliminary
121     \ingroup qpa
122     \brief The QPlatformIntegration class is the entry for WindowSystem specific functionality.
123
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.
127
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.
132
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.
136
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.
140 */
141
142 /*!
143     \fn QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
144
145     Factory function for QPlatformPixmap. PixelType can be either PixmapType or BitmapType.
146     \sa QPlatformPixmap
147 */
148
149 /*!
150     \fn QPlatformWindow *QPlatformIntegration::createPlatformWindow(QWindow *window) const
151
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.
154
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.
159
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.
164
165     \sa QPlatformWindow, QPlatformWindowFormat
166     \sa createPlatformBackingStore()
167 */
168
169 /*!
170     \fn QPlatformBackingStore *QPlatformIntegration::createPlatformBackingStore(QWindow *window) const
171
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.
175
176     \sa QBackingStore
177     \sa createPlatformWindow()
178 */
179
180 /*!
181     \enum QPlatformIntegration::Capability
182
183     Capabilities are used to determing specific features of a platform integration
184
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
187     pixmaps.
188
189     \value OpenGL The platform supports OpenGL
190
191     \value ThreadedOpenGL The platform supports using OpenGL outside the GUI thread.
192
193     \value SharedGraphicsCache The platform supports a shared graphics cache
194
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.
198  */
199
200
201 /*!
202
203     \fn QAbstractEventDispatcher *QPlatformIntegration::guiThreadEventDispatcher() const = 0
204
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
209     a flat pointer.
210     \sa QGuiApplicationPrivate
211 */
212
213 bool QPlatformIntegration::hasCapability(Capability cap) const
214 {
215     Q_UNUSED(cap);
216     return false;
217 }
218
219 QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
220 {
221     return new QRasterPlatformPixmap(type);
222 }
223
224 #ifndef QT_NO_OPENGL
225 QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
226 {
227     Q_UNUSED(context);
228     qWarning("This plugin does not support createPlatformOpenGLContext!");
229     return 0;
230 }
231 #endif
232
233 /*!
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.
236 */
237 QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const
238 {
239     qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!",
240              cacheId);
241     return 0;
242 }
243
244 /*!
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.
247 */
248 QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
249 {
250     Q_UNUSED(paintDevice)
251     return 0;
252 }
253
254 /*!
255   Returns the platforms input context.
256
257   The default implementation returns 0, implying no input method support.
258 */
259 QPlatformInputContext *QPlatformIntegration::inputContext() const
260 {
261     return 0;
262 }
263
264 #ifndef QT_NO_ACCESSIBILITY
265
266 /*!
267   Returns the platforms accessibility.
268
269   The default implementation returns 0, implying no accessibility support.
270 */
271 QPlatformAccessibility *QPlatformIntegration::accessibility() const
272 {
273     return 0;
274 }
275
276 #endif
277
278 QVariant QPlatformIntegration::styleHint(StyleHint hint) const
279 {
280     switch (hint) {
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);
291     case StartDragTime:
292         return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragTime);
293     case ShowIsFullScreen:
294         return false;
295     case PasswordMaskDelay:
296         return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskDelay);
297     case FontSmoothingGamma:
298         return qreal(1.7);
299     case StartDragVelocity:
300         return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
301     case UseRtlExtensions:
302         return QVariant(false);
303     case SynthesizeMouseFromTouchEvents:
304         return true;
305     }
306
307     return 0;
308 }
309
310 Qt::KeyboardModifiers QPlatformIntegration::queryKeyboardModifiers() const
311 {
312     return QGuiApplication::keyboardModifiers();
313 }
314
315 /*!
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.
318
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.
323 */
324 QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const
325 {
326     return QList<int>();
327 }
328
329 /*!
330   Should be called by the implementation whenever a new screen is added.
331
332   The first screen added will be the primary screen, used for default-created
333   windows, GL contexts, and other resources unless otherwise specified.
334
335   This adds the screen to QGuiApplication::screens(), and emits the
336   QGuiApplication::screenAdded() signal.
337
338   The screen is automatically removed when the QPlatformScreen is destroyed.
339 */
340 void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
341 {
342     QScreen *screen = new QScreen(ps);
343     ps->d_func()->screen = screen;
344     QGuiApplicationPrivate::screen_list << screen;
345     emit qGuiApp->screenAdded(screen);
346 }
347
348 QStringList QPlatformIntegration::themeNames() const
349 {
350     return QStringList();
351 }
352
353 class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
354 {
355     Q_UNUSED(name)
356     return new QPlatformTheme;
357 }
358
359 QT_END_NAMESPACE