1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
45 #include <QtQuick/qtquickglobal.h>
46 #include <QtQml/qqml.h>
47 #include <QtQml/qqmlcomponent.h>
49 #include <QtCore/QObject>
50 #include <QtCore/QList>
51 #include <QtGui/qevent.h>
52 #include <QtGui/qfont.h>
53 #include <QtGui/qaccessible.h>
60 class QQuickTransformPrivate;
61 class QQuickTransform : public QObject
65 QQuickTransform(QObject *parent = 0);
68 void appendToItem(QQuickItem *);
69 void prependToItem(QQuickItem *);
71 virtual void applyTo(QMatrix4x4 *matrix) const = 0;
77 QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
80 Q_DECLARE_PRIVATE(QQuickTransform)
83 class QQuickItemLayer;
86 class QQuickAnchorLine;
87 class QQuickTransition;
90 class QQuickItemPrivate;
94 class QSGTransformNode;
95 class QSGTextureProvider;
97 class Q_QUICK_EXPORT QQuickItem : public QObject, public QQmlParserStatus
100 Q_INTERFACES(QQmlParserStatus)
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)
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)
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)
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)
133 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
135 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
136 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
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)
144 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
145 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
146 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
148 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickItemLayer *layer READ layer DESIGNABLE false CONSTANT FINAL)
150 Q_ENUMS(TransformOrigin)
151 Q_CLASSINFO("DefaultProperty", "data")
152 Q_CLASSINFO("qt_HasQmlAccessors", "true")
156 ItemClipsChildrenToShape = 0x01,
157 ItemAcceptsInputMethod = 0x02,
158 ItemIsFocusScope = 0x04,
159 ItemHasContents = 0x08,
160 ItemAcceptsDrops = 0x10
161 // Remember to increment the size of QQuickItemPrivate::flags
163 Q_DECLARE_FLAGS(Flags, Flag)
166 ItemChildAddedChange, // value.item
167 ItemChildRemovedChange, // value.item
168 ItemSceneChange, // value.canvas
169 ItemVisibleHasChanged, // value.boolValue
170 ItemParentHasChanged, // value.item
171 ItemOpacityHasChanged, // value.realValue
172 ItemActiveFocusHasChanged, // value.boolValue
173 ItemRotationHasChanged // value.realValue
176 union ItemChangeData {
177 ItemChangeData(QQuickItem *v) : item(v) {}
178 ItemChangeData(QQuickCanvas *v) : canvas(v) {}
179 ItemChangeData(qreal v) : realValue(v) {}
180 ItemChangeData(bool v) : boolValue(v) {}
183 QQuickCanvas *canvas;
188 enum TransformOrigin {
189 TopLeft, Top, TopRight,
191 BottomLeft, Bottom, BottomRight
194 QQuickItem(QQuickItem *parent = 0);
195 virtual ~QQuickItem();
197 QQuickCanvas *canvas() const;
198 QQuickItem *parentItem() const;
199 void setParentItem(QQuickItem *parent);
200 void stackBefore(const QQuickItem *);
201 void stackAfter(const QQuickItem *);
203 QRectF childrenRect();
204 QList<QQuickItem *> childItems() const;
209 QString state() const;
210 void setState(const QString &);
212 qreal baselineOffset() const;
213 void setBaselineOffset(qreal);
215 QQmlListProperty<QQuickTransform> transform();
222 void setPos(const QPointF &);
225 void setWidth(qreal);
227 qreal implicitWidth() const;
229 qreal height() const;
230 void setHeight(qreal);
232 qreal implicitHeight() const;
234 void setSize(const QSizeF &size);
236 TransformOrigin transformOrigin() const;
237 void setTransformOrigin(TransformOrigin);
238 QPointF transformOriginPoint() const;
239 void setTransformOriginPoint(const QPointF &);
244 qreal rotation() const;
245 void setRotation(qreal);
247 void setScale(qreal);
249 qreal opacity() const;
250 void setOpacity(qreal);
252 bool isVisible() const;
253 void setVisible(bool);
255 bool isEnabled() const;
256 void setEnabled(bool);
259 void setSmooth(bool);
262 void setFlag(Flag flag, bool enabled = true);
263 void setFlags(Flags flags);
265 virtual QRectF boundingRect() const;
266 virtual QRectF clipRect() const;
268 bool hasActiveFocus() const;
269 bool hasFocus() const;
271 bool isFocusScope() const;
272 QQuickItem *scopedFocusItem() const;
274 Qt::MouseButtons acceptedMouseButtons() const;
275 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
276 bool acceptHoverEvents() const;
277 void setAcceptHoverEvents(bool enabled);
279 bool isUnderMouse() const;
282 bool keepMouseGrab() const;
283 void setKeepMouseGrab(bool);
284 bool filtersChildMouseEvents() const;
285 void setFiltersChildMouseEvents(bool filter);
287 void grabTouchPoints(const QList<int> &ids);
288 void ungrabTouchPoints();
289 bool keepTouchGrab() const;
290 void setKeepTouchGrab(bool);
292 Q_INVOKABLE virtual bool contains(const QPointF &point) const;
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(QQmlV8Function*) const;
307 Q_INVOKABLE void mapToItem(QQmlV8Function*) const;
308 Q_INVOKABLE void forceActiveFocus();
309 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
311 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
313 struct UpdatePaintNodeData {
314 QSGTransformNode *transformNode;
316 friend class QQuickCanvasPrivate;
317 UpdatePaintNodeData();
320 virtual bool isTextureProvider() const;
321 virtual QSGTextureProvider *textureProvider() const;
327 void childrenRectChanged(const QRectF &);
328 void baselineOffsetChanged(qreal);
329 void stateChanged(const QString &);
330 void focusChanged(bool);
331 void activeFocusChanged(bool);
332 void parentChanged(QQuickItem *);
333 void transformOriginChanged(TransformOrigin);
334 void smoothChanged(bool);
335 void clipChanged(bool);
338 void childrenChanged();
339 void opacityChanged();
340 void enabledChanged();
341 void visibleChanged();
342 void visibleChildrenChanged();
343 void rotationChanged();
349 void heightChanged();
351 void implicitWidthChanged();
352 void implicitHeightChanged();
355 virtual bool event(QEvent *);
357 bool isComponentComplete() const;
358 virtual void itemChange(ItemChange, const ItemChangeData &);
360 void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
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 releaseResources();
399 virtual void updatePolish();
402 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
405 friend class QQuickCanvas;
406 friend class QQuickCanvasPrivate;
407 friend class QSGRenderer;
408 friend class QAccessibleQuickItem;
409 friend class QQuickAccessibleAttached;
410 Q_DISABLE_COPY(QQuickItem)
411 Q_DECLARE_PRIVATE(QQuickItem)
415 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
417 #ifndef QT_NO_DEBUG_STREAM
418 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
423 QML_DECLARE_TYPE(QQuickItem)
424 QML_DECLARE_TYPE(QQuickTransform)
428 #endif // QQUICKITEM_H