Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgitem.h
1 // Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
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, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGITEM_H
44 #define QSGITEM_H
45
46 #include <QtDeclarative/qdeclarative.h>
47 #include <QtDeclarative/qdeclarativecomponent.h>
48
49 #include <QtCore/QObject>
50 #include <QtCore/QList>
51 #include <QtGui/qgraphicssceneevent.h>
52 #include <QtGui/qfont.h>
53 #include <QtGui/qaction.h>
54
55 QT_BEGIN_HEADER
56
57 QT_BEGIN_NAMESPACE
58
59 QT_MODULE(Declarative)
60
61 class QSGItem;
62 class QSGTransformPrivate;
63 class QSGTransform : public QObject
64 {
65     Q_OBJECT
66 public:
67     QSGTransform(QObject *parent = 0);
68     ~QSGTransform();
69
70     void appendToItem(QSGItem *);
71     void prependToItem(QSGItem *);
72
73     virtual void applyTo(QMatrix4x4 *matrix) const = 0;
74
75 protected Q_SLOTS:
76     void update();
77
78 protected:
79     QSGTransform(QSGTransformPrivate &dd, QObject *parent);
80
81 private:
82     Q_DECLARE_PRIVATE(QSGTransform);
83 };
84
85 class QDeclarativeState;
86 class QSGAnchorLine;
87 class QDeclarativeTransition;
88 class QSGKeyEvent;
89 class QSGAnchors;
90 class QSGItemPrivate;
91 class QSGCanvas;
92 class QSGEngine;
93 class QTouchEvent;
94 class QSGNode;
95 class QSGTransformNode;
96 class Q_DECLARATIVE_EXPORT QSGItem : public QObject, public QDeclarativeParserStatus
97 {
98     Q_OBJECT
99     Q_INTERFACES(QDeclarativeParserStatus)
100
101     Q_PROPERTY(QSGItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
102     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
103     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
104     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QDeclarativeListProperty<QSGItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
105
106     Q_PROPERTY(QPointF pos READ pos FINAL)
107     Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
108     Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
109     Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
110     Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
111     Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
112
113     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
114     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
115     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
116
117     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
118     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
119     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QString state READ state WRITE setState NOTIFY stateChanged)
120     Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
121     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
122     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine left READ left CONSTANT FINAL)
123     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine right READ right CONSTANT FINAL)
124     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
125     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine top READ top CONSTANT FINAL)
126     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine bottom READ bottom CONSTANT FINAL)
127     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
128     Q_PRIVATE_PROPERTY(QSGItem::d_func(), QSGAnchorLine baseline READ baseline CONSTANT FINAL)
129     Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
130
131     Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
132
133     Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
134     Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
135
136     Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
137     Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
138     Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
139     Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint)  // XXX todo - notify?
140     Q_PROPERTY(QDeclarativeListProperty<QSGTransform> transform READ transform DESIGNABLE false FINAL)
141
142     Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
143     Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
144     Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
145
146     Q_ENUMS(TransformOrigin)
147     Q_CLASSINFO("DefaultProperty", "data")
148
149 public:
150     enum Flag {
151         ItemClipsChildrenToShape  = 0x01,
152         ItemAcceptsInputMethod    = 0x02,
153         ItemIsFocusScope          = 0x04,
154         ItemHasContents           = 0x08,
155         // Remember to increment the size of QSGItemPrivate::flags
156     };
157     Q_DECLARE_FLAGS(Flags, Flag)
158
159     enum ItemChange {
160         ItemChildAddedChange,      // value.item
161         ItemChildRemovedChange,    // value.item
162         ItemSceneChange,           // value.canvas
163         ItemVisibleHasChanged,     // value.realValue
164         ItemParentHasChanged,      // value.item
165         ItemOpacityHasChanged,     // value.realValue
166         ItemActiveFocusHasChanged, // value.boolValue
167         ItemRotationHasChanged,    // value.realValue
168     };
169
170     union ItemChangeData {
171         ItemChangeData(QSGItem *v) : item(v) {}
172         ItemChangeData(QSGCanvas *v) : canvas(v) {}
173         ItemChangeData(qreal v) : realValue(v) {}
174         ItemChangeData(bool v) : boolValue(v) {}
175
176         QSGItem *item;
177         QSGCanvas *canvas;
178         qreal realValue;
179         bool boolValue;
180     };
181
182     enum TransformOrigin {
183         TopLeft, Top, TopRight,
184         Left, Center, Right,
185         BottomLeft, Bottom, BottomRight
186     };
187
188     QSGItem(QSGItem *parent = 0);
189     virtual ~QSGItem();
190
191     QSGEngine *sceneGraphEngine() const;
192
193     QSGCanvas *canvas() const;
194     QSGItem *parentItem() const;
195     void setParentItem(QSGItem *parent);
196     void stackBefore(const QSGItem *);
197     void stackAfter(const QSGItem *);
198
199     QRectF childrenRect();
200     QList<QSGItem *> childItems() const;
201
202     bool clip() const;
203     void setClip(bool);
204
205     qreal baselineOffset() const;
206     void setBaselineOffset(qreal);
207
208     QDeclarativeListProperty<QSGTransform> transform();
209
210     qreal x() const;
211     qreal y() const;
212     QPointF pos() const;
213     void setX(qreal);
214     void setY(qreal);
215     void setPos(const QPointF &);
216
217     qreal width() const;
218     void setWidth(qreal);
219     void resetWidth();
220     qreal implicitWidth() const;
221
222     qreal height() const;
223     void setHeight(qreal);
224     void resetHeight();
225     qreal implicitHeight() const;
226
227     void setSize(const QSizeF &size);
228
229     TransformOrigin transformOrigin() const;
230     void setTransformOrigin(TransformOrigin);
231     QPointF transformOriginPoint() const;
232
233     qreal z() const;
234     void setZ(qreal);
235
236     qreal rotation() const;
237     void setRotation(qreal);
238     qreal scale() const;
239     void setScale(qreal);
240
241     qreal opacity() const;
242     void setOpacity(qreal);
243
244     bool isVisible() const;
245     void setVisible(bool);
246
247     bool isEnabled() const;
248     void setEnabled(bool);
249
250     bool smooth() const;
251     void setSmooth(bool);
252
253     Flags flags() const;
254     void setFlag(Flag flag, bool enabled = true);
255     void setFlags(Flags flags);
256
257     QRectF boundingRect() const;
258
259     bool hasActiveFocus() const;
260     bool hasFocus() const;
261     void setFocus(bool);
262     bool isFocusScope() const;
263     QSGItem *scopedFocusItem() const;
264
265     Qt::MouseButtons acceptedMouseButtons() const;
266     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
267     bool acceptHoverEvents() const;
268     void setAcceptHoverEvents(bool enabled);
269
270     bool isUnderMouse() const;
271     void grabMouse();
272     void ungrabMouse();
273     bool keepMouseGrab() const;
274     void setKeepMouseGrab(bool);
275     bool filtersChildMouseEvents() const;
276     void setFiltersChildMouseEvents(bool filter);
277
278     QTransform itemTransform(QSGItem *, bool *) const;
279     QPointF mapToItem(const QSGItem *item, const QPointF &point) const;
280     QPointF mapToScene(const QPointF &point) const;
281     QRectF mapRectToItem(const QSGItem *item, const QRectF &rect) const;
282     QRectF mapRectToScene(const QRectF &rect) const;
283     QPointF mapFromItem(const QSGItem *item, const QPointF &point) const;
284     QPointF mapFromScene(const QPointF &point) const;
285     QRectF mapRectFromItem(const QSGItem *item, const QRectF &rect) const;
286     QRectF mapRectFromScene(const QRectF &rect) const;
287
288     void polish();
289
290     Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
291     Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
292     Q_INVOKABLE void forceActiveFocus();
293     Q_INVOKABLE QSGItem *childAt(qreal x, qreal y) const;
294
295     Qt::InputMethodHints inputMethodHints() const;
296     void setInputMethodHints(Qt::InputMethodHints hints);
297     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
298
299     struct UpdatePaintNodeData {
300        QSGTransformNode *transformNode;
301     private:
302        friend class QSGCanvasPrivate;
303        UpdatePaintNodeData();
304     };
305
306 public Q_SLOTS:
307     void update();
308     void updateMicroFocus();
309
310 Q_SIGNALS:
311     void childrenRectChanged(const QRectF &);
312     void baselineOffsetChanged(qreal);
313     void stateChanged(const QString &);
314     void focusChanged(bool);
315     void activeFocusChanged(bool);
316     void parentChanged(QSGItem *);
317     void transformOriginChanged(TransformOrigin);
318     void smoothChanged(bool);
319     void clipChanged(bool);
320
321     // XXX todo
322     void childrenChanged();
323     void opacityChanged();
324     void enabledChanged();
325     void visibleChanged();
326     void rotationChanged();
327     void scaleChanged();
328
329     void xChanged();
330     void yChanged();
331     void widthChanged();
332     void heightChanged();
333     void zChanged();
334     void implicitWidthChanged();
335     void implicitHeightChanged();
336
337 protected:
338     virtual bool event(QEvent *);
339
340     bool isComponentComplete() const;
341     virtual void itemChange(ItemChange, const ItemChangeData &);
342
343     void setImplicitWidth(qreal);
344     bool widthValid() const; // ### better name?
345     void setImplicitHeight(qreal);
346     bool heightValid() const; // ### better name?
347
348     virtual void classBegin();
349     virtual void componentComplete();
350
351     virtual void keyPressEvent(QKeyEvent *event);
352     virtual void keyReleaseEvent(QKeyEvent *event);
353     virtual void inputMethodEvent(QInputMethodEvent *);
354     virtual void focusInEvent(QFocusEvent *);
355     virtual void focusOutEvent(QFocusEvent *);
356     virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
357     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
358     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
359     virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
360     virtual void mouseUngrabEvent(); // XXX todo - params?
361     virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
362     virtual void touchEvent(QTouchEvent *event);
363     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
364     virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
365     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
366     virtual bool childMouseEventFilter(QSGItem *, QEvent *);
367
368     virtual void geometryChanged(const QRectF &newGeometry,
369                                  const QRectF &oldGeometry);
370
371     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
372     virtual void updatePolish();
373
374 protected:
375     QSGItem(QSGItemPrivate &dd, QSGItem *parent = 0);
376
377 private:
378     friend class QSGCanvas;
379     friend class QSGCanvasPrivate;
380     friend class QSGRenderer;
381     Q_DISABLE_COPY(QSGItem)
382     Q_DECLARE_PRIVATE(QSGItem)
383 };
384
385 // XXX todo
386 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGItem::Flags)
387
388 #ifndef QT_NO_DEBUG_STREAM
389 QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QSGItem *item);
390 #endif
391
392 QT_END_NAMESPACE
393
394 QML_DECLARE_TYPE(QSGItem)
395 QML_DECLARE_TYPE(QSGTransform)
396
397 QT_END_HEADER
398
399 #endif // QSGITEM_H