1 // Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
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)
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)
134 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
136 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
137 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
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)
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)
149 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickItemLayer *layer READ layer DESIGNABLE false CONSTANT FINAL)
151 Q_ENUMS(TransformOrigin)
152 Q_CLASSINFO("DefaultProperty", "data")
153 Q_CLASSINFO("qt_HasQmlAccessors", "true")
157 ItemClipsChildrenToShape = 0x01,
158 ItemAcceptsInputMethod = 0x02,
159 ItemIsFocusScope = 0x04,
160 ItemHasContents = 0x08,
161 ItemAcceptsDrops = 0x10
162 // Remember to increment the size of QQuickItemPrivate::flags
164 Q_DECLARE_FLAGS(Flags, Flag)
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
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) {}
184 QQuickCanvas *canvas;
189 enum TransformOrigin {
190 TopLeft, Top, TopRight,
192 BottomLeft, Bottom, BottomRight
195 QQuickItem(QQuickItem *parent = 0);
196 virtual ~QQuickItem();
198 QSGEngine *sceneGraphEngine() const;
200 QQuickCanvas *canvas() const;
201 QQuickItem *parentItem() const;
202 void setParentItem(QQuickItem *parent);
203 void stackBefore(const QQuickItem *);
204 void stackAfter(const QQuickItem *);
206 QRectF childrenRect();
207 QList<QQuickItem *> childItems() const;
212 QString state() const;
213 void setState(const QString &);
215 qreal baselineOffset() const;
216 void setBaselineOffset(qreal);
218 QDeclarativeListProperty<QQuickTransform> transform();
225 void setPos(const QPointF &);
228 void setWidth(qreal);
230 qreal implicitWidth() const;
232 qreal height() const;
233 void setHeight(qreal);
235 qreal implicitHeight() const;
237 void setSize(const QSizeF &size);
239 TransformOrigin transformOrigin() const;
240 void setTransformOrigin(TransformOrigin);
241 QPointF transformOriginPoint() const;
242 void setTransformOriginPoint(const QPointF &);
247 qreal rotation() const;
248 void setRotation(qreal);
250 void setScale(qreal);
252 qreal opacity() const;
253 void setOpacity(qreal);
255 bool isVisible() const;
256 void setVisible(bool);
258 bool isEnabled() const;
259 void setEnabled(bool);
262 void setSmooth(bool);
265 void setFlag(Flag flag, bool enabled = true);
266 void setFlags(Flags flags);
268 virtual QRectF boundingRect() const;
270 bool hasActiveFocus() const;
271 bool hasFocus() const;
273 bool isFocusScope() const;
274 QQuickItem *scopedFocusItem() const;
276 Qt::MouseButtons acceptedMouseButtons() const;
277 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
278 bool acceptHoverEvents() const;
279 void setAcceptHoverEvents(bool enabled);
281 bool isUnderMouse() const;
284 bool keepMouseGrab() const;
285 void setKeepMouseGrab(bool);
286 bool filtersChildMouseEvents() const;
287 void setFiltersChildMouseEvents(bool filter);
289 void grabTouchPoints(const QList<int> &ids);
290 void ungrabTouchPoints();
291 bool keepTouchGrab() const;
292 void setKeepTouchGrab(bool);
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;
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;
311 Qt::InputMethodHints inputMethodHints() const;
312 void setInputMethodHints(Qt::InputMethodHints hints);
313 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
315 struct UpdatePaintNodeData {
316 QSGTransformNode *transformNode;
318 friend class QQuickCanvasPrivate;
319 UpdatePaintNodeData();
322 virtual bool isTextureProvider() const;
323 virtual QSGTextureProvider *textureProvider() const;
327 void updateMicroFocus();
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 rotationChanged();
351 void heightChanged();
353 void implicitWidthChanged();
354 void implicitHeightChanged();
357 virtual bool event(QEvent *);
359 bool isComponentComplete() const;
360 virtual void itemChange(ItemChange, const ItemChangeData &);
362 void setImplicitWidth(qreal);
363 bool widthValid() const; // ### better name?
364 void setImplicitHeight(qreal);
365 bool heightValid() const; // ### better name?
366 void setImplicitSize(qreal, qreal);
368 virtual void classBegin();
369 virtual void componentComplete();
371 virtual void keyPressEvent(QKeyEvent *event);
372 virtual void keyReleaseEvent(QKeyEvent *event);
373 virtual void inputMethodEvent(QInputMethodEvent *);
374 virtual void focusInEvent(QFocusEvent *);
375 virtual void focusOutEvent(QFocusEvent *);
376 virtual void mousePressEvent(QMouseEvent *event);
377 virtual void mouseMoveEvent(QMouseEvent *event);
378 virtual void mouseReleaseEvent(QMouseEvent *event);
379 virtual void mouseDoubleClickEvent(QMouseEvent *event);
380 virtual void mouseUngrabEvent(); // XXX todo - params?
381 virtual void touchUngrabEvent();
382 virtual void wheelEvent(QWheelEvent *event);
383 virtual void touchEvent(QTouchEvent *event);
384 virtual void hoverEnterEvent(QHoverEvent *event);
385 virtual void hoverMoveEvent(QHoverEvent *event);
386 virtual void hoverLeaveEvent(QHoverEvent *event);
387 virtual void dragEnterEvent(QDragEnterEvent *);
388 virtual void dragMoveEvent(QDragMoveEvent *);
389 virtual void dragLeaveEvent(QDragLeaveEvent *);
390 virtual void dropEvent(QDropEvent *);
391 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
392 virtual void windowDeactivateEvent();
394 virtual void geometryChanged(const QRectF &newGeometry,
395 const QRectF &oldGeometry);
397 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
398 virtual void updatePolish();
401 void sendAccessibilityUpdate();
404 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
407 friend class QQuickCanvas;
408 friend class QQuickCanvasPrivate;
409 friend class QSGRenderer;
410 friend class QAccessibleQuickItem;
411 friend class QQuickAccessibleAttached;
412 Q_DISABLE_COPY(QQuickItem)
413 Q_DECLARE_PRIVATE(QQuickItem)
417 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
419 #ifndef QT_NO_DEBUG_STREAM
420 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
425 QML_DECLARE_TYPE(QQuickItem)
426 QML_DECLARE_TYPE(QQuickTransform)
430 #endif // QQUICKITEM_H