c190c4f481c1ac28c4fce20715706cad64ba5c10
[profile/ivi/qtbase.git] / src / gui / kernel / qplatformintegration_qpa.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qplatformintegration_qpa.h"
43
44 #include <QtGui/QPlatformFontDatabase>
45 #include <QtGui/QPlatformClipboard>
46 #include <QtGui/QPlatformPrinterSupport>
47 #include <QtGui/private/qguiapplication_p.h>
48 #include <QtGui/private/qpixmap_raster_p.h>
49 #include <private/qdnd_p.h>
50
51 QT_BEGIN_NAMESPACE
52
53 /*!
54     Accessor for the platform integrations fontdatabase.
55
56     Default implementation returns a default QPlatformFontDatabase.
57
58     \sa QPlatformFontDatabase
59 */
60 QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
61 {
62     static QPlatformFontDatabase *db = 0;
63     if (!db) {
64         db = new QPlatformFontDatabase;
65     }
66     return db;
67 }
68
69 /*!
70     Accessor for the platform integrations clipboard.
71
72     Default implementation returns a default QPlatformClipboard.
73
74     \sa QPlatformClipboard
75
76 */
77
78 #ifndef QT_NO_CLIPBOARD
79
80 QPlatformClipboard *QPlatformIntegration::clipboard() const
81 {
82     static QPlatformClipboard *clipboard = 0;
83     if (!clipboard) {
84         clipboard = new QPlatformClipboard;
85     }
86     return clipboard;
87 }
88
89 #endif
90
91 #ifndef QT_NO_DRAGANDDROP
92 /*!
93     Accessor for the platform integrations drag object.
94
95     Default implementation returns 0, implying no drag and drop support.
96
97 */
98 QPlatformDrag *QPlatformIntegration::drag() const
99 {
100     return 0;
101 }
102 #endif
103
104 QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
105 {
106     return 0;
107 }
108
109 /*!
110     \class QPlatformIntegration
111     \since 4.8
112     \internal
113     \preliminary
114     \ingroup qpa
115     \brief The QPlatformIntegration class is the entry for WindowSystem specific functionality.
116
117     QPlatformIntegration is the single entry point for windowsystem specific functionality when
118     using the QPA platform. It has factory functions for creating platform specific pixmaps and
119     windows. The class also controls the font subsystem.
120
121     QPlatformIntegration is a singelton class which gets instansiated in the QApplication
122     constructor. The QPlatformIntegration instance do not have ownership of objects it creates in
123     functions where the name starts with create. However, functions which don't have a name
124     starting with create acts as assessors to member variables.
125
126     It is not trivial to create or build a platform plugin outside of the Qt source tree. Therefor
127     the recommended approach for making new platform plugin is to copy an existing plugin inside
128     the QTSRCTREE/src/plugins/platform and develop the plugin inside the source tree.
129
130     The minimal platform integration is the smallest platform integration it is possible to make,
131     which makes it an ideal starting point for new plugins. For a slightly more advanced plugin,
132     consider reviewing the directfb plugin, or the testlite plugin.
133 */
134
135 /*!
136     \fn QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
137
138     Factory function for QPlatformPixmap. PixelType can be either PixmapType or BitmapType.
139     \sa QPlatformPixmap
140 */
141
142 /*!
143     \fn QPlatformWindow *QPlatformIntegration::createPlatformWindow(QWindow *window, WId winId = 0) const
144
145     Factory function for QPlatformWindow. The widget parameter is a pointer to the top level
146     widget(tlw) which the QPlatformWindow is suppose to be created for. The WId handle is actually
147     never used, but there for future reference. Its purpose is if it is going to be possible to
148     create QPlatformWindows on existing WId.
149
150     All tlw has to have a QPlatformWindow, and it will be created when the QPlatformWindow is set
151     to be visible for the first time. If the tlw's window flags are changed, or if the tlw's
152     QPlatformWindowFormat is changed, then the tlw's QPlatformWindow is deleted and a new one is
153     created.
154
155     \sa QPlatformWindow, QPlatformWindowFormat
156     \sa createPlatformBackingStore(QWindow *window) const
157 */
158
159 /*!
160     \fn QPlatformBackingStore *QPlatformIntegration::createPlatformBackingStore(QWindow *window) const
161
162     Factory function for QPlatformBackingStore. The QWindow parameter is a pointer to the
163     top level widget(tlw) the window surface is created for. A QPlatformWindow is always created
164     before the QPlatformBackingStore for tlw where the widget also requires a backing store.
165
166     \sa QBackingStore
167     \sa createPlatformWindow(QWindow *window, WId winId = 0) const
168 */
169
170
171 /*!
172     \fn void QPlatformIntegration::moveToScreen(QWindow *window, int screen)
173
174     This function is called when a QWindow is displayed on screen, or the QWindow is to be
175     displayed on a new screen. The QWindow parameter is a pointer to the top level widget and
176     the int parameter is the index to the screen in QList<QPlatformScreen *> screens() const.
177
178     Default implementation does nothing.
179
180     \sa screens() const
181 */
182
183 /*!
184     \fn QList<QPlatformScreen *> QPlatformIntegration::screens() const
185
186     Accessor function to a list of all the screens on the current system. The screen with the
187     index == 0 is the default/main screen.
188 */
189
190 /*!
191     \fn bool QPlatformIntegration::isVirtualDesktop()
192
193     Returns if the current windowing system configuration defines all the screens to be one
194     desktop(virtual desktop), or if each screen is a desktop of its own.
195
196     Default implementation returns false.
197 */
198
199 /*!
200     \fn QAbstractEventDispatcher *createEventDispatcher() const
201
202     Factory function for the event dispatcher. The platform plugin
203     must create and and return a QAbstractEventDispatcher subclass when
204     this function is called.
205 */
206
207 bool QPlatformIntegration::hasCapability(Capability cap) const
208 {
209     Q_UNUSED(cap);
210     return false;
211 }
212
213 QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
214 {
215     return new QRasterPlatformPixmap(type);
216 }
217
218 QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(QGuiGLContext *context) const
219 {
220     qWarning("This plugin does not support createPlatformGLContext!");
221     return 0;
222 }
223
224 /*!
225
226     Returns the platform's printing support.
227
228     \since 5.0
229 */
230
231 QPlatformPrinterSupport *QPlatformIntegration::printerSupport() const
232 {
233     static QPlatformPrinterSupport *ps = 0;
234 #ifndef QT_NO_PRINTER
235     if (!ps)
236         ps = new QPlatformPrinterSupport;
237 #endif
238     return ps;
239 }
240
241 /*!
242   Returns the platforms input context.
243
244   The default implementation returns 0, implying no input method support.
245 */
246 QPlatformInputContext *QPlatformIntegration::inputContext() const
247 {
248     return 0;
249 }
250
251 /*!
252   Should be called by the implementation whenever a new screen is added.
253
254   The first screen added will be the primary screen, used for default-created
255   windows, GL contexts, and other resources unless otherwise specified.
256
257   This adds the screen to QGuiApplication::screens(), and emits the
258   QGuiApplication::screenAdded() signal.
259
260   The screen is automatically removed when the QPlatformScreen is destroyed.
261 */
262 void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
263 {
264     QScreen *screen = ps ? ps->screen() : 0;
265     if (screen && !QGuiApplicationPrivate::screen_list.contains(screen)) {
266         QGuiApplicationPrivate::screen_list << screen;
267         emit qGuiApp->screenAdded(screen);
268     }
269 }
270
271 QT_END_NAMESPACE