530e547f3eb426efed7e2f96fa5bb5107f08a36f
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickwindow_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
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_CURSOR
117     QQuickItem *cursorItem;
118 #endif
119 #ifndef QT_NO_DRAGANDDROP
120     QQuickDragGrabber dragGrabber;
121 #endif
122     int touchMouseId;
123     ulong touchMousePressTimestamp;
124
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);
146     bool clearHover();
147 #ifndef QT_NO_DRAGANDDROP
148     void deliverDragEvent(QQuickDragGrabber *, QEvent *);
149     bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
150 #endif
151 #ifndef QT_NO_CURSOR
152     void updateCursor(const QPointF &scenePos);
153     QQuickItem *findCursorItem(QQuickItem *item, const QPointF &scenePos);
154 #endif
155
156     QList<QQuickItem*> hoverItems;
157     enum FocusOption {
158         DontChangeFocusProperty = 0x01,
159         DontChangeSubFocusItem  = 0x02
160     };
161     Q_DECLARE_FLAGS(FocusOptions, FocusOption)
162
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);
166
167     void updateFocusItemTransform();
168
169     void dirtyItem(QQuickItem *);
170     void cleanup(QSGNode *);
171
172     void polishItems();
173     void syncSceneGraph();
174     void renderSceneGraph(const QSize &size);
175
176     bool isRenderable() const;
177
178     bool renderWithoutShowing;
179     void setRenderWithoutShowing(bool enabled);
180
181     QQuickItem::UpdatePaintNodeData updatePaintNodeData;
182
183     QQuickItem *dirtyItemList;
184     QList<QSGNode *> cleanupNodeList;
185
186     QSet<QQuickItem *> itemsToPolish;
187
188     void updateDirtyNodes();
189     void cleanupNodes();
190     void cleanupNodesOnShutdown();
191     bool updateEffectiveOpacity(QQuickItem *);
192     void updateEffectiveOpacityRoot(QQuickItem *, qreal);
193     void updateDirtyNode(QQuickItem *);
194
195     void fireFrameSwapped() { emit q_func()->frameSwapped(); }
196
197     QSGContext *context;
198     QSGRenderer *renderer;
199
200     QQuickWindowManager *windowManager;
201
202     QColor clearColor;
203
204     uint clearBeforeRendering : 1;
205
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;
210
211     uint lastWheelEventAccepted : 1;
212
213     QOpenGLFramebufferObject *renderTarget;
214     uint renderTargetId;
215     QSize renderTargetSize;
216
217     // Keeps track of which touch point (int) was last accepted by which item
218     QHash<int, QQuickItem *> itemForTouchPointId;
219
220     mutable QQuickWindowIncubationController *incubationController;
221
222     static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event);
223
224 private:
225     static void cleanupNodesOnShutdown(QQuickItem *);
226 };
227
228
229 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickWindowPrivate::FocusOptions)
230
231 QT_END_NAMESPACE
232
233 #endif // QQUICKWINDOW_P_H