1 // Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4
2 /****************************************************************************
4 ** Copyright (C) 2011 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>
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 QDeclarativeV8Function;
84 class QDeclarativeState;
85 class QQuickAnchorLine;
86 class QDeclarativeTransition;
89 class QQuickItemPrivate;
94 class QSGTransformNode;
95 class QSGTextureProvider;
97 class Q_QUICK_EXPORT QQuickItem : public QObject, public QDeclarativeParserStatus
100 Q_INTERFACES(QDeclarativeParserStatus)
102 Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
103 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
104 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
105 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<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)
118 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
119 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
120 Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
121 Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
122 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
123 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
124 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
125 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
126 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
127 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
128 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
129 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
130 Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
132 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
134 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
135 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
137 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
138 Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
139 Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
140 Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // XXX todo - notify?
141 Q_PROPERTY(QDeclarativeListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
143 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
144 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
145 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
147 Q_ENUMS(TransformOrigin)
148 Q_CLASSINFO("DefaultProperty", "data")
152 ItemClipsChildrenToShape = 0x01,
153 ItemAcceptsInputMethod = 0x02,
154 ItemIsFocusScope = 0x04,
155 ItemHasContents = 0x08,
156 ItemAcceptsDrops = 0x10
157 // Remember to increment the size of QQuickItemPrivate::flags
159 Q_DECLARE_FLAGS(Flags, Flag)
162 ItemChildAddedChange, // value.item
163 ItemChildRemovedChange, // value.item
164 ItemSceneChange, // value.canvas
165 ItemVisibleHasChanged, // value.realValue
166 ItemParentHasChanged, // value.item
167 ItemOpacityHasChanged, // value.realValue
168 ItemActiveFocusHasChanged, // value.boolValue
169 ItemRotationHasChanged // value.realValue
172 union ItemChangeData {
173 ItemChangeData(QQuickItem *v) : item(v) {}
174 ItemChangeData(QQuickCanvas *v) : canvas(v) {}
175 ItemChangeData(qreal v) : realValue(v) {}
176 ItemChangeData(bool v) : boolValue(v) {}
179 QQuickCanvas *canvas;
184 enum TransformOrigin {
185 TopLeft, Top, TopRight,
187 BottomLeft, Bottom, BottomRight
190 QQuickItem(QQuickItem *parent = 0);
191 virtual ~QQuickItem();
193 QSGEngine *sceneGraphEngine() const;
195 QQuickCanvas *canvas() const;
196 QQuickItem *parentItem() const;
197 void setParentItem(QQuickItem *parent);
198 void stackBefore(const QQuickItem *);
199 void stackAfter(const QQuickItem *);
201 QRectF childrenRect();
202 QList<QQuickItem *> childItems() const;
207 QString state() const;
208 void setState(const QString &);
210 qreal baselineOffset() const;
211 void setBaselineOffset(qreal);
213 QDeclarativeListProperty<QQuickTransform> transform();
220 void setPos(const QPointF &);
223 void setWidth(qreal);
225 qreal implicitWidth() const;
227 qreal height() const;
228 void setHeight(qreal);
230 qreal implicitHeight() const;
232 void setSize(const QSizeF &size);
234 TransformOrigin transformOrigin() const;
235 void setTransformOrigin(TransformOrigin);
236 QPointF transformOriginPoint() const;
237 void setTransformOriginPoint(const QPointF &);
242 qreal rotation() const;
243 void setRotation(qreal);
245 void setScale(qreal);
247 qreal opacity() const;
248 void setOpacity(qreal);
250 bool isVisible() const;
251 void setVisible(bool);
253 bool isEnabled() const;
254 void setEnabled(bool);
257 void setSmooth(bool);
260 void setFlag(Flag flag, bool enabled = true);
261 void setFlags(Flags flags);
263 virtual QRectF boundingRect() const;
265 bool hasActiveFocus() const;
266 bool hasFocus() const;
268 bool isFocusScope() const;
269 QQuickItem *scopedFocusItem() const;
271 Qt::MouseButtons acceptedMouseButtons() const;
272 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
273 bool acceptHoverEvents() const;
274 void setAcceptHoverEvents(bool enabled);
276 bool isUnderMouse() const;
279 bool keepMouseGrab() const;
280 void setKeepMouseGrab(bool);
281 bool filtersChildMouseEvents() const;
282 void setFiltersChildMouseEvents(bool filter);
284 void grabTouchPoints(const QList<int> &ids);
285 void ungrabTouchPoints();
286 bool keepTouchGrab() const;
287 void setKeepTouchGrab(bool);
289 QTransform itemTransform(QQuickItem *, bool *) const;
290 QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
291 QPointF mapToScene(const QPointF &point) const;
292 QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
293 QRectF mapRectToScene(const QRectF &rect) const;
294 QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
295 QPointF mapFromScene(const QPointF &point) const;
296 QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
297 QRectF mapRectFromScene(const QRectF &rect) const;
301 Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
302 Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
303 Q_INVOKABLE void forceActiveFocus();
304 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
306 Qt::InputMethodHints inputMethodHints() const;
307 void setInputMethodHints(Qt::InputMethodHints hints);
308 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
310 struct UpdatePaintNodeData {
311 QSGTransformNode *transformNode;
313 friend class QQuickCanvasPrivate;
314 UpdatePaintNodeData();
317 virtual bool isTextureProvider() const { return false; }
318 virtual QSGTextureProvider *textureProvider() const { return 0; }
322 void updateMicroFocus();
325 void childrenRectChanged(const QRectF &);
326 void baselineOffsetChanged(qreal);
327 void stateChanged(const QString &);
328 void focusChanged(bool);
329 void activeFocusChanged(bool);
330 void parentChanged(QQuickItem *);
331 void transformOriginChanged(TransformOrigin);
332 void smoothChanged(bool);
333 void clipChanged(bool);
336 void childrenChanged();
337 void opacityChanged();
338 void enabledChanged();
339 void visibleChanged();
340 void rotationChanged();
346 void heightChanged();
348 void implicitWidthChanged();
349 void implicitHeightChanged();
352 virtual bool event(QEvent *);
354 bool isComponentComplete() const;
355 virtual void itemChange(ItemChange, const ItemChangeData &);
357 void setImplicitWidth(qreal);
358 bool widthValid() const; // ### better name?
359 void setImplicitHeight(qreal);
360 bool heightValid() const; // ### better name?
361 void setImplicitSize(qreal, qreal);
363 virtual void classBegin();
364 virtual void componentComplete();
366 virtual void keyPressEvent(QKeyEvent *event);
367 virtual void keyReleaseEvent(QKeyEvent *event);
368 virtual void inputMethodEvent(QInputMethodEvent *);
369 virtual void focusInEvent(QFocusEvent *);
370 virtual void focusOutEvent(QFocusEvent *);
371 virtual void mousePressEvent(QMouseEvent *event);
372 virtual void mouseMoveEvent(QMouseEvent *event);
373 virtual void mouseReleaseEvent(QMouseEvent *event);
374 virtual void mouseDoubleClickEvent(QMouseEvent *event);
375 virtual void mouseUngrabEvent(); // XXX todo - params?
376 virtual void touchUngrabEvent();
377 virtual void wheelEvent(QWheelEvent *event);
378 virtual void touchEvent(QTouchEvent *event);
379 virtual void hoverEnterEvent(QHoverEvent *event);
380 virtual void hoverMoveEvent(QHoverEvent *event);
381 virtual void hoverLeaveEvent(QHoverEvent *event);
382 virtual void dragEnterEvent(QDragEnterEvent *);
383 virtual void dragMoveEvent(QDragMoveEvent *);
384 virtual void dragLeaveEvent(QDragLeaveEvent *);
385 virtual void dropEvent(QDropEvent *);
386 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
387 virtual void windowDeactivateEvent();
389 virtual void geometryChanged(const QRectF &newGeometry,
390 const QRectF &oldGeometry);
392 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
393 virtual void updatePolish();
396 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
399 friend class QQuickCanvas;
400 friend class QQuickCanvasPrivate;
401 friend class QSGRenderer;
402 Q_DISABLE_COPY(QQuickItem)
403 Q_DECLARE_PRIVATE(QQuickItem)
407 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
409 #ifndef QT_NO_DEBUG_STREAM
410 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
415 QML_DECLARE_TYPE(QQuickItem)
416 QML_DECLARE_TYPE(QQuickTransform)
420 #endif // QQUICKITEM_H