Say hello to QtQuick module
[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
150 public:
151     enum Flag {
152         ItemClipsChildrenToShape  = 0x01,
153         ItemAcceptsInputMethod    = 0x02,
154         ItemIsFocusScope          = 0x04,
155         ItemHasContents           = 0x08,
156         ItemAcceptsDrops          = 0x10
157         // Remember to increment the size of QQuickItemPrivate::flags
158     };
159     Q_DECLARE_FLAGS(Flags, Flag)
160
161     enum ItemChange {
162         ItemChildAddedChange,      // value.item
163         ItemChildRemovedChange,    // value.item
164         ItemSceneChange,           // value.canvas
165         ItemVisibleHasChanged,     // value.realValue
166         ItemParentHasChanged,      // value.item
167         ItemOpacityHasChanged,     // value.realValue
168         ItemActiveFocusHasChanged, // value.boolValue
169         ItemRotationHasChanged     // value.realValue
170     };
171
172     union ItemChangeData {
173         ItemChangeData(QQuickItem *v) : item(v) {}
174         ItemChangeData(QQuickCanvas *v) : canvas(v) {}
175         ItemChangeData(qreal v) : realValue(v) {}
176         ItemChangeData(bool v) : boolValue(v) {}
177
178         QQuickItem *item;
179         QQuickCanvas *canvas;
180         qreal realValue;
181         bool boolValue;
182     };
183
184     enum TransformOrigin {
185         TopLeft, Top, TopRight,
186         Left, Center, Right,
187         BottomLeft, Bottom, BottomRight
188     };
189
190     QQuickItem(QQuickItem *parent = 0);
191     virtual ~QQuickItem();
192
193     QSGEngine *sceneGraphEngine() const;
194
195     QQuickCanvas *canvas() const;
196     QQuickItem *parentItem() const;
197     void setParentItem(QQuickItem *parent);
198     void stackBefore(const QQuickItem *);
199     void stackAfter(const QQuickItem *);
200
201     QRectF childrenRect();
202     QList<QQuickItem *> childItems() const;
203
204     bool clip() const;
205     void setClip(bool);
206
207     QString state() const;
208     void setState(const QString &);
209
210     qreal baselineOffset() const;
211     void setBaselineOffset(qreal);
212
213     QDeclarativeListProperty<QQuickTransform> transform();
214
215     qreal x() const;
216     qreal y() const;
217     QPointF pos() const;
218     void setX(qreal);
219     void setY(qreal);
220     void setPos(const QPointF &);
221
222     qreal width() const;
223     void setWidth(qreal);
224     void resetWidth();
225     qreal implicitWidth() const;
226
227     qreal height() const;
228     void setHeight(qreal);
229     void resetHeight();
230     qreal implicitHeight() const;
231
232     void setSize(const QSizeF &size);
233
234     TransformOrigin transformOrigin() const;
235     void setTransformOrigin(TransformOrigin);
236     QPointF transformOriginPoint() const;
237     void setTransformOriginPoint(const QPointF &);
238
239     qreal z() const;
240     void setZ(qreal);
241
242     qreal rotation() const;
243     void setRotation(qreal);
244     qreal scale() const;
245     void setScale(qreal);
246
247     qreal opacity() const;
248     void setOpacity(qreal);
249
250     bool isVisible() const;
251     void setVisible(bool);
252
253     bool isEnabled() const;
254     void setEnabled(bool);
255
256     bool smooth() const;
257     void setSmooth(bool);
258
259     Flags flags() const;
260     void setFlag(Flag flag, bool enabled = true);
261     void setFlags(Flags flags);
262
263     virtual QRectF boundingRect() const;
264
265     bool hasActiveFocus() const;
266     bool hasFocus() const;
267     void setFocus(bool);
268     bool isFocusScope() const;
269     QQuickItem *scopedFocusItem() const;
270
271     Qt::MouseButtons acceptedMouseButtons() const;
272     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
273     bool acceptHoverEvents() const;
274     void setAcceptHoverEvents(bool enabled);
275
276     bool isUnderMouse() const;
277     void grabMouse();
278     void ungrabMouse();
279     bool keepMouseGrab() const;
280     void setKeepMouseGrab(bool);
281     bool filtersChildMouseEvents() const;
282     void setFiltersChildMouseEvents(bool filter);
283
284     void grabTouchPoints(const QList<int> &ids);
285     void ungrabTouchPoints();
286     bool keepTouchGrab() const;
287     void setKeepTouchGrab(bool);
288
289     QTransform itemTransform(QQuickItem *, bool *) const;
290     QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
291     QPointF mapToScene(const QPointF &point) const;
292     QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
293     QRectF mapRectToScene(const QRectF &rect) const;
294     QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
295     QPointF mapFromScene(const QPointF &point) const;
296     QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
297     QRectF mapRectFromScene(const QRectF &rect) const;
298
299     void polish();
300
301     Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
302     Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
303     Q_INVOKABLE void forceActiveFocus();
304     Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
305
306     Qt::InputMethodHints inputMethodHints() const;
307     void setInputMethodHints(Qt::InputMethodHints hints);
308     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
309
310     struct UpdatePaintNodeData {
311        QSGTransformNode *transformNode;
312     private:
313        friend class QQuickCanvasPrivate;
314        UpdatePaintNodeData();
315     };
316
317     virtual bool isTextureProvider() const { return false; }
318     virtual QSGTextureProvider *textureProvider() const { return 0; }
319
320 public Q_SLOTS:
321     void update();
322     void updateMicroFocus();
323
324 Q_SIGNALS:
325     void childrenRectChanged(const QRectF &);
326     void baselineOffsetChanged(qreal);
327     void stateChanged(const QString &);
328     void focusChanged(bool);
329     void activeFocusChanged(bool);
330     void parentChanged(QQuickItem *);
331     void transformOriginChanged(TransformOrigin);
332     void smoothChanged(bool);
333     void clipChanged(bool);
334
335     // XXX todo
336     void childrenChanged();
337     void opacityChanged();
338     void enabledChanged();
339     void visibleChanged();
340     void rotationChanged();
341     void scaleChanged();
342
343     void xChanged();
344     void yChanged();
345     void widthChanged();
346     void heightChanged();
347     void zChanged();
348     void implicitWidthChanged();
349     void implicitHeightChanged();
350
351 protected:
352     virtual bool event(QEvent *);
353
354     bool isComponentComplete() const;
355     virtual void itemChange(ItemChange, const ItemChangeData &);
356
357     void setImplicitWidth(qreal);
358     bool widthValid() const; // ### better name?
359     void setImplicitHeight(qreal);
360     bool heightValid() const; // ### better name?
361     void setImplicitSize(qreal, qreal);
362
363     virtual void classBegin();
364     virtual void componentComplete();
365
366     virtual void keyPressEvent(QKeyEvent *event);
367     virtual void keyReleaseEvent(QKeyEvent *event);
368     virtual void inputMethodEvent(QInputMethodEvent *);
369     virtual void focusInEvent(QFocusEvent *);
370     virtual void focusOutEvent(QFocusEvent *);
371     virtual void mousePressEvent(QMouseEvent *event);
372     virtual void mouseMoveEvent(QMouseEvent *event);
373     virtual void mouseReleaseEvent(QMouseEvent *event);
374     virtual void mouseDoubleClickEvent(QMouseEvent *event);
375     virtual void mouseUngrabEvent(); // XXX todo - params?
376     virtual void touchUngrabEvent();
377     virtual void wheelEvent(QWheelEvent *event);
378     virtual void touchEvent(QTouchEvent *event);
379     virtual void hoverEnterEvent(QHoverEvent *event);
380     virtual void hoverMoveEvent(QHoverEvent *event);
381     virtual void hoverLeaveEvent(QHoverEvent *event);
382     virtual void dragEnterEvent(QDragEnterEvent *);
383     virtual void dragMoveEvent(QDragMoveEvent *);
384     virtual void dragLeaveEvent(QDragLeaveEvent *);
385     virtual void dropEvent(QDropEvent *);
386     virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
387     virtual void windowDeactivateEvent();
388
389     virtual void geometryChanged(const QRectF &newGeometry,
390                                  const QRectF &oldGeometry);
391
392     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
393     virtual void updatePolish();
394
395 protected:
396     QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
397
398 private:
399     friend class QQuickCanvas;
400     friend class QQuickCanvasPrivate;
401     friend class QSGRenderer;
402     Q_DISABLE_COPY(QQuickItem)
403     Q_DECLARE_PRIVATE(QQuickItem)
404 };
405
406 // XXX todo
407 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
408
409 #ifndef QT_NO_DEBUG_STREAM
410 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
411 #endif
412
413 QT_END_NAMESPACE
414
415 QML_DECLARE_TYPE(QQuickItem)
416 QML_DECLARE_TYPE(QQuickTransform)
417
418 QT_END_HEADER
419
420 #endif // QQUICKITEM_H