Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitem.h
1 // Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
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 **
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 #include <QtGui/qaccessible.h>
55
56 QT_BEGIN_HEADER
57
58 QT_BEGIN_NAMESPACE
59
60 class QQuickItem;
61 class QQuickTransformPrivate;
62 class QQuickTransform : public QObject
63 {
64     Q_OBJECT
65 public:
66     QQuickTransform(QObject *parent = 0);
67     ~QQuickTransform();
68
69     void appendToItem(QQuickItem *);
70     void prependToItem(QQuickItem *);
71
72     virtual void applyTo(QMatrix4x4 *matrix) const = 0;
73
74 protected Q_SLOTS:
75     void update();
76
77 protected:
78     QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
79
80 private:
81     Q_DECLARE_PRIVATE(QQuickTransform)
82 };
83
84 class QQuickItemLayer;
85 class QDeclarativeV8Function;
86 class QDeclarativeState;
87 class QQuickAnchorLine;
88 class QDeclarativeTransition;
89 class QQuickKeyEvent;
90 class QQuickAnchors;
91 class QQuickItemPrivate;
92 class QQuickCanvas;
93 class QSGEngine;
94 class QTouchEvent;
95 class QSGNode;
96 class QSGTransformNode;
97 class QSGTextureProvider;
98
99 class Q_QUICK_EXPORT QQuickItem : public QObject, public QDeclarativeParserStatus
100 {
101     Q_OBJECT
102     Q_INTERFACES(QDeclarativeParserStatus)
103
104     Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
105     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
106     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
107     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
108
109     Q_PROPERTY(QPointF pos READ pos FINAL)
110     Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
111     Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
112     Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
113     Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
114     Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
115
116     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
117     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
118     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
119
120     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
121     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
122     Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
123     Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
124     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
125     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
126     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
127     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
128     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
129     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
130     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
131     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
132     Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
133
134     Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
135
136     Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
137     Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
138
139     Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
140     Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
141     Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
142     Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint)  // XXX todo - notify?
143     Q_PROPERTY(QDeclarativeListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
144
145     Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
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.realValue
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     QSGEngine *sceneGraphEngine() const;
199
200     QQuickCanvas *canvas() const;
201     QQuickItem *parentItem() const;
202     void setParentItem(QQuickItem *parent);
203     void stackBefore(const QQuickItem *);
204     void stackAfter(const QQuickItem *);
205
206     QRectF childrenRect();
207     QList<QQuickItem *> childItems() const;
208
209     bool clip() const;
210     void setClip(bool);
211
212     QString state() const;
213     void setState(const QString &);
214
215     qreal baselineOffset() const;
216     void setBaselineOffset(qreal);
217
218     QDeclarativeListProperty<QQuickTransform> transform();
219
220     qreal x() const;
221     qreal y() const;
222     QPointF pos() const;
223     void setX(qreal);
224     void setY(qreal);
225     void setPos(const QPointF &);
226
227     qreal width() const;
228     void setWidth(qreal);
229     void resetWidth();
230     qreal implicitWidth() const;
231
232     qreal height() const;
233     void setHeight(qreal);
234     void resetHeight();
235     qreal implicitHeight() const;
236
237     void setSize(const QSizeF &size);
238
239     TransformOrigin transformOrigin() const;
240     void setTransformOrigin(TransformOrigin);
241     QPointF transformOriginPoint() const;
242     void setTransformOriginPoint(const QPointF &);
243
244     qreal z() const;
245     void setZ(qreal);
246
247     qreal rotation() const;
248     void setRotation(qreal);
249     qreal scale() const;
250     void setScale(qreal);
251
252     qreal opacity() const;
253     void setOpacity(qreal);
254
255     bool isVisible() const;
256     void setVisible(bool);
257
258     bool isEnabled() const;
259     void setEnabled(bool);
260
261     bool smooth() const;
262     void setSmooth(bool);
263
264     Flags flags() const;
265     void setFlag(Flag flag, bool enabled = true);
266     void setFlags(Flags flags);
267
268     virtual QRectF boundingRect() const;
269
270     bool hasActiveFocus() const;
271     bool hasFocus() const;
272     void setFocus(bool);
273     bool isFocusScope() const;
274     QQuickItem *scopedFocusItem() const;
275
276     Qt::MouseButtons acceptedMouseButtons() const;
277     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
278     bool acceptHoverEvents() const;
279     void setAcceptHoverEvents(bool enabled);
280
281     bool isUnderMouse() const;
282     void grabMouse();
283     void ungrabMouse();
284     bool keepMouseGrab() const;
285     void setKeepMouseGrab(bool);
286     bool filtersChildMouseEvents() const;
287     void setFiltersChildMouseEvents(bool filter);
288
289     void grabTouchPoints(const QList<int> &ids);
290     void ungrabTouchPoints();
291     bool keepTouchGrab() const;
292     void setKeepTouchGrab(bool);
293
294     QTransform itemTransform(QQuickItem *, bool *) const;
295     QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
296     QPointF mapToScene(const QPointF &point) const;
297     QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
298     QRectF mapRectToScene(const QRectF &rect) const;
299     QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
300     QPointF mapFromScene(const QPointF &point) const;
301     QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
302     QRectF mapRectFromScene(const QRectF &rect) const;
303
304     void polish();
305
306     Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
307     Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
308     Q_INVOKABLE void forceActiveFocus();
309     Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
310
311     Qt::InputMethodHints inputMethodHints() const;
312     void setInputMethodHints(Qt::InputMethodHints hints);
313     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
314
315     struct UpdatePaintNodeData {
316        QSGTransformNode *transformNode;
317     private:
318        friend class QQuickCanvasPrivate;
319        UpdatePaintNodeData();
320     };
321
322     virtual bool isTextureProvider() const;
323     virtual QSGTextureProvider *textureProvider() const;
324
325 public Q_SLOTS:
326     void update();
327
328 Q_SIGNALS:
329     void childrenRectChanged(const QRectF &);
330     void baselineOffsetChanged(qreal);
331     void stateChanged(const QString &);
332     void focusChanged(bool);
333     void activeFocusChanged(bool);
334     void parentChanged(QQuickItem *);
335     void transformOriginChanged(TransformOrigin);
336     void smoothChanged(bool);
337     void clipChanged(bool);
338
339     // XXX todo
340     void childrenChanged();
341     void opacityChanged();
342     void enabledChanged();
343     void visibleChanged();
344     void rotationChanged();
345     void scaleChanged();
346
347     void xChanged();
348     void yChanged();
349     void widthChanged();
350     void heightChanged();
351     void zChanged();
352     void implicitWidthChanged();
353     void implicitHeightChanged();
354
355 protected:
356     virtual bool event(QEvent *);
357
358     bool isComponentComplete() const;
359     virtual void itemChange(ItemChange, const ItemChangeData &);
360
361     void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
362
363     void setImplicitWidth(qreal);
364     bool widthValid() const; // ### better name?
365     void setImplicitHeight(qreal);
366     bool heightValid() const; // ### better name?
367     void setImplicitSize(qreal, qreal);
368
369     virtual void classBegin();
370     virtual void componentComplete();
371
372     virtual void keyPressEvent(QKeyEvent *event);
373     virtual void keyReleaseEvent(QKeyEvent *event);
374     virtual void inputMethodEvent(QInputMethodEvent *);
375     virtual void focusInEvent(QFocusEvent *);
376     virtual void focusOutEvent(QFocusEvent *);
377     virtual void mousePressEvent(QMouseEvent *event);
378     virtual void mouseMoveEvent(QMouseEvent *event);
379     virtual void mouseReleaseEvent(QMouseEvent *event);
380     virtual void mouseDoubleClickEvent(QMouseEvent *event);
381     virtual void mouseUngrabEvent(); // XXX todo - params?
382     virtual void touchUngrabEvent();
383     virtual void wheelEvent(QWheelEvent *event);
384     virtual void touchEvent(QTouchEvent *event);
385     virtual void hoverEnterEvent(QHoverEvent *event);
386     virtual void hoverMoveEvent(QHoverEvent *event);
387     virtual void hoverLeaveEvent(QHoverEvent *event);
388     virtual void dragEnterEvent(QDragEnterEvent *);
389     virtual void dragMoveEvent(QDragMoveEvent *);
390     virtual void dragLeaveEvent(QDragLeaveEvent *);
391     virtual void dropEvent(QDropEvent *);
392     virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
393     virtual void windowDeactivateEvent();
394
395     virtual void geometryChanged(const QRectF &newGeometry,
396                                  const QRectF &oldGeometry);
397
398     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
399     virtual void updatePolish();
400
401 protected Q_SLOTS:
402     void sendAccessibilityUpdate();
403
404 protected:
405     QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
406
407 private:
408     friend class QQuickCanvas;
409     friend class QQuickCanvasPrivate;
410     friend class QSGRenderer;
411     friend class QAccessibleQuickItem;
412     friend class QQuickAccessibleAttached;
413     Q_DISABLE_COPY(QQuickItem)
414     Q_DECLARE_PRIVATE(QQuickItem)
415 };
416
417 // XXX todo
418 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
419
420 #ifndef QT_NO_DEBUG_STREAM
421 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
422 #endif
423
424 QT_END_NAMESPACE
425
426 QML_DECLARE_TYPE(QQuickItem)
427 QML_DECLARE_TYPE(QQuickTransform)
428
429 QT_END_HEADER
430
431 #endif // QQUICKITEM_H