1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKITEM_H
41#define QQUICKITEM_H
42
43#include <QtQuick/qtquickglobal.h>
44#include <QtQml/qqml.h>
45#include <QtQml/qqmlcomponent.h>
46
47#include <QtCore/QObject>
48#include <QtCore/QList>
49#include <QtGui/qevent.h>
50#include <QtGui/qfont.h>
51#include <QtGui/qaccessible.h>
52
53
54QT_BEGIN_NAMESPACE
55
56class QQuickItem;
57class QQuickTransformPrivate;
58class Q_QUICK_EXPORT QQuickTransform : public QObject
59{
60 Q_OBJECT
61 QML_ANONYMOUS
62public:
63 explicit QQuickTransform(QObject *parent = nullptr);
64 ~QQuickTransform() override;
65
66 void appendToItem(QQuickItem *);
67 void prependToItem(QQuickItem *);
68
69 virtual void applyTo(QMatrix4x4 *matrix) const = 0;
70
71protected Q_SLOTS:
72 void update();
73
74protected:
75 QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
76
77private:
78 Q_DECLARE_PRIVATE(QQuickTransform)
79};
80
81class QCursor;
82class QQuickItemLayer;
83class QQmlV4Function;
84class QQuickState;
85class QQuickAnchorLine;
86class QQuickTransition;
87class QQuickKeyEvent;
88class QQuickAnchors;
89class QQuickItemPrivate;
90class QQuickWindow;
91class QTouchEvent;
92class QSGNode;
93class QSGTransformNode;
94class QSGTextureProvider;
95class QQuickItemGrabResult;
96
97class Q_QUICK_EXPORT QQuickItem : public QObject, public QQmlParserStatus
98{
99 Q_OBJECT
100 Q_INTERFACES(QQmlParserStatus)
101
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)
106
107 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
108 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
109 Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
110 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
111 Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
112
113 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
114 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
115 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
116 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> visibleChildren READ visibleChildren NOTIFY visibleChildrenChanged DESIGNABLE false)
117
118 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickState> states READ states DESIGNABLE false)
119 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickTransition> 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)
131
132 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
133
134 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
135 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
136 Q_PROPERTY(bool activeFocusOnTab READ activeFocusOnTab WRITE setActiveFocusOnTab NOTIFY activeFocusOnTabChanged FINAL REVISION 1)
137
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)
143
144 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
145 Q_PROPERTY(bool antialiasing READ antialiasing WRITE setAntialiasing NOTIFY antialiasingChanged RESET resetAntialiasing)
146 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
147 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
148 Q_PROPERTY(QObject *containmentMask READ containmentMask WRITE setContainmentMask NOTIFY containmentMaskChanged REVISION 11)
149
150 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickItemLayer *layer READ layer DESIGNABLE false CONSTANT FINAL)
151
152 Q_CLASSINFO("DefaultProperty", "data")
153 Q_CLASSINFO("qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QV4::ExecutionEngine*)")
154 QML_NAMED_ELEMENT(Item)
155
156public:
157 enum Flag {
158 ItemClipsChildrenToShape = 0x01,
159#if QT_CONFIG(im)
160 ItemAcceptsInputMethod = 0x02,
161#endif
162 ItemIsFocusScope = 0x04,
163 ItemHasContents = 0x08,
164 ItemAcceptsDrops = 0x10
165 // Remember to increment the size of QQuickItemPrivate::flags
166 };
167 Q_DECLARE_FLAGS(Flags, Flag)
168 Q_FLAG(Flags)
169
170 enum ItemChange {
171 ItemChildAddedChange, // value.item
172 ItemChildRemovedChange, // value.item
173 ItemSceneChange, // value.window
174 ItemVisibleHasChanged, // value.boolValue
175 ItemParentHasChanged, // value.item
176 ItemOpacityHasChanged, // value.realValue
177 ItemActiveFocusHasChanged, // value.boolValue
178 ItemRotationHasChanged, // value.realValue
179 ItemAntialiasingHasChanged, // value.boolValue
180 ItemDevicePixelRatioHasChanged, // value.realValue
181 ItemEnabledHasChanged // value.boolValue
182 };
183
184 union ItemChangeData {
185 ItemChangeData(QQuickItem *v) : item(v) {}
186 ItemChangeData(QQuickWindow *v) : window(v) {}
187 ItemChangeData(qreal v) : realValue(v) {}
188 ItemChangeData(bool v) : boolValue(v) {}
189
190 QQuickItem *item;
191 QQuickWindow *window;
192 qreal realValue;
193 bool boolValue;
194 };
195
196 enum TransformOrigin {
197 TopLeft, Top, TopRight,
198 Left, Center, Right,
199 BottomLeft, Bottom, BottomRight
200 };
201 Q_ENUM(TransformOrigin)
202
203 explicit QQuickItem(QQuickItem *parent = nullptr);
204 ~QQuickItem() override;
205
206 QQuickWindow *window() const;
207 QQuickItem *parentItem() const;
208 void setParentItem(QQuickItem *parent);
209 void stackBefore(const QQuickItem *);
210 void stackAfter(const QQuickItem *);
211
212 QRectF childrenRect();
213 QList<QQuickItem *> childItems() const;
214
215 bool clip() const;
216 void setClip(bool);
217
218 QString state() const;
219 void setState(const QString &);
220
221 qreal baselineOffset() const;
222 void setBaselineOffset(qreal);
223
224 QQmlListProperty<QQuickTransform> transform();
225
226 qreal x() const;
227 qreal y() const;
228 QPointF position() const;
229 void setX(qreal);
230 void setY(qreal);
231 void setPosition(const QPointF &);
232
233 qreal width() const;
234 void setWidth(qreal);
235 void resetWidth();
236 void setImplicitWidth(qreal);
237 qreal implicitWidth() const;
238
239 qreal height() const;
240 void setHeight(qreal);
241 void resetHeight();
242 void setImplicitHeight(qreal);
243 qreal implicitHeight() const;
244
245 QSizeF size() const;
246 void setSize(const QSizeF &size);
247
248 TransformOrigin transformOrigin() const;
249 void setTransformOrigin(TransformOrigin);
250 QPointF transformOriginPoint() const;
251 void setTransformOriginPoint(const QPointF &);
252
253 qreal z() const;
254 void setZ(qreal);
255
256 qreal rotation() const;
257 void setRotation(qreal);
258 qreal scale() const;
259 void setScale(qreal);
260
261 qreal opacity() const;
262 void setOpacity(qreal);
263
264 bool isVisible() const;
265 void setVisible(bool);
266
267 bool isEnabled() const;
268 void setEnabled(bool);
269
270 bool smooth() const;
271 void setSmooth(bool);
272
273 bool activeFocusOnTab() const;
274 void setActiveFocusOnTab(bool);
275
276 bool antialiasing() const;
277 void setAntialiasing(bool);
278 void resetAntialiasing();
279
280 Flags flags() const;
281 void setFlag(Flag flag, bool enabled = true);
282 void setFlags(Flags flags);
283
284 virtual QRectF boundingRect() const;
285 virtual QRectF clipRect() const;
286
287 bool hasActiveFocus() const;
288 bool hasFocus() const;
289 void setFocus(bool);
290 void setFocus(bool focus, Qt::FocusReason reason);
291 bool isFocusScope() const;
292 QQuickItem *scopedFocusItem() const;
293
294 bool isAncestorOf(const QQuickItem *child) const;
295
296 Qt::MouseButtons acceptedMouseButtons() const;
297 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
298 bool acceptHoverEvents() const;
299 void setAcceptHoverEvents(bool enabled);
300 bool acceptTouchEvents() const;
301 void setAcceptTouchEvents(bool accept);
302
303#if QT_CONFIG(cursor)
304 QCursor cursor() const;
305 void setCursor(const QCursor &cursor);
306 void unsetCursor();
307#endif
308
309 bool isUnderMouse() const;
310 void grabMouse();
311 void ungrabMouse();
312 bool keepMouseGrab() const;
313 void setKeepMouseGrab(bool);
314 bool filtersChildMouseEvents() const;
315 void setFiltersChildMouseEvents(bool filter);
316
317 void grabTouchPoints(const QVector<int> &ids);
318 void ungrabTouchPoints();
319 bool keepTouchGrab() const;
320 void setKeepTouchGrab(bool);
321
322 // implemented in qquickitemgrabresult.cpp
323 Q_REVISION(4) Q_INVOKABLE bool grabToImage(const QJSValue &callback, const QSize &targetSize = QSize());
324 QSharedPointer<QQuickItemGrabResult> grabToImage(const QSize &targetSize = QSize());
325
326 Q_INVOKABLE virtual bool contains(const QPointF &point) const;
327 QObject *containmentMask() const;
328 void setContainmentMask(QObject *mask);
329
330 QTransform itemTransform(QQuickItem *, bool *) const;
331 QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
332 QPointF mapToScene(const QPointF &point) const;
333 QPointF mapToGlobal(const QPointF &point) const;
334 QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
335 QRectF mapRectToScene(const QRectF &rect) const;
336 QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
337 QPointF mapFromScene(const QPointF &point) const;
338 QPointF mapFromGlobal(const QPointF &point) const;
339 QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
340 QRectF mapRectFromScene(const QRectF &rect) const;
341
342 void polish();
343
344 Q_INVOKABLE void mapFromItem(QQmlV4Function*) const;
345 Q_INVOKABLE void mapToItem(QQmlV4Function*) const;
346 Q_REVISION(7) Q_INVOKABLE void mapFromGlobal(QQmlV4Function*) const;
347 Q_REVISION(7) Q_INVOKABLE void mapToGlobal(QQmlV4Function*) const;
348 Q_INVOKABLE void forceActiveFocus();
349 Q_INVOKABLE void forceActiveFocus(Qt::FocusReason reason);
350 Q_REVISION(1) Q_INVOKABLE QQuickItem *nextItemInFocusChain(bool forward = true);
351 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
352
353#if QT_CONFIG(im)
354 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
355#endif
356
357 struct UpdatePaintNodeData {
358 QSGTransformNode *transformNode;
359 private:
360 friend class QQuickWindowPrivate;
361 UpdatePaintNodeData();
362 };
363
364 virtual bool isTextureProvider() const;
365 virtual QSGTextureProvider *textureProvider() const;
366
367public Q_SLOTS:
368 void update();
369
370Q_SIGNALS:
371 void childrenRectChanged(const QRectF &);
372 void baselineOffsetChanged(qreal);
373 void stateChanged(const QString &);
374 void focusChanged(bool);
375 void activeFocusChanged(bool);
376 Q_REVISION(1) void activeFocusOnTabChanged(bool);
377 void parentChanged(QQuickItem *);
378 void transformOriginChanged(TransformOrigin);
379 void smoothChanged(bool);
380 void antialiasingChanged(bool);
381 void clipChanged(bool);
382 Q_REVISION(1) void windowChanged(QQuickWindow* window);
383
384 void childrenChanged();
385 void opacityChanged();
386 void enabledChanged();
387 void visibleChanged();
388 void visibleChildrenChanged();
389 void rotationChanged();
390 void scaleChanged();
391
392 void xChanged();
393 void yChanged();
394 void widthChanged();
395 void heightChanged();
396 void zChanged();
397 void implicitWidthChanged();
398 void implicitHeightChanged();
399 Q_REVISION(11) void containmentMaskChanged();
400
401protected:
402 bool event(QEvent *) override;
403
404 bool isComponentComplete() const;
405 virtual void itemChange(ItemChange, const ItemChangeData &);
406
407#if QT_CONFIG(im)
408 void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
409#endif
410
411 bool widthValid() const; // ### better name?
412 bool heightValid() const; // ### better name?
413 void setImplicitSize(qreal, qreal);
414
415 void classBegin() override;
416 void componentComplete() override;
417
418 virtual void keyPressEvent(QKeyEvent *event);
419 virtual void keyReleaseEvent(QKeyEvent *event);
420#if QT_CONFIG(im)
421 virtual void inputMethodEvent(QInputMethodEvent *);
422#endif
423 virtual void focusInEvent(QFocusEvent *);
424 virtual void focusOutEvent(QFocusEvent *);
425 virtual void mousePressEvent(QMouseEvent *event);
426 virtual void mouseMoveEvent(QMouseEvent *event);
427 virtual void mouseReleaseEvent(QMouseEvent *event);
428 virtual void mouseDoubleClickEvent(QMouseEvent *event);
429 virtual void mouseUngrabEvent(); // XXX todo - params?
430 virtual void touchUngrabEvent();
431#if QT_CONFIG(wheelevent)
432 virtual void wheelEvent(QWheelEvent *event);
433#endif
434 virtual void touchEvent(QTouchEvent *event);
435 virtual void hoverEnterEvent(QHoverEvent *event);
436 virtual void hoverMoveEvent(QHoverEvent *event);
437 virtual void hoverLeaveEvent(QHoverEvent *event);
438#if QT_CONFIG(quick_draganddrop)
439 virtual void dragEnterEvent(QDragEnterEvent *);
440 virtual void dragMoveEvent(QDragMoveEvent *);
441 virtual void dragLeaveEvent(QDragLeaveEvent *);
442 virtual void dropEvent(QDropEvent *);
443#endif
444 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
445 virtual void windowDeactivateEvent();
446
447 virtual void geometryChanged(const QRectF &newGeometry,
448 const QRectF &oldGeometry);
449
450 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
451 virtual void releaseResources();
452 virtual void updatePolish();
453
454protected:
455 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = nullptr);
456
457private:
458 Q_PRIVATE_SLOT(d_func(), void _q_resourceObjectDeleted(QObject *))
459 Q_PRIVATE_SLOT(d_func(), quint64 _q_createJSWrapper(QV4::ExecutionEngine *))
460
461 friend class QQuickEventPoint;
462 friend class QQuickWindow;
463 friend class QQuickWindowPrivate;
464 friend class QSGRenderer;
465 friend class QAccessibleQuickItem;
466 friend class QQuickAccessibleAttached;
467 Q_DISABLE_COPY(QQuickItem)
468 Q_DECLARE_PRIVATE(QQuickItem)
469};
470
471Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
472
473#ifndef QT_NO_DEBUG_STREAM
474QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
475#endif
476
477QT_END_NAMESPACE
478
479QML_DECLARE_TYPE(QQuickItem)
480QML_DECLARE_TYPE(QQuickTransform)
481
482#endif // QQUICKITEM_H
483

source code of qtdeclarative/src/quick/items/qquickitem.h