1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QGUIAPPLICATION_P_H
43 #define QGUIAPPLICATION_P_H
45 #include <QtGui/qguiapplication.h>
47 #include <QtCore/QPointF>
48 #include <QtCore/private/qcoreapplication_p.h>
50 #include <QtCore/private/qthread_p.h>
52 #include <QWindowSystemInterface>
53 #include "private/qwindowsysteminterface_qpa_p.h"
54 #include "private/qshortcutmap_p.h"
61 class QPlatformIntegration;
63 class QPlatformDragQtResponse;
64 struct QDrawHelperGammaTables;
66 class Q_GUI_EXPORT QGuiApplicationPrivate : public QCoreApplicationPrivate
68 Q_DECLARE_PUBLIC(QGuiApplication)
70 QGuiApplicationPrivate(int &argc, char **argv, int flags);
71 ~QGuiApplicationPrivate();
73 void createPlatformIntegration();
74 void createEventDispatcher();
75 void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
77 virtual void notifyLayoutDirectionChange();
78 virtual void notifyActiveWindowChange(QWindow *previous);
80 virtual bool shouldQuit();
82 static Qt::KeyboardModifiers modifier_buttons;
83 static Qt::MouseButtons mouse_buttons;
85 static QPlatformIntegration *platform_integration;
87 static QPlatformIntegration *platformIntegration()
88 { return platform_integration; }
90 static QPlatformTheme *platform_theme;
92 static QPlatformTheme *platformTheme()
93 { return platform_theme; }
95 static QAbstractEventDispatcher *qt_qpa_core_dispatcher()
96 { return QCoreApplication::instance()->d_func()->threadData->eventDispatcher; }
98 static void processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent *e);
99 static void processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e);
100 static void processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e);
101 static void processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent *e);
103 static void processCloseEvent(QWindowSystemInterfacePrivate::CloseEvent *e);
105 static void processGeometryChangeEvent(QWindowSystemInterfacePrivate::GeometryChangeEvent *e);
107 static void processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e);
108 static void processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e);
110 static void processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *e);
111 static void processWindowStateChangedEvent(QWindowSystemInterfacePrivate::WindowStateChangedEvent *e);
113 static void processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent *e);
115 static void reportScreenOrientationChange(QScreen *screen);
116 static void reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e);
117 static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e);
118 static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e);
119 static void reportLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e);
120 static void reportRefreshRateChange(QWindowSystemInterfacePrivate::ScreenRefreshRateEvent *e);
121 static void processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce);
123 static void processExposeEvent(QWindowSystemInterfacePrivate::ExposeEvent *e);
125 static void processFileOpenEvent(QWindowSystemInterfacePrivate::FileOpenEvent *e);
127 static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
128 static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
129 static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
131 #ifndef QT_NO_DRAGANDDROP
132 static QPlatformDragQtResponse processDrag(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
133 static QPlatformDropQtResponse processDrop(QWindow *w, const QMimeData *dropData, const QPoint &p, Qt::DropActions supportedActions);
136 static bool processNativeEvent(QWindow *window, const QByteArray &eventType, void *message, long *result);
138 static void sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event);
140 static inline Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
142 if (!(alignment & Qt::AlignHorizontal_Mask))
143 alignment |= Qt::AlignLeft;
144 if ((alignment & Qt::AlignAbsolute) == 0 && (alignment & (Qt::AlignLeft | Qt::AlignRight))) {
145 if (direction == Qt::RightToLeft)
146 alignment ^= (Qt::AlignLeft | Qt::AlignRight);
147 alignment |= Qt::AlignAbsolute;
152 static void emitLastWindowClosed();
154 QPixmap getPixmapCursor(Qt::CursorShape cshape);
156 void q_updateFocusObject(QObject *object);
158 static QGuiApplicationPrivate *instance() { return self; }
160 static QString *platform_name;
162 QWindowList modalWindowList;
163 static void showModalWindow(QWindow *window);
164 static void hideModalWindow(QWindow *window);
165 virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const;
167 static Qt::MouseButtons buttons;
168 static ulong mousePressTime;
169 static Qt::MouseButton mousePressButton;
170 static int mousePressX;
171 static int mousePressY;
172 static int mouse_double_click_distance;
173 static QPointF lastCursorPosition;
174 static bool tabletState;
175 static QWindow *tabletPressTarget;
177 #ifndef QT_NO_CLIPBOARD
178 static QClipboard *qt_clipboard;
181 static QPalette *app_pal;
183 static QWindowList window_list;
184 static QWindow *focus_window;
187 QList<QCursor> cursor_list;
189 static QList<QScreen *> screen_list;
191 static QFont *app_font;
193 QStyleHints *styleHints;
194 static bool obey_desktop_settings;
195 QInputMethod *inputMethod;
197 static QList<QObject *> generic_plugin_list;
198 #ifndef QT_NO_SHORTCUT
199 QShortcutMap shortcutMap;
202 struct ActiveTouchPointsKey {
203 ActiveTouchPointsKey(QTouchDevice *dev, int id) : device(dev), touchPointId(id) { }
204 QTouchDevice *device;
207 struct ActiveTouchPointsValue {
208 QWeakPointer<QWindow> window;
209 QWeakPointer<QObject> target;
210 QTouchEvent::TouchPoint touchPoint;
212 QHash<ActiveTouchPointsKey, ActiveTouchPointsValue> activeTouchPoints;
213 QEvent::Type lastTouchType;
214 struct SynthesizedMouseData {
215 SynthesizedMouseData(const QPointF &p, const QPointF &sp, QWindow *w)
216 : pos(p), screenPos(sp), window(w) { }
219 QWeakPointer<QWindow> window;
221 QHash<QWindow *, SynthesizedMouseData> synthesizedMousePoints;
223 static int mouseEventCaps(QMouseEvent *event);
224 static QVector2D mouseEventVelocity(QMouseEvent *event);
225 static void setMouseEventCapsAndVelocity(QMouseEvent *event, int caps, const QVector2D &velocity);
226 static void setMouseEventCapsAndVelocity(QMouseEvent *event, QMouseEvent *other);
228 const QDrawHelperGammaTables *gammaTables();
230 // hook reimplemented in QApplication to apply the QStyle function on the QIcon
231 virtual QPixmap applyQIconStyleHelper(QIcon::Mode, const QPixmap &basePixmap) const { return basePixmap; }
234 virtual void notifyThemeChanged();
239 static QGuiApplicationPrivate *self;
240 static QTouchDevice *m_fakeTouchDevice;
241 static int m_fakeMouseSourcePointId;
242 QAtomicPointer<QDrawHelperGammaTables> m_gammaTables;
245 Q_GUI_EXPORT uint qHash(const QGuiApplicationPrivate::ActiveTouchPointsKey &k);
247 Q_GUI_EXPORT bool operator==(const QGuiApplicationPrivate::ActiveTouchPointsKey &a,
248 const QGuiApplicationPrivate::ActiveTouchPointsKey &b);
254 #endif // QGUIAPPLICATION_P_H