1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKWINDOW_P_H
43 #define QQUICKWINDOW_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qquickitem.h"
57 #include "qquickwindow.h"
58 #include <private/qqmlguard_p.h>
60 #include <QtQuick/private/qsgcontext_p.h>
61 #include <private/qquickdrag_p.h>
63 #include <QtCore/qthread.h>
64 #include <QtCore/qmutex.h>
65 #include <QtCore/qwaitcondition.h>
66 #include <private/qwindow_p.h>
67 #include <private/qopengl_p.h>
68 #include <qopenglcontext.h>
69 #include <QtGui/qopenglframebufferobject.h>
70 #include <QtGui/qevent.h>
74 //Make it easy to identify and customize the root item if needed
76 class QQuickWindowManager;
78 class QQuickRootItem : public QQuickItem
84 void setWidth(int w) {QQuickItem::setWidth(qreal(w));}
85 void setHeight(int h) {QQuickItem::setHeight(qreal(h));}
88 class QQuickItemPrivate;
89 class QQuickWindowPrivate;
92 class QQuickWindowRenderLoop;
93 class QQuickWindowIncubationController;
95 class Q_QUICK_PRIVATE_EXPORT QQuickWindowPrivate : public QWindowPrivate
98 Q_DECLARE_PUBLIC(QQuickWindow)
100 static inline QQuickWindowPrivate *get(QQuickWindow *c) { return c->d_func(); }
102 QQuickWindowPrivate();
103 virtual ~QQuickWindowPrivate();
105 void init(QQuickWindow *);
106 void initRootItem();//Currently only used if items added in QML
108 QQuickRootItem *rootItem;
109 QSet<QQuickItem *> parentlessItems;
110 QQmlListProperty<QObject> data();
112 QQuickItem *activeFocusItem;
114 // Keeps track of the item currently receiving mouse events
115 QQuickItem *mouseGrabberItem;
117 QQuickItem *cursorItem;
119 #ifndef QT_NO_DRAGANDDROP
120 QQuickDragGrabber dragGrabber;
123 ulong touchMousePressTimestamp;
125 // Mouse positions are saved in widget coordinates
126 QPointF lastMousePosition;
127 bool translateTouchToMouse(QQuickItem *item, QTouchEvent *event);
128 void translateTouchEvent(QTouchEvent *touchEvent);
129 static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
130 static QMouseEvent *cloneMouseEvent(QMouseEvent *event, QPointF *transformedLocalPos = 0);
131 bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *);
132 bool deliverMouseEvent(QMouseEvent *);
133 bool sendFilteredMouseEvent(QQuickItem *, QQuickItem *, QEvent *);
134 bool deliverWheelEvent(QQuickItem *, QWheelEvent *);
135 bool deliverTouchPoints(QQuickItem *, QTouchEvent *, const QList<QTouchEvent::TouchPoint> &, QSet<int> *,
136 QHash<QQuickItem *, QList<QTouchEvent::TouchPoint> > *);
137 bool deliverTouchEvent(QTouchEvent *);
138 bool deliverTouchCancelEvent(QTouchEvent *);
139 bool deliverHoverEvent(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, bool &accepted);
140 bool deliverMatchingPointsToItem(QQuickItem *item, QTouchEvent *event, QSet<int> *acceptedNewPoints, const QSet<int> &matchingNewPoints, const QList<QTouchEvent::TouchPoint> &matchingPoints);
141 QTouchEvent *touchEventForItemBounds(QQuickItem *target, const QTouchEvent &originalEvent);
142 QTouchEvent *touchEventWithPoints(const QTouchEvent &event, const QList<QTouchEvent::TouchPoint> &newPoints);
143 bool sendFilteredTouchEvent(QQuickItem *target, QQuickItem *item, QTouchEvent *event);
144 bool sendHoverEvent(QEvent::Type, QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos,
145 Qt::KeyboardModifiers modifiers, bool accepted);
147 #ifndef QT_NO_DRAGANDDROP
148 void deliverDragEvent(QQuickDragGrabber *, QEvent *);
149 bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
152 void updateCursor(const QPointF &scenePos);
153 QQuickItem *findCursorItem(QQuickItem *item, const QPointF &scenePos);
156 QList<QQuickItem*> hoverItems;
158 DontChangeFocusProperty = 0x01,
159 DontChangeSubFocusItem = 0x02
161 Q_DECLARE_FLAGS(FocusOptions, FocusOption)
163 void setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
164 void clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
165 static void notifyFocusChangesRecur(QQuickItem **item, int remaining);
167 void updateFocusItemTransform();
169 void dirtyItem(QQuickItem *);
170 void cleanup(QSGNode *);
173 void syncSceneGraph();
174 void renderSceneGraph(const QSize &size);
176 bool isRenderable() const;
178 bool renderWithoutShowing;
179 void setRenderWithoutShowing(bool enabled);
181 QQuickItem::UpdatePaintNodeData updatePaintNodeData;
183 QQuickItem *dirtyItemList;
184 QList<QSGNode *> cleanupNodeList;
186 QSet<QQuickItem *> itemsToPolish;
188 void updateDirtyNodes();
190 void cleanupNodesOnShutdown();
191 bool updateEffectiveOpacity(QQuickItem *);
192 void updateEffectiveOpacityRoot(QQuickItem *, qreal);
193 void updateDirtyNode(QQuickItem *);
195 void fireFrameSwapped() { emit q_func()->frameSwapped(); }
198 QSGRenderer *renderer;
200 QQuickWindowManager *windowManager;
204 uint clearBeforeRendering : 1;
206 // Currently unused in the default implementation, as we're not stopping
207 // rendering when obscured as we should...
208 uint persistentGLContext : 1;
209 uint persistentSceneGraph : 1;
211 uint lastWheelEventAccepted : 1;
213 QOpenGLFramebufferObject *renderTarget;
215 QSize renderTargetSize;
217 // Keeps track of which touch point (int) was last accepted by which item
218 QHash<int, QQuickItem *> itemForTouchPointId;
220 mutable QQuickWindowIncubationController *incubationController;
222 static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event);
225 static void cleanupNodesOnShutdown(QQuickItem *);
229 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::FocusOptions)
233 #endif // QQUICKWINDOW_P_H