9#include <QtQml/qjsengine.h>
16#include <QtQml/qqmlengine.h>
17#include <QtQml/qqmlcomponent.h>
18#include <QtQml/qqmlinfo.h>
19#include <QtGui/qpen.h>
20#include <QtGui/qguiapplication.h>
21#include <QtGui/qstylehints.h>
22#include <QtGui/private/qeventpoint_p.h>
23#include <QtGui/private/qguiapplication_p.h>
24#include <QtGui/private/qpointingdevice_p.h>
25#include <QtGui/qinputmethod.h>
26#include <QtCore/qcoreevent.h>
27#include <QtCore/private/qnumeric_p.h>
28#include <QtGui/qpa/qplatformtheme.h>
29#include <QtCore/qloggingcategory.h>
30#include <QtCore/private/qduplicatetracker_p.h>
32#include <private/qqmlglobal_p.h>
33#include <private/qqmlengine_p.h>
34#include <QtQuick/private/qquickstategroup_p.h>
35#include <private/qqmlopenmetaobject_p.h>
36#include <QtQuick/private/qquickstate_p.h>
37#include <private/qquickitem_p.h>
38#include <QtQuick/private/qquickaccessibleattached_p.h>
39#include <QtQuick/private/qquickattachedpropertypropagator_p.h>
40#include <QtQuick/private/qquickhoverhandler_p.h>
41#include <QtQuick/private/qquickpointerhandler_p.h>
42#include <QtQuick/private/qquickpointerhandler_p_p.h>
44#include <private/qv4engine_p.h>
45#include <private/qv4object_p.h>
46#include <private/qv4qobjectwrapper_p.h>
47#include <private/qdebug_p.h>
48#include <private/qqmlvaluetypewrapper_p.h>
51# include <QtGui/qcursor.h>
54#if QT_CONFIG(accessibility)
55# include <private/qaccessiblecache_p.h>
58#include <QtCore/qpointer.h>
68Q_LOGGING_CATEGORY(lcVP,
"qt.quick.viewport")
69Q_STATIC_LOGGING_CATEGORY(lcEffClip,
"qt.quick.effectiveclip")
70Q_STATIC_LOGGING_CATEGORY(lcChangeListeners,
"qt.quick.item.changelisteners")
73static const quint64 kCursorOverrideTimeout = 100;
75void debugFocusTree(QQuickItem *item, QQuickItem *scope =
nullptr,
int depth = 1)
77 if (lcFocus().isEnabled(QtDebugMsg)) {
79 << QByteArray(depth,
'\t').constData()
80 << (scope && QQuickItemPrivate::get(scope)->subFocusItem == item ?
'*' :
' ')
82 << item->hasActiveFocus()
83 << item->isFocusScope()
85 const auto childItems = item->childItems();
86 for (QQuickItem *child : childItems) {
89 item->isFocusScope() || !scope ? item : scope,
90 item->isFocusScope() || !scope ? depth + 1 : depth);
97 QQuickItemPrivate *d = QQuickItemPrivate::get(item);
98 if (d->subFocusItem && d->window && d->flags & QQuickItem::ItemIsFocusScope)
99 d->deliveryAgentPrivate()->clearFocusInScope(item, d->subFocusItem, reason);
100 item->forceActiveFocus(reason);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127QQuickTransformPrivate::QQuickTransformPrivate()
131QQuickTransform::QQuickTransform(QObject *parent)
132: QObject(*(
new QQuickTransformPrivate), parent)
136QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent)
141QQuickTransform::~QQuickTransform()
143 Q_D(QQuickTransform);
144 for (
int ii = 0; ii < d->items.size(); ++ii) {
145 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
146 p->transforms.removeOne(
this);
147 p->dirty(QQuickItemPrivate::Transform);
151void QQuickTransform::update()
153 Q_D(QQuickTransform);
154 for (
int ii = 0; ii < d->items.size(); ++ii) {
155 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
156 p->dirty(QQuickItemPrivate::Transform);
160QQuickContents::QQuickContents(QQuickItem *item)
165QQuickContents::~QQuickContents()
168 QList<QQuickItem *> children = m_item->childItems();
169 for (
int i = 0; i < children.size(); ++i) {
170 QQuickItem *child = children.at(i);
171 QQuickItemPrivate::get(child)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
175bool QQuickContents::calcHeight(QQuickItem *changed)
177 qreal oldy = m_contents.y();
178 qreal oldheight = m_contents.height();
182 qreal bottom = oldy + oldheight;
183 qreal y = changed->y();
184 if (y + changed->height() > bottom)
185 bottom = y + changed->height();
188 m_contents.setY(top);
189 m_contents.setHeight(bottom - top);
191 qreal top = std::numeric_limits<qreal>::max();
192 qreal bottom = -std::numeric_limits<qreal>::max();
193 QList<QQuickItem *> children = m_item->childItems();
194 for (
int i = 0; i < children.size(); ++i) {
195 QQuickItem *child = children.at(i);
196 qreal y = child->y();
197 if (y + child->height() > bottom)
198 bottom = y + child->height();
202 if (!children.isEmpty())
203 m_contents.setY(top);
204 m_contents.setHeight(qMax(bottom - top, qreal(0.0)));
207 return (m_contents.height() != oldheight || m_contents.y() != oldy);
210bool QQuickContents::calcWidth(QQuickItem *changed)
212 qreal oldx = m_contents.x();
213 qreal oldwidth = m_contents.width();
217 qreal right = oldx + oldwidth;
218 qreal x = changed->x();
219 if (x + changed->width() > right)
220 right = x + changed->width();
223 m_contents.setX(left);
224 m_contents.setWidth(right - left);
226 qreal left = std::numeric_limits<qreal>::max();
227 qreal right = -std::numeric_limits<qreal>::max();
228 QList<QQuickItem *> children = m_item->childItems();
229 for (
int i = 0; i < children.size(); ++i) {
230 QQuickItem *child = children.at(i);
231 qreal x = child->x();
232 if (x + child->width() > right)
233 right = x + child->width();
237 if (!children.isEmpty())
238 m_contents.setX(left);
239 m_contents.setWidth(qMax(right - left, qreal(0.0)));
242 return (m_contents.width() != oldwidth || m_contents.x() != oldx);
245void QQuickContents::complete()
247 QQuickItemPrivate::get(m_item)->addItemChangeListener(
this, QQuickItemPrivate::Children);
249 QList<QQuickItem *> children = m_item->childItems();
250 for (
int i = 0; i < children.size(); ++i) {
251 QQuickItem *child = children.at(i);
252 QQuickItemPrivate::get(child)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
258void QQuickContents::updateRect()
260 QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF());
263void QQuickContents::itemGeometryChanged(QQuickItem *changed, QQuickGeometryChange change,
const QRectF &)
266 bool wChanged =
false;
267 bool hChanged =
false;
269 if (change.horizontalChange())
270 wChanged = calcWidth();
271 if (change.verticalChange())
272 hChanged = calcHeight();
273 if (wChanged || hChanged)
277void QQuickContents::itemDestroyed(QQuickItem *item)
280 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
284void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item)
287 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
291void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item)
294 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
298QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item)
299: m_processPost(
false), m_next(
nullptr)
301 QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):
nullptr;
303 m_next = p->extra.value().keyHandler;
304 p->extra->keyHandler =
this;
308QQuickItemKeyFilter::~QQuickItemKeyFilter()
312void QQuickItemKeyFilter::keyPressed(QKeyEvent *event,
bool post)
314 if (m_next) m_next->keyPressed(event, post);
317void QQuickItemKeyFilter::keyReleased(QKeyEvent *event,
bool post)
319 if (m_next) m_next->keyReleased(event, post);
323void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event,
bool post)
326 m_next->inputMethodEvent(event, post);
331QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query)
const
333 if (m_next)
return m_next->inputMethodQuery(query);
338void QQuickItemKeyFilter::shortcutOverrideEvent(QKeyEvent *event)
341 m_next->shortcutOverrideEvent(event);
346void QQuickItemKeyFilter::componentComplete()
348 if (m_next) m_next->componentComplete();
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
395
396
397
398
399
402
403
404
405
406
409
410
411
412
413
416
417
418
419
420
423
424
425
426
427
430
431
432
433
434
436QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent)
437: QObject(*(
new QQuickKeyNavigationAttachedPrivate), parent),
438 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
440 m_processPost =
true;
443QQuickKeyNavigationAttached *
444QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
446 return new QQuickKeyNavigationAttached(obj);
449QQuickItem *QQuickKeyNavigationAttached::left()
const
451 Q_D(
const QQuickKeyNavigationAttached);
455void QQuickKeyNavigationAttached::setLeft(QQuickItem *i)
457 Q_D(QQuickKeyNavigationAttached);
458 if (d->leftSet && d->left == i)
460 d->leftSet = d->left != i;
462 QQuickKeyNavigationAttached* other =
463 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
464 if (other && !other->d_func()->rightSet){
465 other->d_func()->right = qobject_cast<QQuickItem*>(parent());
466 emit other->rightChanged();
471QQuickItem *QQuickKeyNavigationAttached::right()
const
473 Q_D(
const QQuickKeyNavigationAttached);
477void QQuickKeyNavigationAttached::setRight(QQuickItem *i)
479 Q_D(QQuickKeyNavigationAttached);
480 if (d->rightSet && d->right == i)
482 d->rightSet = d->right != i;
484 QQuickKeyNavigationAttached* other =
485 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
486 if (other && !other->d_func()->leftSet){
487 other->d_func()->left = qobject_cast<QQuickItem*>(parent());
488 emit other->leftChanged();
493QQuickItem *QQuickKeyNavigationAttached::up()
const
495 Q_D(
const QQuickKeyNavigationAttached);
499void QQuickKeyNavigationAttached::setUp(QQuickItem *i)
501 Q_D(QQuickKeyNavigationAttached);
502 if (d->upSet && d->up == i)
504 d->upSet = d->up != i;
506 QQuickKeyNavigationAttached* other =
507 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
508 if (other && !other->d_func()->downSet){
509 other->d_func()->down = qobject_cast<QQuickItem*>(parent());
510 emit other->downChanged();
515QQuickItem *QQuickKeyNavigationAttached::down()
const
517 Q_D(
const QQuickKeyNavigationAttached);
521void QQuickKeyNavigationAttached::setDown(QQuickItem *i)
523 Q_D(QQuickKeyNavigationAttached);
524 if (d->downSet && d->down == i)
526 d->downSet = d->down != i;
528 QQuickKeyNavigationAttached* other =
529 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
530 if (other && !other->d_func()->upSet) {
531 other->d_func()->up = qobject_cast<QQuickItem*>(parent());
532 emit other->upChanged();
537QQuickItem *QQuickKeyNavigationAttached::tab()
const
539 Q_D(
const QQuickKeyNavigationAttached);
543void QQuickKeyNavigationAttached::setTab(QQuickItem *i)
545 Q_D(QQuickKeyNavigationAttached);
546 if (d->tabSet && d->tab == i)
548 d->tabSet = d->tab != i;
550 QQuickKeyNavigationAttached* other =
551 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
552 if (other && !other->d_func()->backtabSet) {
553 other->d_func()->backtab = qobject_cast<QQuickItem*>(parent());
554 emit other->backtabChanged();
559QQuickItem *QQuickKeyNavigationAttached::backtab()
const
561 Q_D(
const QQuickKeyNavigationAttached);
565void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i)
567 Q_D(QQuickKeyNavigationAttached);
568 if (d->backtabSet && d->backtab == i)
570 d->backtabSet = d->backtab != i;
572 QQuickKeyNavigationAttached* other =
573 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
574 if (other && !other->d_func()->tabSet) {
575 other->d_func()->tab = qobject_cast<QQuickItem*>(parent());
576 emit other->tabChanged();
578 emit backtabChanged();
582
583
584
585
586
587
588
589
590
591
592
593
594QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority()
const
596 return m_processPost ? AfterItem : BeforeItem;
599void QQuickKeyNavigationAttached::setPriority(Priority order)
601 bool processPost = order == AfterItem;
602 if (processPost != m_processPost) {
603 m_processPost = processPost;
604 emit priorityChanged();
608void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event,
bool post)
610 Q_D(QQuickKeyNavigationAttached);
613 if (post != m_processPost) {
614 QQuickItemKeyFilter::keyPressed(event, post);
619 switch (event->key()) {
621 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
622 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
623 QQuickItem* leftItem = mirror ? d->right : d->left;
625 setFocusNavigation(leftItem, mirror ?
"right" :
"left", mirror ? Qt::TabFocusReason : Qt::BacktabFocusReason);
630 case Qt::Key_Right: {
631 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
632 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
633 QQuickItem* rightItem = mirror ? d->left : d->right;
635 setFocusNavigation(rightItem, mirror ?
"left" :
"right", mirror ? Qt::BacktabFocusReason : Qt::TabFocusReason);
642 setFocusNavigation(d->up,
"up", Qt::BacktabFocusReason);
648 setFocusNavigation(d->down,
"down", Qt::TabFocusReason);
654 setFocusNavigation(d->tab,
"tab", Qt::TabFocusReason);
658 case Qt::Key_Backtab:
660 setFocusNavigation(d->backtab,
"backtab", Qt::BacktabFocusReason);
668 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
671void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event,
bool post)
673 Q_D(QQuickKeyNavigationAttached);
676 if (post != m_processPost) {
677 QQuickItemKeyFilter::keyReleased(event, post);
682 switch (event->key()) {
684 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
685 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
686 if (mirror ? d->right : d->left)
690 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
691 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
692 if (mirror ? d->left : d->right)
710 case Qt::Key_Backtab:
719 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
722void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem,
const char *dir,
723 Qt::FocusReason reason)
725 QQuickItem *initialItem = currentItem;
726 bool isNextItem =
false;
727 QList<QQuickItem *> visitedItems;
730 if (currentItem->isVisible() && currentItem->isEnabled()) {
731 currentItem->forceActiveFocus(reason);
734 qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(currentItem,
false);
736 QQuickItem *tempItem = qvariant_cast<QQuickItem*>(attached->property(dir));
738 visitedItems.append(currentItem);
739 currentItem = tempItem;
745 while (currentItem != initialItem && isNextItem && !visitedItems.contains(currentItem));
754 { Qt::Key_Left,
"leftPressed" },
755 { Qt::Key_Right,
"rightPressed" },
756 { Qt::Key_Up,
"upPressed" },
757 { Qt::Key_Down,
"downPressed" },
758 { Qt::Key_Tab,
"tabPressed" },
759 { Qt::Key_Backtab,
"backtabPressed" },
760 { Qt::Key_Asterisk,
"asteriskPressed" },
761 { Qt::Key_NumberSign,
"numberSignPressed" },
762 { Qt::Key_Escape,
"escapePressed" },
763 { Qt::Key_Return,
"returnPressed" },
764 { Qt::Key_Enter,
"enterPressed" },
765 { Qt::Key_Delete,
"deletePressed" },
766 { Qt::Key_Space,
"spacePressed" },
767 { Qt::Key_Back,
"backPressed" },
768 { Qt::Key_Cancel,
"cancelPressed" },
769 { Qt::Key_Select,
"selectPressed" },
770 { Qt::Key_Yes,
"yesPressed" },
771 { Qt::Key_No,
"noPressed" },
772 { Qt::Key_Context1,
"context1Pressed" },
773 { Qt::Key_Context2,
"context2Pressed" },
774 { Qt::Key_Context3,
"context3Pressed" },
775 { Qt::Key_Context4,
"context4Pressed" },
776 { Qt::Key_Call,
"callPressed" },
777 { Qt::Key_Hangup,
"hangupPressed" },
778 { Qt::Key_Flip,
"flipPressed" },
779 { Qt::Key_Menu,
"menuPressed" },
780 { Qt::Key_VolumeUp,
"volumeUpPressed" },
781 { Qt::Key_VolumeDown,
"volumeDownPressed" },
785QByteArray QQuickKeysAttached::keyToSignal(
int key)
787 QByteArray keySignal;
788 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
789 keySignal =
"digit0Pressed";
790 keySignal[5] =
'0' + (key - Qt::Key_0);
793 while (sigMap[i].key && sigMap[i].key != key)
795 keySignal = sigMap[i].sig;
800bool QQuickKeysAttached::isConnected(
const char *signalName)
const
802 Q_D(
const QQuickKeysAttached);
803 int signal_index = d->signalIndex(signalName);
804 return d->isSignalConnected(signal_index);
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
873
874
875
876
877
880
881
882
883
884
885
886
887
888
889
890
891
892
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
925
926
927
928
929
932
933
934
935
936
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
977
978
979
980
981
984
985
986
987
988
991
992
993
994
995
998
999
1000
1001
1002
1005
1006
1007
1008
1009
1012
1013
1014
1015
1016
1019
1020
1021
1022
1023
1026
1027
1028
1029
1030
1033
1034
1035
1036
1037
1040
1041
1042
1043
1044
1047
1048
1049
1050
1051
1054
1055
1056
1057
1058
1061
1062
1063
1064
1065
1068
1069
1070
1071
1072
1075
1076
1077
1078
1079
1082
1083
1084
1085
1086
1089
1090
1091
1092
1093
1096
1097
1098
1099
1100
1103
1104
1105
1106
1107
1110
1111
1112
1113
1114
1117
1118
1119
1120
1121
1124
1125
1126
1127
1128
1131
1132
1133
1134
1135
1138
1139
1140
1141
1142
1145
1146
1147
1148
1149
1152
1153
1154
1155
1156
1159
1160
1161
1162
1163
1166
1167
1168
1169
1170
1173
1174
1175
1176
1177
1180
1181
1182
1183
1184
1187
1188
1189
1190
1191
1194
1195
1196
1197
1198
1201
1202
1203
1204
1205
1208
1209
1210
1211
1212
1215
1216
1217
1218
1219
1222
1223
1224
1225
1226
1229
1230
1231
1232
1233
1235QQuickKeysAttached::QQuickKeysAttached(QObject *parent)
1236: QObject(*(
new QQuickKeysAttachedPrivate), parent),
1237 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
1239 Q_D(QQuickKeysAttached);
1240 m_processPost =
false;
1241 d->item = qmlobject_cast<QQuickItem*>(parent);
1242 if (d->item != parent)
1243 qWarning() <<
"Could not attach Keys property to: " << parent <<
" is not an Item";
1246QQuickKeysAttached::~QQuickKeysAttached()
1250QQuickKeysAttached::Priority QQuickKeysAttached::priority()
const
1252 return m_processPost ? AfterItem : BeforeItem;
1255void QQuickKeysAttached::setPriority(Priority order)
1257 bool processPost = order == AfterItem;
1258 if (processPost != m_processPost) {
1259 m_processPost = processPost;
1260 emit priorityChanged();
1264void QQuickKeysAttached::componentComplete()
1267 Q_D(QQuickKeysAttached);
1269 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1270 QQuickItem *targetItem = d->targets.at(ii);
1271 if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1272 d->item->setFlag(QQuickItem::ItemAcceptsInputMethod);
1280void QQuickKeysAttached::keyPressed(QKeyEvent *event,
bool post)
1282 Q_D(QQuickKeysAttached);
1283 if (post != m_processPost || !d->enabled || d->inPress) {
1285 QQuickItemKeyFilter::keyPressed(event, post);
1290 if (d->item && d->item->window()) {
1292 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1293 QQuickItem *i = d->targets.at(ii);
1294 if (i && i->isVisible()) {
1296 QCoreApplication::sendEvent(i, event);
1297 if (event->isAccepted()) {
1306 QQuickKeyEvent &ke = d->theKeyEvent;
1308 QByteArray keySignal = keyToSignal(event->key());
1309 if (!keySignal.isEmpty()) {
1310 keySignal +=
"(QQuickKeyEvent*)";
1311 if (isConnected(keySignal)) {
1313 ke.setAccepted(
true);
1314 int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal);
1315 metaObject()->method(idx).invoke(
this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke));
1318 if (!ke.isAccepted())
1320 event->setAccepted(ke.isAccepted());
1322 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
1325void QQuickKeysAttached::keyReleased(QKeyEvent *event,
bool post)
1327 Q_D(QQuickKeysAttached);
1328 if (post != m_processPost || !d->enabled || d->inRelease) {
1330 QQuickItemKeyFilter::keyReleased(event, post);
1334 if (d->item && d->item->window()) {
1335 d->inRelease =
true;
1336 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1337 QQuickItem *i = d->targets.at(ii);
1338 if (i && i->isVisible()) {
1340 QCoreApplication::sendEvent(i, event);
1341 if (event->isAccepted()) {
1342 d->inRelease =
false;
1347 d->inRelease =
false;
1350 QQuickKeyEvent &ke = d->theKeyEvent;
1353 event->setAccepted(ke.isAccepted());
1355 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
1359void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event,
bool post)
1361 Q_D(QQuickKeysAttached);
1362 if (post == m_processPost && d->item && !d->inIM && d->item->window()) {
1364 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1365 QQuickItem *targetItem = d->targets.at(ii);
1366 if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1367 QCoreApplication::sendEvent(targetItem, event);
1368 if (event->isAccepted()) {
1369 d->imeItem = targetItem;
1377 QQuickItemKeyFilter::inputMethodEvent(event, post);
1380QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query)
const
1382 Q_D(
const QQuickKeysAttached);
1384 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1385 QQuickItem *i = d->targets.at(ii);
1386 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) {
1388 QVariant v = i->inputMethodQuery(query);
1389 if (v.userType() == QMetaType::QRectF)
1390 v = d->item->mapRectFromItem(i, v.toRectF());
1395 return QQuickItemKeyFilter::inputMethodQuery(query);
1399void QQuickKeysAttached::shortcutOverrideEvent(QKeyEvent *event)
1401 Q_D(QQuickKeysAttached);
1402 QQuickKeyEvent &keyEvent = d->theKeyEvent;
1403 keyEvent.reset(*event);
1404 emit shortcutOverride(&keyEvent);
1406 event->setAccepted(keyEvent.isAccepted());
1409QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
1411 return new QQuickKeysAttached(obj);
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1481
1482
1483
1484
1485
1486
1487
1490QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1492 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1493 itemPrivate = QQuickItemPrivate::get(item);
1494 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1495 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1498 itemPrivate->extra.value().layoutDirectionAttached =
this;
1500 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1503QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1505 return new QQuickLayoutMirroringAttached(object);
1508bool QQuickLayoutMirroringAttached::enabled()
const
1510 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1513void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1518 itemPrivate->isMirrorImplicit =
false;
1519 if (enabled != itemPrivate->effectiveLayoutMirror) {
1520 itemPrivate->setLayoutMirror(enabled);
1521 if (itemPrivate->inheritMirrorFromItem)
1522 itemPrivate->resolveLayoutMirror();
1526void QQuickLayoutMirroringAttached::resetEnabled()
1528 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1529 itemPrivate->isMirrorImplicit =
true;
1530 itemPrivate->resolveLayoutMirror();
1534bool QQuickLayoutMirroringAttached::childrenInherit()
const
1536 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1539void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1540 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1541 itemPrivate->inheritMirrorFromItem = childrenInherit;
1542 itemPrivate->resolveLayoutMirror();
1543 childrenInheritChanged();
1547void QQuickItemPrivate::resolveLayoutMirror()
1550 if (QQuickItem *parentItem = q->parentItem()) {
1551 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1552 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1554 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1558void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1560 inherit = inherit || inheritMirrorFromItem;
1561 if (!isMirrorImplicit && inheritMirrorFromItem)
1562 mirror = effectiveLayoutMirror;
1563 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1566 inheritMirrorFromParent = inherit;
1567 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1569 if (isMirrorImplicit)
1570 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1571 for (
int i = 0; i < childItems.size(); ++i) {
1572 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1573 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1574 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1579void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1581 if (mirror != effectiveLayoutMirror) {
1582 effectiveLayoutMirror = mirror;
1584 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1585 anchor_d->fillChanged();
1586 anchor_d->centerInChanged();
1587 anchor_d->updateHorizontalAnchors();
1590 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1591 emit extra->layoutDirectionAttached->enabledChanged();
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1643QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1644 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1646 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1647 itemPrivate = QQuickItemPrivate::get(item);
1648 itemPrivate->extra.value().enterKeyAttached =
this;
1650 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1653QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1655 return new QQuickEnterKeyAttached(object);
1658Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1663void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1665 if (keyType != type) {
1668 if (itemPrivate && itemPrivate->activeFocus)
1669 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1675void QQuickItemPrivate::setAccessible()
1677 isAccessible =
true;
1681
1682
1683
1684
1685void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1690 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1692 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1694 if (oldSubFocusItem) {
1695 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1696 while (sfi && sfi != scope) {
1697 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1698 sfi = sfi->parentItem();
1703 scopePrivate->subFocusItem = q;
1704 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1705 while (sfi && sfi != scope) {
1706 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1707 sfi = sfi->parentItem();
1710 scopePrivate->subFocusItem =
nullptr;
1715bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1718 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1719 Qt::FocusPolicy policy = Qt::ClickFocus;
1721 switch (eventType) {
1722 case QEvent::MouseButtonPress:
1723 case QEvent::MouseButtonDblClick:
1724 case QEvent::TouchBegin:
1725 if (setFocusOnRelease)
1728 case QEvent::MouseButtonRelease:
1729 case QEvent::TouchEnd:
1730 if (!setFocusOnRelease)
1734 policy = Qt::WheelFocus;
1740 if ((focusPolicy & policy) == policy) {
1741 setActiveFocus(q, Qt::MouseFocusReason);
1748Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1750 return static_cast<Qt::FocusReason>(focusReason);
1753bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1755 if (focusReason == reason)
1758 focusReason = reason;
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2152
2153
2154
2155
2156
2157
2158
2159
2160
2163
2164
2165
2168
2169
2170
2173
2174
2175
2178
2179
2180
2183
2184
2185
2186
2187
2188
2189
2192
2193
2194
2195
2196
2197
2200
2201
2202
2203
2204
2207
2208
2209
2210
2211
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2232
2233
2234
2237
2238
2239
2242
2243
2244
2247
2248
2249
2252
2253
2254
2257
2258
2259
2262
2263
2264
2267
2268
2269
2272
2273
2274
2277
2278
2279
2282
2283
2284
2287
2288
2289
2292
2293
2294
2297
2298
2299
2302
2303
2304
2307
2308
2309
2312
2313
2314
2317
2318
2319
2322
2323
2324
2327
2328
2329
2332
2333
2334
2337
2338
2339
2342
2343
2344
2347
2348
2349
2352
2353
2354
2357
2358
2359
2362
2363
2364
2365
2366
2367
2368
2369QQuickItem::QQuickItem(QQuickItem* parent)
2370: QObject(*(
new QQuickItemPrivate), parent)
2377
2378QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2379: QObject(dd, parent)
2386
2387
2388QQuickItem::~QQuickItem()
2391 d->inDestructor =
true;
2393#if QT_CONFIG(accessibility)
2394 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
2395 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
2398 if (d->windowRefCount > 1)
2399 d->windowRefCount = 1;
2401 setParentItem(
nullptr);
2405 for (QQuickItem *child : std::as_const(d->childItems))
2406 child->setParentItem(
nullptr);
2407 d->childItems.clear();
2409 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2410 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2412 anchor->clearItem(
this);
2415
2416
2417
2418 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2419 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2420 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2423 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2424 d->changeListeners.clear();
2427
2428
2429
2430
2431 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2432 QQuickTransform *t = d->transforms.at(ii);
2433 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2434 tp->items.removeOne(
this);
2437 if (d->extra.isAllocated()) {
2438 delete d->extra->contents; d->extra->contents =
nullptr;
2439#if QT_CONFIG(quick_shadereffect)
2440 delete d->extra->layer; d->extra->layer =
nullptr;
2444 delete d->_anchors; d->_anchors =
nullptr;
2445 delete d->_stateGroup; d->_stateGroup =
nullptr;
2447 d->isQuickItem =
false;
2451
2452
2453bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2455 if (!item->window())
2458 if (item == item->window()->contentItem())
2461 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2462 if (tabFocus == Qt::NoTabFocus)
2464 if (tabFocus == Qt::TabFocusAllControls)
2467 QVariant editable = item->property(
"editable");
2468 if (editable.isValid())
2469 return editable.toBool();
2471 QVariant readonly = item->property(
"readOnly");
2472 if (readonly.isValid())
2473 return !readonly.toBool() && item->property(
"text").isValid();
2475#if QT_CONFIG(accessibility)
2476 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2477 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2479 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2480 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2481 return iface->state().editable;
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2500 QQuickWindow *window = item->window();
2501 const bool wrap = !window || window->isTopLevel();
2503 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2508 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2510 if (!wrap && !next) {
2514 Q_ASSERT(window->parent());
2517 qt_window_private(window->parent())->setFocusToTarget(
2518 forward ? QWindowPrivate::FocusTarget::Next
2519 : QWindowPrivate::FocusTarget::Prev,
2521 window->parent()->requestActivate();
2525 next->forceActiveFocus(reason);
2530QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2533 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2536 const QList<QQuickItem *> &children = item->childItems();
2537 const int count = children.size();
2538 if (start < 0 || start >= count) {
2539 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2542 while (start < count) {
2543 QQuickItem *child = children.at(start);
2544 if (!child->d_func()->isTabFence)
2551QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2554 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2557 const QList<QQuickItem *> &children = item->childItems();
2558 const int count = children.size();
2561 if (start < 0 || start >= count) {
2562 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2565 while (start >= 0) {
2566 QQuickItem *child = children.at(start);
2567 if (!child->d_func()->isTabFence)
2574QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2577 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2579 if (!item->window())
2581 const QQuickItem *
const contentItem = item->window()->contentItem();
2585 QQuickItem *from =
nullptr;
2586 bool isTabFence = item->d_func()->isTabFence;
2589 from = item->parentItem();
2591 if (!item->childItems().isEmpty())
2592 from = item->d_func()->childItems.constFirst();
2593 else if (!isTabFence)
2594 from = item->parentItem();
2598 QQuickItem *startItem = item;
2599 QQuickItem *originalStartItem = startItem;
2604 while (startItem && !startItem->isVisible()) {
2605 startItem = startItem->parentItem();
2610 QQuickItem *firstFromItem = from;
2611 QQuickItem *current = item;
2612 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2613 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2614 QDuplicateTracker<QQuickItem *> cycleDetector;
2616 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2617 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2619 QQuickItem *last = current;
2621 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2622 QQuickItem *firstChild =
nullptr;
2623 QQuickItem *lastChild =
nullptr;
2625 firstChild = nextTabChildItem(current, 0);
2627 hasChildren =
false;
2629 lastChild = prevTabChildItem(current, -1);
2631 isTabFence = current->d_func()->isTabFence;
2632 if (isTabFence && !hasChildren)
2636 if (hasChildren && from == current->parentItem()) {
2638 current = firstChild;
2640 current = lastChild;
2641 if (!current->childItems().isEmpty())
2644 }
else if (hasChildren && forward && from != lastChild) {
2646 int nextChild = current->childItems().indexOf(from) + 1;
2647 current = nextTabChildItem(current, nextChild);
2648 }
else if (hasChildren && !forward && from != firstChild) {
2650 int prevChild = current->childItems().indexOf(from) - 1;
2651 current = prevTabChildItem(current, prevChild);
2652 if (!current->childItems().isEmpty())
2655 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2659 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2660 if (last != firstSibling
2661 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2665 }
else if (hasChildren) {
2667 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2668 <<
"Focus chain about to wrap but wrapping was set to false."
2675 current = firstChild;
2676 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2677 <<
"wrapping from last to first:" << current;
2679 current = lastChild;
2680 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2681 <<
"wrapping from first to last:" << current;
2682 if (!current->childItems().isEmpty())
2694 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2695 (!skip && cycleDetector.hasSeen(current))) {
2697 if (item == contentItem) {
2698 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2701 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2705 if (!firstFromItem) {
2706 if (startItem->d_func()->isTabFence) {
2707 if (current == startItem)
2708 firstFromItem = from;
2710 startItem = current;
2711 firstFromItem = from;
2714 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2715 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2721
2722
2723
2724
2725
2726
2727
2728
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744QQuickItem *QQuickItem::parentItem()
const
2746 Q_D(
const QQuickItem);
2747 return d->parentItem;
2750void QQuickItem::setParentItem(QQuickItem *parentItem)
2753 if (parentItem == d->parentItem)
2757 QQuickItem *itemAncestor = parentItem;
2758 while (itemAncestor !=
nullptr) {
2759 if (Q_UNLIKELY(itemAncestor ==
this)) {
2760 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2763 itemAncestor = itemAncestor->parentItem();
2765 auto engine = qmlEngine(
this);
2767 QV4::ExecutionEngine *v4 = engine->handle();
2768 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2769 QV4::QObjectWrapper::markWrapper(
this, ms);
2774 d->removeFromDirtyList();
2776 QQuickItem *oldParentItem = d->parentItem;
2777 QQuickItem *scopeFocusedItem =
nullptr;
2779 if (oldParentItem) {
2780 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2782 QQuickItem *scopeItem =
nullptr;
2784 if (hasFocus() || op->subFocusItem ==
this)
2785 scopeFocusedItem =
this;
2786 else if (!isFocusScope() && d->subFocusItem)
2787 scopeFocusedItem = d->subFocusItem;
2789 if (scopeFocusedItem) {
2790 scopeItem = oldParentItem;
2791 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2792 scopeItem = scopeItem->parentItem();
2794 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2795 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2796 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2798 if (scopeFocusedItem !=
this)
2799 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2801 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2805 const bool wasVisible = isVisible();
2806 op->removeChild(
this);
2807 if (wasVisible && !op->inDestructor)
2808 emit oldParentItem->visibleChildrenChanged();
2809 }
else if (d->window) {
2810 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2813 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2814 bool alreadyAddedChild =
false;
2815 if (d->window == parentWindow) {
2817 d->parentItem = parentItem;
2819 auto oldParentItem = d->parentItem;
2820 d->parentItem = parentItem;
2821 if (d->parentItem) {
2822 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2823 alreadyAddedChild =
true;
2831 if (!oldParentItem && d->window) {
2832 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2836 d->refWindow(parentWindow);
2839 d->dirty(QQuickItemPrivate::ParentChanged);
2841 if (d->parentItem && !alreadyAddedChild)
2842 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2843 else if (d->window && !alreadyAddedChild)
2844 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2846 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2847 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2849 if (d->parentItem) {
2850 if (!scopeFocusedItem) {
2852 scopeFocusedItem =
this;
2853 else if (!isFocusScope() && d->subFocusItem)
2854 scopeFocusedItem = d->subFocusItem;
2857 if (scopeFocusedItem) {
2859 QQuickItem *scopeItem = d->parentItem;
2860 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2861 scopeItem = scopeItem->parentItem();
2863 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2864 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2865 if (scopeFocusedItem !=
this)
2866 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2867 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2868 emit scopeFocusedItem->focusChanged(
false);
2871 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2872 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2873 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2876 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2883 d->resolveLayoutMirror();
2885 d->itemChange(ItemParentHasChanged, d->parentItem);
2887 if (!d->inDestructor)
2888 emit parentChanged(d->parentItem);
2889 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2890 emit d->parentItem->visibleChildrenChanged();
2892#if QT_CONFIG(accessibility)
2893 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2894 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2895 QAccessible::updateAccessibility(&qaEvent);
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918void QQuickItem::stackBefore(
const QQuickItem *sibling)
2921 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2922 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2923 <<
this <<
" before " << sibling <<
", which must be a sibling";
2927 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2929 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2930 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2932 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2934 if (myIndex == siblingIndex - 1)
2937 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2939 parentPrivate->markSortedChildrenDirty(
this);
2940 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2942 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2943 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964void QQuickItem::stackAfter(
const QQuickItem *sibling)
2967 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2968 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2969 <<
this <<
" after " << sibling <<
", which must be a sibling";
2973 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2975 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2976 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2978 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2980 if (myIndex == siblingIndex + 1)
2983 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2985 parentPrivate->markSortedChildrenDirty(
this);
2986 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2988 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2989 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2993
2994
2997
2998
2999
3000
3001
3002
3003QQuickWindow *QQuickItem::window()
const
3005 Q_D(
const QQuickItem);
3011 return lhs->z() < rhs->z();
3014QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3016 if (sortedChildItems)
3017 return *sortedChildItems;
3022 for (
int i = 0; i < childItems.size(); ++i) {
3023 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3029 sortedChildItems =
new QList<QQuickItem*>(childItems);
3030 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3031 return *sortedChildItems;
3034 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3039void QQuickItemPrivate::addChild(QQuickItem *child)
3043 Q_ASSERT(!childItems.contains(child));
3045 childItems.append(child);
3047 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3049#if QT_CONFIG(cursor)
3052 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3053 setHasCursorInChild(
true);
3056 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3057 setHasHoverInChild(
true);
3059 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3060 markSortedChildrenDirty(child);
3061 dirty(QQuickItemPrivate::ChildrenChanged);
3063 itemChange(QQuickItem::ItemChildAddedChange, child);
3065 emit q->childrenChanged();
3068void QQuickItemPrivate::removeChild(QQuickItem *child)
3073 if (!inDestructor) {
3075 Q_ASSERT(childItems.contains(child));
3076 childItems.removeOne(child);
3077 Q_ASSERT(!childItems.contains(child));
3080 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3082#if QT_CONFIG(cursor)
3084 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3085 setHasCursorInChild(
false);
3088 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3089 setHasHoverInChild(
false);
3091 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3092 if (!inDestructor) {
3093 markSortedChildrenDirty(child);
3094 dirty(QQuickItemPrivate::ChildrenChanged);
3097 itemChange(QQuickItem::ItemChildRemovedChange, child);
3100 emit q->childrenChanged();
3103void QQuickItemPrivate::refWindow(QQuickWindow *c)
3115 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3117 if (++windowRefCount > 1) {
3119 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3123 Q_ASSERT(window ==
nullptr);
3126 if (polishScheduled)
3127 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3130 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3132 for (
int ii = 0; ii < childItems.size(); ++ii) {
3133 QQuickItem *child = childItems.at(ii);
3134 QQuickItemPrivate::get(child)->refWindow(c);
3139 if (extra.isAllocated() && extra->screenAttached)
3140 extra->screenAttached->windowChanged(c);
3141 itemChange(QQuickItem::ItemSceneChange, c);
3144void QQuickItemPrivate::derefWindow()
3147 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3152 if (--windowRefCount > 0)
3155 q->releaseResources();
3156 removeFromDirtyList();
3157 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3158 if (polishScheduled)
3159 c->itemsToPolish.removeOne(q);
3160#if QT_CONFIG(cursor)
3161 if (c->cursorItem == q) {
3162 c->cursorItem =
nullptr;
3163 window->unsetCursor();
3166 if (itemNodeInstance)
3167 c->cleanup(itemNodeInstance);
3169 c->parentlessItems.remove(q);
3171 if (
auto *da = deliveryAgentPrivate()) {
3172 if (da->activeFocusItem == q) {
3173 qCDebug(lcFocus) <<
"Removing active focus item from window's delivery agent";
3174 da->activeFocusItem =
nullptr;
3179 itemNodeInstance =
nullptr;
3181 if (extra.isAllocated()) {
3182 extra->opacityNode =
nullptr;
3183 extra->clipNode =
nullptr;
3184 extra->rootNode =
nullptr;
3187 paintNode =
nullptr;
3189 for (
int ii = 0; ii < childItems.size(); ++ii) {
3190 if (QQuickItem *child = childItems.at(ii))
3191 QQuickItemPrivate::get(child)->derefWindow();
3196 if (extra.isAllocated() && extra->screenAttached)
3197 extra->screenAttached->windowChanged(
nullptr);
3198 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3201qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3203 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3207
3208
3209QTransform QQuickItemPrivate::windowToItemTransform()
const
3212#ifdef QT_BUILD_INTERNAL
3213 ++windowToItemTransform_counter;
3215 return itemToWindowTransform().inverted();
3219
3220
3221QTransform QQuickItemPrivate::itemToWindowTransform()
const
3223#ifdef QT_BUILD_INTERNAL
3224 ++itemToWindowTransform_counter;
3227 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3228 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3229 itemToParentTransform(&rv);
3234
3235
3236void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3238#ifdef QT_BUILD_INTERNAL
3239 ++itemToParentTransform_counter;
3242
3243
3244
3245
3246
3248 qreal x =
this->x.valueBypassingBindings();
3249 qreal y =
this->y.valueBypassingBindings();
3253 if (!transforms.isEmpty()) {
3255 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3256 transforms.at(ii)->applyTo(&m);
3257 *t = m.toTransform();
3260 if (scale() != 1. || rotation() != 0.) {
3261 QPointF tp = computeTransformOrigin();
3262 t->translate(tp.x(), tp.y());
3263 t->scale(scale(), scale());
3264 t->rotate(rotation());
3265 t->translate(-tp.x(), -tp.y());
3270
3271
3272
3273
3274
3275
3276
3277
3278bool QQuickItem::isComponentComplete()
const
3280 Q_D(
const QQuickItem);
3281 return d->componentComplete;
3284QQuickItemPrivate::QQuickItemPrivate()
3286 , _stateGroup(
nullptr)
3288 , widthValidFlag(
false)
3289 , heightValidFlag(
false)
3290 , componentComplete(
true)
3293 , hoverEnabled(
false)
3295 , antialiasing(
false)
3297 , activeFocus(
false)
3298 , notifiedFocus(
false)
3299 , notifiedActiveFocus(
false)
3300 , filtersChildMouseEvents(
false)
3301 , explicitVisible(
true)
3302 , effectiveVisible(
true)
3303 , explicitEnable(
true)
3304 , effectiveEnable(
true)
3305 , polishScheduled(
false)
3306 , inheritedLayoutMirror(
false)
3307 , effectiveLayoutMirror(
false)
3308 , isMirrorImplicit(
true)
3309 , inheritMirrorFromParent(
false)
3310 , inheritMirrorFromItem(
false)
3311 , isAccessible(
false)
3314 , subtreeCursorEnabled(
false)
3315 , subtreeHoverEnabled(
false)
3316 , activeFocusOnTab(
false)
3317 , implicitAntialiasing(
false)
3318 , antialiasingValid(
false)
3320 , replayingPressEvent(
false)
3321 , touchEnabled(
false)
3322 , hasCursorHandler(
false)
3323 , maybeHasSubsceneDeliveryAgent(
true)
3324 , subtreeTransformChangedEnabled(
true)
3325 , inDestructor(
false)
3326 , focusReason(Qt::OtherFocusReason)
3327 , focusPolicy(Qt::NoFocus)
3328 , eventHandlingChildrenWithinBounds(
false)
3329 , eventHandlingChildrenWithinBoundsSet(
false)
3330 , customOverlay(
false)
3331 , dirtyAttributes(0)
3332 , nextDirtyItem(
nullptr)
3333 , prevDirtyItem(
nullptr)
3336 , parentItem(
nullptr)
3337 , sortedChildItems(&childItems)
3338 , subFocusItem(
nullptr)
3346 , itemNodeInstance(
nullptr)
3347 , paintNode(
nullptr)
3348 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3350#ifdef QT_BUILD_INTERNAL
3355QQuickItemPrivate::~QQuickItemPrivate()
3357 if (sortedChildItems != &childItems)
3358 delete sortedChildItems;
3361void QQuickItemPrivate::init(QQuickItem *parent)
3367 baselineOffset = 0.0;
3370 q->setParentItem(parent);
3371 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3372 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3376QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3381void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3383 szPolicy.setHorizontalPolicy(horizontalPolicy);
3384 szPolicy.setVerticalPolicy(verticalPolicy);
3387void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3392 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3394 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3395 item->setParentItem(that);
3396 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3397 if (pointerHandler->parent() != that) {
3398 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3399 pointerHandler->setParent(that);
3401 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3404 resources_append(prop, o);
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3443qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3445 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3446 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3447 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3448 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3450 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3453QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3455 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3456 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3457 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3458 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3460 qsizetype resourcesCount = resources_count(&resourcesProperty);
3461 if (i < resourcesCount)
3462 return resources_at(&resourcesProperty, i);
3463 const qsizetype j = i - resourcesCount;
3464 if (j < children_count(&childrenProperty))
3465 return children_at(&childrenProperty, j);
3469void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3471 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3472 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3473 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3474 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3476 resources_clear(&resourcesProperty);
3477 children_clear(&childrenProperty);
3480void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3482 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3483 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3485 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3486 if (children_count(&childrenProperty) > 0) {
3487 children_removeLast(&childrenProperty);
3491 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3492 if (resources_count(&resourcesProperty) > 0)
3493 resources_removeLast(&resourcesProperty);
3496QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3498 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3499 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3502void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3504 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3505 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3506 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3507 quickItemPrivate->extra.value().resourcesList.append(object);
3508 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3509 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3513qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3515 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3516 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3519void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3521 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3522 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3523 if (quickItemPrivate->extra.isAllocated()) {
3524 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3525 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3526 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3528 quickItemPrivate->extra->resourcesList.clear();
3532void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3534 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3535 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3536 if (quickItemPrivate->extra.isAllocated()) {
3537 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3538 if (resources->isEmpty())
3541 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3542 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3543 resources->removeLast();
3547QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3549 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3550 if (index >= p->childItems.size() || index < 0)
3553 return p->childItems.at(index);
3556void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3561 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3562 if (o->parentItem() == that)
3563 o->setParentItem(
nullptr);
3565 o->setParentItem(that);
3568qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3570 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3571 return p->childItems.size();
3574void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3576 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3577 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3578 while (!p->childItems.isEmpty())
3579 p->childItems.at(0)->setParentItem(
nullptr);
3582void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3584 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3585 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3586 if (!p->childItems.isEmpty())
3587 p->childItems.last()->setParentItem(
nullptr);
3590qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3592 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3593 qsizetype visibleCount = 0;
3594 qsizetype c = p->childItems.size();
3596 if (p->childItems.at(c)->isVisible()) visibleCount++;
3599 return visibleCount;
3602QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3604 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3605 const qsizetype childCount = p->childItems.size();
3606 if (index >= childCount || index < 0)
3609 qsizetype visibleCount = -1;
3610 for (qsizetype i = 0; i < childCount; i++) {
3611 if (p->childItems.at(i)->isVisible()) visibleCount++;
3612 if (visibleCount == index)
return p->childItems.at(i);
3617qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3619 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3620 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3622 return p->transforms.size();
3625void QQuickTransform::appendToItem(QQuickItem *item)
3627 Q_D(QQuickTransform);
3631 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3633 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3634 p->transforms.removeOne(
this);
3635 p->transforms.append(
this);
3637 p->transforms.append(
this);
3638 d->items.append(item);
3641 p->dirty(QQuickItemPrivate::Transform);
3644void QQuickTransform::prependToItem(QQuickItem *item)
3646 Q_D(QQuickTransform);
3650 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3652 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3653 p->transforms.removeOne(
this);
3654 p->transforms.prepend(
this);
3656 p->transforms.prepend(
this);
3657 d->items.append(item);
3660 p->dirty(QQuickItemPrivate::Transform);
3663void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3668 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3669 transform->appendToItem(that);
3672QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3674 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3675 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3677 if (idx < 0 || idx >= p->transforms.size())
3680 return p->transforms.at(idx);
3683void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3685 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3686 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3688 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3689 QQuickTransform *t = p->transforms.at(ii);
3690 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3691 tp->items.removeOne(that);
3694 p->transforms.clear();
3696 p->dirty(QQuickItemPrivate::Transform);
3699void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3701 if (extra.isAllocated() && extra->resourcesList.contains(object))
3702 extra->resourcesList.removeAll(object);
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799QQuickAnchors *QQuickItemPrivate::anchors()
const
3802 Q_Q(
const QQuickItem);
3803 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3804 if (!componentComplete)
3805 _anchors->classBegin();
3810void QQuickItemPrivate::siblingOrderChanged()
3813 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3816QQmlListProperty<QObject> QQuickItemPrivate::data()
3820 QQmlListProperty<QObject> result;
3821 result.object = q_func();
3822 result.append = QQuickItemPrivate::data_append;
3823 result.count = QQuickItemPrivate::data_count;
3824 result.at = QQuickItemPrivate::data_at;
3825 result.clear = QQuickItemPrivate::data_clear;
3826 result.removeLast = QQuickItemPrivate::data_removeLast;
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861QRectF QQuickItem::childrenRect()
3864 if (!d->extra.isAllocated() || !d->extra->contents) {
3865 d->extra.value().contents =
new QQuickContents(
this);
3866 if (d->componentComplete)
3867 d->extra->contents->complete();
3869 return d->extra->contents->rectF();
3873
3874
3875QList<QQuickItem *> QQuickItem::childItems()
const
3877 Q_D(
const QQuickItem);
3878 return d->childItems;
3882
3883
3884
3885
3886
3887
3888
3889
3890
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909bool QQuickItem::clip()
const
3911 return flags() & ItemClipsChildrenToShape;
3914void QQuickItem::setClip(
bool c)
3919 setFlag(ItemClipsChildrenToShape, c);
3921 setFlag(ItemIsViewport);
3922 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3923 setFlag(ItemIsViewport,
false);
3925 emit clipChanged(c);
3929
3930
3931
3932
3933
3934
3935
3936
3937void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3942 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3944 QQuickGeometryChange change;
3945 change.setXChange(newGeometry.x() != oldGeometry.x());
3946 change.setYChange(newGeometry.y() != oldGeometry.y());
3947 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3948 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3950 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3951 if (change.matches(listener.gTypes))
3952 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3957 if (change.xChange())
3959 if (change.yChange())
3961 if (change.widthChange())
3963 if (change.heightChange())
3965#if QT_CONFIG(accessibility)
3966 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3967 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3968 QAccessible::updateAccessibility(&ev);
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4027QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4029 Q_UNUSED(updatePaintNodeData);
4034QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4035: transformNode(
nullptr)
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4056void QQuickItem::releaseResources()
4060QSGTransformNode *QQuickItemPrivate::createTransformNode()
4062 return new QSGTransformNode;
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075void QQuickItem::updatePolish()
4079#define PRINT_LISTENERS() do
4081 qDebug().nospace() << q_func() << " (" << this
4082 << ") now has the following listeners:";
4083 for (const auto &listener : std::as_const(changeListeners)) {
4084 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4085 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4087}while
4090void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4093 changeListeners.append(ChangeListener(listener, types));
4094 listener->addSourceItem(q);
4096 if (lcChangeListeners().isDebugEnabled())
4100void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4104 const ChangeListener changeListener(listener, types);
4105 const int index = changeListeners.indexOf(changeListener);
4107 changeListeners[index].types = changeListener.types;
4109 changeListeners.append(changeListener);
4110 listener->addSourceItem(q);
4113 if (lcChangeListeners().isDebugEnabled())
4117void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4121 ChangeListener change(listener, types);
4122 changeListeners.removeOne(change);
4123 listener->removeSourceItem(q);
4125 if (lcChangeListeners().isDebugEnabled())
4129void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4130 QQuickGeometryChange types)
4134 ChangeListener change(listener, types);
4135 int index = changeListeners.indexOf(change);
4137 changeListeners[index].gTypes = change.gTypes;
4139 changeListeners.append(change);
4140 listener->addSourceItem(q);
4143 if (lcChangeListeners().isDebugEnabled())
4147void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4148 QQuickGeometryChange types)
4152 ChangeListener change(listener, types);
4153 if (types.noChange()) {
4154 changeListeners.removeOne(change);
4155 listener->removeSourceItem(q);
4157 int index = changeListeners.indexOf(change);
4159 changeListeners[index].gTypes = change.gTypes;
4162 if (lcChangeListeners().isDebugEnabled())
4167
4168
4169
4170
4171
4172
4173void QQuickItem::keyPressEvent(QKeyEvent *event)
4179
4180
4181
4182
4183
4184
4185void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4192
4193
4194
4195
4196
4197
4198void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214void QQuickItem::focusInEvent(QFocusEvent *event)
4217#if QT_CONFIG(accessibility)
4218 if (QAccessible::isActive()) {
4219 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4220 QAccessibleEvent ev(acc, QAccessible::Focus);
4221 QAccessible::updateAccessibility(&ev);
4225 d->setLastFocusChangeReason(event->reason());
4229
4230
4231
4232
4233
4234
4235void QQuickItem::focusOutEvent(QFocusEvent *event)
4238 d->setLastFocusChangeReason(event->reason());
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251void QQuickItem::mousePressEvent(QMouseEvent *event)
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4289
4290
4291
4292
4293
4294
4295void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4301
4302
4303
4304void QQuickItem::mouseUngrabEvent()
4310
4311
4312
4313void QQuickItem::touchUngrabEvent()
4318#if QT_CONFIG(wheelevent)
4320
4321
4322
4323
4324
4325
4326void QQuickItem::wheelEvent(QWheelEvent *event)
4333
4334
4335
4336
4337
4338
4339void QQuickItem::touchEvent(QTouchEvent *event)
4345
4346
4347
4348
4349
4350
4351
4352
4353void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4359
4360
4361
4362
4363
4364
4365
4366
4367void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4373
4374
4375
4376
4377
4378
4379
4380
4381void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4386#if QT_CONFIG(quick_draganddrop)
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450void QQuickItem::dropEvent(QDropEvent *event)
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4495
4496
4497
4498
4499
4500
4501
4502QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4504 Q_D(
const QQuickItem);
4509 v = (
bool)(flags() & ItemAcceptsInputMethod);
4512 case Qt::ImAnchorRectangle:
4513 case Qt::ImCursorRectangle:
4515 case Qt::ImCursorPosition:
4516 case Qt::ImSurroundingText:
4517 case Qt::ImCurrentSelection:
4518 case Qt::ImMaximumTextLength:
4519 case Qt::ImAnchorPosition:
4520 case Qt::ImPreferredLanguage:
4521 case Qt::ImReadOnly:
4522 if (d->extra.isAllocated() && d->extra->keyHandler)
4523 v = d->extra->keyHandler->inputMethodQuery(query);
4525 case Qt::ImEnterKeyType:
4526 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4527 v = d->extra->enterKeyAttached->type();
4529 case Qt::ImInputItemClipRectangle:
4530 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4531 QRectF rect = QRectF(0,0, width(), height());
4532 const QQuickItem *par =
this;
4533 while (QQuickItem *parpar = par->parentItem()) {
4534 rect = parpar->mapRectFromItem(par, rect);
4536 rect = rect.intersected(parpar->clipRect());
4539 rect = par->mapRectToScene(rect);
4541 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4543 v = mapRectFromScene(rect);
4554QQuickAnchorLine QQuickItemPrivate::left()
const
4556 Q_Q(
const QQuickItem);
4557 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4560QQuickAnchorLine QQuickItemPrivate::right()
const
4562 Q_Q(
const QQuickItem);
4563 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4566QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4568 Q_Q(
const QQuickItem);
4569 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4572QQuickAnchorLine QQuickItemPrivate::top()
const
4574 Q_Q(
const QQuickItem);
4575 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4578QQuickAnchorLine QQuickItemPrivate::bottom()
const
4580 Q_Q(
const QQuickItem);
4581 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4584QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4586 Q_Q(
const QQuickItem);
4587 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4590QQuickAnchorLine QQuickItemPrivate::baseline()
const
4592 Q_Q(
const QQuickItem);
4593 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618qreal QQuickItem::baselineOffset()
const
4620 Q_D(
const QQuickItem);
4621 return d->baselineOffset;
4624void QQuickItem::setBaselineOffset(qreal offset)
4627 if (offset == d->baselineOffset)
4630 d->baselineOffset = offset;
4632 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4633 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4635 anchor->updateVerticalAnchors();
4638 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4639 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4641 emit baselineOffsetChanged(offset);
4646
4647
4648
4649
4650
4651
4652
4653
4654void QQuickItem::update()
4657 if (!(flags() & ItemHasContents)) {
4659 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4663 d->dirty(QQuickItemPrivate::Content);
4667
4668
4669
4670
4671
4672
4673
4674void QQuickItem::polish()
4677 if (!d->polishScheduled) {
4678 d->polishScheduled =
true;
4680 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4681 bool maybeupdate = p->itemsToPolish.isEmpty();
4682 p->itemsToPolish.append(
this);
4683 if (maybeupdate) d->window->maybeUpdate();
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703void QQuickItem::ensurePolished()
4708#if QT_DEPRECATED_SINCE(6
, 5
)
4709static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4710 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4712 QV4::ExecutionEngine *v4 = args->v4engine();
4713 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4714 v4->throwTypeError();
4718 QV4::Scope scope(v4);
4719 QV4::ScopedValue item(scope, (*args)[0]);
4722 if (!item->isNull()) {
4723 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4725 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4728 if (!(*itemObj) && !item->isNull()) {
4729 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4730 <<
"\" which is neither null nor an Item";
4731 v4->throwTypeError();
4737 if (args->length() == 2) {
4738 QV4::ScopedValue sv(scope, (*args)[1]);
4740 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4741 <<
"\" which is neither a point nor a rect";
4742 v4->throwTypeError();
4745 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4746 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4747 if (v.canConvert<QPointF>()) {
4748 const QPointF p = v.toPointF();
4751 }
else if (v.canConvert<QRectF>()) {
4752 const QRectF r = v.toRectF();
4759 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4760 <<
"\" which is neither a point nor a rect";
4761 v4->throwTypeError();
4765 QV4::ScopedValue vx(scope, (*args)[1]);
4766 QV4::ScopedValue vy(scope, (*args)[2]);
4768 if (!vx->isNumber() || !vy->isNumber()) {
4769 v4->throwTypeError();
4773 *x = vx->asDouble();
4774 *y = vy->asDouble();
4776 if (args->length() > 3) {
4777 QV4::ScopedValue vw(scope, (*args)[3]);
4778 QV4::ScopedValue vh(scope, (*args)[4]);
4779 if (!vw->isNumber() || !vh->isNumber()) {
4780 v4->throwTypeError();
4783 *w = vw->asDouble();
4784 *h = vh->asDouble();
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4811#if QT_DEPRECATED_SINCE(6
, 5
)
4813
4814
4815void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4817 QV4::ExecutionEngine *v4 = args->v4engine();
4818 QV4::Scope scope(v4);
4822 QQuickItem *itemObj;
4823 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4826 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4827 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4829 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4830 args->setReturnValue(rv.asReturnedValue());
4835
4836
4837QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4839 Q_D(
const QQuickItem);
4845 QTransform t = d->itemToWindowTransform();
4846 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4869#if QT_DEPRECATED_SINCE(6
, 5
)
4871
4872
4873void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4875 QV4::ExecutionEngine *v4 = args->v4engine();
4876 QV4::Scope scope(v4);
4880 QQuickItem *itemObj;
4881 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4884 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4885 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4887 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4888 args->setReturnValue(rv.asReturnedValue());
4891static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4893 QV4::ExecutionEngine *v4 = args->v4engine();
4894 if (args->length() != 1 && args->length() != 2) {
4895 v4->throwTypeError();
4899 QV4::Scope scope(v4);
4901 if (args->length() == 1) {
4902 QV4::ScopedValue sv(scope, (*args)[0]);
4904 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4905 <<
"\" which is not a point";
4906 v4->throwTypeError();
4909 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4910 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4911 if (v.canConvert<QPointF>()) {
4912 const QPointF p = v.toPointF();
4916 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4917 <<
"\" which is not a point";
4918 v4->throwTypeError();
4922 QV4::ScopedValue vx(scope, (*args)[0]);
4923 QV4::ScopedValue vy(scope, (*args)[1]);
4925 if (!vx->isNumber() || !vy->isNumber()) {
4926 v4->throwTypeError();
4930 *x = vx->asDouble();
4931 *y = vy->asDouble();
4938
4939
4940
4941
4942
4943
4944
4945
4947
4948
4949void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4951 QV4::ExecutionEngine *v4 = args->v4engine();
4952 QV4::Scope scope(v4);
4955 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4958 QVariant result = mapFromGlobal(QPointF(x, y));
4960 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4961 args->setReturnValue(rv.asReturnedValue());
4966
4967
4968
4969
4970
4971
4972
4973
4975#if QT_DEPRECATED_SINCE(6
, 5
)
4977
4978
4979void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4981 QV4::ExecutionEngine *v4 = args->v4engine();
4982 QV4::Scope scope(v4);
4985 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4988 QVariant result = mapToGlobal(QPointF(x, y));
4990 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4991 args->setReturnValue(rv.asReturnedValue());
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021void QQuickItem::forceActiveFocus()
5023 forceActiveFocus(Qt::OtherFocusReason);
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5051void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5053 setFocus(
true, reason);
5054 QQuickItem *parent = parentItem();
5055 QQuickItem *scope =
nullptr;
5057 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5058 parent->setFocus(
true, reason);
5062 parent = parent->parentItem();
5067
5068
5069
5070
5071
5072
5073
5074
5075
5077
5078
5079
5080
5081
5083QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5085 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5089
5090
5091
5092
5093
5094
5095
5097
5098
5099
5100
5101
5102QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5104 const QList<QQuickItem *> children = childItems();
5105 for (
int i = children.size()-1; i >= 0; --i) {
5106 QQuickItem *child = children.at(i);
5108 QPointF point = mapToItem(child, QPointF(x, y));
5109 if (child->isVisible() && child->contains(point))
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156void QQuickItem::dumpItemTree()
const
5158 Q_D(
const QQuickItem);
5162void QQuickItemPrivate::dumpItemTree(
int indent)
const
5164 Q_Q(
const QQuickItem);
5166 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5167 qDebug().nospace().noquote() << indentStr <<
5168#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5169 const_cast<QQuickItem *>(q);
5173 if (extra.isAllocated()) {
5174 for (
const auto handler : extra->pointerHandlers)
5175 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5177 for (
const QQuickItem *ch : childItems) {
5178 auto itemPriv = QQuickItemPrivate::get(ch);
5179 itemPriv->dumpItemTree(indent + 1);
5183QQmlListProperty<QObject> QQuickItemPrivate::resources()
5187 QQmlListProperty<QObject> result;
5188 result.object = q_func();
5189 result.append = QQuickItemPrivate::resources_append;
5190 result.count = QQuickItemPrivate::resources_count;
5191 result.at = QQuickItemPrivate::resources_at;
5192 result.clear = QQuickItemPrivate::resources_clear;
5193 result.removeLast = QQuickItemPrivate::resources_removeLast;
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5211
5212
5213
5214QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5218 QQmlListProperty<QQuickItem> result;
5219 result.object = q_func();
5220 result.append = QQuickItemPrivate::children_append;
5221 result.count = QQuickItemPrivate::children_count;
5222 result.at = QQuickItemPrivate::children_at;
5223 result.clear = QQuickItemPrivate::children_clear;
5224 result.removeLast = QQuickItemPrivate::children_removeLast;
5229
5230
5231
5232
5233
5235
5236
5237
5238QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5240 return QQmlListProperty<QQuickItem>(q_func(),
5242 QQuickItemPrivate::visibleChildren_count,
5243 QQuickItemPrivate::visibleChildren_at);
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5284
5285
5286
5287QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5289 return _states()->statesProperty();
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5321
5322
5323
5324QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5326 return _states()->transitionsProperty();
5329QString QQuickItemPrivate::state()
const
5334 return _stateGroup->state();
5337void QQuickItemPrivate::setState(
const QString &state)
5339 _states()->setState(state);
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364QString QQuickItem::state()
const
5366 Q_D(
const QQuickItem);
5370void QQuickItem::setState(
const QString &state)
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5389
5390
5391
5393
5394
5395QQmlListProperty<QQuickTransform> QQuickItem::transform()
5397 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5398 QQuickItemPrivate::transform_count,
5399 QQuickItemPrivate::transform_at,
5400 QQuickItemPrivate::transform_clear);
5404
5405
5406
5407
5408void QQuickItem::classBegin()
5411 d->componentComplete =
false;
5413 d->_stateGroup->classBegin();
5415 d->_anchors->classBegin();
5416#if QT_CONFIG(quick_shadereffect)
5417 if (d->extra.isAllocated() && d->extra->layer)
5418 d->extra->layer->classBegin();
5423
5424
5425
5426
5427void QQuickItem::componentComplete()
5430 d->componentComplete =
true;
5432 d->_stateGroup->componentComplete();
5434 d->_anchors->componentComplete();
5435 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5438 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5439 safeArea->updateSafeArea();
5441 if (d->extra.isAllocated()) {
5442#if QT_CONFIG(quick_shadereffect)
5443 if (d->extra->layer)
5444 d->extra->layer->componentComplete();
5447 if (d->extra->keyHandler)
5448 d->extra->keyHandler->componentComplete();
5450 if (d->extra->contents)
5451 d->extra->contents->complete();
5454 if (d->window && d->dirtyAttributes) {
5455 d->addToDirtyList();
5456 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5459#if QT_CONFIG(accessibility)
5460 if (d->isAccessible && d->effectiveVisible) {
5461 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5462 QAccessible::updateAccessibility(&ev);
5467QQuickStateGroup *QQuickItemPrivate::_states()
5471 _stateGroup =
new QQuickStateGroup;
5472 if (!componentComplete)
5473 _stateGroup->classBegin();
5474 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5475 q, QQuickItem, SIGNAL(stateChanged(QString)));
5481bool QQuickItemPrivate::customOverlayRequested =
false;
5483void QQuickItemPrivate::requestCustomOverlay()
5485 customOverlayRequested =
true;
5486 customOverlay =
true;
5489QPointF QQuickItemPrivate::computeTransformOrigin()
const
5493 case QQuickItem::TopLeft:
5494 return QPointF(0, 0);
5495 case QQuickItem::Top:
5496 return QPointF(width / 2., 0);
5497 case QQuickItem::TopRight:
5498 return QPointF(width, 0);
5499 case QQuickItem::Left:
5500 return QPointF(0, height / 2.);
5501 case QQuickItem::Center:
5502 return QPointF(width / 2., height / 2.);
5503 case QQuickItem::Right:
5504 return QPointF(width, height / 2.);
5505 case QQuickItem::BottomLeft:
5506 return QPointF(0, height);
5507 case QQuickItem::Bottom:
5508 return QPointF(width / 2., height);
5509 case QQuickItem::BottomRight:
5510 return QPointF(width, height);
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5532#if QT_CONFIG(quick_shadereffect)
5533 if (q == transformedItem) {
5534 if (extra.isAllocated() && extra->layer)
5535 extra->layer->updateMatrix();
5539 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5541 bool childWantsIt =
false;
5542 if (subtreeTransformChangedEnabled) {
5545 const auto children = paintOrderChildItems();
5546 for (QQuickItem *child : children)
5547 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5550 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5551 const bool ret = childWantsIt || thisWantsIt;
5552 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5553 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5554 subtreeTransformChangedEnabled =
false;
5558 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5559 dirty(QQuickItemPrivate::Clip);
5564 QQuickItemPrivate *itemPriv =
this;
5565 while (itemPriv->parentItem) {
5566 auto *parentPriv = QQuickItemPrivate::get(itemPriv->parentItem);
5567 if (parentPriv->eventHandlingChildrenWithinBounds) {
5568 Q_ASSERT(parentPriv->eventHandlingChildrenWithinBoundsSet);
5569 if (itemPriv->parentFullyContains())
5572 parentPriv->eventHandlingChildrenWithinBounds =
false;
5574 itemPriv = parentPriv;
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5597 const QPointF &startPos,
5598 const QVector2D &activeTranslation,
5601 qreal startRotation,
5602 qreal activeRotation)
5605 QVector3D xformOrigin(q->transformOriginPoint());
5606 QMatrix4x4 startMatrix;
5607 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5608 startMatrix.translate(xformOrigin);
5609 startMatrix.scale(
float(startScale));
5610 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5611 startMatrix.translate(-xformOrigin);
5613 const QVector3D centroidParentVector(centroidParentPos);
5615 mat.translate(centroidParentVector);
5616 mat.rotate(
float(activeRotation), 0, 0, 1);
5617 mat.scale(
float(activeScale));
5618 mat.translate(-centroidParentVector);
5619 mat.translate(QVector3D(activeTranslation));
5621 mat = mat * startMatrix;
5623 QPointF xformOriginPoint = q->transformOriginPoint();
5624 QPointF pos = mat.map(xformOriginPoint);
5625 pos -= xformOriginPoint;
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5655 if (maybeHasSubsceneDeliveryAgent) {
5656 QQuickItemPrivate *p =
this;
5658 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5663 maybeHasSubsceneDeliveryAgent =
false;
5666 if (p->extra.isAllocated()) {
5667 if (
auto da = p->extra->subsceneDeliveryAgent)
5670 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5674 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5677 return QQuickWindowPrivate::get(window)->deliveryAgent;
5681QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5683 auto da = deliveryAgent();
5684 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5688
5689
5690
5691
5692
5693
5694
5695QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5701 maybeHasSubsceneDeliveryAgent =
true;
5702 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5703 return extra->subsceneDeliveryAgent;
5704 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5705 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5708 q->setFlag(QQuickItem::ItemIsFocusScope);
5709 return extra->subsceneDeliveryAgent;
5712bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5714 if (!extra.isAllocated() || !extra->keyHandler)
5720 if (e->type() == QEvent::KeyPress)
5721 extra->keyHandler->keyPressed(e, post);
5723 extra->keyHandler->keyReleased(e, post);
5725 return e->isAccepted();
5728void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5731 const auto eventType = event->type();
5732 const bool focusAccepted = setFocusIfNeeded(eventType);
5734 switch (eventType) {
5735 case QEvent::MouseButtonPress:
5736 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5738 case QEvent::MouseButtonRelease:
5739 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5741 case QEvent::MouseButtonDblClick:
5742 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5744#if QT_CONFIG(wheelevent)
5746 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5749 case QEvent::TouchBegin:
5750 case QEvent::TouchUpdate:
5751 case QEvent::TouchEnd:
5752 case QEvent::TouchCancel:
5753 q->touchEvent(
static_cast<QTouchEvent *>(event));
5763void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5767 Q_ASSERT(e->isAccepted());
5768 if (filterKeyEvent(e,
false))
5773 if (e->type() == QEvent::KeyPress)
5774 q->keyPressEvent(e);
5776 q->keyReleaseEvent(e);
5778 if (e->isAccepted())
5781 if (filterKeyEvent(e,
true) || !q->window())
5785 if (e->type() == QEvent::KeyPress &&
5786 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5788 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5789 if (e->key() == Qt::Key_Backtab
5790 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5791 res = QQuickItemPrivate::focusNextPrev(q,
false);
5792 else if (e->key() == Qt::Key_Tab)
5793 res = QQuickItemPrivate::focusNextPrev(q,
true);
5795 e->setAccepted(
true);
5801void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5805 Q_ASSERT(e->isAccepted());
5806 if (extra.isAllocated() && extra->keyHandler) {
5807 extra->keyHandler->inputMethodEvent(e,
false);
5809 if (e->isAccepted())
5815 q->inputMethodEvent(e);
5817 if (e->isAccepted())
5820 if (extra.isAllocated() && extra->keyHandler) {
5823 extra->keyHandler->inputMethodEvent(e,
true);
5828void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5830 if (extra.isAllocated() && extra->keyHandler)
5831 extra->keyHandler->shortcutOverrideEvent(event);
5836bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5838 if (!hasPointerHandlers())
5840 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5841 if (handler->wantsEventPoint(event, point))
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5863 bool delivered =
false;
5864 if (extra.isAllocated()) {
5865 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5866 bool avoidThisHandler =
false;
5867 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5868 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5869 avoidThisHandler =
true;
5870 }
else if (avoidGrabbers) {
5871 for (
auto &p : event->points()) {
5872 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5873 avoidThisHandler =
true;
5878 if (!avoidThisHandler &&
5879 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5880 handler->handlePointerEvent(event);
5888#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5889bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5891bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5894 if (extra.isAllocated() && extra->contextMenu)
5895 return extra->contextMenu->event(event);
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5915 if (change == ItemSceneChange)
5916 emit windowChanged(value.window);
5921
5922
5923
5924void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5926 if (hasActiveFocus())
5927 QGuiApplication::inputMethod()->update(queries);
5932
5933
5934
5935QRectF QQuickItem::boundingRect()
const
5937 Q_D(
const QQuickItem);
5938 return QRectF(0, 0, d->width, d->height);
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962QRectF QQuickItem::clipRect()
const
5964 Q_D(
const QQuickItem);
5965 QRectF ret(0, 0, d->width.valueBypassingBindings(), d->height.valueBypassingBindings());
5966 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5967 if (QQuickItem *viewport = viewportItem()) {
5970 if (viewport ==
this)
5972 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5973 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5974 return mappedViewportRect.intersected(ret);
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991QQuickItem *QQuickItem::viewportItem()
const
5993 if (flags().testFlag(ItemObservesViewport)) {
5994 QQuickItem *par = parentItem();
5996 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
5998 par = par->parentItem();
6001 return (window() ? window()->contentItem() :
nullptr);
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6026
6027
6028
6029
6030
6031
6032
6033
6034QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6036 Q_D(
const QQuickItem);
6040void QQuickItem::setTransformOrigin(TransformOrigin origin)
6043 if (origin == d->origin())
6046 d->extra.value().origin = origin;
6047 d->dirty(QQuickItemPrivate::TransformOrigin);
6049 emit transformOriginChanged(d->origin());
6053
6054
6055
6057
6058
6059QPointF QQuickItem::transformOriginPoint()
const
6061 Q_D(
const QQuickItem);
6062 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6063 return d->extra->userTransformOriginPoint;
6064 return d->computeTransformOrigin();
6068
6069
6070void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6073 if (d->extra.value().userTransformOriginPoint == point)
6076 d->extra->userTransformOriginPoint = point;
6077 d->dirty(QQuickItemPrivate::TransformOrigin);
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234qreal QQuickItem::z()
const
6236 Q_D(
const QQuickItem);
6240void QQuickItem::setZ(qreal v)
6246 d->extra.value().z = v;
6248 d->dirty(QQuickItemPrivate::ZValue);
6249 if (d->parentItem) {
6250 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6251 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6256#if QT_CONFIG(quick_shadereffect)
6257 if (d->extra.isAllocated() && d->extra->layer)
6258 d->extra->layer->updateZ();
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314qreal QQuickItem::rotation()
const
6316 Q_D(
const QQuickItem);
6317 return d->rotation();
6320void QQuickItem::setRotation(qreal r)
6323 if (d->rotation() == r)
6326 d->extra.value().rotation = r;
6328 d->dirty(QQuickItemPrivate::BasicTransform);
6330 d->itemChange(ItemRotationHasChanged, r);
6332 emit rotationChanged();
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414qreal QQuickItem::scale()
const
6416 Q_D(
const QQuickItem);
6420void QQuickItem::setScale(qreal s)
6423 if (d->scale() == s)
6426 d->extra.value().scale = s;
6428 d->dirty(QQuickItemPrivate::BasicTransform);
6430 d->itemChange(ItemScaleHasChanged, s);
6432 emit scaleChanged();
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545qreal QQuickItem::opacity()
const
6547 Q_D(
const QQuickItem);
6548 return d->opacity();
6551void QQuickItem::setOpacity(qreal newOpacity)
6554 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6555 if (d->opacity() == o)
6558 d->extra.value().opacity = o;
6560 d->dirty(QQuickItemPrivate::OpacityValue);
6562 d->itemChange(ItemOpacityHasChanged, o);
6564 emit opacityChanged();
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631bool QQuickItem::isVisible()
const
6633 Q_D(
const QQuickItem);
6634 return d->effectiveVisible;
6637void QQuickItemPrivate::setVisible(
bool visible)
6639 if (visible == explicitVisible)
6642 explicitVisible = visible;
6644 dirty(QQuickItemPrivate::Visible);
6646 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6647 if (childVisibilityChanged && parentItem)
6648 emit parentItem->visibleChildrenChanged();
6651void QQuickItem::setVisible(
bool v)
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706bool QQuickItem::isEnabled()
const
6708 Q_D(
const QQuickItem);
6709 return d->effectiveEnable;
6712void QQuickItem::setEnabled(
bool e)
6715 if (e == d->explicitEnable)
6718 d->explicitEnable = e;
6720 QQuickItem *scope = parentItem();
6721 while (scope && !scope->isFocusScope())
6722 scope = scope->parentItem();
6724 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6727bool QQuickItemPrivate::calcEffectiveVisible()
const
6730 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6733bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6737 if (newEffectiveVisible && !explicitVisible) {
6742 if (newEffectiveVisible == effectiveVisible) {
6747 effectiveVisible = newEffectiveVisible;
6750 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6752 if (
auto agent = deliveryAgentPrivate())
6753 agent->removeGrabber(q,
true,
true,
true);
6756 bool childVisibilityChanged =
false;
6757 for (
int ii = 0; ii < childItems.size(); ++ii)
6758 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6760 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6761#if QT_CONFIG(accessibility)
6763 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6764 QAccessible::updateAccessibility(&ev);
6767 if (!inDestructor) {
6768 emit q->visibleChanged();
6769 if (childVisibilityChanged)
6770 emit q->visibleChildrenChanged();
6776bool QQuickItemPrivate::calcEffectiveEnable()
const
6781 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6784void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6788 if (newEffectiveEnable && !explicitEnable) {
6793 if (newEffectiveEnable == effectiveEnable) {
6798 effectiveEnable = newEffectiveEnable;
6800 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6802 da->removeGrabber(q,
true,
true,
true);
6803 if (scope && !effectiveEnable && activeFocus) {
6804 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6805 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6806 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6810 for (
int ii = 0; ii < childItems.size(); ++ii) {
6811 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6812 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6815 if (scope && effectiveEnable && focus && da) {
6816 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6817 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6818 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6821 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6822#if QT_CONFIG(accessibility)
6824 QAccessible::State changedState;
6825 changedState.disabled =
true;
6826 changedState.focusable =
true;
6827 QAccessibleStateChangeEvent ev(q, changedState);
6828 QAccessible::updateAccessibility(&ev);
6831 emit q->enabledChanged();
6835
6836
6837
6838qreal QQuickItemPrivate::biggestPointerHandlerMargin()
const
6840 if (hasPointerHandlers()) {
6841 if (extra->biggestPointerHandlerMarginCache < 0) {
6842 const auto maxMarginIt = std::max_element(extra->pointerHandlers.constBegin(),
6843 extra->pointerHandlers.constEnd(),
6844 [](
const QQuickPointerHandler *a,
const QQuickPointerHandler *b) {
6845 return a->margin() < b->margin(); });
6846 Q_ASSERT(maxMarginIt != extra->pointerHandlers.constEnd());
6847 extra->biggestPointerHandlerMarginCache = (*maxMarginIt)->margin();
6849 return extra->biggestPointerHandlerMarginCache;
6855
6856
6857
6858
6859
6860
6861QRectF QQuickItemPrivate::eventHandlingBounds(qreal margin)
const
6863 const qreal biggestMargin = margin > 0 ? margin : biggestPointerHandlerMargin();
6864 return QRectF(-biggestMargin, -biggestMargin, width + biggestMargin * 2, height + biggestMargin * 2);
6868
6869
6870
6871bool QQuickItemPrivate::parentFullyContains()
const
6873 Q_Q(
const QQuickItem);
6877 itemToParentTransform(&t);
6878 const auto bounds = eventHandlingBounds();
6879 const auto boundsInParent = t.mapRect(bounds);
6880 const bool ret = parentItem->clipRect().contains(boundsInParent);
6881 qCDebug(lcEffClip) <<
"in parent bounds?" << ret << q << boundsInParent << parentItem << parentItem->clipRect();
6886
6887
6888
6889bool QQuickItemPrivate::effectivelyClipsEventHandlingChildren()
const
6891 Q_Q(
const QQuickItem);
6893 if (flags & QQuickItem::ItemClipsChildrenToShape) {
6894 qCDebug(lcEffClip) << q <<
"result: true because clip is true";
6897 if (!eventHandlingChildrenWithinBoundsSet) {
6899 eventHandlingChildrenWithinBounds =
true;
6900 for (
const auto *child : childItems) {
6901 const auto *childPriv = QQuickItemPrivate::get(child);
6905 if (childPriv->childItems.isEmpty() &&
6906 !(childPriv->hoverEnabled || childPriv->subtreeHoverEnabled || childPriv->touchEnabled ||
6907 childPriv->hasCursor || childPriv->hasCursorHandler || child->acceptedMouseButtons() ||
6908 childPriv->hasPointerHandlers())) {
6909 qCDebug(lcEffClip) << child <<
"doesn't handle pointer events";
6912 if (!childPriv->parentFullyContains()) {
6913 eventHandlingChildrenWithinBounds =
false;
6914 qCDebug(lcEffClip) <<
"child goes outside: giving up" << child;
6917 if (!childPriv->eventHandlingChildrenWithinBoundsSet) {
6918 eventHandlingChildrenWithinBounds = childPriv->effectivelyClipsEventHandlingChildren();
6919 if (!eventHandlingChildrenWithinBounds)
6920 qCDebug(lcEffClip) <<
"child has children that go outside: giving up" << child;
6923#ifdef QT_BUILD_INTERNAL
6924 if (!eventHandlingChildrenWithinBoundsSet && eventHandlingChildrenWithinBounds)
6925 ++eventHandlingChildrenWithinBounds_counter;
6928 eventHandlingChildrenWithinBoundsSet =
true;
6929 qCDebug(lcEffClip) << q << q->clipRect() <<
"result:" <<
static_cast<
bool>(eventHandlingChildrenWithinBounds);
6931 return eventHandlingChildrenWithinBounds;
6934bool QQuickItemPrivate::isTransparentForPositioner()
const
6936 return extra.isAllocated() && extra.value().transparentForPositioner;
6939void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6941 extra.value().transparentForPositioner = transparent;
6945QString QQuickItemPrivate::dirtyToString()
const
6947#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6949 rv.append(QLatin1Char('|'));
6950 rv.append(QLatin1String(#value)); \
6951}
6978void QQuickItemPrivate::dirty(DirtyType type)
6981 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6982 dirtyAttributes |= type;
6983 if (window && componentComplete) {
6985 QQuickWindowPrivate::get(window)->dirtyItem(q);
6988 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6989 transformChanged(q);
6992void QQuickItemPrivate::addToDirtyList()
6997 if (!prevDirtyItem) {
6998 Q_ASSERT(!nextDirtyItem);
7000 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
7001 nextDirtyItem = p->dirtyItemList;
7002 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
7003 prevDirtyItem = &p->dirtyItemList;
7004 p->dirtyItemList = q;
7007 Q_ASSERT(prevDirtyItem);
7010void QQuickItemPrivate::removeFromDirtyList()
7012 if (prevDirtyItem) {
7013 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
7014 *prevDirtyItem = nextDirtyItem;
7015 prevDirtyItem =
nullptr;
7016 nextDirtyItem =
nullptr;
7018 Q_ASSERT(!prevDirtyItem);
7019 Q_ASSERT(!nextDirtyItem);
7022void QQuickItemPrivate::refFromEffectItem(
bool hide)
7024 ++extra.value().effectRefCount;
7025 if (extra->effectRefCount == 1) {
7026 dirty(EffectReference);
7028 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7031 if (++extra->hideRefCount == 1)
7032 dirty(HideReference);
7034 recursiveRefFromEffectItem(1);
7037void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
7042 extra.value().recursiveEffectRefCount += refs;
7043 for (
int ii = 0; ii < childItems.size(); ++ii) {
7044 QQuickItem *child = childItems.at(ii);
7045 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
7049 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
7053void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
7055 Q_ASSERT(extra->effectRefCount);
7056 --extra->effectRefCount;
7057 if (extra->effectRefCount == 0) {
7058 dirty(EffectReference);
7060 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7063 if (--extra->hideRefCount == 0)
7064 dirty(HideReference);
7066 recursiveRefFromEffectItem(-1);
7069void QQuickItemPrivate::setCulled(
bool cull)
7075 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
7076 dirty(HideReference);
7079void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
7083 case QQuickItem::ItemChildAddedChange: {
7084 q->itemChange(change, data);
7090 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
7091 if (!subtreeTransformChangedEnabled) {
7092 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
7093 subtreeTransformChangedEnabled =
true;
7095 enableSubtreeChangeNotificationsForParentHierachy();
7097 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
7100 case QQuickItem::ItemChildRemovedChange: {
7101 q->itemChange(change, data);
7102 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
7105 case QQuickItem::ItemSceneChange:
7106 q->itemChange(change, data);
7108 case QQuickItem::ItemVisibleHasChanged: {
7109 q->itemChange(change, data);
7110 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
7113 case QQuickItem::ItemEnabledHasChanged: {
7114 q->itemChange(change, data);
7115 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
7118 case QQuickItem::ItemParentHasChanged: {
7119 q->itemChange(change, data);
7120 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
7123 case QQuickItem::ItemOpacityHasChanged: {
7124 q->itemChange(change, data);
7125 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
7128 case QQuickItem::ItemActiveFocusHasChanged:
7129 q->itemChange(change, data);
7131 case QQuickItem::ItemRotationHasChanged: {
7132 q->itemChange(change, data);
7133 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7136 case QQuickItem::ItemScaleHasChanged: {
7137 q->itemChange(change, data);
7138 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7141 case QQuickItem::ItemTransformHasChanged: {
7142 q->itemChange(change, data);
7143 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7146 case QQuickItem::ItemAntialiasingHasChanged:
7148 case QQuickItem::ItemDevicePixelRatioHasChanged:
7149 q->itemChange(change, data);
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177bool QQuickItem::smooth()
const
7179 Q_D(
const QQuickItem);
7182void QQuickItem::setSmooth(
bool smooth)
7185 if (d->smooth == smooth)
7189 d->dirty(QQuickItemPrivate::Smooth);
7191 emit smoothChanged(smooth);
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7233bool QQuickItem::activeFocusOnTab()
const
7235 Q_D(
const QQuickItem);
7236 return d->activeFocusOnTab;
7238void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7241 if (d->activeFocusOnTab == activeFocusOnTab)
7245 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7246 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7251 d->activeFocusOnTab = activeFocusOnTab;
7253 emit activeFocusOnTabChanged(activeFocusOnTab);
7257
7258
7259
7260
7261
7262
7263
7264
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275bool QQuickItem::antialiasing()
const
7277 Q_D(
const QQuickItem);
7278 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7281void QQuickItem::setAntialiasing(
bool aa)
7285 if (!d->antialiasingValid) {
7286 d->antialiasingValid =
true;
7287 d->antialiasing = d->implicitAntialiasing;
7290 if (aa == d->antialiasing)
7293 d->antialiasing = aa;
7294 d->dirty(QQuickItemPrivate::Antialiasing);
7296 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7298 emit antialiasingChanged(antialiasing());
7301void QQuickItem::resetAntialiasing()
7304 if (!d->antialiasingValid)
7307 d->antialiasingValid =
false;
7309 if (d->implicitAntialiasing != d->antialiasing)
7310 emit antialiasingChanged(antialiasing());
7313void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7316 bool prev = q->antialiasing();
7317 implicitAntialiasing = antialiasing;
7318 if (componentComplete && (q->antialiasing() != prev))
7319 emit q->antialiasingChanged(q->antialiasing());
7323
7324
7325
7326
7327QQuickItem::Flags QQuickItem::flags()
const
7329 Q_D(
const QQuickItem);
7330 return (QQuickItem::Flags)d->flags;
7334
7335
7336
7337
7338
7339
7340
7341void QQuickItem::setFlag(Flag flag,
bool enabled)
7345 setFlags((Flags)(d->flags | (quint32)flag));
7347 setFlags((Flags)(d->flags & ~(quint32)flag));
7351 if (enabled && flag == ItemObservesViewport)
7352 d->enableSubtreeChangeNotificationsForParentHierachy();
7355void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7359 QQuickItem *par = q->parentItem();
7361 auto parPriv = QQuickItemPrivate::get(par);
7362 if (!parPriv->subtreeTransformChangedEnabled)
7363 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7364 parPriv->subtreeTransformChangedEnabled =
true;
7365 par = par->parentItem();
7370
7371
7372
7373
7374void QQuickItem::setFlags(Flags flags)
7378 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7379 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7380 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7381 flags &= ~ItemIsFocusScope;
7382 }
else if (d->flags & ItemIsFocusScope) {
7383 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7384 flags |= ItemIsFocusScope;
7388 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7389 d->dirty(QQuickItemPrivate::Clip);
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7410
7411
7412
7413
7415
7416
7417
7418
7419qreal QQuickItem::x()
const
7421 Q_D(
const QQuickItem);
7425qreal QQuickItem::y()
const
7427 Q_D(
const QQuickItem);
7432
7433
7434QPointF QQuickItem::position()
const
7436 Q_D(
const QQuickItem);
7437 return QPointF(d->x, d->y);
7440void QQuickItem::setX(qreal v)
7444
7445
7446
7447
7448
7449
7450
7451
7452 d->x.removeBindingUnlessInWrapper();
7456 const qreal oldx = d->x.valueBypassingBindings();
7460 d->x.setValueBypassingBindings(v);
7462 d->dirty(QQuickItemPrivate::Position);
7464 const qreal y = d->y.valueBypassingBindings();
7465 const qreal w = d->width.valueBypassingBindings();
7466 const qreal h = d->height.valueBypassingBindings();
7467 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7470void QQuickItem::setY(qreal v)
7473 d->y.removeBindingUnlessInWrapper();
7477 const qreal oldy = d->y.valueBypassingBindings();
7481 d->y.setValueBypassingBindings(v);
7483 d->dirty(QQuickItemPrivate::Position);
7487 const qreal x = d->x.valueBypassingBindings();
7488 const qreal w = d->width.valueBypassingBindings();
7489 const qreal h = d->height.valueBypassingBindings();
7490 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7494
7495
7496void QQuickItem::setPosition(
const QPointF &pos)
7500 const qreal oldx = d->x.valueBypassingBindings();
7501 const qreal oldy = d->y.valueBypassingBindings();
7503 if (QPointF(oldx, oldy) == pos)
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7519 d->x.setValueBypassingBindings(pos.x());
7520 d->y.setValueBypassingBindings(pos.y());
7522 d->dirty(QQuickItemPrivate::Position);
7524 const qreal w = d->width.valueBypassingBindings();
7525 const qreal h = d->height.valueBypassingBindings();
7526 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7530
7531
7532QBindable<qreal> QQuickItem::bindableX()
7534 return QBindable<qreal>(&d_func()->x);
7537QBindable<qreal> QQuickItem::bindableY()
7539 return QBindable<qreal>(&d_func()->y);
7543
7544
7545
7546
7547qreal QQuickItem::width()
const
7549 Q_D(
const QQuickItem);
7553void QQuickItem::setWidth(qreal w)
7556 d->width.removeBindingUnlessInWrapper();
7560 d->widthValidFlag =
true;
7561 const qreal oldWidth = d->width.valueBypassingBindings();
7565 d->width.setValueBypassingBindings(w);
7567 d->dirty(QQuickItemPrivate::Size);
7569 const qreal x = d->x.valueBypassingBindings();
7570 const qreal y = d->y.valueBypassingBindings();
7571 const qreal h = d->height.valueBypassingBindings();
7572 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7575void QQuickItem::resetWidth()
7578 d->width.takeBinding();
7579 d->widthValidFlag =
false;
7580 setImplicitWidth(implicitWidth());
7583void QQuickItemPrivate::implicitWidthChanged()
7586 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7587 emit q->implicitWidthChanged();
7590qreal QQuickItemPrivate::getImplicitWidth()
const
7592 return implicitWidth;
7595
7596
7597qreal QQuickItem::implicitWidth()
const
7599 Q_D(
const QQuickItem);
7600 return d->getImplicitWidth();
7603QBindable<qreal> QQuickItem::bindableWidth()
7605 return QBindable<qreal>(&d_func()->width);
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690void QQuickItem::setImplicitWidth(qreal w)
7693 bool changed = w != d->implicitWidth;
7694 d->implicitWidth = w;
7696 if (d->width.valueBypassingBindings() == w || widthValid()) {
7698 d->implicitWidthChanged();
7699 if (d->width.valueBypassingBindings() == w || widthValid())
7704 const qreal oldWidth = d->width.valueBypassingBindings();
7705 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7707 d->width.setValueBypassingBindings(w);
7709 d->dirty(QQuickItemPrivate::Size);
7711 const qreal x = d->x.valueBypassingBindings();
7712 const qreal y = d->y.valueBypassingBindings();
7713 const qreal width = w;
7714 const qreal height = d->height.valueBypassingBindings();
7715 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7718 d->implicitWidthChanged();
7722
7723
7724bool QQuickItem::widthValid()
const
7726 Q_D(
const QQuickItem);
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7744 return d->widthValid();
7748
7749
7750
7751
7752qreal QQuickItem::height()
const
7754 Q_D(
const QQuickItem);
7758void QQuickItem::setHeight(qreal h)
7764 d->height.removeBindingUnlessInWrapper();
7768 d->heightValidFlag =
true;
7769 const qreal oldHeight = d->height.valueBypassingBindings();
7773 d->height.setValueBypassingBindings(h);
7775 d->dirty(QQuickItemPrivate::Size);
7777 const qreal x = d->x.valueBypassingBindings();
7778 const qreal y = d->y.valueBypassingBindings();
7779 const qreal w = d->width.valueBypassingBindings();
7780 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7783void QQuickItem::resetHeight()
7789 d->height.takeBinding();
7790 d->heightValidFlag =
false;
7791 setImplicitHeight(implicitHeight());
7794void QQuickItemPrivate::implicitHeightChanged()
7797 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7798 emit q->implicitHeightChanged();
7801qreal QQuickItemPrivate::getImplicitHeight()
const
7803 return implicitHeight;
7806qreal QQuickItem::implicitHeight()
const
7808 Q_D(
const QQuickItem);
7809 return d->getImplicitHeight();
7812QBindable<qreal> QQuickItem::bindableHeight()
7814 return QBindable<qreal>(&d_func()->height);
7817void QQuickItem::setImplicitHeight(qreal h)
7820 bool changed = h != d->implicitHeight;
7821 d->implicitHeight = h;
7822 if (d->height.valueBypassingBindings() == h || heightValid()) {
7824 d->implicitHeightChanged();
7825 if (d->height.valueBypassingBindings() == h || heightValid())
7830 const qreal oldHeight = d->height.valueBypassingBindings();
7831 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7833 d->height.setValueBypassingBindings(h);
7835 d->dirty(QQuickItemPrivate::Size);
7837 const qreal x = d->x.valueBypassingBindings();
7838 const qreal y = d->y.valueBypassingBindings();
7839 const qreal width = d->width.valueBypassingBindings();
7840 const qreal height = d->height.valueBypassingBindings();
7841 geometryChange(QRectF(x, y, width, height),
7842 QRectF(x, y, width, oldHeight));
7845 d->implicitHeightChanged();
7849
7850
7851void QQuickItem::setImplicitSize(qreal w, qreal h)
7854 bool wChanged = w != d->implicitWidth;
7855 bool hChanged = h != d->implicitHeight;
7857 d->implicitWidth = w;
7858 d->implicitHeight = h;
7862 qreal width = d->width.valueBypassingBindings();
7863 qreal height = d->height.valueBypassingBindings();
7864 if (width == w || widthValid()) {
7866 d->implicitWidthChanged();
7867 wDone = width == w || widthValid();
7870 if (height == h || heightValid()) {
7872 d->implicitHeightChanged();
7873 hDone = height == h || heightValid();
7879 const qreal oldWidth = width;
7880 const qreal oldHeight = height;
7883 d->width.setValueBypassingBindings(w);
7887 d->height.setValueBypassingBindings(h);
7890 d->dirty(QQuickItemPrivate::Size);
7892 const qreal x = d->x.valueBypassingBindings();
7893 const qreal y = d->y.valueBypassingBindings();
7894 geometryChange(QRectF(x, y, width, height),
7895 QRectF(x, y, oldWidth, oldHeight));
7897 if (!wDone && wChanged)
7898 d->implicitWidthChanged();
7899 if (!hDone && hChanged)
7900 d->implicitHeightChanged();
7904
7905
7906bool QQuickItem::heightValid()
const
7908 Q_D(
const QQuickItem);
7909 return d->heightValid();
7913
7914
7915
7916
7917
7918
7920QSizeF QQuickItem::size()
const
7922 Q_D(
const QQuickItem);
7923 return QSizeF(d->width, d->height);
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937void QQuickItem::setSize(
const QSizeF &size)
7940 d->heightValidFlag =
true;
7941 d->widthValidFlag =
true;
7943 const qreal oldHeight = d->height.valueBypassingBindings();
7944 const qreal oldWidth = d->width.valueBypassingBindings();
7946 if (oldWidth == size.width() && oldHeight == size.height())
7949 d->height.setValueBypassingBindings(size.height());
7950 d->width.setValueBypassingBindings(size.width());
7952 d->dirty(QQuickItemPrivate::Size);
7954 const qreal x = d->x.valueBypassingBindings();
7955 const qreal y = d->y.valueBypassingBindings();
7956 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028bool QQuickItem::hasActiveFocus()
const
8030 Q_D(
const QQuickItem);
8031 return d->activeFocus;
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122bool QQuickItem::hasFocus()
const
8124 Q_D(
const QQuickItem);
8128void QQuickItem::setFocus(
bool focus)
8130 setFocus(focus, Qt::OtherFocusReason);
8133void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8137 QQuickItem *scope = parentItem();
8138 while (scope && !scope->isFocusScope() && scope->parentItem())
8139 scope = scope->parentItem();
8141 if (d->focus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8144 bool notifyListeners =
false;
8145 if (d->window || d->parentItem) {
8147 auto da = d->deliveryAgentPrivate();
8150 da->setFocusInScope(scope,
this, reason);
8152 da->clearFocusInScope(scope,
this, reason);
8156 QVarLengthArray<QQuickItem *, 20> changed;
8157 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8158 if (oldSubFocusItem) {
8159 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8160 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8161 changed << oldSubFocusItem;
8162 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8163 QQuickItemPrivate::get(scope)->focus =
false;
8166 d->updateSubFocusItem(scope, focus);
8170 notifyListeners =
true;
8171 emit focusChanged(focus);
8173 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8176 QVarLengthArray<QQuickItem *, 20> changed;
8177 QQuickItem *oldSubFocusItem = d->subFocusItem;
8178 if (!isFocusScope() && oldSubFocusItem) {
8179 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8180 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8181 changed << oldSubFocusItem;
8186 notifyListeners =
true;
8187 emit focusChanged(focus);
8189 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8191 if (notifyListeners)
8192 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8196
8197
8198bool QQuickItem::isFocusScope()
const
8200 return flags() & ItemIsFocusScope;
8204
8205
8206
8207
8208
8209QQuickItem *QQuickItem::scopedFocusItem()
const
8211 Q_D(
const QQuickItem);
8212 if (!isFocusScope())
8215 return d->subFocusItem;
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8233
8234
8235
8236
8237
8238
8239Qt::FocusPolicy QQuickItem::focusPolicy()
const
8241 Q_D(
const QQuickItem);
8242 uint policy = d->focusPolicy;
8243 if (activeFocusOnTab())
8244 policy |= Qt::TabFocus;
8245 return static_cast<Qt::FocusPolicy>(policy);
8249
8250
8251
8252
8253void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8256 if (d->focusPolicy == policy)
8259 d->focusPolicy = policy;
8260 setActiveFocusOnTab(policy & Qt::TabFocus);
8261 emit focusPolicyChanged(policy);
8265
8266
8267
8268
8269
8270
8271
8272bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8274 if (!child || child ==
this)
8276 const QQuickItem *ancestor = child;
8277 while ((ancestor = ancestor->parentItem())) {
8278 if (ancestor ==
this)
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8297 Q_D(
const QQuickItem);
8298 return d->acceptedMouseButtons();
8302
8303
8304
8305
8306
8307
8308
8309
8310void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8313 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8315 buttons &= ~Qt::LeftButton;
8316 if (buttons || d->extra.isAllocated()) {
8317 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8318 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333bool QQuickItem::filtersChildMouseEvents()
const
8335 Q_D(
const QQuickItem);
8336 return d->filtersChildMouseEvents;
8340
8341
8342
8343
8344
8345
8346
8347
8348void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8351 d->filtersChildMouseEvents = filter;
8355
8356
8357bool QQuickItem::isUnderMouse()
const
8359 Q_D(
const QQuickItem);
8366 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8369 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8370 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8374
8375
8376
8377
8378
8379
8380
8381bool QQuickItem::acceptHoverEvents()
const
8383 Q_D(
const QQuickItem);
8384 return d->hoverEnabled;
8388
8389
8390
8391
8392
8393void QQuickItem::setAcceptHoverEvents(
bool enabled)
8400 d->hoverEnabled = enabled;
8406 d->setHasHoverInChild(enabled);
8410 d->dirty(QQuickItemPrivate::Content);
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423bool QQuickItem::acceptTouchEvents()
const
8425 Q_D(
const QQuickItem);
8426 return d->touchEnabled;
8430
8431
8432
8433
8434
8435
8436
8437void QQuickItem::setAcceptTouchEvents(
bool enabled)
8440 d->touchEnabled = enabled;
8443void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8445#if QT_CONFIG(cursor)
8450 if (!hc && subtreeCursorEnabled) {
8453 for (QQuickItem *otherChild : std::as_const(childItems)) {
8454 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8455 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8460 subtreeCursorEnabled = hc;
8461 QQuickItem *parent = q->parentItem();
8463 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8464 parentPrivate->setHasCursorInChild(hc);
8471void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8477 if (!hasHover && subtreeHoverEnabled) {
8480 if (hasEnabledHoverHandlers())
8483 for (QQuickItem *otherChild : std::as_const(childItems)) {
8484 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8485 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8487 if (otherChildPrivate->hasEnabledHoverHandlers())
8492 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8493 subtreeHoverEnabled = hasHover;
8494 QQuickItem *parent = q->parentItem();
8496 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8497 parentPrivate->setHasHoverInChild(hasHover);
8501#if QT_CONFIG(cursor)
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8517QCursor QQuickItem::cursor()
const
8519 Q_D(
const QQuickItem);
8520 return d->extra.isAllocated()
8526
8527
8528
8529
8531void QQuickItem::setCursor(
const QCursor &cursor)
8535 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8536 qCDebug(lcHoverCursor) << oldShape <<
"->" << cursor.shape();
8538 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8539 d->extra.value().cursor = cursor;
8541 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8542 QWindow *window = renderWindow ? renderWindow : d->window;
8543 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8544 window->setCursor(cursor);
8548 QPointF updateCursorPos;
8549 if (!d->hasCursor) {
8550 d->hasCursor =
true;
8552 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8553 QWindow *window = renderWindow ? renderWindow : d->window;
8554 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8555 if (contains(mapFromScene(pos)))
8556 updateCursorPos = pos;
8559 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8560 if (!updateCursorPos.isNull())
8561 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8565
8566
8567
8568
8570void QQuickItem::unsetCursor()
8573 qCDebug(lcHoverTrace) <<
"clearing cursor";
8576 d->hasCursor =
false;
8577 d->setHasCursorInChild(d->hasCursorHandler);
8578 if (d->extra.isAllocated())
8579 d->extra->cursor = QCursor();
8582 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8583 if (windowPrivate->cursorItem ==
this) {
8584 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8585 windowPrivate->updateCursor(pos);
8591
8592
8593
8594
8595
8596
8597QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8599 Q_Q(
const QQuickItem);
8602 bool hoverCursorSet =
false;
8603 QCursor hoverCursor;
8604 bool activeCursorSet =
false;
8605 QCursor activeCursor;
8606 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8607 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8608 hoverCursor = hoverHandler->cursorShape();
8609 }
else if (handler->active()) {
8610 activeCursorSet = handler->isCursorShapeExplicitlySet();
8611 activeCursor = handler->cursorShape();
8613 if (activeCursorSet)
8614 return activeCursor;
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8642 if (!hasPointerHandlers())
8644 QQuickPointerHandler* activeHandler =
nullptr;
8645 QQuickPointerHandler* mouseHandler =
nullptr;
8646 QQuickPointerHandler* nonMouseHandler =
nullptr;
8647 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8648 if (!h->isCursorShapeExplicitlySet())
8650 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8655 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8656 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8657 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8659 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8660 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8661 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8663 mouseHandler = hoverHandler;
8666 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8667 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8668 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8670 nonMouseHandler = hoverHandler;
8673 if (!hoverHandler && h->active())
8676 if (activeHandler) {
8677 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8678 return activeHandler;
8684 if (nonMouseHandler) {
8686 const bool beforeTimeout =
8687 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8688 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8689 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8690 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8691 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8692 <<
"choosing cursor according to" << winner << winner->cursorShape();
8695 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8696 return nonMouseHandler;
8699 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8700 return mouseHandler;
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719void QQuickItem::grabMouse()
8724 auto da = d->deliveryAgentPrivate();
8726 auto eventInDelivery = da->eventInDelivery();
8727 if (!eventInDelivery) {
8728 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8731 auto epd = da->mousePointData();
8732 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746void QQuickItem::ungrabMouse()
8751 auto da = d->deliveryAgentPrivate();
8753 auto eventInDelivery = da->eventInDelivery();
8754 if (!eventInDelivery) {
8756 da->removeGrabber(
this);
8759 const auto &eventPoint = da->mousePointData()->eventPoint;
8760 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8761 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8765
8766
8767
8768
8769bool QQuickItem::keepMouseGrab()
const
8771 Q_D(
const QQuickItem);
8772 return d->keepMouse;
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791void QQuickItem::setKeepMouseGrab(
bool keep)
8794 d->keepMouse = keep;
8798
8799
8800
8801
8802
8803
8804
8805
8806void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8809 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8810 if (Q_UNLIKELY(!event)) {
8811 qWarning() <<
"cannot grab: no event is currently being delivered";
8814 for (
auto pt : event->points()) {
8815 if (ids.contains(pt.id()))
8816 event->setExclusiveGrabber(pt,
this);
8821
8822
8823
8824void QQuickItem::ungrabTouchPoints()
8829 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8830 da->removeGrabber(
this,
false,
true);
8834
8835
8836
8837
8838
8839bool QQuickItem::keepTouchGrab()
const
8841 Q_D(
const QQuickItem);
8842 return d->keepTouch;
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862void QQuickItem::setKeepTouchGrab(
bool keep)
8865 d->keepTouch = keep;
8869
8870
8871
8872
8873
8874
8875
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887bool QQuickItem::contains(
const QPointF &point)
const
8889 Q_D(
const QQuickItem);
8890 if (d->extra.isAllocated() && d->extra->mask) {
8891 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8892 return quickMask->contains(point - quickMask->position());
8895 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8896 maskContains.invoke(d->extra->mask,
8897 Qt::DirectConnection,
8898 Q_RETURN_ARG(
bool, res),
8899 Q_ARG(QPointF, point));
8903 qreal x = point.x();
8904 qreal y = point.y();
8905 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971QObject *QQuickItem::containmentMask()
const
8973 Q_D(
const QQuickItem);
8974 if (!d->extra.isAllocated())
8976 return d->extra->mask.data();
8979void QQuickItem::setContainmentMask(QObject *mask)
8982 const bool extraDataExists = d->extra.isAllocated();
8984 if (mask ==
static_cast<QObject *>(
this))
8987 if (!extraDataExists && !mask)
8990 if (extraDataExists && d->extra->mask == mask)
8993 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8996 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8997 maskPrivate->registerAsContainmentMask(
this,
false);
9000 if (!extraDataExists)
9003 int methodIndex = mask->metaObject()->indexOfMethod(QByteArrayLiteral(
"contains(QPointF)"));
9004 if (methodIndex < 0) {
9005 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
9008 d->extra->maskContainsIndex = methodIndex;
9010 d->extra->mask = mask;
9011 quickMask = qobject_cast<QQuickItem *>(mask);
9013 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9014 maskPrivate->registerAsContainmentMask(
this,
true);
9016 emit containmentMaskChanged();
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
9033 QPointF p = mapToScene(point);
9035 const auto *itemWindow = item->window();
9036 const auto *thisWindow = window();
9037 if (thisWindow && itemWindow && itemWindow != thisWindow)
9038 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
9040 p = item->mapFromScene(p);
9046
9047
9048
9049
9050
9051
9052
9053
9054QPointF QQuickItem::mapToScene(
const QPointF &point)
const
9056 Q_D(
const QQuickItem);
9057 return d->itemToWindowTransform().map(point);
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
9079 Q_D(
const QQuickItem);
9081 if (Q_UNLIKELY(d->window ==
nullptr))
9082 return mapToScene(point);
9084 QPoint renderOffset;
9085 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9086 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9087 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
9104 Q_D(
const QQuickItem);
9105 QTransform t = d->itemToWindowTransform();
9107 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
9108 return t.mapRect(rect);
9112
9113
9114
9115
9116
9117
9118
9119
9120QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
9122 Q_D(
const QQuickItem);
9123 return d->itemToWindowTransform().mapRect(rect);
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9142 p = item->mapToScene(point);
9143 const auto *itemWindow = item->window();
9144 const auto *thisWindow = window();
9145 if (thisWindow && itemWindow && itemWindow != thisWindow)
9146 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9148 return mapFromScene(p);
9152
9153
9154
9155
9156
9157
9158
9159
9160QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9162 Q_D(
const QQuickItem);
9163 return d->windowToItemTransform().map(point);
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9191 Q_D(
const QQuickItem);
9194 if (Q_LIKELY(d->window)) {
9195 QPoint renderOffset;
9196 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9197 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9198 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9203 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9204 if (
auto sceneTransform = da->sceneTransform())
9205 scenePoint = sceneTransform->map(scenePoint);
9207 return mapFromScene(scenePoint);
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9224 Q_D(
const QQuickItem);
9225 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9226 t *= d->windowToItemTransform();
9227 return t.mapRect(rect);
9231
9232
9233
9234
9235
9236
9237
9238
9239QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9241 Q_D(
const QQuickItem);
9242 return d->windowToItemTransform().mapRect(rect);
9246
9247
9248
9251
9252
9253
9256
9257
9258
9261
9262
9263
9266
9267
9268
9271
9272
9273
9276
9277
9278
9281
9282
9283
9286
9287
9288
9291
9292
9293
9296
9297
9298bool QQuickItem::event(QEvent *ev)
9302 switch (ev->type()) {
9304 case QEvent::InputMethodQuery: {
9305 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9306 Qt::InputMethodQueries queries = query->queries();
9307 for (uint i = 0; i < 32; ++i) {
9308 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9310 QVariant v = inputMethodQuery(q);
9311 query->setValue(q, v);
9317 case QEvent::InputMethod:
9318 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9321 case QEvent::TouchBegin:
9322 case QEvent::TouchUpdate:
9323 case QEvent::TouchEnd:
9324 case QEvent::TouchCancel:
9325 case QEvent::MouseButtonPress:
9326 case QEvent::MouseButtonRelease:
9327 case QEvent::MouseButtonDblClick:
9328#if QT_CONFIG(wheelevent)
9331 d->deliverPointerEvent(ev);
9333 case QEvent::StyleAnimationUpdate:
9339 case QEvent::HoverEnter:
9340 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9342 case QEvent::HoverLeave:
9343 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9345 case QEvent::HoverMove:
9346 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9348 case QEvent::KeyPress:
9349 case QEvent::KeyRelease:
9350 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9352 case QEvent::ShortcutOverride:
9353 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9355 case QEvent::FocusIn:
9356 focusInEvent(
static_cast<QFocusEvent*>(ev));
9358 case QEvent::FocusOut:
9359 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9361 case QEvent::MouseMove:
9362 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9364#if QT_CONFIG(quick_draganddrop)
9365 case QEvent::DragEnter:
9366 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9368 case QEvent::DragLeave:
9369 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9371 case QEvent::DragMove:
9372 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9375 dropEvent(
static_cast<QDropEvent*>(ev));
9378#if QT_CONFIG(gestures)
9379 case QEvent::NativeGesture:
9383 case QEvent::LanguageChange:
9384 case QEvent::LocaleChange:
9385 for (QQuickItem *item : std::as_const(d->childItems))
9386 QCoreApplication::sendEvent(item, ev);
9388 case QEvent::WindowActivate:
9389 case QEvent::WindowDeactivate:
9390 if (d->providesPalette())
9391 d->setCurrentColorGroup();
9392 for (QQuickItem *item : std::as_const(d->childItems))
9393 QCoreApplication::sendEvent(item, ev);
9395 case QEvent::ApplicationPaletteChange:
9396 for (QQuickItem *item : std::as_const(d->childItems))
9397 QCoreApplication::sendEvent(item, ev);
9399 case QEvent::ContextMenu:
9401 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9404 return QObject::event(ev);
9410#ifndef QT_NO_DEBUG_STREAM
9412#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9417 QDebugStateSaver saver(debug);
9420 debug <<
"QQuickItem(nullptr)";
9424 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9426 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9430 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9431 if (QQmlContext *context = qmlContext(item)) {
9432 const auto objectId = context->nameForObject(item);
9433 if (!objectId.isEmpty())
9434 debug <<
", id=" << objectId;
9437 if (!item->objectName().isEmpty())
9438 debug <<
", name=" << item->objectName();
9439 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9441 QtDebugUtils::formatQRect(debug, rect);
9442 if (
const qreal z = item->z())
9443 debug <<
", z=" << z;
9444 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9445 debug <<
" \U0001f5bc";
9446 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9454
9455
9456
9457
9458
9459
9460
9462bool QQuickItem::isTextureProvider()
const
9464#if QT_CONFIG(quick_shadereffect)
9465 Q_D(
const QQuickItem);
9466 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9467 d->extra->layer->effectSource()->isTextureProvider() :
false;
9474
9475
9476
9477
9478
9479
9480
9482QSGTextureProvider *QQuickItem::textureProvider()
const
9484#if QT_CONFIG(quick_shadereffect)
9485 Q_D(
const QQuickItem);
9486 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9487 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9535#if QT_CONFIG(quick_shadereffect)
9537
9538
9539
9540QQuickItemLayer *QQuickItemPrivate::layer()
const
9542 if (!extra.isAllocated() || !extra->layer) {
9543 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9544 if (!componentComplete)
9545 extra->layer->classBegin();
9547 return extra->layer;
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9571 QList<QEventPoint> touchPoints;
9572 QEventPoint::States eventStates;
9574 bool anyPressOrReleaseInside =
false;
9575 bool anyGrabber =
false;
9576 for (
auto &p : event->points()) {
9581 auto pointGrabber = event->exclusiveGrabber(p);
9582 bool isGrabber = (pointGrabber == q);
9583 if (!isGrabber && pointGrabber && isFiltering) {
9584 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9585 if (handlerGrabber && handlerGrabber->parentItem() == q)
9592 const auto localPos = q->mapFromScene(p.scenePosition());
9593 bool isInside = q->contains(localPos);
9594 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9596 if (isFiltering && !pointGrabber) {
9597 const auto pg = event->passiveGrabbers(p);
9598 if (!pg.isEmpty()) {
9602 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9604 pointGrabber = handler->parentItem();
9609 bool grabberIsChild =
false;
9610 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9611 while (isFiltering && parent) {
9613 grabberIsChild =
true;
9616 parent = parent->parentItem();
9619 bool filterRelevant = isFiltering && grabberIsChild;
9620 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9622 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9623 anyPressOrReleaseInside =
true;
9624 QEventPoint pCopy(p);
9625 eventStates |= p.state();
9626 if (p.state() == QEventPoint::State::Released)
9627 QMutableEventPoint::detach(pCopy);
9628 QMutableEventPoint::setPosition(pCopy, localPos);
9629 touchPoints.append(std::move(pCopy));
9634 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9635 *localized = QMutableTouchEvent(QEvent::None);
9640 QEvent::Type eventType = event->type();
9641 switch (eventStates) {
9642 case QEventPoint::State::Pressed:
9643 eventType = QEvent::TouchBegin;
9645 case QEventPoint::State::Released:
9646 eventType = QEvent::TouchEnd;
9649 eventType = QEvent::TouchUpdate;
9653 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9655 ret.setTimestamp(event->timestamp());
9660bool QQuickItemPrivate::hasPointerHandlers()
const
9662 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9665bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9667 if (!hasPointerHandlers())
9669 for (QQuickPointerHandler *h : extra->pointerHandlers)
9670 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9675void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9681 extra.value().acceptedMouseButtons = Qt::AllButtons;
9682 auto &handlers = extra.value().pointerHandlers;
9683 if (!handlers.contains(h))
9684 handlers.prepend(h);
9685 auto &res = extra.value().resourcesList;
9686 if (!res.contains(h)) {
9688 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9689 _q_resourceObjectDeleted(o);
9694void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9698 auto &handlers = extra.value().pointerHandlers;
9699 handlers.removeOne(h);
9700 auto &res = extra.value().resourcesList;
9702 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9703 if (handlers.isEmpty())
9704 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9708
9709
9710
9711QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9713 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9714 extra.value().contextMenu = menu;
9718QtPrivate::QQuickAttachedPropertyPropagator *QQuickItemPrivate::attachedPropertyPropagator_parent(
9719 const QMetaObject *attachedType)
9722 qCDebug(lcAttachedPropertyPropagator).noquote() <<
"- attachedPropertyPropagator_parent called on"
9723 << q <<
"with attachedType" << attachedType->metaType().name();
9725 QQuickItem *parent = q->parentItem();
9726 if (
auto *attached = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(attachedType, parent)) {
9727 qCDebug(lcAttachedPropertyPropagator).noquote() <<
" - parent item has attached object"
9728 << attached <<
"- returning";
9735#if QT_CONFIG(quick_shadereffect)
9736QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9742 , m_componentComplete(
true)
9743 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9744 , m_format(QQuickShaderEffectSource::RGBA8)
9746 , m_effectComponent(
nullptr)
9748 , m_effectSource(
nullptr)
9749 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9754QQuickItemLayer::~QQuickItemLayer()
9756 delete m_effectSource;
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774void QQuickItemLayer::setEnabled(
bool e)
9779 if (m_componentComplete) {
9786 emit enabledChanged(e);
9789void QQuickItemLayer::classBegin()
9791 Q_ASSERT(!m_effectSource);
9792 Q_ASSERT(!m_effect);
9793 m_componentComplete =
false;
9796void QQuickItemLayer::componentComplete()
9798 Q_ASSERT(!m_componentComplete);
9799 m_componentComplete =
true;
9804void QQuickItemLayer::activate()
9806 Q_ASSERT(!m_effectSource);
9807 m_effectSource =
new QQuickShaderEffectSource();
9808 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9810 QQuickItem *parentItem = m_item->parentItem();
9812 m_effectSource->setParentItem(parentItem);
9813 m_effectSource->stackAfter(m_item);
9816 m_effectSource->setSourceItem(m_item);
9817 m_effectSource->setHideSource(
true);
9818 m_effectSource->setSmooth(m_smooth);
9819 m_effectSource->setLive(m_live);
9820 m_effectSource->setTextureSize(m_size);
9821 m_effectSource->setSourceRect(m_sourceRect);
9822 m_effectSource->setMipmap(m_mipmap);
9823 m_effectSource->setWrapMode(m_wrapMode);
9824 m_effectSource->setFormat(m_format);
9825 m_effectSource->setTextureMirroring(m_textureMirroring);
9826 m_effectSource->setSamples(m_samples);
9828 if (m_effectComponent)
9831 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9838 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9839 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9842void QQuickItemLayer::deactivate()
9844 Q_ASSERT(m_effectSource);
9846 if (m_effectComponent)
9849 delete m_effectSource;
9850 m_effectSource =
nullptr;
9852 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9853 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9856void QQuickItemLayer::activateEffect()
9858 Q_ASSERT(m_effectSource);
9859 Q_ASSERT(m_effectComponent);
9860 Q_ASSERT(!m_effect);
9862 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9863 m_effect = qobject_cast<QQuickItem *>(created);
9865 qWarning(
"Item: layer.effect is not a QML Item.");
9866 m_effectComponent->completeCreate();
9870 QQuickItem *parentItem = m_item->parentItem();
9872 m_effect->setParentItem(parentItem);
9873 m_effect->stackAfter(m_effectSource);
9875 m_effect->setVisible(m_item->isVisible());
9876 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9877 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9878 m_effectComponent->completeCreate();
9881void QQuickItemLayer::deactivateEffect()
9883 Q_ASSERT(m_effectSource);
9884 Q_ASSERT(m_effectComponent);
9892
9893
9894
9895
9896
9897
9898
9899
9900
9902void QQuickItemLayer::setEffect(QQmlComponent *component)
9904 if (component == m_effectComponent)
9907 bool updateNeeded =
false;
9908 if (m_effectSource && m_effectComponent) {
9910 updateNeeded =
true;
9913 m_effectComponent = component;
9915 if (m_effectSource && m_effectComponent) {
9917 updateNeeded =
true;
9925 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9928 emit effectChanged(component);
9933
9934
9935
9936
9937
9938
9939
9940
9941
9943void QQuickItemLayer::setMipmap(
bool mipmap)
9945 if (mipmap == m_mipmap)
9950 m_effectSource->setMipmap(m_mipmap);
9952 emit mipmapChanged(mipmap);
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9973void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9980 m_effectSource->setFormat(m_format);
9982 emit formatChanged(m_format);
9987
9988
9989
9990
9991
9992
9993
9994
9995
9997void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
9999 if (sourceRect == m_sourceRect)
10001 m_sourceRect = sourceRect;
10003 if (m_effectSource)
10004 m_effectSource->setSourceRect(m_sourceRect);
10006 emit sourceRectChanged(sourceRect);
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10021void QQuickItemLayer::setSmooth(
bool s)
10027 if (m_effectSource)
10028 m_effectSource->setSmooth(m_smooth);
10030 emit smoothChanged(s);
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10045void QQuickItemLayer::setLive(
bool live)
10047 if (m_live == live)
10051 if (m_effectSource)
10052 m_effectSource->setLive(m_live);
10054 emit liveChanged(live);
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10070void QQuickItemLayer::setSize(
const QSize &size)
10072 if (size == m_size)
10076 if (m_effectSource)
10077 m_effectSource->setTextureSize(size);
10079 emit sizeChanged(size);
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10100void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
10102 if (mode == m_wrapMode)
10106 if (m_effectSource)
10107 m_effectSource->setWrapMode(m_wrapMode);
10109 emit wrapModeChanged(mode);
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10127void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
10129 if (mirroring == m_textureMirroring)
10131 m_textureMirroring = mirroring;
10133 if (m_effectSource)
10134 m_effectSource->setTextureMirroring(m_textureMirroring);
10136 emit textureMirroringChanged(mirroring);
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10164void QQuickItemLayer::setSamples(
int count)
10166 if (m_samples == count)
10171 if (m_effectSource)
10172 m_effectSource->setSamples(m_samples);
10174 emit samplesChanged(count);
10178
10179
10180
10181
10182
10183
10184
10185
10186
10188void QQuickItemLayer::setName(
const QByteArray &name) {
10189 if (m_name == name)
10192 m_effect->setProperty(m_name, QVariant());
10193 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10196 emit nameChanged(name);
10199void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10205void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10210void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10213 Q_ASSERT(item == m_item);
10214 Q_ASSERT(parent != m_effectSource);
10215 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10217 m_effectSource->setParentItem(parent);
10219 m_effectSource->stackAfter(m_item);
10222 m_effect->setParentItem(parent);
10224 m_effect->stackAfter(m_effectSource);
10228void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10230 m_effectSource->stackAfter(m_item);
10232 m_effect->stackAfter(m_effectSource);
10235void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10237 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10240 l->setVisible(m_item->isVisible());
10243void QQuickItemLayer::updateZ()
10245 if (!m_componentComplete || !m_enabled)
10247 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10250 l->setZ(m_item->z());
10253void QQuickItemLayer::updateOpacity()
10255 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10258 l->setOpacity(m_item->opacity());
10261void QQuickItemLayer::updateGeometry()
10263 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10268 QRectF bounds = m_item->QQuickItem::boundingRect();
10269 l->setSize(bounds.size());
10270 l->setPosition(bounds.topLeft() + m_item->position());
10273void QQuickItemLayer::updateMatrix()
10277 if (!m_componentComplete || !m_enabled)
10279 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10282 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10283 l->setScale(m_item->scale());
10284 l->setRotation(m_item->rotation());
10285 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10286 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10287 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10288 ld->dirty(QQuickItemPrivate::Transform);
10292QQuickItemPrivate::ExtraData::ExtraData()
10293: z(0), scale(1), rotation(0), opacity(1), biggestPointerHandlerMarginCache(-1),
10294 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10295 enterKeyAttached(
nullptr),
10296 keyHandler(
nullptr), contextMenu(
nullptr),
10297#if QT_CONFIG(quick_shadereffect)
10300 effectRefCount(0), hideRefCount(0),
10301 recursiveEffectRefCount(0),
10302 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10303 origin(QQuickItem::Center),
10304 transparentForPositioner(
false)
10306#ifdef QT_BUILD_INTERNAL
10307 ++QQuickItemPrivate::itemExtra_counter;
10312#if QT_CONFIG(accessibility)
10313QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10315 Q_Q(
const QQuickItem);
10316 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10317 auto role = QAccessible::NoRole;
10318 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10319 role = accessibleAttached->role();
10320 if (role == QAccessible::NoRole)
10321 role = accessibleRole();
10325QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10327 return QAccessible::NoRole;
10336 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10349 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10350 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10351 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10352 QV4::QObjectWrapper::markWrapper(child, markStack);
10354 QObjectWrapper::markObjects(that, markStack);
10357quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10359 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10364 QDebugStateSaver stateSaver(debug);
10365 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10370QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10371{
return mapFromItem(item, QPointF(x, y) ); }
10374QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10375{
return mapRectFromItem(item, rect); }
10378QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10379{
return mapFromItem(item, QRectF(x, y, width, height)); }
10382QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10383{
return mapToItem(item, QPointF(x, y)); }
10386QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10387{
return mapRectToItem(item, rect); }
10390QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10391{
return mapToItem(item, QRectF(x, y, width, height)); }
10394QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10395{
return mapToGlobal(QPointF(x, y)); }
10398QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10399{
return mapFromGlobal(QPointF(x, y)); }
10402QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10406#include <moc_qquickitem.cpp>
10408#include "moc_qquickitem_p.cpp"
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
#define PRINT_LISTENERS()
QDebug operator<<(QDebug debug, const QQuickItem *item)
static bool itemZOrder_sort(QQuickItem *lhs, QQuickItem *rhs)
#define DIRTY_TO_STRING(value)
void debugFocusTree(QQuickItem *item, QQuickItem *scope=nullptr, int depth=1)
DEFINE_OBJECT_VTABLE(QQuickItemWrapper)
static void setActiveFocus(QQuickItem *item, Qt::FocusReason reason)
static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack)