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