QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickwindow_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 QtQml 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 QQUICKWINDOW_P_H
43 #define QQUICKWINDOW_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include "qquickitem.h"
57 #include "qquickwindow.h"
58 #include <private/qqmlguard_p.h>
59
60 #include <QtQuick/private/qsgcontext_p.h>
61 #include <private/qquickdrag_p.h>
62
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>
71
72 QT_BEGIN_NAMESPACE
73
74 //Make it easy to identify and customize the root item if needed
75
76 class QQuickWindowManager;
77
78 class QQuickRootItem : public QQuickItem
79 {
80     Q_OBJECT
81 public:
82     QQuickRootItem();
83 public Q_SLOTS:
84     void setWidth(int w) {QQuickItem::setWidth(qreal(w));}
85     void setHeight(int h) {QQuickItem::setHeight(qreal(h));}
86 };
87
88 class QQuickItemPrivate;
89 class QQuickWindowPrivate;
90
91 class QTouchEvent;
92 class QQuickWindowRenderLoop;
93 class QQuickWindowIncubationController;
94
95 class Q_QUICK_PRIVATE_EXPORT QQuickWindowPrivate : public QWindowPrivate
96 {
97 public:
98     Q_DECLARE_PUBLIC(QQuickWindow)
99
100     static inline QQuickWindowPrivate *get(QQuickWindow *c) { return c->d_func(); }
101
102     QQuickWindowPrivate();
103     virtual ~QQuickWindowPrivate();
104
105     void init(QQuickWindow *);
106     void initRootItem();//Currently only used if items added in QML
107
108     QQuickRootItem *rootItem;
109     QSet<QQuickItem *> parentlessItems;
110     QQmlListProperty<QObject> data();
111
112     QQuickItem *activeFocusItem;
113
114     // Keeps track of the item currently receiving mouse events
115     QQuickItem *mouseGrabberItem;
116 #ifndef QT_NO_DRAGANDDROP
117     QQuickDragGrabber dragGrabber;
118 #endif
119     int touchMouseId;
120     ulong touchMousePressTimestamp;
121
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);
143     bool clearHover();
144 #ifndef QT_NO_DRAGANDDROP
145     void deliverDragEvent(QQuickDragGrabber *, QEvent *);
146     bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
147 #endif
148
149     QList<QQuickItem*> hoverItems;
150     enum FocusOption {
151         DontChangeFocusProperty = 0x01,
152         DontChangeSubFocusItem  = 0x02
153     };
154     Q_DECLARE_FLAGS(FocusOptions, FocusOption)
155
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);
159
160     void updateFocusItemTransform();
161
162     void dirtyItem(QQuickItem *);
163     void cleanup(QSGNode *);
164
165     void polishItems();
166     void syncSceneGraph();
167     void renderSceneGraph(const QSize &size);
168
169     bool renderWithoutShowing;
170     void setRenderWithoutShowing(bool enabled);
171
172     QQuickItem::UpdatePaintNodeData updatePaintNodeData;
173
174     QQuickItem *dirtyItemList;
175     QList<QSGNode *> cleanupNodeList;
176
177     QSet<QQuickItem *> itemsToPolish;
178
179     void updateDirtyNodes();
180     void cleanupNodes();
181     void cleanupNodesOnShutdown();
182     bool updateEffectiveOpacity(QQuickItem *);
183     void updateEffectiveOpacityRoot(QQuickItem *, qreal);
184     void updateDirtyNode(QQuickItem *);
185
186     void fireFrameSwapped() { emit q_func()->frameSwapped(); }
187
188     QSGContext *context;
189     QSGRenderer *renderer;
190
191     QQuickWindowManager *windowManager;
192
193     QColor clearColor;
194
195     uint clearBeforeRendering : 1;
196
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;
201
202     uint lastWheelEventAccepted : 1;
203
204     QOpenGLFramebufferObject *renderTarget;
205     uint renderTargetId;
206     QSize renderTargetSize;
207
208     // Keeps track of which touch point (int) was last accepted by which item
209     QHash<int, QQuickItem *> itemForTouchPointId;
210
211     mutable QQuickWindowIncubationController *incubationController;
212
213     static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event);
214
215 private:
216     static void cleanupNodesOnShutdown(QQuickItem *);
217 };
218
219
220 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::FocusOptions)
221
222 QT_END_NAMESPACE
223
224 #endif // QQUICKWINDOW_P_H