ec12ef12a5bda29a0ba40564aed1ff494d400e87
[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 integration's 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 integration's 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 integration's 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 singleton class which gets instantiated in the QGuiApplication
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 accessors to member variables.
125
126     It is not trivial to create or build a platform plugin outside of the Qt source tree. Therefore
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) const
144
145     Factory function for QPlatformWindow. The \a window parameter is a pointer to the top level
146     window which the QPlatformWindow is supposed to be created for.
147
148     All top level windows have to have a QPlatformWindow, and it will be created when the
149     QPlatformWindow is set to be visible for the first time. If the top level window's flags are
150     changed, or if the top level window's QPlatformWindowFormat is changed, then the top level
151     window's QPlatformWindow is deleted and a new one is created.
152
153     In the constructor, of the QPlatformWindow, the window flags, state, title and geometry
154     of the \a window should be applied to the underlying window. If the resulting flags or state
155     differs, the resulting values should be set on the \a window using QWindow::setWindowFlags()
156     or QWindow::setWindowState(), respectively.
157
158     \sa QPlatformWindow, QPlatformWindowFormat
159     \sa createPlatformBackingStore(QWindow *window) const
160 */
161
162 /*!
163     \fn QPlatformBackingStore *QPlatformIntegration::createPlatformBackingStore(QWindow *window) const
164
165     Factory function for QPlatformBackingStore. The QWindow parameter is a pointer to the
166     top level widget(tlw) the window surface is created for. A QPlatformWindow is always created
167     before the QPlatformBackingStore for tlw where the widget also requires a backing store.
168
169     \sa QBackingStore
170     \sa createPlatformWindow(QWindow *window, WId winId = 0) const
171 */
172
173 /*!
174     \fn QAbstractEventDispatcher *createEventDispatcher() const
175
176     Factory function for the event dispatcher. The platform plugin
177     must create and and return a QAbstractEventDispatcher subclass when
178     this function is called.
179 */
180
181 bool QPlatformIntegration::hasCapability(Capability cap) const
182 {
183     Q_UNUSED(cap);
184     return false;
185 }
186
187 QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
188 {
189     return new QRasterPlatformPixmap(type);
190 }
191
192 QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(QGuiGLContext *context) const
193 {
194     qWarning("This plugin does not support createPlatformGLContext!");
195     return 0;
196 }
197
198 /*!
199
200     Returns the platform's printing support.
201
202     \since 5.0
203 */
204
205 QPlatformPrinterSupport *QPlatformIntegration::printerSupport() const
206 {
207     static QPlatformPrinterSupport *ps = 0;
208 #ifndef QT_NO_PRINTER
209     if (!ps)
210         ps = new QPlatformPrinterSupport;
211 #endif
212     return ps;
213 }
214
215 /*!
216   Returns the platforms input context.
217
218   The default implementation returns 0, implying no input method support.
219 */
220 QPlatformInputContext *QPlatformIntegration::inputContext() const
221 {
222     return 0;
223 }
224
225 /*!
226   Should be called by the implementation whenever a new screen is added.
227
228   The first screen added will be the primary screen, used for default-created
229   windows, GL contexts, and other resources unless otherwise specified.
230
231   This adds the screen to QGuiApplication::screens(), and emits the
232   QGuiApplication::screenAdded() signal.
233
234   The screen is automatically removed when the QPlatformScreen is destroyed.
235 */
236 void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
237 {
238     QScreen *screen = ps ? ps->screen() : 0;
239     if (screen && !QGuiApplicationPrivate::screen_list.contains(screen)) {
240         QGuiApplicationPrivate::screen_list << screen;
241         emit qGuiApp->screenAdded(screen);
242     }
243 }
244
245 QT_END_NAMESPACE