1 // Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
41 ****************************************************************************/
46 #include <QtQuick/qtquickglobal.h>
47 #include <QtDeclarative/qdeclarative.h>
48 #include <QtDeclarative/qdeclarativecomponent.h>
50 #include <QtCore/QObject>
51 #include <QtCore/QList>
52 #include <QtGui/qevent.h>
53 #include <QtGui/qfont.h>
54 #include <QtGui/qaccessible.h>
61 class QQuickTransformPrivate;
62 class QQuickTransform : public QObject
66 QQuickTransform(QObject *parent = 0);
69 void appendToItem(QQuickItem *);
70 void prependToItem(QQuickItem *);
72 virtual void applyTo(QMatrix4x4 *matrix) const = 0;
78 QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
81 Q_DECLARE_PRIVATE(QQuickTransform)
84 class QQuickItemLayer;
85 class QDeclarativeV8Function;
86 class QDeclarativeState;
87 class QQuickAnchorLine;
88 class QDeclarativeTransition;
91 class QQuickItemPrivate;
96 class QSGTransformNode;
97 class QSGTextureProvider;
99 class Q_QUICK_EXPORT QQuickItem : public QObject, public QDeclarativeParserStatus
102 Q_INTERFACES(QDeclarativeParserStatus)
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)
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)
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 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QQuickItem> visibleChildren READ visibleChildren NOTIFY visibleChildrenChanged DESIGNABLE false)
121 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
122 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
123 Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
124 Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
125 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
126 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
127 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
128 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
129 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
130 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
131 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
132 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
133 Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
135 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
137 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
138 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
140 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
141 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
142 Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
143 Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // XXX todo - notify?
144 Q_PROPERTY(QDeclarativeListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
146 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
147 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
148 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
150 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickItemLayer *layer READ layer DESIGNABLE false CONSTANT FINAL)
152 Q_ENUMS(TransformOrigin)
153 Q_CLASSINFO("DefaultProperty", "data")
154 Q_CLASSINFO("qt_HasQmlAccessors", "true")
158 ItemClipsChildrenToShape = 0x01,
159 ItemAcceptsInputMethod = 0x02,
160 ItemIsFocusScope = 0x04,
161 ItemHasContents = 0x08,
162 ItemAcceptsDrops = 0x10
163 // Remember to increment the size of QQuickItemPrivate::flags
165 Q_DECLARE_FLAGS(Flags, Flag)
168 ItemChildAddedChange, // value.item
169 ItemChildRemovedChange, // value.item
170 ItemSceneChange, // value.canvas
171 ItemVisibleHasChanged, // value.realValue
172 ItemParentHasChanged, // value.item
173 ItemOpacityHasChanged, // value.realValue
174 ItemActiveFocusHasChanged, // value.boolValue
175 ItemRotationHasChanged // value.realValue
178 union ItemChangeData {
179 ItemChangeData(QQuickItem *v) : item(v) {}
180 ItemChangeData(QQuickCanvas *v) : canvas(v) {}
181 ItemChangeData(qreal v) : realValue(v) {}
182 ItemChangeData(bool v) : boolValue(v) {}
185 QQuickCanvas *canvas;
190 enum TransformOrigin {
191 TopLeft, Top, TopRight,
193 BottomLeft, Bottom, BottomRight
196 QQuickItem(QQuickItem *parent = 0);
197 virtual ~QQuickItem();
199 QSGEngine *sceneGraphEngine() const;
201 QQuickCanvas *canvas() const;
202 QQuickItem *parentItem() const;
203 void setParentItem(QQuickItem *parent);
204 void stackBefore(const QQuickItem *);
205 void stackAfter(const QQuickItem *);
207 QRectF childrenRect();
208 QList<QQuickItem *> childItems() const;
213 QString state() const;
214 void setState(const QString &);
216 qreal baselineOffset() const;
217 void setBaselineOffset(qreal);
219 QDeclarativeListProperty<QQuickTransform> transform();
226 void setPos(const QPointF &);
229 void setWidth(qreal);
231 qreal implicitWidth() const;
233 qreal height() const;
234 void setHeight(qreal);
236 qreal implicitHeight() const;
238 void setSize(const QSizeF &size);
240 TransformOrigin transformOrigin() const;
241 void setTransformOrigin(TransformOrigin);
242 QPointF transformOriginPoint() const;
243 void setTransformOriginPoint(const QPointF &);
248 qreal rotation() const;
249 void setRotation(qreal);
251 void setScale(qreal);
253 qreal opacity() const;
254 void setOpacity(qreal);
256 bool isVisible() const;
257 void setVisible(bool);
259 bool isEnabled() const;
260 void setEnabled(bool);
263 void setSmooth(bool);
266 void setFlag(Flag flag, bool enabled = true);
267 void setFlags(Flags flags);
269 virtual QRectF boundingRect() const;
271 bool hasActiveFocus() const;
272 bool hasFocus() const;
274 bool isFocusScope() const;
275 QQuickItem *scopedFocusItem() const;
277 Qt::MouseButtons acceptedMouseButtons() const;
278 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
279 bool acceptHoverEvents() const;
280 void setAcceptHoverEvents(bool enabled);
282 bool isUnderMouse() const;
285 bool keepMouseGrab() const;
286 void setKeepMouseGrab(bool);
287 bool filtersChildMouseEvents() const;
288 void setFiltersChildMouseEvents(bool filter);
290 void grabTouchPoints(const QList<int> &ids);
291 void ungrabTouchPoints();
292 bool keepTouchGrab() const;
293 void setKeepTouchGrab(bool);
295 QTransform itemTransform(QQuickItem *, bool *) const;
296 QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
297 QPointF mapToScene(const QPointF &point) const;
298 QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
299 QRectF mapRectToScene(const QRectF &rect) const;
300 QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
301 QPointF mapFromScene(const QPointF &point) const;
302 QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
303 QRectF mapRectFromScene(const QRectF &rect) const;
307 Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
308 Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
309 Q_INVOKABLE void forceActiveFocus();
310 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
312 Qt::InputMethodHints inputMethodHints() const;
313 void setInputMethodHints(Qt::InputMethodHints hints);
314 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
316 struct UpdatePaintNodeData {
317 QSGTransformNode *transformNode;
319 friend class QQuickCanvasPrivate;
320 UpdatePaintNodeData();
323 virtual bool isTextureProvider() const;
324 virtual QSGTextureProvider *textureProvider() const;
330 void childrenRectChanged(const QRectF &);
331 void baselineOffsetChanged(qreal);
332 void stateChanged(const QString &);
333 void focusChanged(bool);
334 void activeFocusChanged(bool);
335 void parentChanged(QQuickItem *);
336 void transformOriginChanged(TransformOrigin);
337 void smoothChanged(bool);
338 void clipChanged(bool);
341 void childrenChanged();
342 void opacityChanged();
343 void enabledChanged();
344 void visibleChanged();
345 void visibleChildrenChanged();
346 void rotationChanged();
352 void heightChanged();
354 void implicitWidthChanged();
355 void implicitHeightChanged();
358 virtual bool event(QEvent *);
360 bool isComponentComplete() const;
361 virtual void itemChange(ItemChange, const ItemChangeData &);
363 void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
365 void setImplicitWidth(qreal);
366 bool widthValid() const; // ### better name?
367 void setImplicitHeight(qreal);
368 bool heightValid() const; // ### better name?
369 void setImplicitSize(qreal, qreal);
371 virtual void classBegin();
372 virtual void componentComplete();
374 virtual void keyPressEvent(QKeyEvent *event);
375 virtual void keyReleaseEvent(QKeyEvent *event);
376 virtual void inputMethodEvent(QInputMethodEvent *);
377 virtual void focusInEvent(QFocusEvent *);
378 virtual void focusOutEvent(QFocusEvent *);
379 virtual void mousePressEvent(QMouseEvent *event);
380 virtual void mouseMoveEvent(QMouseEvent *event);
381 virtual void mouseReleaseEvent(QMouseEvent *event);
382 virtual void mouseDoubleClickEvent(QMouseEvent *event);
383 virtual void mouseUngrabEvent(); // XXX todo - params?
384 virtual void touchUngrabEvent();
385 virtual void wheelEvent(QWheelEvent *event);
386 virtual void touchEvent(QTouchEvent *event);
387 virtual void hoverEnterEvent(QHoverEvent *event);
388 virtual void hoverMoveEvent(QHoverEvent *event);
389 virtual void hoverLeaveEvent(QHoverEvent *event);
390 virtual void dragEnterEvent(QDragEnterEvent *);
391 virtual void dragMoveEvent(QDragMoveEvent *);
392 virtual void dragLeaveEvent(QDragLeaveEvent *);
393 virtual void dropEvent(QDropEvent *);
394 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
395 virtual void windowDeactivateEvent();
397 virtual void geometryChanged(const QRectF &newGeometry,
398 const QRectF &oldGeometry);
400 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
401 virtual void updatePolish();
404 void sendAccessibilityUpdate();
407 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
410 friend class QQuickCanvas;
411 friend class QQuickCanvasPrivate;
412 friend class QSGRenderer;
413 friend class QAccessibleQuickItem;
414 friend class QQuickAccessibleAttached;
415 Q_DISABLE_COPY(QQuickItem)
416 Q_DECLARE_PRIVATE(QQuickItem)
420 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
422 #ifndef QT_NO_DEBUG_STREAM
423 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
428 QML_DECLARE_TYPE(QQuickItem)
429 QML_DECLARE_TYPE(QQuickTransform)
433 #endif // QQUICKITEM_H