82da4d092d3706db8e42d3ec037da58837cf3f71
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickcanvas_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKCANVAS_P_H
43 #define QQUICKCANVAS_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 "qquickcanvas.h"
58 #include <private/qdeclarativeguard_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 #include <QtGui/qinputpanel.h>
72
73 QT_BEGIN_NAMESPACE
74
75 //Make it easy to identify and customize the root item if needed
76
77 class QQuickWindowManager;
78
79 class QQuickRootItem : public QQuickItem
80 {
81     Q_OBJECT
82 public:
83     QQuickRootItem();
84 public Q_SLOTS:
85     void setWidth(int w) {QQuickItem::setWidth(qreal(w));}
86     void setHeight(int h) {QQuickItem::setHeight(qreal(h));}
87 };
88
89 class QQuickItemPrivate;
90 class QQuickCanvasPrivate;
91
92 class QTouchEvent;
93 class QQuickCanvasRenderLoop;
94 class QQuickCanvasIncubationController;
95
96 class QQuickCanvasPrivate : public QWindowPrivate
97 {
98 public:
99     Q_DECLARE_PUBLIC(QQuickCanvas)
100
101     static inline QQuickCanvasPrivate *get(QQuickCanvas *c) { return c->d_func(); }
102
103     QQuickCanvasPrivate();
104     virtual ~QQuickCanvasPrivate();
105
106     void init(QQuickCanvas *);
107     void initRootItem();//Currently only used if items added in QML
108
109     QQuickRootItem *rootItem;
110     QSet<QQuickItem *> parentlessItems;
111     QDeclarativeListProperty<QObject> data();
112
113     QQuickItem *activeFocusItem;
114     QQuickItem *mouseGrabberItem;
115     QQuickDragGrabber dragGrabber;
116
117     // Mouse positions are saved in widget coordinates
118     QPointF lastMousePosition;
119     void translateTouchEvent(QTouchEvent *touchEvent);
120     static void transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform);
121     bool deliverInitialMousePressEvent(QQuickItem *, QMouseEvent *);
122     bool deliverMouseEvent(QMouseEvent *);
123     bool sendFilteredMouseEvent(QQuickItem *, QQuickItem *, QEvent *);
124     bool deliverWheelEvent(QQuickItem *, QWheelEvent *);
125     bool deliverTouchPoints(QQuickItem *, QTouchEvent *, const QList<QTouchEvent::TouchPoint> &, QSet<int> *,
126             QHash<QQuickItem *, QList<QTouchEvent::TouchPoint> > *);
127     bool deliverTouchEvent(QTouchEvent *);
128     bool deliverHoverEvent(QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, bool &accepted);
129     bool sendHoverEvent(QEvent::Type, QQuickItem *, const QPointF &scenePos, const QPointF &lastScenePos,
130                         Qt::KeyboardModifiers modifiers, bool accepted);
131     bool clearHover();
132     void deliverDragEvent(QQuickDragGrabber *, QEvent *);
133     bool deliverDragEvent(QQuickDragGrabber *, QQuickItem *, QDragMoveEvent *);
134
135     QList<QQuickItem*> hoverItems;
136     enum FocusOption {
137         DontChangeFocusProperty = 0x01,
138     };
139     Q_DECLARE_FLAGS(FocusOptions, FocusOption)
140
141     void setFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
142     void clearFocusInScope(QQuickItem *scope, QQuickItem *item, FocusOptions = 0);
143     void notifyFocusChangesRecur(QQuickItem **item, int remaining);
144
145     void updateInputMethodData();
146     void updateFocusItemTransform();
147
148     void dirtyItem(QQuickItem *);
149     void cleanup(QSGNode *);
150
151     void polishItems();
152     void syncSceneGraph();
153     void renderSceneGraph(const QSize &size);
154
155     QQuickItem::UpdatePaintNodeData updatePaintNodeData;
156
157     QQuickItem *dirtyItemList;
158     QList<QSGNode *> cleanupNodeList;
159
160     QSet<QQuickItem *> itemsToPolish;
161
162     void updateDirtyNodes();
163     void cleanupNodes();
164     void cleanupNodesOnShutdown();
165     bool updateEffectiveOpacity(QQuickItem *);
166     void updateEffectiveOpacityRoot(QQuickItem *, qreal);
167     void updateDirtyNode(QQuickItem *);
168
169     void fireFrameSwapped() { emit q_func()->frameSwapped(); }
170
171     QSGEngine *engine;
172     QSGContext *context;
173     QSGRenderer *renderer;
174
175     QQuickWindowManager *windowManager;
176
177     QColor clearColor;
178
179     uint clearBeforeRendering : 1;
180
181     QOpenGLFramebufferObject *renderTarget;
182
183     QHash<int, QQuickItem *> itemForTouchPointId;
184
185     mutable QQuickCanvasIncubationController *incubationController;
186
187 private:
188     static void cleanupNodesOnShutdown(QQuickItem *);
189 };
190
191
192 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickCanvasPrivate::FocusOptions)
193
194 QT_END_NAMESPACE
195
196 #endif // QQUICKCANVAS_P_H