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 QtQml 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 QQUICKCANVAS_P_H
43 #define QQUICKCANVAS_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 "qquickcanvas.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 QQuickCanvasPrivate;
92 class QQuickCanvasRenderLoop;
93 class QQuickCanvasIncubationController;
95 class Q_QUICK_PRIVATE_EXPORT QQuickCanvasPrivate : public QWindowPrivate
98 Q_DECLARE_PUBLIC(QQuickCanvas)
100 static inline QQuickCanvasPrivate *get(QQuickCanvas *c) { return c->d_func(); }
102 QQuickCanvasPrivate();
103 virtual ~QQuickCanvasPrivate();
105 void init(QQuickCanvas *);
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;
116 #ifndef QT_NO_DRAGANDDROP
117 QQuickDragGrabber dragGrabber;
120 ulong touchMousePressTimestamp;
122 // Mouse positions are saved in widget coordinates
123 QPointF lastMousePosition;
124 bool translateTouchToMouse(QQuickItem *item, QTouchEvent *event);
125 void translateTouchEvent(QTouchEvent *touchEvent);
126 static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
127 static QMouseEvent *cloneMouseEvent(QMouseEvent *event, QPointF *transformedLocalPos = 0);
128 bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *);
129 bool deliverMouseEvent(QMouseEvent *);
130 bool sendFilteredMouseEvent(QQuickItem *, QQuickItem *, QEvent *);
131 bool deliverWheelEvent(QQuickItem *, QWheelEvent *);
132 bool deliverTouchPoints(QQuickItem *, QTouchEvent *, const QList<QTouchEvent::TouchPoint> &, QSet<int> *,
133 QHash<QQuickItem *, QList<QTouchEvent::TouchPoint> > *);
134 bool deliverTouchEvent(QTouchEvent *);
135 bool deliverTouchCancelEvent(QTouchEvent *);
136 bool deliverHoverEvent(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, bool &accepted);
137 bool deliverMatchingPointsToItem(QQuickItem *item, QTouchEvent *event, QSet<int> *acceptedNewPoints, const QSet<int> &matchingNewPoints, const QList<QTouchEvent::TouchPoint> &matchingPoints);
138 QTouchEvent *touchEventForItemBounds(QQuickItem *target, const QTouchEvent &originalEvent);
139 QTouchEvent *touchEventWithPoints(const QTouchEvent &event, const QList<QTouchEvent::TouchPoint> &newPoints);
140 bool sendFilteredTouchEvent(QQuickItem *target, QQuickItem *item, QTouchEvent *event);
141 bool sendHoverEvent(QEvent::Type, QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos,
142 Qt::KeyboardModifiers modifiers, bool accepted);
144 #ifndef QT_NO_DRAGANDDROP
145 void deliverDragEvent(QQuickDragGrabber *, QEvent *);
146 bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
149 QList<QQuickItem*> hoverItems;
151 DontChangeFocusProperty = 0x01,
152 DontChangeSubFocusItem = 0x02
154 Q_DECLARE_FLAGS(FocusOptions, FocusOption)
156 void setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
157 void clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
158 static void notifyFocusChangesRecur(QQuickItem **item, int remaining);
160 void updateFocusItemTransform();
162 void dirtyItem(QQuickItem *);
163 void cleanup(QSGNode *);
166 void syncSceneGraph();
167 void renderSceneGraph(const QSize &size);
169 bool renderWithoutShowing;
170 void setRenderWithoutShowing(bool enabled);
172 QQuickItem::UpdatePaintNodeData updatePaintNodeData;
174 QQuickItem *dirtyItemList;
175 QList<QSGNode *> cleanupNodeList;
177 QSet<QQuickItem *> itemsToPolish;
179 void updateDirtyNodes();
181 void cleanupNodesOnShutdown();
182 bool updateEffectiveOpacity(QQuickItem *);
183 void updateEffectiveOpacityRoot(QQuickItem *, qreal);
184 void updateDirtyNode(QQuickItem *);
186 void fireFrameSwapped() { emit q_func()->frameSwapped(); }
189 QSGRenderer *renderer;
191 QQuickWindowManager *windowManager;
195 uint clearBeforeRendering : 1;
197 // Currently unused in the default implementation, as we're not stopping
198 // rendering when obscured as we should...
199 uint persistentGLContext : 1;
200 uint persistentSceneGraph : 1;
202 QOpenGLFramebufferObject *renderTarget;
204 QSize renderTargetSize;
206 // Keeps track of which touch point (int) was last accepted by which item
207 QHash<int, QQuickItem *> itemForTouchPointId;
209 mutable QQuickCanvasIncubationController *incubationController;
211 static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event);
214 static void cleanupNodesOnShutdown(QQuickItem *);
218 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickCanvasPrivate::FocusOptions)
222 #endif // QQUICKCANVAS_P_H