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
61public:
62 explicit QQuickTransform(QObject *parent = nullptr);
63 ~QQuickTransform() override;
64
65 void appendToItem(QQuickItem *);
66 void prependToItem(QQuickItem *);
67
68 virtual void applyTo(QMatrix4x4 *matrix) const = 0;
69
70protected Q_SLOTS:
71 void update();
72
73protected:
74 QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
75
76private:
77 Q_DECLARE_PRIVATE(QQuickTransform)
78};
79
80class QCursor;
81class QQuickItemLayer;
82class QQmlV4Function;
83class QQuickState;
84class QQuickAnchorLine;
85class QQuickTransition;
86class QQuickKeyEvent;
87class QQuickAnchors;
88class QQuickItemPrivate;
89class QQuickWindow;
90class QTouchEvent;
91class QSGNode;
92class QSGTransformNode;
93class QSGTextureProvider;
94class QQuickItemGrabResult;
95
96class Q_QUICK_EXPORT QQuickItem : public QObject, public QQmlParserStatus
97{
98 Q_OBJECT
99 Q_INTERFACES(QQmlParserStatus)
100
101 Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
102 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false)
103 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> resources READ resources DESIGNABLE false)
104 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
105
106 Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
107 Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
108 Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
109 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
110 Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
111
112 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
113 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
114 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
115 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> visibleChildren READ visibleChildren NOTIFY visibleChildrenChanged DESIGNABLE false)
116
117 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickState> states READ states DESIGNABLE false)
118 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickTransition> transitions READ transitions DESIGNABLE false)
119 Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
120 Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
121 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
122 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
123 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
124 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
125 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
126 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
127 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
128 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
129 Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
130
131 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
132
133 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
134 Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
135 Q_PROPERTY(bool activeFocusOnTab READ activeFocusOnTab WRITE setActiveFocusOnTab NOTIFY activeFocusOnTabChanged FINAL REVISION 1)
136
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) // deprecated - see QTBUG-26423
141 Q_PROPERTY(QQmlListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
142
143 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
144 Q_PROPERTY(bool antialiasing READ antialiasing WRITE setAntialiasing NOTIFY antialiasingChanged RESET resetAntialiasing)
145 Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
146 Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
147 Q_PROPERTY(QObject *containmentMask READ containmentMask WRITE setContainmentMask NOTIFY containmentMaskChanged REVISION 11)
148
149 Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickItemLayer *layer READ layer DESIGNABLE false CONSTANT FINAL)
150
151 Q_CLASSINFO("DefaultProperty", "data")
152 Q_CLASSINFO("qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QV4::ExecutionEngine*)")
153
154public:
155 enum Flag {
156 ItemClipsChildrenToShape = 0x01,
157#if QT_CONFIG(im)
158 ItemAcceptsInputMethod = 0x02,
159#endif
160 ItemIsFocusScope = 0x04,
161 ItemHasContents = 0x08,
162 ItemAcceptsDrops = 0x10
163 // Remember to increment the size of QQuickItemPrivate::flags
164 };
165 Q_DECLARE_FLAGS(Flags, Flag)
166 Q_FLAG(Flags)
167
168 enum ItemChange {
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
177 ItemAntialiasingHasChanged, // value.boolValue
178 ItemDevicePixelRatioHasChanged, // value.realValue
179 ItemEnabledHasChanged // value.boolValue
180 };
181
182 union ItemChangeData {
183 ItemChangeData(QQuickItem *v) : item(v) {}
184 ItemChangeData(QQuickWindow *v) : window(v) {}
185 ItemChangeData(qreal v) : realValue(v) {}
186 ItemChangeData(bool v) : boolValue(v) {}
187
188 QQuickItem *item;
189 QQuickWindow *window;
190 qreal realValue;
191 bool boolValue;
192 };
193
194 enum TransformOrigin {
195 TopLeft, Top, TopRight,
196 Left, Center, Right,
197 BottomLeft, Bottom, BottomRight
198 };
199 Q_ENUM(TransformOrigin)
200
201 explicit QQuickItem(QQuickItem *parent = nullptr);
202 ~QQuickItem() override;
203
204 QQuickWindow *window() const;
205 QQuickItem *parentItem() const;
206 void setParentItem(QQuickItem *parent);
207 void stackBefore(const QQuickItem *);
208 void stackAfter(const QQuickItem *);
209
210 QRectF childrenRect();
211 QList<QQuickItem *> childItems() const;
212
213 bool clip() const;
214 void setClip(bool);
215
216 QString state() const;
217 void setState(const QString &);
218
219 qreal baselineOffset() const;
220 void setBaselineOffset(qreal);
221
222 QQmlListProperty<QQuickTransform> transform();
223
224 qreal x() const;
225 qreal y() const;
226 QPointF position() const;
227 void setX(qreal);
228 void setY(qreal);
229 void setPosition(const QPointF &);
230
231 qreal width() const;
232 void setWidth(qreal);
233 void resetWidth();
234 void setImplicitWidth(qreal);
235 qreal implicitWidth() const;
236
237 qreal height() const;
238 void setHeight(qreal);
239 void resetHeight();
240 void setImplicitHeight(qreal);
241 qreal implicitHeight() const;
242
243 QSizeF size() const;
244 void setSize(const QSizeF &size);
245
246 TransformOrigin transformOrigin() const;
247 void setTransformOrigin(TransformOrigin);
248 QPointF transformOriginPoint() const;
249 void setTransformOriginPoint(const QPointF &);
250
251 qreal z() const;
252 void setZ(qreal);
253
254 qreal rotation() const;
255 void setRotation(qreal);
256 qreal scale() const;
257 void setScale(qreal);
258
259 qreal opacity() const;
260 void setOpacity(qreal);
261
262 bool isVisible() const;
263 void setVisible(bool);
264
265 bool isEnabled() const;
266 void setEnabled(bool);
267
268 bool smooth() const;
269 void setSmooth(bool);
270
271 bool activeFocusOnTab() const;
272 void setActiveFocusOnTab(bool);
273
274 bool antialiasing() const;
275 void setAntialiasing(bool);
276 void resetAntialiasing();
277
278 Flags flags() const;
279 void setFlag(Flag flag, bool enabled = true);
280 void setFlags(Flags flags);
281
282 virtual QRectF boundingRect() const;
283 virtual QRectF clipRect() const;
284
285 bool hasActiveFocus() const;
286 bool hasFocus() const;
287 void setFocus(bool);
288 void setFocus(bool focus, Qt::FocusReason reason);
289 bool isFocusScope() const;
290 QQuickItem *scopedFocusItem() const;
291
292 bool isAncestorOf(const QQuickItem *child) const;
293
294 Qt::MouseButtons acceptedMouseButtons() const;
295 void setAcceptedMouseButtons(Qt::MouseButtons buttons);
296 bool acceptHoverEvents() const;
297 void setAcceptHoverEvents(bool enabled);
298 bool acceptTouchEvents() const;
299 void setAcceptTouchEvents(bool accept);
300
301#if QT_CONFIG(cursor)
302 QCursor cursor() const;
303 void setCursor(const QCursor &cursor);
304 void unsetCursor();
305#endif
306
307 bool isUnderMouse() const;
308 void grabMouse();
309 void ungrabMouse();
310 bool keepMouseGrab() const;
311 void setKeepMouseGrab(bool);
312 bool filtersChildMouseEvents() const;
313 void setFiltersChildMouseEvents(bool filter);
314
315 void grabTouchPoints(const QVector<int> &ids);
316 void ungrabTouchPoints();
317 bool keepTouchGrab() const;
318 void setKeepTouchGrab(bool);
319
320 // implemented in qquickitemgrabresult.cpp
321 Q_REVISION(2) Q_INVOKABLE bool grabToImage(const QJSValue &callback, const QSize &targetSize = QSize());
322 QSharedPointer<QQuickItemGrabResult> grabToImage(const QSize &targetSize = QSize());
323
324 Q_INVOKABLE virtual bool contains(const QPointF &point) const;
325 QObject *containmentMask() const;
326 void setContainmentMask(QObject *mask);
327
328 QTransform itemTransform(QQuickItem *, bool *) const;
329 QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
330 QPointF mapToScene(const QPointF &point) const;
331 QPointF mapToGlobal(const QPointF &point) const;
332 QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
333 QRectF mapRectToScene(const QRectF &rect) const;
334 QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
335 QPointF mapFromScene(const QPointF &point) const;
336 QPointF mapFromGlobal(const QPointF &point) const;
337 QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
338 QRectF mapRectFromScene(const QRectF &rect) const;
339
340 void polish();
341
342 Q_INVOKABLE void mapFromItem(QQmlV4Function*) const;
343 Q_INVOKABLE void mapToItem(QQmlV4Function*) const;
344 Q_REVISION(7) Q_INVOKABLE void mapFromGlobal(QQmlV4Function*) const;
345 Q_REVISION(7) Q_INVOKABLE void mapToGlobal(QQmlV4Function*) const;
346 Q_INVOKABLE void forceActiveFocus();
347 Q_INVOKABLE void forceActiveFocus(Qt::FocusReason reason);
348 Q_REVISION(1) Q_INVOKABLE QQuickItem *nextItemInFocusChain(bool forward = true);
349 Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
350
351#if QT_CONFIG(im)
352 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
353#endif
354
355 struct UpdatePaintNodeData {
356 QSGTransformNode *transformNode;
357 private:
358 friend class QQuickWindowPrivate;
359 UpdatePaintNodeData();
360 };
361
362 virtual bool isTextureProvider() const;
363 virtual QSGTextureProvider *textureProvider() const;
364
365public Q_SLOTS:
366 void update();
367
368Q_SIGNALS:
369 void childrenRectChanged(const QRectF &);
370 void baselineOffsetChanged(qreal);
371 void stateChanged(const QString &);
372 void focusChanged(bool);
373 void activeFocusChanged(bool);
374 Q_REVISION(1) void activeFocusOnTabChanged(bool);
375 void parentChanged(QQuickItem *);
376 void transformOriginChanged(TransformOrigin);
377 void smoothChanged(bool);
378 void antialiasingChanged(bool);
379 void clipChanged(bool);
380 Q_REVISION(1) void windowChanged(QQuickWindow* window);
381
382 void childrenChanged();
383 void opacityChanged();
384 void enabledChanged();
385 void visibleChanged();
386 void visibleChildrenChanged();
387 void rotationChanged();
388 void scaleChanged();
389
390 void xChanged();
391 void yChanged();
392 void widthChanged();
393 void heightChanged();
394 void zChanged();
395 void implicitWidthChanged();
396 void implicitHeightChanged();
397 Q_REVISION(11) void containmentMaskChanged();
398
399protected:
400 bool event(QEvent *) override;
401
402 bool isComponentComplete() const;
403 virtual void itemChange(ItemChange, const ItemChangeData &);
404
405#if QT_CONFIG(im)
406 void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
407#endif
408
409 bool widthValid() const; // ### better name?
410 bool heightValid() const; // ### better name?
411 void setImplicitSize(qreal, qreal);
412
413 void classBegin() override;
414 void componentComplete() override;
415
416 virtual void keyPressEvent(QKeyEvent *event);
417 virtual void keyReleaseEvent(QKeyEvent *event);
418#if QT_CONFIG(im)
419 virtual void inputMethodEvent(QInputMethodEvent *);
420#endif
421 virtual void focusInEvent(QFocusEvent *);
422 virtual void focusOutEvent(QFocusEvent *);
423 virtual void mousePressEvent(QMouseEvent *event);
424 virtual void mouseMoveEvent(QMouseEvent *event);
425 virtual void mouseReleaseEvent(QMouseEvent *event);
426 virtual void mouseDoubleClickEvent(QMouseEvent *event);
427 virtual void mouseUngrabEvent(); // XXX todo - params?
428 virtual void touchUngrabEvent();
429#if QT_CONFIG(wheelevent)
430 virtual void wheelEvent(QWheelEvent *event);
431#endif
432 virtual void touchEvent(QTouchEvent *event);
433 virtual void hoverEnterEvent(QHoverEvent *event);
434 virtual void hoverMoveEvent(QHoverEvent *event);
435 virtual void hoverLeaveEvent(QHoverEvent *event);
436#if QT_CONFIG(draganddrop)
437 virtual void dragEnterEvent(QDragEnterEvent *);
438 virtual void dragMoveEvent(QDragMoveEvent *);
439 virtual void dragLeaveEvent(QDragLeaveEvent *);
440 virtual void dropEvent(QDropEvent *);
441#endif
442 virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
443 virtual void windowDeactivateEvent();
444
445 virtual void geometryChanged(const QRectF &newGeometry,
446 const QRectF &oldGeometry);
447
448 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
449 virtual void releaseResources();
450 virtual void updatePolish();
451
452protected:
453 QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = nullptr);
454
455private:
456 Q_PRIVATE_SLOT(d_func(), void _q_resourceObjectDeleted(QObject *))
457 Q_PRIVATE_SLOT(d_func(), quint64 _q_createJSWrapper(QV4::ExecutionEngine *))
458
459 friend class QQuickEventPoint;
460 friend class QQuickWindow;
461 friend class QQuickWindowPrivate;
462 friend class QSGRenderer;
463 friend class QAccessibleQuickItem;
464 friend class QQuickAccessibleAttached;
465 Q_DISABLE_COPY(QQuickItem)
466 Q_DECLARE_PRIVATE(QQuickItem)
467};
468
469Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
470
471#ifndef QT_NO_DEBUG_STREAM
472QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
473#endif
474
475QT_END_NAMESPACE
476
477QML_DECLARE_TYPE(QQuickItem)
478QML_DECLARE_TYPE(QQuickTransform)
479
480#endif // QQUICKITEM_H
481