1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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)
84 class QQuickItemLayer;
87 class QQuickAnchorLine;
88 class QQuickTransition;
91 class QQuickItemPrivate;
95 class QSGTransformNode;
96 class QSGTextureProvider;
98 class Q_QUICK_EXPORT QQuickItem : public QObject, public QQmlParserStatus
101 Q_INTERFACES(QQmlParserStatus)
103 Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
104 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false)
105 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> resources READ resources DESIGNABLE false)
106 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
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) // deprecated - see QTBUG-26423
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(bool antialiasing READ antialiasing WRITE setAntialiasing NOTIFY antialiasingChanged)
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,
159 ItemAcceptsInputMethod = 0x02,
161 ItemIsFocusScope = 0x04,
162 ItemHasContents = 0x08,
163 ItemAcceptsDrops = 0x10
164 // Remember to increment the size of QQuickItemPrivate::flags
166 Q_DECLARE_FLAGS(Flags, Flag)
169 ItemChildAddedChange, // value.item
170 ItemChildRemovedChange, // value.item
171 ItemSceneChange, // value.window
172 ItemVisibleHasChanged, // value.boolValue
173 ItemParentHasChanged, // value.item
174 ItemOpacityHasChanged, // value.realValue
175 ItemActiveFocusHasChanged, // value.boolValue
176 ItemRotationHasChanged // value.realValue
179 union ItemChangeData {
180 ItemChangeData(QQuickItem *v) : item(v) {}
181 ItemChangeData(QQuickWindow *v) : window(v) {}
182 ItemChangeData(qreal v) : realValue(v) {}
183 ItemChangeData(bool v) : boolValue(v) {}
186 QQuickWindow *window;
191 enum TransformOrigin {
192 TopLeft, Top, TopRight,
194 BottomLeft, Bottom, BottomRight
197 QQuickItem(QQuickItem *parent = 0);
198 virtual ~QQuickItem();
200 QQuickWindow *window() 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 QQmlListProperty<QQuickTransform> transform();
222 QPointF position() const;
225 void setPosition(const QPointF &);
228 void setWidth(qreal);
230 void setImplicitWidth(qreal);
231 qreal implicitWidth() const;
233 qreal height() const;
234 void setHeight(qreal);
236 void setImplicitHeight(qreal);
237 qreal implicitHeight() const;
239 void setSize(const QSizeF &size);
241 TransformOrigin transformOrigin() const;
242 void setTransformOrigin(TransformOrigin);
243 QPointF transformOriginPoint() const;
244 void setTransformOriginPoint(const QPointF &);
249 qreal rotation() const;
250 void setRotation(qreal);
252 void setScale(qreal);
254 qreal opacity() const;
255 void setOpacity(qreal);
257 bool isVisible() const;
258 void setVisible(bool);
260 bool isEnabled() const;
261 void setEnabled(bool);
264 void setSmooth(bool);
266 bool antialiasing() const;
267 void setAntialiasing(bool);
270 void setFlag(Flag flag, bool enabled = true);
271 void setFlags(Flags flags);
273 virtual QRectF boundingRect() const;
274 virtual QRectF clipRect() const;
276 bool hasActiveFocus() const;
277 bool hasFocus() const;
279 bool isFocusScope() const;
280 QQuickItem *scopedFocusItem() const;
282 Qt::MouseButtons acceptedMouseButtons() const;
283 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
284 bool acceptHoverEvents() const;
285 void setAcceptHoverEvents(bool enabled);
288 QCursor cursor() const;
289 void setCursor(const QCursor &cursor);
293 bool isUnderMouse() const;
296 bool keepMouseGrab() const;
297 void setKeepMouseGrab(bool);
298 bool filtersChildMouseEvents() const;
299 void setFiltersChildMouseEvents(bool filter);
301 void grabTouchPoints(const QVector<int> &ids);
302 void ungrabTouchPoints();
303 bool keepTouchGrab() const;
304 void setKeepTouchGrab(bool);
306 Q_INVOKABLE virtual bool contains(const QPointF &point) const;
308 QTransform itemTransform(QQuickItem *, bool *) const;
309 QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
310 QPointF mapToScene(const QPointF &point) const;
311 QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
312 QRectF mapRectToScene(const QRectF &rect) const;
313 QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
314 QPointF mapFromScene(const QPointF &point) const;
315 QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
316 QRectF mapRectFromScene(const QRectF &rect) const;
320 Q_INVOKABLE void mapFromItem(QQmlV8Function*) const;
321 Q_INVOKABLE void mapToItem(QQmlV8Function*) const;
322 Q_INVOKABLE void forceActiveFocus();
323 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
326 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
329 struct UpdatePaintNodeData {
330 QSGTransformNode *transformNode;
332 friend class QQuickWindowPrivate;
333 UpdatePaintNodeData();
336 virtual bool isTextureProvider() const;
337 virtual QSGTextureProvider *textureProvider() const;
343 void childrenRectChanged(const QRectF &);
344 void baselineOffsetChanged(qreal);
345 void stateChanged(const QString &);
346 void focusChanged(bool);
347 void activeFocusChanged(bool);
348 void parentChanged(QQuickItem *);
349 void transformOriginChanged(TransformOrigin);
350 void smoothChanged(bool);
351 void antialiasingChanged(bool);
352 void clipChanged(bool);
355 void childrenChanged();
356 void opacityChanged();
357 void enabledChanged();
358 void visibleChanged();
359 void visibleChildrenChanged();
360 void rotationChanged();
366 void heightChanged();
368 void implicitWidthChanged();
369 void implicitHeightChanged();
372 virtual bool event(QEvent *);
374 bool isComponentComplete() const;
375 virtual void itemChange(ItemChange, const ItemChangeData &);
378 void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
381 bool widthValid() const; // ### better name?
382 bool heightValid() const; // ### better name?
383 void setImplicitSize(qreal, qreal);
385 virtual void classBegin();
386 virtual void componentComplete();
388 virtual void keyPressEvent(QKeyEvent *event);
389 virtual void keyReleaseEvent(QKeyEvent *event);
391 virtual void inputMethodEvent(QInputMethodEvent *);
393 virtual void focusInEvent(QFocusEvent *);
394 virtual void focusOutEvent(QFocusEvent *);
395 virtual void mousePressEvent(QMouseEvent *event);
396 virtual void mouseMoveEvent(QMouseEvent *event);
397 virtual void mouseReleaseEvent(QMouseEvent *event);
398 virtual void mouseDoubleClickEvent(QMouseEvent *event);
399 virtual void mouseUngrabEvent(); // XXX todo - params?
400 virtual void touchUngrabEvent();
401 virtual void wheelEvent(QWheelEvent *event);
402 virtual void touchEvent(QTouchEvent *event);
403 virtual void hoverEnterEvent(QHoverEvent *event);
404 virtual void hoverMoveEvent(QHoverEvent *event);
405 virtual void hoverLeaveEvent(QHoverEvent *event);
406 #ifndef QT_NO_DRAGANDDROP
407 virtual void dragEnterEvent(QDragEnterEvent *);
408 virtual void dragMoveEvent(QDragMoveEvent *);
409 virtual void dragLeaveEvent(QDragLeaveEvent *);
410 virtual void dropEvent(QDropEvent *);
412 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
413 virtual void windowDeactivateEvent();
415 virtual void geometryChanged(const QRectF &newGeometry,
416 const QRectF &oldGeometry);
418 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
419 virtual void releaseResources();
420 virtual void updatePolish();
423 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
426 friend class QQuickWindow;
427 friend class QQuickWindowPrivate;
428 friend class QSGRenderer;
429 friend class QAccessibleQuickItem;
430 friend class QQuickAccessibleAttached;
431 Q_DISABLE_COPY(QQuickItem)
432 Q_DECLARE_PRIVATE(QQuickItem)
436 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
438 #ifndef QT_NO_DEBUG_STREAM
439 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
444 QML_DECLARE_TYPE(QQuickItem)
445 QML_DECLARE_TYPE(QQuickTransform)
449 #endif // QQUICKITEM_H