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")
149 Q_CLASSINFO("qt_HasQmlAccessors", "true")
153 ItemClipsChildrenToShape = 0x01,
154 ItemAcceptsInputMethod = 0x02,
155 ItemIsFocusScope = 0x04,
156 ItemHasContents = 0x08,
157 ItemAcceptsDrops = 0x10
158 // Remember to increment the size of QQuickItemPrivate::flags
160 Q_DECLARE_FLAGS(Flags, Flag)
163 ItemChildAddedChange, // value.item
164 ItemChildRemovedChange, // value.item
165 ItemSceneChange, // value.canvas
166 ItemVisibleHasChanged, // value.realValue
167 ItemParentHasChanged, // value.item
168 ItemOpacityHasChanged, // value.realValue
169 ItemActiveFocusHasChanged, // value.boolValue
170 ItemRotationHasChanged // value.realValue
173 union ItemChangeData {
174 ItemChangeData(QQuickItem *v) : item(v) {}
175 ItemChangeData(QQuickCanvas *v) : canvas(v) {}
176 ItemChangeData(qreal v) : realValue(v) {}
177 ItemChangeData(bool v) : boolValue(v) {}
180 QQuickCanvas *canvas;
185 enum TransformOrigin {
186 TopLeft, Top, TopRight,
188 BottomLeft, Bottom, BottomRight
191 QQuickItem(QQuickItem *parent = 0);
192 virtual ~QQuickItem();
194 QSGEngine *sceneGraphEngine() const;
196 QQuickCanvas *canvas() const;
197 QQuickItem *parentItem() const;
198 void setParentItem(QQuickItem *parent);
199 void stackBefore(const QQuickItem *);
200 void stackAfter(const QQuickItem *);
202 QRectF childrenRect();
203 QList<QQuickItem *> childItems() const;
208 QString state() const;
209 void setState(const QString &);
211 qreal baselineOffset() const;
212 void setBaselineOffset(qreal);
214 QDeclarativeListProperty<QQuickTransform> transform();
221 void setPos(const QPointF &);
224 void setWidth(qreal);
226 qreal implicitWidth() const;
228 qreal height() const;
229 void setHeight(qreal);
231 qreal implicitHeight() const;
233 void setSize(const QSizeF &size);
235 TransformOrigin transformOrigin() const;
236 void setTransformOrigin(TransformOrigin);
237 QPointF transformOriginPoint() const;
238 void setTransformOriginPoint(const QPointF &);
243 qreal rotation() const;
244 void setRotation(qreal);
246 void setScale(qreal);
248 qreal opacity() const;
249 void setOpacity(qreal);
251 bool isVisible() const;
252 void setVisible(bool);
254 bool isEnabled() const;
255 void setEnabled(bool);
258 void setSmooth(bool);
261 void setFlag(Flag flag, bool enabled = true);
262 void setFlags(Flags flags);
264 virtual QRectF boundingRect() const;
266 bool hasActiveFocus() const;
267 bool hasFocus() const;
269 bool isFocusScope() const;
270 QQuickItem *scopedFocusItem() const;
272 Qt::MouseButtons acceptedMouseButtons() const;
273 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
274 bool acceptHoverEvents() const;
275 void setAcceptHoverEvents(bool enabled);
277 bool isUnderMouse() const;
280 bool keepMouseGrab() const;
281 void setKeepMouseGrab(bool);
282 bool filtersChildMouseEvents() const;
283 void setFiltersChildMouseEvents(bool filter);
285 void grabTouchPoints(const QList<int> &ids);
286 void ungrabTouchPoints();
287 bool keepTouchGrab() const;
288 void setKeepTouchGrab(bool);
290 QTransform itemTransform(QQuickItem *, bool *) const;
291 QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
292 QPointF mapToScene(const QPointF &point) const;
293 QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
294 QRectF mapRectToScene(const QRectF &rect) const;
295 QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
296 QPointF mapFromScene(const QPointF &point) const;
297 QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
298 QRectF mapRectFromScene(const QRectF &rect) const;
302 Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
303 Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
304 Q_INVOKABLE void forceActiveFocus();
305 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
307 Qt::InputMethodHints inputMethodHints() const;
308 void setInputMethodHints(Qt::InputMethodHints hints);
309 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
311 struct UpdatePaintNodeData {
312 QSGTransformNode *transformNode;
314 friend class QQuickCanvasPrivate;
315 UpdatePaintNodeData();
318 virtual bool isTextureProvider() const { return false; }
319 virtual QSGTextureProvider *textureProvider() const { return 0; }
323 void updateMicroFocus();
326 void childrenRectChanged(const QRectF &);
327 void baselineOffsetChanged(qreal);
328 void stateChanged(const QString &);
329 void focusChanged(bool);
330 void activeFocusChanged(bool);
331 void parentChanged(QQuickItem *);
332 void transformOriginChanged(TransformOrigin);
333 void smoothChanged(bool);
334 void clipChanged(bool);
337 void childrenChanged();
338 void opacityChanged();
339 void enabledChanged();
340 void visibleChanged();
341 void rotationChanged();
347 void heightChanged();
349 void implicitWidthChanged();
350 void implicitHeightChanged();
353 virtual bool event(QEvent *);
355 bool isComponentComplete() const;
356 virtual void itemChange(ItemChange, const ItemChangeData &);
358 void setImplicitWidth(qreal);
359 bool widthValid() const; // ### better name?
360 void setImplicitHeight(qreal);
361 bool heightValid() const; // ### better name?
362 void setImplicitSize(qreal, qreal);
364 virtual void classBegin();
365 virtual void componentComplete();
367 virtual void keyPressEvent(QKeyEvent *event);
368 virtual void keyReleaseEvent(QKeyEvent *event);
369 virtual void inputMethodEvent(QInputMethodEvent *);
370 virtual void focusInEvent(QFocusEvent *);
371 virtual void focusOutEvent(QFocusEvent *);
372 virtual void mousePressEvent(QMouseEvent *event);
373 virtual void mouseMoveEvent(QMouseEvent *event);
374 virtual void mouseReleaseEvent(QMouseEvent *event);
375 virtual void mouseDoubleClickEvent(QMouseEvent *event);
376 virtual void mouseUngrabEvent(); // XXX todo - params?
377 virtual void touchUngrabEvent();
378 virtual void wheelEvent(QWheelEvent *event);
379 virtual void touchEvent(QTouchEvent *event);
380 virtual void hoverEnterEvent(QHoverEvent *event);
381 virtual void hoverMoveEvent(QHoverEvent *event);
382 virtual void hoverLeaveEvent(QHoverEvent *event);
383 virtual void dragEnterEvent(QDragEnterEvent *);
384 virtual void dragMoveEvent(QDragMoveEvent *);
385 virtual void dragLeaveEvent(QDragLeaveEvent *);
386 virtual void dropEvent(QDropEvent *);
387 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
388 virtual void windowDeactivateEvent();
390 virtual void geometryChanged(const QRectF &newGeometry,
391 const QRectF &oldGeometry);
393 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
394 virtual void updatePolish();
397 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
400 friend class QQuickCanvas;
401 friend class QQuickCanvasPrivate;
402 friend class QSGRenderer;
403 Q_DISABLE_COPY(QQuickItem)
404 Q_DECLARE_PRIVATE(QQuickItem)
408 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
410 #ifndef QT_NO_DEBUG_STREAM
411 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
416 QML_DECLARE_TYPE(QQuickItem)
417 QML_DECLARE_TYPE(QQuickTransform)
421 #endif // QQUICKITEM_H