b3cafc5d2c2439fff88e74eb8e3ebfacfd1e6740
[profile/ivi/qtbase.git] / src / gui / kernel / qguiapplication_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QGUIAPPLICATION_P_H
43 #define QGUIAPPLICATION_P_H
44
45 #include <QtGui/qguiapplication.h>
46
47 #include <QtCore/QPointF>
48 #include <QtCore/private/qcoreapplication_p.h>
49
50 #include <QtCore/private/qthread_p.h>
51
52 #include <QWindowSystemInterface>
53 #include "private/qwindowsysteminterface_p.h"
54 #include "private/qshortcutmap_p.h"
55 #include <qicon.h>
56
57 QT_BEGIN_HEADER
58
59 QT_BEGIN_NAMESPACE
60
61 class QPlatformIntegration;
62 class QPlatformTheme;
63 class QPlatformDragQtResponse;
64 struct QDrawHelperGammaTables;
65 #ifndef QT_NO_DRAGANDDROP
66 class QDrag;
67 #endif // QT_NO_DRAGANDDROP
68
69 class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
70 {
71     Q_DECLARE_PUBLIC(QGuiApplication)
72 public:
73     QGuiApplicationPrivate(int &argc, char **argv, int flags);
74     ~QGuiApplicationPrivate();
75
76     void createPlatformIntegration();
77     void createEventDispatcher();
78     void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
79
80     virtual void notifyLayoutDirectionChange();
81     virtual void notifyActiveWindowChange(QWindow *previous);
82
83     virtual bool shouldQuit();
84
85     static Qt::KeyboardModifiers modifier_buttons;
86     static Qt::MouseButtons mouse_buttons;
87
88     static QPlatformIntegration *platform_integration;
89
90     static QPlatformIntegration *platformIntegration()
91     { return platform_integration; }
92
93     static QPlatformTheme *platform_theme;
94
95     static QPlatformTheme *platformTheme()
96     { return platform_theme; }
97
98     static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
99     {
100         if (QCoreApplication::instance())
101             return QCoreApplication::instance()->d_func()->threadData->eventDispatcher;
102         else
103             return 0;
104     }
105
106     static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
107     static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
108     static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
109     static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
110
111     static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
112
113     static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
114
115     static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
116     static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
117
118     static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
119     static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
120
121     static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
122
123     static void updateFilteredScreenOrientation(QScreen *screen);
124     static void reportScreenOrientationChange(QScreen *screen);
125     static void reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
126     static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
127     static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e);
128     static void reportLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
129     static void reportRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
130     static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
131
132     static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
133
134     static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
135
136     static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
137     static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
138     static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
139
140 #ifndef QT_NO_DRAGANDDROP
141     static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
142     static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
143 #endif
144
145     static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
146
147     static void sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
148
149     static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
150     {
151         if (!(alignment & Qt::AlignHorizontal_Mask))
152             alignment |= Qt::AlignLeft;
153         if ((alignment & Qt::AlignAbsolute) == 0 && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
154             if (direction == Qt::RightToLeft)
155                 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
156             alignment |= Qt::AlignAbsolute;
157         }
158         return alignment;
159     }
160
161     static void emitLastWindowClosed();
162
163     QPixmap getPixmapCursor(Qt::CursorShape cshape);
164
165     void q_updateFocusObject(QObject *object);
166
167     static QGuiApplicationPrivate *instance() { return self; }
168
169     static QString *platform_name;
170     static QString *displayName;
171
172     QWindowList modalWindowList;
173     static void showModalWindow(QWindow *window);
174     static void hideModalWindow(QWindow *window);
175     static void updateBlockedStatus(QWindow *window);
176     virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const;
177
178     static Qt::MouseButtons buttons;
179     static ulong mousePressTime;
180     static Qt::MouseButton mousePressButton;
181     static int mousePressX;
182     static int mousePressY;
183     static int mouse_double_click_distance;
184     static QPointF lastCursorPosition;
185     static bool tabletState;
186     static QWindow *tabletPressTarget;
187
188 #ifndef QT_NO_CLIPBOARD
189     static QClipboard *qt_clipboard;
190 #endif
191
192     static QPalette *app_pal;
193
194     static QWindowList window_list;
195     static QWindow *focus_window;
196
197 #ifndef QT_NO_CURSOR
198     QList<QCursor> cursor_list;
199 #endif
200     static QList<QScreen *> screen_list;
201
202     static QFont *app_font;
203
204     QStyleHints *styleHints;
205     static bool obey_desktop_settings;
206     QInputMethod *inputMethod;
207
208     static QList<QObject *> generic_plugin_list;
209 #ifndef QT_NO_SHORTCUT
210     QShortcutMap shortcutMap;
211 #endif
212
213     struct ActiveTouchPointsKey {
214         ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { }
215         QTouchDevice *device;
216         int touchPointId;
217     };
218     struct ActiveTouchPointsValue {
219         QPointer<QWindow> window;
220         QPointer<QObject> target;
221         QTouchEvent::TouchPoint touchPoint;
222     };
223     QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
224     QEvent::Type lastTouchType;
225     struct SynthesizedMouseData {
226         SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
227             : pos(p), screenPos(sp), window(w) { }
228         QPointF pos;
229         QPointF screenPos;
230         QPointer<QWindow> window;
231     };
232     QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
233
234     static int mouseEventCaps(QMouseEvent *event);
235     static QVector2D mouseEventVelocity(QMouseEvent *event);
236     static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
237     static void setMouseEventCapsAndVelocity(QMouseEvent *event, QMouseEvent *other);
238
239     const QDrawHelperGammaTables *gammaTables();
240
241     // hook reimplemented in QApplication to apply the QStyle function on the QIcon
242     virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
243
244 protected:
245     virtual void notifyThemeChanged();
246 #ifndef QT_NO_DRAGANDDROP
247     virtual void notifyDragStarted(const QDrag *);
248 #endif // QT_NO_DRAGANDDROP
249
250 private:
251     friend class QDragManager;
252
253     void init();
254
255     static QGuiApplicationPrivate *self;
256     static QTouchDevice *m_fakeTouchDevice;
257     static int m_fakeMouseSourcePointId;
258     QAtomicPointer<QDrawHelperGammaTables> m_gammaTables;
259 };
260
261 Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);
262
263 Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
264                              const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
265
266 QT_END_NAMESPACE
267
268 QT_END_HEADER
269
270 #endif // QGUIAPPLICATION_P_H