1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKITEM_P_H
5#define QQUICKITEM_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/private/qquickanchors_p.h>
19#include <QtQuick/private/qquickanchors_p_p.h>
20#include <QtQuick/private/qquickitemchangelistener_p.h>
21#include <QtQuick/private/qquickevents_p_p.h>
22#include <QtQuick/private/qquickclipnode_p.h>
23#include <QtQuick/private/qquickstate_p.h>
24#include <QtQuick/private/qquickpaletteproviderprivatebase_p.h>
25#include <QtQuick/private/qquickwindow_p.h>
26#include <QtCore/private/qproperty_p.h>
27
28#if QT_CONFIG(quick_shadereffect)
29#include <QtQuick/private/qquickshadereffectsource_p.h>
30#endif
31
32#include <QtQuick/qquickitem.h>
33#include <QtQuick/qsgnode.h>
34
35#include <QtQml/private/qqmlnullablevalue_p.h>
36#include <QtQml/private/qqmlnotifier_p.h>
37#include <QtQml/private/qqmlglobal_p.h>
38#include <QtQml/private/qlazilyallocated_p.h>
39#include <QtQml/qqml.h>
40#include <QtQml/qqmlcontext.h>
41
42#include <QtCore/qlist.h>
43#include <QtCore/qdebug.h>
44#include <QtCore/qelapsedtimer.h>
45
46QT_BEGIN_NAMESPACE
47
48class QNetworkReply;
49class QQuickItemKeyFilter;
50class QQuickLayoutMirroringAttached;
51class QQuickEnterKeyAttached;
52class QQuickScreenAttached;
53class QQuickPointerHandler;
54
55class QQuickContents : public QQuickItemChangeListener
56{
57public:
58 QQuickContents(QQuickItem *item);
59 ~QQuickContents() override;
60
61 QRectF rectF() const { return m_contents; }
62
63 inline void calcGeometry(QQuickItem *changed = nullptr);
64 void complete();
65
66protected:
67 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;
68 void itemDestroyed(QQuickItem *item) override;
69 void itemChildAdded(QQuickItem *, QQuickItem *) override;
70 void itemChildRemoved(QQuickItem *, QQuickItem *) override;
71 //void itemVisibilityChanged(QQuickItem *item)
72
73private:
74 bool calcHeight(QQuickItem *changed = nullptr);
75 bool calcWidth(QQuickItem *changed = nullptr);
76 void updateRect();
77
78 QQuickItem *m_item;
79 QRectF m_contents;
80};
81
82void QQuickContents::calcGeometry(QQuickItem *changed)
83{
84 bool wChanged = calcWidth(changed);
85 bool hChanged = calcHeight(changed);
86 if (wChanged || hChanged)
87 updateRect();
88}
89
90class QQuickTransformPrivate : public QObjectPrivate
91{
92 Q_DECLARE_PUBLIC(QQuickTransform)
93public:
94 static QQuickTransformPrivate* get(QQuickTransform *transform) { return transform->d_func(); }
95
96 QQuickTransformPrivate();
97
98 QList<QQuickItem *> items;
99};
100
101#if QT_CONFIG(quick_shadereffect)
102
103class Q_QUICK_PRIVATE_EXPORT QQuickItemLayer : public QObject, public QQuickItemChangeListener
104{
105 Q_OBJECT
106 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
107 Q_PROPERTY(QSize textureSize READ size WRITE setSize NOTIFY sizeChanged FINAL)
108 Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged FINAL)
109 Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged FINAL)
110 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged FINAL)
111 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged REVISION(6, 5) FINAL)
112 Q_PROPERTY(QQuickShaderEffectSource::WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged FINAL)
113 Q_PROPERTY(QQuickShaderEffectSource::Format format READ format WRITE setFormat NOTIFY formatChanged FINAL)
114 Q_PROPERTY(QByteArray samplerName READ name WRITE setName NOTIFY nameChanged FINAL)
115 Q_PROPERTY(QQmlComponent *effect READ effect WRITE setEffect NOTIFY effectChanged FINAL)
116 Q_PROPERTY(QQuickShaderEffectSource::TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged FINAL)
117 Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged FINAL)
118 QML_ANONYMOUS
119 QML_ADDED_IN_VERSION(2, 0)
120
121public:
122 QQuickItemLayer(QQuickItem *item);
123 ~QQuickItemLayer() override;
124
125 void classBegin();
126 void componentComplete();
127
128 bool enabled() const { return m_enabled; }
129 void setEnabled(bool enabled);
130
131 bool mipmap() const { return m_mipmap; }
132 void setMipmap(bool mipmap);
133
134 bool smooth() const { return m_smooth; }
135 void setSmooth(bool s);
136
137 bool live() const { return m_live; }
138 void setLive(bool live);
139
140 QSize size() const { return m_size; }
141 void setSize(const QSize &size);
142
143 QQuickShaderEffectSource::Format format() const { return m_format; }
144 void setFormat(QQuickShaderEffectSource::Format f);
145
146 QRectF sourceRect() const { return m_sourceRect; }
147 void setSourceRect(const QRectF &sourceRect);
148
149 QQuickShaderEffectSource::WrapMode wrapMode() const { return m_wrapMode; }
150 void setWrapMode(QQuickShaderEffectSource::WrapMode mode);
151
152 QByteArray name() const { return m_name; }
153 void setName(const QByteArray &name);
154
155 QQmlComponent *effect() const { return m_effectComponent; }
156 void setEffect(QQmlComponent *effect);
157
158 QQuickShaderEffectSource::TextureMirroring textureMirroring() const { return m_textureMirroring; }
159 void setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring);
160
161 int samples() const { return m_samples; }
162 void setSamples(int count);
163
164 QQuickShaderEffectSource *effectSource() const { return m_effectSource; }
165
166 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override;
167 void itemOpacityChanged(QQuickItem *) override;
168 void itemParentChanged(QQuickItem *, QQuickItem *) override;
169 void itemSiblingOrderChanged(QQuickItem *) override;
170 void itemVisibilityChanged(QQuickItem *) override;
171
172 void updateMatrix();
173 void updateGeometry();
174 void updateOpacity();
175 void updateZ();
176
177Q_SIGNALS:
178 void enabledChanged(bool enabled);
179 void sizeChanged(const QSize &size);
180 void mipmapChanged(bool mipmap);
181 void wrapModeChanged(QQuickShaderEffectSource::WrapMode mode);
182 void nameChanged(const QByteArray &name);
183 void effectChanged(QQmlComponent *component);
184 void smoothChanged(bool smooth);
185 void liveChanged(bool live);
186 void formatChanged(QQuickShaderEffectSource::Format format);
187 void sourceRectChanged(const QRectF &sourceRect);
188 void textureMirroringChanged(QQuickShaderEffectSource::TextureMirroring mirroring);
189 void samplesChanged(int count);
190
191private:
192 friend class QQuickTransformAnimatorJob;
193 friend class QQuickOpacityAnimatorJob;
194
195 void activate();
196 void deactivate();
197 void activateEffect();
198 void deactivateEffect();
199
200 QQuickItem *m_item;
201 bool m_enabled;
202 bool m_mipmap;
203 bool m_smooth;
204 bool m_live;
205 bool m_componentComplete;
206 QQuickShaderEffectSource::WrapMode m_wrapMode;
207 QQuickShaderEffectSource::Format m_format;
208 QSize m_size;
209 QRectF m_sourceRect;
210 QByteArray m_name;
211 QQmlComponent *m_effectComponent;
212 QQuickItem *m_effect;
213 QQuickShaderEffectSource *m_effectSource;
214 QQuickShaderEffectSource::TextureMirroring m_textureMirroring;
215 int m_samples;
216};
217
218#endif
219
220class Q_QUICK_PRIVATE_EXPORT QQuickItemPrivate
221 : public QObjectPrivate
222 , public QQuickPaletteProviderPrivateBase<QQuickItem, QQuickItemPrivate>
223{
224 Q_DECLARE_PUBLIC(QQuickItem)
225
226public:
227 static QQuickItemPrivate* get(QQuickItem *item) { return item->d_func(); }
228 static const QQuickItemPrivate* get(const QQuickItem *item) { return item->d_func(); }
229
230 QQuickItemPrivate();
231 ~QQuickItemPrivate() override;
232 void init(QQuickItem *parent);
233
234 QQmlListProperty<QObject> data();
235 QQmlListProperty<QObject> resources();
236 QQmlListProperty<QQuickItem> children();
237 QQmlListProperty<QQuickItem> visibleChildren();
238
239 QQmlListProperty<QQuickState> states();
240 QQmlListProperty<QQuickTransition> transitions();
241
242 QString state() const;
243 void setState(const QString &);
244
245 QQuickAnchorLine left() const;
246 QQuickAnchorLine right() const;
247 QQuickAnchorLine horizontalCenter() const;
248 QQuickAnchorLine top() const;
249 QQuickAnchorLine bottom() const;
250 QQuickAnchorLine verticalCenter() const;
251 QQuickAnchorLine baseline() const;
252
253#if QT_CONFIG(quick_shadereffect)
254 QQuickItemLayer *layer() const;
255#endif
256
257 void localizedTouchEvent(const QTouchEvent *event, bool isFiltering, QMutableTouchEvent *localized);
258 bool hasPointerHandlers() const;
259 bool hasEnabledHoverHandlers() const;
260 virtual void addPointerHandler(QQuickPointerHandler *h);
261 virtual void removePointerHandler(QQuickPointerHandler *h);
262
263 // data property
264 static void data_append(QQmlListProperty<QObject> *, QObject *);
265 static qsizetype data_count(QQmlListProperty<QObject> *);
266 static QObject *data_at(QQmlListProperty<QObject> *, qsizetype);
267 static void data_clear(QQmlListProperty<QObject> *);
268 static void data_removeLast(QQmlListProperty<QObject> *);
269
270 // resources property
271 static QObject *resources_at(QQmlListProperty<QObject> *, qsizetype);
272 static void resources_append(QQmlListProperty<QObject> *, QObject *);
273 static qsizetype resources_count(QQmlListProperty<QObject> *);
274 static void resources_clear(QQmlListProperty<QObject> *);
275 static void resources_removeLast(QQmlListProperty<QObject> *);
276
277 // children property
278 static void children_append(QQmlListProperty<QQuickItem> *, QQuickItem *);
279 static qsizetype children_count(QQmlListProperty<QQuickItem> *);
280 static QQuickItem *children_at(QQmlListProperty<QQuickItem> *, qsizetype);
281 static void children_clear(QQmlListProperty<QQuickItem> *);
282 static void children_removeLast(QQmlListProperty<QQuickItem> *);
283
284 // visibleChildren property
285 static void visibleChildren_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o);
286 static qsizetype visibleChildren_count(QQmlListProperty<QQuickItem> *prop);
287 static QQuickItem *visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index);
288
289 // transform property
290 static qsizetype transform_count(QQmlListProperty<QQuickTransform> *list);
291 static void transform_append(QQmlListProperty<QQuickTransform> *list, QQuickTransform *);
292 static QQuickTransform *transform_at(QQmlListProperty<QQuickTransform> *list, qsizetype);
293 static void transform_clear(QQmlListProperty<QQuickTransform> *list);
294
295 void _q_resourceObjectDeleted(QObject *);
296 quint64 _q_createJSWrapper(QV4::ExecutionEngine *engine);
297
298 enum ChangeType {
299 Geometry = 0x01,
300 SiblingOrder = 0x02,
301 Visibility = 0x04,
302 Opacity = 0x08,
303 Destroyed = 0x10,
304 Parent = 0x20,
305 Children = 0x40,
306 Rotation = 0x80,
307 ImplicitWidth = 0x100,
308 ImplicitHeight = 0x200,
309 Enabled = 0x400,
310 Focus = 0x800,
311 AllChanges = 0xFFFFFFFF
312 };
313
314 Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
315
316 struct ChangeListener {
317 using ChangeTypes = QQuickItemPrivate::ChangeTypes;
318
319 ChangeListener(QQuickItemChangeListener *l = nullptr, ChangeTypes t = { })
320 : listener(l)
321 , types(t)
322 , gTypes(QQuickGeometryChange::All)
323 {}
324
325 ChangeListener(QQuickItemChangeListener *l, QQuickGeometryChange gt)
326 : listener(l)
327 , types(Geometry)
328 , gTypes(gt)
329 {}
330
331 bool operator==(const ChangeListener &other) const
332 { return listener == other.listener && types == other.types; }
333
334 QQuickItemChangeListener *listener;
335 ChangeTypes types;
336 QQuickGeometryChange gTypes; //NOTE: not used for ==
337
338#ifndef QT_NO_DEBUG_STREAM
339 private:
340 friend QDebug operator<<(QDebug debug, const QQuickItemPrivate::ChangeListener &listener);
341#endif // QT_NO_DEBUG_STREAM
342 };
343
344 // call QQuickItemChangeListener
345 template <typename Fn, typename ...Args>
346 void notifyChangeListeners(QQuickItemPrivate::ChangeTypes changeTypes, Fn &&function, Args &&...args)
347 {
348 if (changeListeners.isEmpty())
349 return;
350
351 const auto listeners = changeListeners; // NOTE: intentional copy (QTBUG-54732)
352 for (const QQuickItemPrivate::ChangeListener &change : listeners) {
353 if (change.types & changeTypes) {
354 if constexpr (std::is_member_function_pointer_v<Fn>)
355 (change.listener->*function)(args...);
356 else
357 function(change, args...);
358 }
359 }
360 }
361
362 struct ExtraData {
363 ExtraData();
364
365 qreal z;
366 qreal scale;
367 qreal rotation;
368 qreal opacity;
369
370 QQuickContents *contents;
371 QQuickScreenAttached *screenAttached;
372 QQuickLayoutMirroringAttached* layoutDirectionAttached;
373 QQuickEnterKeyAttached *enterKeyAttached;
374 QQuickItemKeyFilter *keyHandler;
375 QVector<QQuickPointerHandler *> pointerHandlers;
376#if QT_CONFIG(quick_shadereffect)
377 mutable QQuickItemLayer *layer;
378#endif
379#if QT_CONFIG(cursor)
380 QCursor cursor;
381#endif
382 QPointF userTransformOriginPoint;
383
384 // these do not include child items
385 int effectRefCount;
386 int hideRefCount;
387 // updated recursively for child items as well
388 int recursiveEffectRefCount;
389 // Mask contains() method index
390 int maskContainsIndex;
391
392 // Contains mask
393 QPointer<QObject> mask;
394
395 QSGOpacityNode *opacityNode;
396 QQuickDefaultClipNode *clipNode;
397 QSGRootNode *rootNode;
398 // subsceneDeliveryAgent is set only if this item is the root of a subscene, not on all items within.
399 QQuickDeliveryAgent *subsceneDeliveryAgent = nullptr;
400
401 QObjectList resourcesList;
402
403 // Although acceptedMouseButtons is inside ExtraData, we actually store
404 // the LeftButton flag in the extra.tag() bit. This is because it is
405 // extremely common to set acceptedMouseButtons to LeftButton, but very
406 // rare to use any of the other buttons.
407 Qt::MouseButtons acceptedMouseButtons;
408 Qt::MouseButtons acceptedMouseButtonsWithoutHandlers;
409
410 uint origin:5; // QQuickItem::TransformOrigin
411 uint transparentForPositioner : 1;
412
413 // 26 bits padding
414 };
415
416 enum ExtraDataTag {
417 NoTag = 0x1,
418 LeftMouseButtonAccepted = 0x2
419 };
420 Q_DECLARE_FLAGS(ExtraDataTags, ExtraDataTag)
421
422 QLazilyAllocated<ExtraData, ExtraDataTags> extra;
423 // If the mask is an Item, inform it that it's being used as a mask (true) or is no longer being used (false)
424 virtual void registerAsContainmentMask(QQuickItem * /* maskedItem */, bool /* set */) { }
425
426 QQuickAnchors *anchors() const;
427 mutable QQuickAnchors *_anchors;
428
429 inline Qt::MouseButtons acceptedMouseButtons() const;
430
431 QVector<QQuickItemPrivate::ChangeListener> changeListeners;
432
433 void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types);
434 void updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types);
435 void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types);
436 void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, QQuickGeometryChange types);
437 void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, QQuickGeometryChange types);
438
439 QQuickStateGroup *_states();
440 QQuickStateGroup *_stateGroup;
441
442 inline QQuickItem::TransformOrigin origin() const;
443
444 // Bit 0
445 quint32 flags:7;
446 quint32 widthValidFlag:1;
447 quint32 heightValidFlag:1;
448 quint32 componentComplete:1;
449 quint32 keepMouse:1;
450 quint32 keepTouch:1;
451 quint32 hoverEnabled:1;
452 quint32 smooth:1;
453 quint32 antialiasing:1;
454 quint32 focus:1;
455 // Bit 16
456 quint32 activeFocus:1;
457 quint32 notifiedFocus:1;
458 quint32 notifiedActiveFocus:1;
459 quint32 filtersChildMouseEvents:1;
460 quint32 explicitVisible:1;
461 quint32 effectiveVisible:1;
462 quint32 explicitEnable:1;
463 quint32 effectiveEnable:1;
464 quint32 polishScheduled:1;
465 quint32 inheritedLayoutMirror:1;
466 quint32 effectiveLayoutMirror:1;
467 quint32 isMirrorImplicit:1;
468 quint32 inheritMirrorFromParent:1;
469 quint32 inheritMirrorFromItem:1;
470 quint32 isAccessible:1;
471 quint32 culled:1;
472 // Bit 32
473 quint32 hasCursor:1;
474 quint32 subtreeCursorEnabled:1;
475 quint32 subtreeHoverEnabled:1;
476 quint32 activeFocusOnTab:1;
477 quint32 implicitAntialiasing:1;
478 quint32 antialiasingValid:1;
479 // isTabFence: When true, the item acts as a fence within the tab focus chain.
480 // This means that the item and its children will be skipped from the tab focus
481 // chain when navigating from its parent or any of its siblings. Similarly,
482 // when any of the item's descendants gets focus, the item constrains the tab
483 // focus chain and prevents tabbing outside.
484 quint32 isTabFence:1;
485 quint32 replayingPressEvent:1;
486 quint32 touchEnabled:1;
487 quint32 hasCursorHandler:1;
488 // set true when this item does not expect events via a subscene delivery agent; false otherwise
489 quint32 maybeHasSubsceneDeliveryAgent:1;
490 // set true if this item or any child wants QQuickItemPrivate::transformChanged() to visit all children
491 // (e.g. when parent has ItemIsViewport and child has ItemObservesViewport)
492 quint32 subtreeTransformChangedEnabled:1;
493 quint32 inDestructor:1; // has entered ~QQuickItem
494
495 enum DirtyType {
496 TransformOrigin = 0x00000001,
497 Transform = 0x00000002,
498 BasicTransform = 0x00000004,
499 Position = 0x00000008,
500 Size = 0x00000010,
501
502 ZValue = 0x00000020,
503 Content = 0x00000040,
504 Smooth = 0x00000080,
505 OpacityValue = 0x00000100,
506 ChildrenChanged = 0x00000200,
507 ChildrenStackingChanged = 0x00000400,
508 ParentChanged = 0x00000800,
509
510 Clip = 0x00001000,
511 Window = 0x00002000,
512
513 EffectReference = 0x00008000,
514 Visible = 0x00010000,
515 HideReference = 0x00020000,
516 Antialiasing = 0x00040000,
517 // When you add an attribute here, don't forget to update
518 // dirtyToString()
519
520 TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position |
521 Window,
522 ComplexTransformUpdateMask = Transform | Window,
523 ContentUpdateMask = Size | Content | Smooth | Window | Antialiasing,
524 ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Window
525 };
526
527 quint32 dirtyAttributes;
528 QString dirtyToString() const;
529 void dirty(DirtyType);
530 void addToDirtyList();
531 void removeFromDirtyList();
532 QQuickItem *nextDirtyItem;
533 QQuickItem**prevDirtyItem;
534
535 void setCulled(bool);
536
537 QQuickWindow *window;
538 int windowRefCount;
539 inline QSGContext *sceneGraphContext() const;
540 inline QSGRenderContext *sceneGraphRenderContext() const;
541
542 QQuickItem *parentItem;
543
544 QList<QQuickItem *> childItems;
545 mutable QList<QQuickItem *> *sortedChildItems;
546 QList<QQuickItem *> paintOrderChildItems() const;
547 void addChild(QQuickItem *);
548 void removeChild(QQuickItem *);
549 void siblingOrderChanged();
550
551 inline void markSortedChildrenDirty(QQuickItem *child);
552
553 void refWindow(QQuickWindow *);
554 void derefWindow();
555
556 QPointer<QQuickItem> subFocusItem;
557 void updateSubFocusItem(QQuickItem *scope, bool focus);
558
559 QTransform windowToItemTransform() const;
560 QTransform itemToWindowTransform() const;
561 void itemToParentTransform(QTransform *) const;
562 QTransform globalToWindowTransform() const;
563 QTransform windowToGlobalTransform() const;
564
565 static bool focusNextPrev(QQuickItem *item, bool forward);
566 static QQuickItem *nextTabChildItem(const QQuickItem *item, int start);
567 static QQuickItem *prevTabChildItem(const QQuickItem *item, int start);
568 static QQuickItem *nextPrevItemInTabFocusChain(QQuickItem *item, bool forward);
569
570 static bool canAcceptTabFocus(QQuickItem *item);
571
572 void setX(qreal x) {q_func()->setX(x);}
573 void xChanged() {q_func()->xChanged();}
574 Q_OBJECT_COMPAT_PROPERTY(QQuickItemPrivate, qreal, x, &QQuickItemPrivate::setX, &QQuickItemPrivate::xChanged);
575 void setY(qreal y) {q_func()->setY(y);}
576 void yChanged() {q_func()->yChanged();}
577 Q_OBJECT_COMPAT_PROPERTY(QQuickItemPrivate, qreal, y, &QQuickItemPrivate::setY, &QQuickItemPrivate::yChanged);
578 void setWidth(qreal width) {q_func()->setWidth(width);}
579 void widthChanged() {q_func()->widthChanged();}
580 Q_OBJECT_COMPAT_PROPERTY(QQuickItemPrivate, qreal, width, &QQuickItemPrivate::setWidth, &QQuickItemPrivate::widthChanged);
581 void setHeight(qreal height) {q_func()->setHeight(height);}
582 void heightChanged() {q_func()->heightChanged();}
583 Q_OBJECT_COMPAT_PROPERTY(QQuickItemPrivate, qreal, height, &QQuickItemPrivate::setHeight, &QQuickItemPrivate::heightChanged);
584 qreal implicitWidth;
585 qreal implicitHeight;
586
587 bool widthValid() const { return widthValidFlag || (width.hasBinding() && !QQmlPropertyBinding::isUndefined(binding: width.binding()) ); }
588 bool heightValid() const { return heightValidFlag || (height.hasBinding() && !QQmlPropertyBinding::isUndefined(binding: height.binding()) ); }
589
590 qreal baselineOffset;
591
592 QList<QQuickTransform *> transforms;
593
594 inline qreal z() const { return extra.isAllocated()?extra->z:0; }
595 inline qreal scale() const { return extra.isAllocated()?extra->scale:1; }
596 inline qreal rotation() const { return extra.isAllocated()?extra->rotation:0; }
597 inline qreal opacity() const { return extra.isAllocated()?extra->opacity:1; }
598
599 void setAccessible();
600
601 virtual qreal getImplicitWidth() const;
602 virtual qreal getImplicitHeight() const;
603 virtual void implicitWidthChanged();
604 virtual void implicitHeightChanged();
605
606#if QT_CONFIG(accessibility)
607 QAccessible::Role effectiveAccessibleRole() const;
608private:
609 virtual QAccessible::Role accessibleRole() const;
610public:
611#endif
612
613 void setImplicitAntialiasing(bool antialiasing);
614
615 void resolveLayoutMirror();
616 void setImplicitLayoutMirror(bool mirror, bool inherit);
617 void setLayoutMirror(bool mirror);
618 bool isMirrored() const {
619 return effectiveLayoutMirror;
620 }
621
622 void emitChildrenRectChanged(const QRectF &rect) {
623 Q_Q(QQuickItem);
624 Q_EMIT q->childrenRectChanged(rect);
625 }
626
627 QPointF computeTransformOrigin() const;
628 virtual bool transformChanged(QQuickItem *transformedItem);
629
630 QPointF adjustedPosForTransform(const QPointF &centroid,
631 const QPointF &startPos, const QVector2D &activeTranslatation,
632 qreal startScale, qreal activeScale,
633 qreal startRotation, qreal activeRotation);
634
635 QQuickDeliveryAgent *deliveryAgent();
636 QQuickDeliveryAgentPrivate *deliveryAgentPrivate();
637 QQuickDeliveryAgent *ensureSubsceneDeliveryAgent();
638
639 void deliverKeyEvent(QKeyEvent *);
640 bool filterKeyEvent(QKeyEvent *, bool post);
641#if QT_CONFIG(im)
642 void deliverInputMethodEvent(QInputMethodEvent *);
643#endif
644 void deliverShortcutOverrideEvent(QKeyEvent *);
645
646 bool anyPointerHandlerWants(const QPointerEvent *event, const QEventPoint &point) const;
647 virtual bool handlePointerEvent(QPointerEvent *, bool avoidGrabbers = false);
648
649 virtual void setVisible(bool visible);
650
651 bool isTransparentForPositioner() const;
652 void setTransparentForPositioner(bool trans);
653
654 bool calcEffectiveVisible() const;
655 bool setEffectiveVisibleRecur(bool);
656 bool calcEffectiveEnable() const;
657 void setEffectiveEnableRecur(QQuickItem *scope, bool);
658
659
660 inline QSGTransformNode *itemNode();
661 inline QSGNode *childContainerNode();
662
663 /*
664 QSGNode order is:
665 - itemNode
666 - (opacityNode)
667 - (clipNode)
668 - (rootNode) (shader effect source's root node)
669 */
670
671 QSGOpacityNode *opacityNode() const { return extra.isAllocated()?extra->opacityNode:nullptr; }
672 QQuickDefaultClipNode *clipNode() const { return extra.isAllocated()?extra->clipNode:nullptr; }
673 QSGRootNode *rootNode() const { return extra.isAllocated()?extra->rootNode:nullptr; }
674
675 QSGTransformNode *itemNodeInstance;
676 QSGNode *paintNode;
677
678 virtual QSGTransformNode *createTransformNode();
679
680 // A reference from an effect item means that this item is used by the effect, so
681 // it should insert a root node.
682 void refFromEffectItem(bool hide);
683 void recursiveRefFromEffectItem(int refs);
684 void derefFromEffectItem(bool unhide);
685
686 void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &);
687
688 virtual void mirrorChange() {}
689
690 void setHasCursorInChild(bool hasCursor);
691 void setHasHoverInChild(bool hasHover);
692#if QT_CONFIG(cursor)
693 QCursor effectiveCursor(const QQuickPointerHandler *handler) const;
694 QQuickPointerHandler *effectiveCursorHandler() const;
695#endif
696
697 virtual void updatePolish() { }
698 virtual void dumpItemTree(int indent) const;
699};
700
701Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ExtraDataTags)
702
703/*
704 Key filters can be installed on a QQuickItem, but not removed. Currently they
705 are only used by attached objects (which are only destroyed on Item
706 destruction), so this isn't a problem. If in future this becomes any form
707 of public API, they will have to support removal too.
708*/
709class QQuickItemKeyFilter
710{
711public:
712 QQuickItemKeyFilter(QQuickItem * = nullptr);
713 virtual ~QQuickItemKeyFilter();
714
715 virtual void keyPressed(QKeyEvent *event, bool post);
716 virtual void keyReleased(QKeyEvent *event, bool post);
717#if QT_CONFIG(im)
718 virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
719 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
720#endif
721 virtual void shortcutOverrideEvent(QKeyEvent *event);
722 virtual void componentComplete();
723
724 bool m_processPost;
725
726private:
727 QQuickItemKeyFilter *m_next;
728};
729
730class QQuickKeyNavigationAttachedPrivate : public QObjectPrivate
731{
732public:
733 QQuickKeyNavigationAttachedPrivate()
734 : leftSet(false), rightSet(false), upSet(false), downSet(false),
735 tabSet(false), backtabSet(false) {}
736
737 QPointer<QQuickItem> left;
738 QPointer<QQuickItem> right;
739 QPointer<QQuickItem> up;
740 QPointer<QQuickItem> down;
741 QPointer<QQuickItem> tab;
742 QPointer<QQuickItem> backtab;
743 bool leftSet : 1;
744 bool rightSet : 1;
745 bool upSet : 1;
746 bool downSet : 1;
747 bool tabSet : 1;
748 bool backtabSet : 1;
749};
750
751class Q_QUICK_PRIVATE_EXPORT QQuickKeyNavigationAttached : public QObject, public QQuickItemKeyFilter
752{
753 Q_OBJECT
754 Q_DECLARE_PRIVATE(QQuickKeyNavigationAttached)
755
756 Q_PROPERTY(QQuickItem *left READ left WRITE setLeft NOTIFY leftChanged FINAL)
757 Q_PROPERTY(QQuickItem *right READ right WRITE setRight NOTIFY rightChanged FINAL)
758 Q_PROPERTY(QQuickItem *up READ up WRITE setUp NOTIFY upChanged FINAL)
759 Q_PROPERTY(QQuickItem *down READ down WRITE setDown NOTIFY downChanged FINAL)
760 Q_PROPERTY(QQuickItem *tab READ tab WRITE setTab NOTIFY tabChanged FINAL)
761 Q_PROPERTY(QQuickItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged FINAL)
762 Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged FINAL)
763
764 QML_NAMED_ELEMENT(KeyNavigation)
765 QML_ADDED_IN_VERSION(2, 0)
766 QML_UNCREATABLE("KeyNavigation is only available via attached properties.")
767 QML_ATTACHED(QQuickKeyNavigationAttached)
768
769public:
770 QQuickKeyNavigationAttached(QObject * = nullptr);
771
772 QQuickItem *left() const;
773 void setLeft(QQuickItem *);
774 QQuickItem *right() const;
775 void setRight(QQuickItem *);
776 QQuickItem *up() const;
777 void setUp(QQuickItem *);
778 QQuickItem *down() const;
779 void setDown(QQuickItem *);
780 QQuickItem *tab() const;
781 void setTab(QQuickItem *);
782 QQuickItem *backtab() const;
783 void setBacktab(QQuickItem *);
784
785 enum Priority { BeforeItem, AfterItem };
786 Q_ENUM(Priority)
787 Priority priority() const;
788 void setPriority(Priority);
789
790 static QQuickKeyNavigationAttached *qmlAttachedProperties(QObject *);
791
792Q_SIGNALS:
793 void leftChanged();
794 void rightChanged();
795 void upChanged();
796 void downChanged();
797 void tabChanged();
798 void backtabChanged();
799 void priorityChanged();
800
801private:
802 void keyPressed(QKeyEvent *event, bool post) override;
803 void keyReleased(QKeyEvent *event, bool post) override;
804 void setFocusNavigation(QQuickItem *currentItem, const char *dir,
805 Qt::FocusReason reason = Qt::OtherFocusReason);
806};
807
808class QQuickLayoutMirroringAttached : public QObject
809{
810 Q_OBJECT
811 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged FINAL)
812 Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged FINAL)
813
814 QML_NAMED_ELEMENT(LayoutMirroring)
815 QML_ADDED_IN_VERSION(2, 0)
816 QML_UNCREATABLE("LayoutMirroring is only available via attached properties.")
817 QML_ATTACHED(QQuickLayoutMirroringAttached)
818
819public:
820 explicit QQuickLayoutMirroringAttached(QObject *parent = nullptr);
821
822 bool enabled() const;
823 void setEnabled(bool);
824 void resetEnabled();
825
826 bool childrenInherit() const;
827 void setChildrenInherit(bool);
828
829 static QQuickLayoutMirroringAttached *qmlAttachedProperties(QObject *);
830Q_SIGNALS:
831 void enabledChanged();
832 void childrenInheritChanged();
833private:
834 friend class QQuickItemPrivate;
835 QQuickItemPrivate *itemPrivate;
836};
837
838class QQuickEnterKeyAttached : public QObject
839{
840 Q_OBJECT
841 Q_PROPERTY(Qt::EnterKeyType type READ type WRITE setType NOTIFY typeChanged FINAL)
842
843 QML_NAMED_ELEMENT(EnterKey)
844 QML_UNCREATABLE("EnterKey is only available via attached properties")
845 QML_ADDED_IN_VERSION(2, 6)
846 QML_ATTACHED(QQuickEnterKeyAttached)
847
848public:
849 explicit QQuickEnterKeyAttached(QObject *parent = nullptr);
850
851 Qt::EnterKeyType type() const;
852 void setType(Qt::EnterKeyType type);
853
854 static QQuickEnterKeyAttached *qmlAttachedProperties(QObject *);
855Q_SIGNALS:
856 void typeChanged();
857private:
858 friend class QQuickItemPrivate;
859 QQuickItemPrivate *itemPrivate;
860
861 Qt::EnterKeyType keyType;
862};
863
864class QQuickKeysAttachedPrivate : public QObjectPrivate
865{
866public:
867 QQuickKeysAttachedPrivate()
868 : inPress(false), inRelease(false), inIM(false), enabled(true)
869 {}
870
871 //loop detection
872 bool inPress:1;
873 bool inRelease:1;
874 bool inIM:1;
875
876 bool enabled : 1;
877
878 QQuickItem *imeItem = nullptr;
879 QList<QQuickItem *> targets;
880 QQuickItem *item = nullptr;
881 QQuickKeyEvent theKeyEvent;
882};
883
884class Q_QUICK_PRIVATE_EXPORT QQuickKeysAttached : public QObject, public QQuickItemKeyFilter
885{
886 Q_OBJECT
887 Q_DECLARE_PRIVATE(QQuickKeysAttached)
888
889 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
890 Q_PROPERTY(QQmlListProperty<QQuickItem> forwardTo READ forwardTo FINAL)
891 Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged FINAL)
892
893 QML_NAMED_ELEMENT(Keys)
894 QML_ADDED_IN_VERSION(2, 0)
895 QML_UNCREATABLE("Keys is only available via attached properties")
896 QML_ATTACHED(QQuickKeysAttached)
897
898public:
899 QQuickKeysAttached(QObject *parent=nullptr);
900 ~QQuickKeysAttached() override;
901
902 bool enabled() const { Q_D(const QQuickKeysAttached); return d->enabled; }
903 void setEnabled(bool enabled) {
904 Q_D(QQuickKeysAttached);
905 if (enabled != d->enabled) {
906 d->enabled = enabled;
907 Q_EMIT enabledChanged();
908 }
909 }
910
911 enum Priority { BeforeItem, AfterItem};
912 Q_ENUM(Priority)
913 Priority priority() const;
914 void setPriority(Priority);
915
916 QQmlListProperty<QQuickItem> forwardTo() {
917 Q_D(QQuickKeysAttached);
918 return QQmlListProperty<QQuickItem>(this, &(d->targets));
919 }
920
921 void componentComplete() override;
922
923 static QQuickKeysAttached *qmlAttachedProperties(QObject *);
924
925Q_SIGNALS:
926 void enabledChanged();
927 void priorityChanged();
928 void pressed(QQuickKeyEvent *event);
929 void released(QQuickKeyEvent *event);
930 void shortcutOverride(QQuickKeyEvent *event);
931 void digit0Pressed(QQuickKeyEvent *event);
932 void digit1Pressed(QQuickKeyEvent *event);
933 void digit2Pressed(QQuickKeyEvent *event);
934 void digit3Pressed(QQuickKeyEvent *event);
935 void digit4Pressed(QQuickKeyEvent *event);
936 void digit5Pressed(QQuickKeyEvent *event);
937 void digit6Pressed(QQuickKeyEvent *event);
938 void digit7Pressed(QQuickKeyEvent *event);
939 void digit8Pressed(QQuickKeyEvent *event);
940 void digit9Pressed(QQuickKeyEvent *event);
941
942 void leftPressed(QQuickKeyEvent *event);
943 void rightPressed(QQuickKeyEvent *event);
944 void upPressed(QQuickKeyEvent *event);
945 void downPressed(QQuickKeyEvent *event);
946 void tabPressed(QQuickKeyEvent *event);
947 void backtabPressed(QQuickKeyEvent *event);
948
949 void asteriskPressed(QQuickKeyEvent *event);
950 void numberSignPressed(QQuickKeyEvent *event);
951 void escapePressed(QQuickKeyEvent *event);
952 void returnPressed(QQuickKeyEvent *event);
953 void enterPressed(QQuickKeyEvent *event);
954 void deletePressed(QQuickKeyEvent *event);
955 void spacePressed(QQuickKeyEvent *event);
956 void backPressed(QQuickKeyEvent *event);
957 void cancelPressed(QQuickKeyEvent *event);
958 void selectPressed(QQuickKeyEvent *event);
959 void yesPressed(QQuickKeyEvent *event);
960 void noPressed(QQuickKeyEvent *event);
961 void context1Pressed(QQuickKeyEvent *event);
962 void context2Pressed(QQuickKeyEvent *event);
963 void context3Pressed(QQuickKeyEvent *event);
964 void context4Pressed(QQuickKeyEvent *event);
965 void callPressed(QQuickKeyEvent *event);
966 void hangupPressed(QQuickKeyEvent *event);
967 void flipPressed(QQuickKeyEvent *event);
968 void menuPressed(QQuickKeyEvent *event);
969 void volumeUpPressed(QQuickKeyEvent *event);
970 void volumeDownPressed(QQuickKeyEvent *event);
971
972private:
973 void keyPressed(QKeyEvent *event, bool post) override;
974 void keyReleased(QKeyEvent *event, bool post) override;
975#if QT_CONFIG(im)
976 void inputMethodEvent(QInputMethodEvent *, bool post) override;
977 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
978#endif
979 void shortcutOverrideEvent(QKeyEvent *event) override;
980 static QByteArray keyToSignal(int key);
981
982 bool isConnected(const char *signalName) const;
983};
984
985Qt::MouseButtons QQuickItemPrivate::acceptedMouseButtons() const
986{
987 return ((extra.tag().testFlag(flag: LeftMouseButtonAccepted) ? Qt::LeftButton : Qt::MouseButton(0)) |
988 (extra.isAllocated() ? extra->acceptedMouseButtons : Qt::MouseButtons{}));
989}
990
991QSGContext *QQuickItemPrivate::sceneGraphContext() const
992{
993 Q_ASSERT(window);
994 return static_cast<QQuickWindowPrivate *>(QObjectPrivate::get(o: window))->context->sceneGraphContext();
995}
996
997QSGRenderContext *QQuickItemPrivate::sceneGraphRenderContext() const
998{
999 Q_ASSERT(window);
1000 return static_cast<QQuickWindowPrivate *>(QObjectPrivate::get(o: window))->context;
1001}
1002
1003void QQuickItemPrivate::markSortedChildrenDirty(QQuickItem *child)
1004{
1005 // If sortedChildItems == &childItems then all in childItems have z == 0
1006 // and we don't need to invalidate if the changed item also has z == 0.
1007 if (child->z() != 0. || sortedChildItems != &childItems) {
1008 if (sortedChildItems != &childItems)
1009 delete sortedChildItems;
1010 sortedChildItems = nullptr;
1011 }
1012}
1013
1014QQuickItem::TransformOrigin QQuickItemPrivate::origin() const
1015{
1016 return extra.isAllocated() ? QQuickItem::TransformOrigin(extra->origin)
1017 : QQuickItem::Center;
1018}
1019
1020QSGTransformNode *QQuickItemPrivate::itemNode()
1021{
1022 if (!itemNodeInstance) {
1023 itemNodeInstance = createTransformNode();
1024 itemNodeInstance->setFlag(QSGNode::OwnedByParent, false);
1025#ifdef QSG_RUNTIME_DESCRIPTION
1026 Q_Q(QQuickItem);
1027 qsgnode_set_description(node: itemNodeInstance, description: QString::fromLatin1(ba: "QQuickItem(%1:%2)").arg(a: QString::fromLatin1(ba: q->metaObject()->className())).arg(a: q->objectName()));
1028#endif
1029 }
1030 return itemNodeInstance;
1031}
1032
1033QSGNode *QQuickItemPrivate::childContainerNode()
1034{
1035 if (rootNode())
1036 return rootNode();
1037 else if (clipNode())
1038 return clipNode();
1039 else if (opacityNode())
1040 return opacityNode();
1041 else
1042 return itemNode();
1043}
1044
1045Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ChangeTypes)
1046Q_DECLARE_TYPEINFO(QQuickItemPrivate::ChangeListener, Q_PRIMITIVE_TYPE);
1047
1048QT_END_NAMESPACE
1049
1050#if QT_CONFIG(quick_shadereffect)
1051QML_DECLARE_TYPE(QQuickItemLayer)
1052#endif
1053QML_DECLARE_TYPE(QQuickKeysAttached)
1054QML_DECLARE_TYPE(QQuickKeyNavigationAttached)
1055QML_DECLARE_TYPE(QQuickLayoutMirroringAttached)
1056QML_DECLARE_TYPE(QQuickEnterKeyAttached)
1057
1058#endif // QQUICKITEM_P_H
1059

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