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