Introduce more generic fast property handling
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitem.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 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKITEM_H
44 #define QQUICKITEM_H
45
46 #include <QtQuick/qtquickglobal.h>
47 #include <QtDeclarative/qdeclarative.h>
48 #include <QtDeclarative/qdeclarativecomponent.h>
49
50 #include <QtCore/QObject>
51 #include <QtCore/QList>
52 #include <QtGui/qevent.h>
53 #include <QtGui/qfont.h>
54
55 QT_BEGIN_HEADER
56
57 QT_BEGIN_NAMESPACE
58
59 class QQuickItem;
60 class QQuickTransformPrivate;
61 class QQuickTransform : public QObject
62 {
63     Q_OBJECT
64 public:
65     QQuickTransform(QObject *parent = 0);
66     ~QQuickTransform();
67
68     void appendToItem(QQuickItem *);
69     void prependToItem(QQuickItem *);
70
71     virtual void applyTo(QMatrix4x4 *matrix) const = 0;
72
73 protected Q_SLOTS:
74     void update();
75
76 protected:
77     QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
78
79 private:
80     Q_DECLARE_PRIVATE(QQuickTransform)
81 };
82
83 class QDeclarativeV8Function;
84 class QDeclarativeState;
85 class QQuickAnchorLine;
86 class QDeclarativeTransition;
87 class QQuickKeyEvent;
88 class QQuickAnchors;
89 class QQuickItemPrivate;
90 class QQuickCanvas;
91 class QSGEngine;
92 class QTouchEvent;
93 class QSGNode;
94 class QSGTransformNode;
95 class QSGTextureProvider;
96
97 class Q_QUICK_EXPORT QQuickItem : public QObject, public QDeclarativeParserStatus
98 {
99     Q_OBJECT
100     Q_INTERFACES(QDeclarativeParserStatus)
101
102     Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
103     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
104     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
105     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
106
107     Q_PROPERTY(QPointF pos READ pos FINAL)
108     Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
109     Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
110     Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
111     Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
112     Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
113
114     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
115     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
116     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
117
118     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
119     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
120     Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
121     Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
122     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
123     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
124     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
125     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
126     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
127     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
128     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
129     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
130     Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
131
132     Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
133
134     Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
135     Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
136
137     Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
138     Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
139     Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
140     Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint)  // XXX todo - notify?
141     Q_PROPERTY(QDeclarativeListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
142
143     Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
144     Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
145     Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
146
147     Q_ENUMS(TransformOrigin)
148     Q_CLASSINFO("DefaultProperty", "data")
149     Q_CLASSINFO("qt_HasQmlAccessors", "true")
150
151 public:
152     enum Flag {
153         ItemClipsChildrenToShape  = 0x01,
154         ItemAcceptsInputMethod    = 0x02,
155         ItemIsFocusScope          = 0x04,
156         ItemHasContents           = 0x08,
157         ItemAcceptsDrops          = 0x10
158         // Remember to increment the size of QQuickItemPrivate::flags
159     };
160     Q_DECLARE_FLAGS(Flags, Flag)
161
162     enum ItemChange {
163         ItemChildAddedChange,      // value.item
164         ItemChildRemovedChange,    // value.item
165         ItemSceneChange,           // value.canvas
166         ItemVisibleHasChanged,     // value.realValue
167         ItemParentHasChanged,      // value.item
168         ItemOpacityHasChanged,     // value.realValue
169         ItemActiveFocusHasChanged, // value.boolValue
170         ItemRotationHasChanged     // value.realValue
171     };
172
173     union ItemChangeData {
174         ItemChangeData(QQuickItem *v) : item(v) {}
175         ItemChangeData(QQuickCanvas *v) : canvas(v) {}
176         ItemChangeData(qreal v) : realValue(v) {}
177         ItemChangeData(bool v) : boolValue(v) {}
178
179         QQuickItem *item;
180         QQuickCanvas *canvas;
181         qreal realValue;
182         bool boolValue;
183     };
184
185     enum TransformOrigin {
186         TopLeft, Top, TopRight,
187         Left, Center, Right,
188         BottomLeft, Bottom, BottomRight
189     };
190
191     QQuickItem(QQuickItem *parent = 0);
192     virtual ~QQuickItem();
193
194     QSGEngine *sceneGraphEngine() const;
195
196     QQuickCanvas *canvas() const;
197     QQuickItem *parentItem() const;
198     void setParentItem(QQuickItem *parent);
199     void stackBefore(const QQuickItem *);
200     void stackAfter(const QQuickItem *);
201
202     QRectF childrenRect();
203     QList<QQuickItem *> childItems() const;
204
205     bool clip() const;
206     void setClip(bool);
207
208     QString state() const;
209     void setState(const QString &);
210
211     qreal baselineOffset() const;
212     void setBaselineOffset(qreal);
213
214     QDeclarativeListProperty<QQuickTransform> transform();
215
216     qreal x() const;
217     qreal y() const;
218     QPointF pos() const;
219     void setX(qreal);
220     void setY(qreal);
221     void setPos(const QPointF &);
222
223     qreal width() const;
224     void setWidth(qreal);
225     void resetWidth();
226     qreal implicitWidth() const;
227
228     qreal height() const;
229     void setHeight(qreal);
230     void resetHeight();
231     qreal implicitHeight() const;
232
233     void setSize(const QSizeF &size);
234
235     TransformOrigin transformOrigin() const;
236     void setTransformOrigin(TransformOrigin);
237     QPointF transformOriginPoint() const;
238     void setTransformOriginPoint(const QPointF &);
239
240     qreal z() const;
241     void setZ(qreal);
242
243     qreal rotation() const;
244     void setRotation(qreal);
245     qreal scale() const;
246     void setScale(qreal);
247
248     qreal opacity() const;
249     void setOpacity(qreal);
250
251     bool isVisible() const;
252     void setVisible(bool);
253
254     bool isEnabled() const;
255     void setEnabled(bool);
256
257     bool smooth() const;
258     void setSmooth(bool);
259
260     Flags flags() const;
261     void setFlag(Flag flag, bool enabled = true);
262     void setFlags(Flags flags);
263
264     virtual QRectF boundingRect() const;
265
266     bool hasActiveFocus() const;
267     bool hasFocus() const;
268     void setFocus(bool);
269     bool isFocusScope() const;
270     QQuickItem *scopedFocusItem() const;
271
272     Qt::MouseButtons acceptedMouseButtons() const;
273     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
274     bool acceptHoverEvents() const;
275     void setAcceptHoverEvents(bool enabled);
276
277     bool isUnderMouse() const;
278     void grabMouse();
279     void ungrabMouse();
280     bool keepMouseGrab() const;
281     void setKeepMouseGrab(bool);
282     bool filtersChildMouseEvents() const;
283     void setFiltersChildMouseEvents(bool filter);
284
285     void grabTouchPoints(const QList<int> &ids);
286     void ungrabTouchPoints();
287     bool keepTouchGrab() const;
288     void setKeepTouchGrab(bool);
289
290     QTransform itemTransform(QQuickItem *, bool *) const;
291     QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
292     QPointF mapToScene(const QPointF &point) const;
293     QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
294     QRectF mapRectToScene(const QRectF &rect) const;
295     QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
296     QPointF mapFromScene(const QPointF &point) const;
297     QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
298     QRectF mapRectFromScene(const QRectF &rect) const;
299
300     void polish();
301
302     Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
303     Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
304     Q_INVOKABLE void forceActiveFocus();
305     Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
306
307     Qt::InputMethodHints inputMethodHints() const;
308     void setInputMethodHints(Qt::InputMethodHints hints);
309     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
310
311     struct UpdatePaintNodeData {
312        QSGTransformNode *transformNode;
313     private:
314        friend class QQuickCanvasPrivate;
315        UpdatePaintNodeData();
316     };
317
318     virtual bool isTextureProvider() const { return false; }
319     virtual QSGTextureProvider *textureProvider() const { return 0; }
320
321 public Q_SLOTS:
322     void update();
323     void updateMicroFocus();
324
325 Q_SIGNALS:
326     void childrenRectChanged(const QRectF &);
327     void baselineOffsetChanged(qreal);
328     void stateChanged(const QString &);
329     void focusChanged(bool);
330     void activeFocusChanged(bool);
331     void parentChanged(QQuickItem *);
332     void transformOriginChanged(TransformOrigin);
333     void smoothChanged(bool);
334     void clipChanged(bool);
335
336     // XXX todo
337     void childrenChanged();
338     void opacityChanged();
339     void enabledChanged();
340     void visibleChanged();
341     void rotationChanged();
342     void scaleChanged();
343
344     void xChanged();
345     void yChanged();
346     void widthChanged();
347     void heightChanged();
348     void zChanged();
349     void implicitWidthChanged();
350     void implicitHeightChanged();
351
352 protected:
353     virtual bool event(QEvent *);
354
355     bool isComponentComplete() const;
356     virtual void itemChange(ItemChange, const ItemChangeData &);
357
358     void setImplicitWidth(qreal);
359     bool widthValid() const; // ### better name?
360     void setImplicitHeight(qreal);
361     bool heightValid() const; // ### better name?
362     void setImplicitSize(qreal, qreal);
363
364     virtual void classBegin();
365     virtual void componentComplete();
366
367     virtual void keyPressEvent(QKeyEvent *event);
368     virtual void keyReleaseEvent(QKeyEvent *event);
369     virtual void inputMethodEvent(QInputMethodEvent *);
370     virtual void focusInEvent(QFocusEvent *);
371     virtual void focusOutEvent(QFocusEvent *);
372     virtual void mousePressEvent(QMouseEvent *event);
373     virtual void mouseMoveEvent(QMouseEvent *event);
374     virtual void mouseReleaseEvent(QMouseEvent *event);
375     virtual void mouseDoubleClickEvent(QMouseEvent *event);
376     virtual void mouseUngrabEvent(); // XXX todo - params?
377     virtual void touchUngrabEvent();
378     virtual void wheelEvent(QWheelEvent *event);
379     virtual void touchEvent(QTouchEvent *event);
380     virtual void hoverEnterEvent(QHoverEvent *event);
381     virtual void hoverMoveEvent(QHoverEvent *event);
382     virtual void hoverLeaveEvent(QHoverEvent *event);
383     virtual void dragEnterEvent(QDragEnterEvent *);
384     virtual void dragMoveEvent(QDragMoveEvent *);
385     virtual void dragLeaveEvent(QDragLeaveEvent *);
386     virtual void dropEvent(QDropEvent *);
387     virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
388     virtual void windowDeactivateEvent();
389
390     virtual void geometryChanged(const QRectF &newGeometry,
391                                  const QRectF &oldGeometry);
392
393     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
394     virtual void updatePolish();
395
396 protected:
397     QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
398
399 private:
400     friend class QQuickCanvas;
401     friend class QQuickCanvasPrivate;
402     friend class QSGRenderer;
403     Q_DISABLE_COPY(QQuickItem)
404     Q_DECLARE_PRIVATE(QQuickItem)
405 };
406
407 // XXX todo
408 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
409
410 #ifndef QT_NO_DEBUG_STREAM
411 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
412 #endif
413
414 QT_END_NAMESPACE
415
416 QML_DECLARE_TYPE(QQuickItem)
417 QML_DECLARE_TYPE(QQuickTransform)
418
419 QT_END_HEADER
420
421 #endif // QQUICKITEM_H