Renamed QQuickItem::pos property to position
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitem.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 QCursor;
84 class QQuickItemLayer;
85 class QQmlV8Function;
86 class QQuickState;
87 class QQuickAnchorLine;
88 class QQuickTransition;
89 class QQuickKeyEvent;
90 class QQuickAnchors;
91 class QQuickItemPrivate;
92 class QQuickWindow;
93 class QTouchEvent;
94 class QSGNode;
95 class QSGTransformNode;
96 class QSGTextureProvider;
97
98 class Q_QUICK_EXPORT QQuickItem : public QObject, public QQmlParserStatus
99 {
100     Q_OBJECT
101     Q_INTERFACES(QQmlParserStatus)
102
103     Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
104     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false)
105     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> resources READ resources DESIGNABLE false)
106     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
107
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)  // deprecated - see QTBUG-26423
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 #ifndef QT_NO_IM
159         ItemAcceptsInputMethod    = 0x02,
160 #endif
161         ItemIsFocusScope          = 0x04,
162         ItemHasContents           = 0x08,
163         ItemAcceptsDrops          = 0x10
164         // Remember to increment the size of QQuickItemPrivate::flags
165     };
166     Q_DECLARE_FLAGS(Flags, Flag)
167
168     enum ItemChange {
169         ItemChildAddedChange,      // value.item
170         ItemChildRemovedChange,    // value.item
171         ItemSceneChange,           // value.window
172         ItemVisibleHasChanged,     // value.boolValue
173         ItemParentHasChanged,      // value.item
174         ItemOpacityHasChanged,     // value.realValue
175         ItemActiveFocusHasChanged, // value.boolValue
176         ItemRotationHasChanged     // value.realValue
177     };
178
179     union ItemChangeData {
180         ItemChangeData(QQuickItem *v) : item(v) {}
181         ItemChangeData(QQuickWindow *v) : window(v) {}
182         ItemChangeData(qreal v) : realValue(v) {}
183         ItemChangeData(bool v) : boolValue(v) {}
184
185         QQuickItem *item;
186         QQuickWindow *window;
187         qreal realValue;
188         bool boolValue;
189     };
190
191     enum TransformOrigin {
192         TopLeft, Top, TopRight,
193         Left, Center, Right,
194         BottomLeft, Bottom, BottomRight
195     };
196
197     QQuickItem(QQuickItem *parent = 0);
198     virtual ~QQuickItem();
199
200     QQuickWindow *window() 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     QQmlListProperty<QQuickTransform> transform();
219
220     qreal x() const;
221     qreal y() const;
222     QPointF position() const;
223     void setX(qreal);
224     void setY(qreal);
225     void setPosition(const QPointF &);
226
227     qreal width() const;
228     void setWidth(qreal);
229     void resetWidth();
230     void setImplicitWidth(qreal);
231     qreal implicitWidth() const;
232
233     qreal height() const;
234     void setHeight(qreal);
235     void resetHeight();
236     void setImplicitHeight(qreal);
237     qreal implicitHeight() const;
238
239     void setSize(const QSizeF &size);
240
241     TransformOrigin transformOrigin() const;
242     void setTransformOrigin(TransformOrigin);
243     QPointF transformOriginPoint() const;
244     void setTransformOriginPoint(const QPointF &);
245
246     qreal z() const;
247     void setZ(qreal);
248
249     qreal rotation() const;
250     void setRotation(qreal);
251     qreal scale() const;
252     void setScale(qreal);
253
254     qreal opacity() const;
255     void setOpacity(qreal);
256
257     bool isVisible() const;
258     void setVisible(bool);
259
260     bool isEnabled() const;
261     void setEnabled(bool);
262
263     bool smooth() const;
264     void setSmooth(bool);
265
266     bool antialiasing() const;
267     void setAntialiasing(bool);
268
269     Flags flags() const;
270     void setFlag(Flag flag, bool enabled = true);
271     void setFlags(Flags flags);
272
273     virtual QRectF boundingRect() const;
274     virtual QRectF clipRect() const;
275
276     bool hasActiveFocus() const;
277     bool hasFocus() const;
278     void setFocus(bool);
279     bool isFocusScope() const;
280     QQuickItem *scopedFocusItem() const;
281
282     Qt::MouseButtons acceptedMouseButtons() const;
283     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
284     bool acceptHoverEvents() const;
285     void setAcceptHoverEvents(bool enabled);
286
287 #ifndef QT_NO_CURSOR
288     QCursor cursor() const;
289     void setCursor(const QCursor &cursor);
290     void unsetCursor();
291 #endif
292
293     bool isUnderMouse() const;
294     void grabMouse();
295     void ungrabMouse();
296     bool keepMouseGrab() const;
297     void setKeepMouseGrab(bool);
298     bool filtersChildMouseEvents() const;
299     void setFiltersChildMouseEvents(bool filter);
300
301     void grabTouchPoints(const QVector<int> &ids);
302     void ungrabTouchPoints();
303     bool keepTouchGrab() const;
304     void setKeepTouchGrab(bool);
305
306     Q_INVOKABLE virtual bool contains(const QPointF &point) const;
307
308     QTransform itemTransform(QQuickItem *, bool *) const;
309     QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
310     QPointF mapToScene(const QPointF &point) const;
311     QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
312     QRectF mapRectToScene(const QRectF &rect) const;
313     QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
314     QPointF mapFromScene(const QPointF &point) const;
315     QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
316     QRectF mapRectFromScene(const QRectF &rect) const;
317
318     void polish();
319
320     Q_INVOKABLE void mapFromItem(QQmlV8Function*) const;
321     Q_INVOKABLE void mapToItem(QQmlV8Function*) const;
322     Q_INVOKABLE void forceActiveFocus();
323     Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
324
325 #ifndef QT_NO_IM
326     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
327 #endif
328
329     struct UpdatePaintNodeData {
330        QSGTransformNode *transformNode;
331     private:
332        friend class QQuickWindowPrivate;
333        UpdatePaintNodeData();
334     };
335
336     virtual bool isTextureProvider() const;
337     virtual QSGTextureProvider *textureProvider() const;
338
339 public Q_SLOTS:
340     void update();
341
342 Q_SIGNALS:
343     void childrenRectChanged(const QRectF &);
344     void baselineOffsetChanged(qreal);
345     void stateChanged(const QString &);
346     void focusChanged(bool);
347     void activeFocusChanged(bool);
348     void parentChanged(QQuickItem *);
349     void transformOriginChanged(TransformOrigin);
350     void smoothChanged(bool);
351     void antialiasingChanged(bool);
352     void clipChanged(bool);
353
354     // XXX todo
355     void childrenChanged();
356     void opacityChanged();
357     void enabledChanged();
358     void visibleChanged();
359     void visibleChildrenChanged();
360     void rotationChanged();
361     void scaleChanged();
362
363     void xChanged();
364     void yChanged();
365     void widthChanged();
366     void heightChanged();
367     void zChanged();
368     void implicitWidthChanged();
369     void implicitHeightChanged();
370
371 protected:
372     virtual bool event(QEvent *);
373
374     bool isComponentComplete() const;
375     virtual void itemChange(ItemChange, const ItemChangeData &);
376
377 #ifndef QT_NO_IM
378     void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
379 #endif
380
381     bool widthValid() const; // ### better name?
382     bool heightValid() const; // ### better name?
383     void setImplicitSize(qreal, qreal);
384
385     virtual void classBegin();
386     virtual void componentComplete();
387
388     virtual void keyPressEvent(QKeyEvent *event);
389     virtual void keyReleaseEvent(QKeyEvent *event);
390 #ifndef QT_NO_IM
391     virtual void inputMethodEvent(QInputMethodEvent *);
392 #endif
393     virtual void focusInEvent(QFocusEvent *);
394     virtual void focusOutEvent(QFocusEvent *);
395     virtual void mousePressEvent(QMouseEvent *event);
396     virtual void mouseMoveEvent(QMouseEvent *event);
397     virtual void mouseReleaseEvent(QMouseEvent *event);
398     virtual void mouseDoubleClickEvent(QMouseEvent *event);
399     virtual void mouseUngrabEvent(); // XXX todo - params?
400     virtual void touchUngrabEvent();
401     virtual void wheelEvent(QWheelEvent *event);
402     virtual void touchEvent(QTouchEvent *event);
403     virtual void hoverEnterEvent(QHoverEvent *event);
404     virtual void hoverMoveEvent(QHoverEvent *event);
405     virtual void hoverLeaveEvent(QHoverEvent *event);
406 #ifndef QT_NO_DRAGANDDROP
407     virtual void dragEnterEvent(QDragEnterEvent *);
408     virtual void dragMoveEvent(QDragMoveEvent *);
409     virtual void dragLeaveEvent(QDragLeaveEvent *);
410     virtual void dropEvent(QDropEvent *);
411 #endif
412     virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
413     virtual void windowDeactivateEvent();
414
415     virtual void geometryChanged(const QRectF &newGeometry,
416                                  const QRectF &oldGeometry);
417
418     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
419     virtual void releaseResources();
420     virtual void updatePolish();
421
422 protected:
423     QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
424
425 private:
426     friend class QQuickWindow;
427     friend class QQuickWindowPrivate;
428     friend class QSGRenderer;
429     friend class QAccessibleQuickItem;
430     friend class QQuickAccessibleAttached;
431     Q_DISABLE_COPY(QQuickItem)
432     Q_DECLARE_PRIVATE(QQuickItem)
433 };
434
435 // XXX todo
436 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
437
438 #ifndef QT_NO_DEBUG_STREAM
439 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
440 #endif
441
442 QT_END_NAMESPACE
443
444 QML_DECLARE_TYPE(QQuickItem)
445 QML_DECLARE_TYPE(QQuickTransform)
446
447 QT_END_HEADER
448
449 #endif // QQUICKITEM_H