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
1467
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1482
1483
1484
1485
1486
1487
1488
1491QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1493 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1494 itemPrivate = QQuickItemPrivate::get(item);
1495 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1496 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1499 itemPrivate->extra.value().layoutDirectionAttached =
this;
1501 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1504QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1506 return new QQuickLayoutMirroringAttached(object);
1509bool QQuickLayoutMirroringAttached::enabled()
const
1511 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1514void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1519 itemPrivate->isMirrorImplicit =
false;
1520 if (enabled != itemPrivate->effectiveLayoutMirror) {
1521 itemPrivate->setLayoutMirror(enabled);
1522 if (itemPrivate->inheritMirrorFromItem)
1523 itemPrivate->resolveLayoutMirror();
1527void QQuickLayoutMirroringAttached::resetEnabled()
1529 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1530 itemPrivate->isMirrorImplicit =
true;
1531 itemPrivate->resolveLayoutMirror();
1535bool QQuickLayoutMirroringAttached::childrenInherit()
const
1537 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1540void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1541 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1542 itemPrivate->inheritMirrorFromItem = childrenInherit;
1543 itemPrivate->resolveLayoutMirror();
1544 childrenInheritChanged();
1548void QQuickItemPrivate::resolveLayoutMirror()
1551 if (QQuickItem *parentItem = q->parentItem()) {
1552 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1553 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1555 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1559void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1561 inherit = inherit || inheritMirrorFromItem;
1562 if (!isMirrorImplicit && inheritMirrorFromItem)
1563 mirror = effectiveLayoutMirror;
1564 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1567 inheritMirrorFromParent = inherit;
1568 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1570 if (isMirrorImplicit)
1571 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1572 for (
int i = 0; i < childItems.size(); ++i) {
1573 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1574 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1575 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1580void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1582 if (mirror != effectiveLayoutMirror) {
1583 effectiveLayoutMirror = mirror;
1585 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1586 anchor_d->fillChanged();
1587 anchor_d->centerInChanged();
1588 anchor_d->updateHorizontalAnchors();
1591 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1592 emit extra->layoutDirectionAttached->enabledChanged();
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
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
1642
1644QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1645 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1647 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1648 itemPrivate = QQuickItemPrivate::get(item);
1649 itemPrivate->extra.value().enterKeyAttached =
this;
1651 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1654QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1656 return new QQuickEnterKeyAttached(object);
1659Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1664void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1666 if (keyType != type) {
1669 if (itemPrivate && itemPrivate->activeFocus)
1670 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1676void QQuickItemPrivate::setAccessible()
1678 isAccessible =
true;
1682
1683
1684
1685
1686void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1691 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1693 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1695 if (oldSubFocusItem) {
1696 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1697 while (sfi && sfi != scope) {
1698 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1699 sfi = sfi->parentItem();
1704 scopePrivate->subFocusItem = q;
1705 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1706 while (sfi && sfi != scope) {
1707 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1708 sfi = sfi->parentItem();
1711 scopePrivate->subFocusItem =
nullptr;
1716bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1719 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1720 Qt::FocusPolicy policy = Qt::ClickFocus;
1722 switch (eventType) {
1723 case QEvent::MouseButtonPress:
1724 case QEvent::MouseButtonDblClick:
1725 case QEvent::TouchBegin:
1726 if (setFocusOnRelease)
1729 case QEvent::MouseButtonRelease:
1730 case QEvent::TouchEnd:
1731 if (!setFocusOnRelease)
1735 policy = Qt::WheelFocus;
1741 if ((focusPolicy & policy) == policy) {
1742 setActiveFocus(q, Qt::MouseFocusReason);
1749Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1751 return static_cast<Qt::FocusReason>(focusReason);
1754bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1756 if (focusReason == reason)
1759 focusReason = reason;
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
1880
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
2079
2080
2081
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
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
2150
2151
2152
2155
2156
2157
2158
2159
2160
2161
2162
2163
2166
2167
2168
2171
2172
2173
2176
2177
2178
2181
2182
2183
2186
2187
2188
2189
2190
2191
2192
2195
2196
2197
2198
2199
2200
2203
2204
2205
2206
2207
2210
2211
2212
2213
2214
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2235
2236
2237
2240
2241
2242
2245
2246
2247
2250
2251
2252
2255
2256
2257
2260
2261
2262
2265
2266
2267
2270
2271
2272
2275
2276
2277
2280
2281
2282
2285
2286
2287
2290
2291
2292
2295
2296
2297
2300
2301
2302
2305
2306
2307
2310
2311
2312
2315
2316
2317
2320
2321
2322
2325
2326
2327
2330
2331
2332
2335
2336
2337
2340
2341
2342
2345
2346
2347
2350
2351
2352
2355
2356
2357
2360
2361
2362
2365
2366
2367
2370
2371
2372
2373
2374
2375
2376
2377QQuickItem::QQuickItem(QQuickItem* parent)
2378: QObject(*(
new QQuickItemPrivate), parent)
2385
2386QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2387: QObject(dd, parent)
2394
2395
2396QQuickItem::~QQuickItem()
2399 d->inDestructor =
true;
2401#if QT_CONFIG(accessibility)
2402 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
2403 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
2405 d->isAccessible =
false;
2408 if (d->windowRefCount > 1)
2409 d->windowRefCount = 1;
2411 setParentItem(
nullptr);
2415 for (QQuickItem *child : std::as_const(d->childItems))
2416 child->setParentItem(
nullptr);
2417 d->childItems.clear();
2419 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2420 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2422 anchor->clearItem(
this);
2425
2426
2427
2428 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2429 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2430 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2433 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2434 d->changeListeners.clear();
2437
2438
2439
2440
2441 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2442 QQuickTransform *t = d->transforms.at(ii);
2443 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2444 tp->items.removeOne(
this);
2447 if (d->extra.isAllocated()) {
2448 delete d->extra->contents; d->extra->contents =
nullptr;
2449#if QT_CONFIG(quick_shadereffect)
2450 delete d->extra->layer; d->extra->layer =
nullptr;
2454 delete d->_anchors; d->_anchors =
nullptr;
2455 delete d->_stateGroup; d->_stateGroup =
nullptr;
2457 d->isQuickItem =
false;
2461
2462
2463bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2465 if (!item->window())
2468 if (item == item->window()->contentItem())
2471 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2472 if (tabFocus == Qt::NoTabFocus)
2474 if (tabFocus == Qt::TabFocusAllControls)
2477 QVariant editable = item->property(
"editable");
2478 if (editable.isValid())
2479 return editable.toBool();
2481 QVariant readonly = item->property(
"readOnly");
2482 if (readonly.isValid())
2483 return !readonly.toBool() && item->property(
"text").isValid();
2485#if QT_CONFIG(accessibility)
2486 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2487 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2489 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2490 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2491 return iface->state().editable;
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2510 QQuickWindow *window = item->window();
2511 const bool wrap = !window || window->isTopLevel();
2513 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2518 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2520 if (!wrap && !next) {
2524 Q_ASSERT(window->parent());
2527 qt_window_private(window->parent())->setFocusToTarget(
2528 forward ? QWindowPrivate::FocusTarget::Next
2529 : QWindowPrivate::FocusTarget::Prev,
2531 window->parent()->requestActivate();
2535 next->forceActiveFocus(reason);
2540QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2543 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2546 const QList<QQuickItem *> &children = item->childItems();
2547 const int count = children.size();
2548 if (start < 0 || start >= count) {
2549 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2552 while (start < count) {
2553 QQuickItem *child = children.at(start);
2554 if (!child->d_func()->isTabFence)
2561QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2564 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2567 const QList<QQuickItem *> &children = item->childItems();
2568 const int count = children.size();
2571 if (start < 0 || start >= count) {
2572 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2575 while (start >= 0) {
2576 QQuickItem *child = children.at(start);
2577 if (!child->d_func()->isTabFence)
2584QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2587 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2589 if (!item->window())
2591 const QQuickItem *
const contentItem = item->window()->contentItem();
2595 QQuickItem *from =
nullptr;
2596 bool isTabFence = item->d_func()->isTabFence;
2599 from = item->parentItem();
2601 if (!item->childItems().isEmpty())
2602 from = item->d_func()->childItems.constFirst();
2603 else if (!isTabFence)
2604 from = item->parentItem();
2608 QQuickItem *startItem = item;
2609 QQuickItem *originalStartItem = startItem;
2614 while (startItem && !startItem->isVisible()) {
2615 startItem = startItem->parentItem();
2620 QQuickItem *firstFromItem = from;
2621 QQuickItem *current = item;
2622 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2623 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2624 QDuplicateTracker<QQuickItem *> cycleDetector;
2626 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2627 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2629 QQuickItem *last = current;
2631 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2632 QQuickItem *firstChild =
nullptr;
2633 QQuickItem *lastChild =
nullptr;
2635 firstChild = nextTabChildItem(current, 0);
2637 hasChildren =
false;
2639 lastChild = prevTabChildItem(current, -1);
2641 isTabFence = current->d_func()->isTabFence;
2642 if (isTabFence && !hasChildren)
2646 if (hasChildren && from == current->parentItem()) {
2648 current = firstChild;
2650 current = lastChild;
2651 if (!current->childItems().isEmpty())
2654 }
else if (hasChildren && forward && from != lastChild) {
2656 int nextChild = current->childItems().indexOf(from) + 1;
2657 current = nextTabChildItem(current, nextChild);
2658 }
else if (hasChildren && !forward && from != firstChild) {
2660 int prevChild = current->childItems().indexOf(from) - 1;
2661 current = prevTabChildItem(current, prevChild);
2662 if (!current->childItems().isEmpty())
2665 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2669 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2670 if (last != firstSibling
2671 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2675 }
else if (hasChildren) {
2676 if (!wrap && !isTabFence) {
2677 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2678 <<
"Focus chain about to wrap but we're outside a tab fence and wrapping was set to false."
2685 current = firstChild;
2686 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2687 <<
"wrapping from last to first:" << current;
2689 current = lastChild;
2690 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2691 <<
"wrapping from first to last:" << current;
2692 if (!current->childItems().isEmpty())
2704 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2705 (!skip && cycleDetector.hasSeen(current))) {
2707 if (item == contentItem) {
2708 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2711 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2715 if (!firstFromItem) {
2716 if (startItem->d_func()->isTabFence) {
2717 if (current == startItem)
2718 firstFromItem = from;
2720 startItem = current;
2721 firstFromItem = from;
2724 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2725 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2731
2732
2733
2734
2735
2736
2737
2738
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754QQuickItem *QQuickItem::parentItem()
const
2756 Q_D(
const QQuickItem);
2757 return d->parentItem;
2760void QQuickItem::setParentItem(QQuickItem *parentItem)
2763 if (parentItem == d->parentItem)
2767 QQuickItem *itemAncestor = parentItem;
2768 while (itemAncestor !=
nullptr) {
2769 if (Q_UNLIKELY(itemAncestor ==
this)) {
2770 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2773 itemAncestor = itemAncestor->parentItem();
2775 auto engine = qmlEngine(
this);
2777 QV4::ExecutionEngine *v4 = engine->handle();
2778 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2779 QV4::QObjectWrapper::markWrapper(
this, ms);
2784 d->removeFromDirtyList();
2786 QQuickItem *oldParentItem = d->parentItem;
2787 QQuickItem *scopeFocusedItem =
nullptr;
2789 if (oldParentItem) {
2790 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2792 QQuickItem *scopeItem =
nullptr;
2794 if (hasFocus() || op->subFocusItem ==
this)
2795 scopeFocusedItem =
this;
2796 else if (!isFocusScope() && d->subFocusItem)
2797 scopeFocusedItem = d->subFocusItem;
2799 if (scopeFocusedItem) {
2800 scopeItem = oldParentItem;
2801 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2802 scopeItem = scopeItem->parentItem();
2804 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2805 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2806 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2808 if (scopeFocusedItem !=
this)
2809 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2811 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2815 const bool wasVisible = isVisible();
2816 op->removeChild(
this);
2817 if (wasVisible && !op->inDestructor)
2818 emit oldParentItem->visibleChildrenChanged();
2819 }
else if (d->window) {
2820 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2823 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2824 bool alreadyAddedChild =
false;
2825 if (d->window == parentWindow) {
2827 d->parentItem = parentItem;
2829 auto oldParentItem = d->parentItem;
2830 d->parentItem = parentItem;
2831 if (d->parentItem) {
2832 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2833 alreadyAddedChild =
true;
2841 if (!oldParentItem && d->window) {
2842 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2846 d->refWindow(parentWindow);
2849 d->dirty(QQuickItemPrivate::ParentChanged);
2851 if (d->parentItem && !alreadyAddedChild)
2852 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2853 else if (d->window && !alreadyAddedChild)
2854 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2856 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2857 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2859 if (d->parentItem) {
2860 if (!scopeFocusedItem) {
2862 scopeFocusedItem =
this;
2863 else if (!isFocusScope() && d->subFocusItem)
2864 scopeFocusedItem = d->subFocusItem;
2867 if (scopeFocusedItem) {
2869 QQuickItem *scopeItem = d->parentItem;
2870 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2871 scopeItem = scopeItem->parentItem();
2873 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2874 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2875 if (scopeFocusedItem !=
this)
2876 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2877 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2878 emit scopeFocusedItem->focusChanged(
false);
2881 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2882 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2883 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2886 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2893 d->resolveLayoutMirror();
2895 d->itemChange(ItemParentHasChanged, d->parentItem);
2897 if (!d->inDestructor)
2898 emit parentChanged(d->parentItem);
2899 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2900 emit d->parentItem->visibleChildrenChanged();
2902#if QT_CONFIG(accessibility)
2903 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2904 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2905 QAccessible::updateAccessibility(&qaEvent);
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928void QQuickItem::stackBefore(
const QQuickItem *sibling)
2931 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2932 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2933 <<
this <<
" before " << sibling <<
", which must be a sibling";
2937 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2939 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2940 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2942 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2944 if (myIndex == siblingIndex - 1)
2947 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2949 parentPrivate->markSortedChildrenDirty(
this);
2950 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2952 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2953 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974void QQuickItem::stackAfter(
const QQuickItem *sibling)
2977 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2978 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2979 <<
this <<
" after " << sibling <<
", which must be a sibling";
2983 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2985 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2986 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2988 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2990 if (myIndex == siblingIndex + 1)
2993 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2995 parentPrivate->markSortedChildrenDirty(
this);
2996 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2998 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2999 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
3003
3004
3007
3008
3009
3010
3011
3012
3013QQuickWindow *QQuickItem::window()
const
3015 Q_D(
const QQuickItem);
3021 return lhs->z() < rhs->z();
3024QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3026 if (sortedChildItems)
3027 return *sortedChildItems;
3032 for (
int i = 0; i < childItems.size(); ++i) {
3033 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3039 sortedChildItems =
new QList<QQuickItem*>(childItems);
3040 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3041 return *sortedChildItems;
3044 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3049void QQuickItemPrivate::addChild(QQuickItem *child)
3053 Q_ASSERT(!childItems.contains(child));
3055 childItems.append(child);
3057 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3059#if QT_CONFIG(cursor)
3062 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3063 setHasCursorInChild(
true);
3066 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3067 setHasHoverInChild(
true);
3069 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3070 markSortedChildrenDirty(child);
3071 dirty(QQuickItemPrivate::ChildrenChanged);
3073 itemChange(QQuickItem::ItemChildAddedChange, child);
3075 emit q->childrenChanged();
3078void QQuickItemPrivate::removeChild(QQuickItem *child)
3083 if (!inDestructor) {
3085 Q_ASSERT(childItems.contains(child));
3086 childItems.removeOne(child);
3087 Q_ASSERT(!childItems.contains(child));
3090 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3092#if QT_CONFIG(cursor)
3094 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3095 setHasCursorInChild(
false);
3098 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3099 setHasHoverInChild(
false);
3101 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3102 if (!inDestructor) {
3103 markSortedChildrenDirty(child);
3104 dirty(QQuickItemPrivate::ChildrenChanged);
3107 itemChange(QQuickItem::ItemChildRemovedChange, child);
3110 emit q->childrenChanged();
3113void QQuickItemPrivate::refWindow(QQuickWindow *c)
3125 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3127 if (++windowRefCount > 1) {
3129 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3133 Q_ASSERT(window ==
nullptr);
3136 if (polishScheduled)
3137 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3140 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3142 for (
int ii = 0; ii < childItems.size(); ++ii) {
3143 QQuickItem *child = childItems.at(ii);
3144 QQuickItemPrivate::get(child)->refWindow(c);
3149 if (extra.isAllocated() && extra->screenAttached)
3150 extra->screenAttached->windowChanged(c);
3151 itemChange(QQuickItem::ItemSceneChange, c);
3154void QQuickItemPrivate::derefWindow()
3157 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3162 if (--windowRefCount > 0)
3165 q->releaseResources();
3166 removeFromDirtyList();
3167 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3168 if (polishScheduled)
3169 c->itemsToPolish.removeOne(q);
3170#if QT_CONFIG(cursor)
3171 if (c->cursorItem == q) {
3172 c->cursorItem =
nullptr;
3173 window->unsetCursor();
3176 if (itemNodeInstance)
3177 c->cleanup(itemNodeInstance);
3179 c->parentlessItems.remove(q);
3181 if (
auto *da = deliveryAgentPrivate()) {
3182 if (da->activeFocusItem == q) {
3183 qCDebug(lcFocus) <<
"Removing active focus item from window's delivery agent";
3184 da->activeFocusItem =
nullptr;
3189 itemNodeInstance =
nullptr;
3191 if (extra.isAllocated()) {
3192 extra->opacityNode =
nullptr;
3193 extra->clipNode =
nullptr;
3194 extra->rootNode =
nullptr;
3197 paintNode =
nullptr;
3199 for (
int ii = 0; ii < childItems.size(); ++ii) {
3200 if (QQuickItem *child = childItems.at(ii))
3201 QQuickItemPrivate::get(child)->derefWindow();
3206 if (extra.isAllocated() && extra->screenAttached)
3207 extra->screenAttached->windowChanged(
nullptr);
3208 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3211qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3213 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3216#ifdef QT_BUILD_INTERNAL
3217quint32 QQuickItemPrivate::item_counter = 0;
3218quint32 QQuickItemPrivate::itemExtra_counter = 0;
3219quint32 QQuickItemPrivate::eventHandlingChildrenWithinBounds_counter = 0;
3220quint64 QQuickItemPrivate::itemToParentTransform_counter = 0;
3221quint64 QQuickItemPrivate::itemToWindowTransform_counter = 0;
3222quint64 QQuickItemPrivate::windowToItemTransform_counter = 0;
3223quint64 QQuickItemPrivate::effectiveClippingSkips_counter = 0;
3227
3228
3229QTransform QQuickItemPrivate::windowToItemTransform()
const
3232#ifdef QT_BUILD_INTERNAL
3233 ++windowToItemTransform_counter;
3235 return itemToWindowTransform().inverted();
3239
3240
3241QTransform QQuickItemPrivate::itemToWindowTransform()
const
3243#ifdef QT_BUILD_INTERNAL
3244 ++itemToWindowTransform_counter;
3247 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3248 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3249 itemToParentTransform(&rv);
3254
3255
3256void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3258#ifdef QT_BUILD_INTERNAL
3259 ++itemToParentTransform_counter;
3262
3263
3264
3265
3266
3268 qreal x =
this->x.valueBypassingBindings();
3269 qreal y =
this->y.valueBypassingBindings();
3273 if (!transforms.isEmpty()) {
3275 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3276 transforms.at(ii)->applyTo(&m);
3277 *t = m.toTransform();
3280 if (scale() != 1. || rotation() != 0.) {
3281 QPointF tp = computeTransformOrigin();
3282 t->translate(tp.x(), tp.y());
3283 t->scale(scale(), scale());
3284 t->rotate(rotation());
3285 t->translate(-tp.x(), -tp.y());
3290
3291
3292
3293
3294
3295
3296
3297
3298bool QQuickItem::isComponentComplete()
const
3300 Q_D(
const QQuickItem);
3301 return d->componentComplete;
3304QQuickItemPrivate::QQuickItemPrivate()
3306 , _stateGroup(
nullptr)
3308 , widthValidFlag(
false)
3309 , heightValidFlag(
false)
3310 , componentComplete(
true)
3313 , hoverEnabled(
false)
3315 , antialiasing(
false)
3317 , activeFocus(
false)
3318 , notifiedFocus(
false)
3319 , notifiedActiveFocus(
false)
3320 , filtersChildMouseEvents(
false)
3321 , explicitVisible(
true)
3322 , effectiveVisible(
true)
3323 , explicitEnable(
true)
3324 , effectiveEnable(
true)
3325 , polishScheduled(
false)
3326 , inheritedLayoutMirror(
false)
3327 , effectiveLayoutMirror(
false)
3328 , isMirrorImplicit(
true)
3329 , inheritMirrorFromParent(
false)
3330 , inheritMirrorFromItem(
false)
3331 , isAccessible(
false)
3334 , subtreeCursorEnabled(
false)
3335 , subtreeHoverEnabled(
false)
3336 , activeFocusOnTab(
false)
3337 , implicitAntialiasing(
false)
3338 , antialiasingValid(
false)
3340 , replayingPressEvent(
false)
3341 , touchEnabled(
false)
3342 , hasCursorHandler(
false)
3343 , maybeHasSubsceneDeliveryAgent(
true)
3344 , subtreeTransformChangedEnabled(
true)
3345 , inDestructor(
false)
3346 , focusReason(Qt::OtherFocusReason)
3347 , focusPolicy(Qt::NoFocus)
3348 , eventHandlingChildrenWithinBounds(
false)
3349 , eventHandlingChildrenWithinBoundsSet(
false)
3350 , customOverlay(
false)
3351 , dirtyAttributes(0)
3352 , nextDirtyItem(
nullptr)
3353 , prevDirtyItem(
nullptr)
3356 , parentItem(
nullptr)
3357 , sortedChildItems(&childItems)
3358 , subFocusItem(
nullptr)
3366 , itemNodeInstance(
nullptr)
3367 , paintNode(
nullptr)
3368 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3370#ifdef QT_BUILD_INTERNAL
3375QQuickItemPrivate::~QQuickItemPrivate()
3377 if (sortedChildItems != &childItems)
3378 delete sortedChildItems;
3381void QQuickItemPrivate::init(QQuickItem *parent)
3387 baselineOffset = 0.0;
3390 q->setParentItem(parent);
3391 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3392 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3396QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3401void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3403 szPolicy.setHorizontalPolicy(horizontalPolicy);
3404 szPolicy.setVerticalPolicy(verticalPolicy);
3407void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3412 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3414 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3415 item->setParentItem(that);
3416 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3417 if (pointerHandler->parent() != that) {
3418 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3419 pointerHandler->setParent(that);
3421 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3424 resources_append(prop, o);
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3463qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3465 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3466 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3467 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3468 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3470 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3473QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3475 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3476 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3477 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3478 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3480 qsizetype resourcesCount = resources_count(&resourcesProperty);
3481 if (i < resourcesCount)
3482 return resources_at(&resourcesProperty, i);
3483 const qsizetype j = i - resourcesCount;
3484 if (j < children_count(&childrenProperty))
3485 return children_at(&childrenProperty, j);
3489void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3491 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3492 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3493 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3494 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3496 resources_clear(&resourcesProperty);
3497 children_clear(&childrenProperty);
3500void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3502 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3503 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3505 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3506 if (children_count(&childrenProperty) > 0) {
3507 children_removeLast(&childrenProperty);
3511 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3512 if (resources_count(&resourcesProperty) > 0)
3513 resources_removeLast(&resourcesProperty);
3516QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3518 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3519 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3522void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3524 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3525 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3526 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3527 quickItemPrivate->extra.value().resourcesList.append(object);
3528 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3529 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3533qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3535 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3536 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3539void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3541 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3542 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3543 if (quickItemPrivate->extra.isAllocated()) {
3544 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3545 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3546 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3548 quickItemPrivate->extra->resourcesList.clear();
3552void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3554 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3555 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3556 if (quickItemPrivate->extra.isAllocated()) {
3557 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3558 if (resources->isEmpty())
3561 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3562 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3563 resources->removeLast();
3567QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3569 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3570 if (index >= p->childItems.size() || index < 0)
3573 return p->childItems.at(index);
3576void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3581 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3582 if (o->parentItem() == that)
3583 o->setParentItem(
nullptr);
3585 o->setParentItem(that);
3588qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3590 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3591 return p->childItems.size();
3594void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3596 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3597 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3598 while (!p->childItems.isEmpty())
3599 p->childItems.at(0)->setParentItem(
nullptr);
3602void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3604 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3605 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3606 if (!p->childItems.isEmpty())
3607 p->childItems.last()->setParentItem(
nullptr);
3610qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3612 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3613 qsizetype visibleCount = 0;
3614 qsizetype c = p->childItems.size();
3616 if (p->childItems.at(c)->isVisible()) visibleCount++;
3619 return visibleCount;
3622QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3624 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3625 const qsizetype childCount = p->childItems.size();
3626 if (index >= childCount || index < 0)
3629 qsizetype visibleCount = -1;
3630 for (qsizetype i = 0; i < childCount; i++) {
3631 if (p->childItems.at(i)->isVisible()) visibleCount++;
3632 if (visibleCount == index)
return p->childItems.at(i);
3637qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3639 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3640 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3642 return p->transforms.size();
3645void QQuickTransform::appendToItem(QQuickItem *item)
3647 Q_D(QQuickTransform);
3651 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3653 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3654 p->transforms.removeOne(
this);
3655 p->transforms.append(
this);
3657 p->transforms.append(
this);
3658 d->items.append(item);
3661 p->dirty(QQuickItemPrivate::Transform);
3664void QQuickTransform::prependToItem(QQuickItem *item)
3666 Q_D(QQuickTransform);
3670 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3672 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3673 p->transforms.removeOne(
this);
3674 p->transforms.prepend(
this);
3676 p->transforms.prepend(
this);
3677 d->items.append(item);
3680 p->dirty(QQuickItemPrivate::Transform);
3683void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3688 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3689 transform->appendToItem(that);
3692QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3694 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3695 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3697 if (idx < 0 || idx >= p->transforms.size())
3700 return p->transforms.at(idx);
3703void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3705 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3706 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3708 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3709 QQuickTransform *t = p->transforms.at(ii);
3710 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3711 tp->items.removeOne(that);
3714 p->transforms.clear();
3716 p->dirty(QQuickItemPrivate::Transform);
3719void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3721 if (extra.isAllocated() && extra->resourcesList.contains(object))
3722 extra->resourcesList.removeAll(object);
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
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821QQuickAnchors *QQuickItemPrivate::anchors()
const
3824 Q_Q(
const QQuickItem);
3825 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3826 if (!componentComplete)
3827 _anchors->classBegin();
3832void QQuickItemPrivate::siblingOrderChanged()
3835 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3838QQmlListProperty<QObject> QQuickItemPrivate::data()
3842 QQmlListProperty<QObject> result;
3843 result.object = q_func();
3844 result.append = QQuickItemPrivate::data_append;
3845 result.count = QQuickItemPrivate::data_count;
3846 result.at = QQuickItemPrivate::data_at;
3847 result.clear = QQuickItemPrivate::data_clear;
3848 result.removeLast = QQuickItemPrivate::data_removeLast;
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883QRectF QQuickItem::childrenRect()
3886 if (!d->extra.isAllocated() || !d->extra->contents) {
3887 d->extra.value().contents =
new QQuickContents(
this);
3888 if (d->componentComplete)
3889 d->extra->contents->complete();
3891 return d->extra->contents->rectF();
3895
3896
3897QList<QQuickItem *> QQuickItem::childItems()
const
3899 Q_D(
const QQuickItem);
3900 return d->childItems;
3904
3905
3906
3907
3908
3909
3910
3911
3912
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931bool QQuickItem::clip()
const
3933 return flags() & ItemClipsChildrenToShape;
3936void QQuickItem::setClip(
bool c)
3941 setFlag(ItemClipsChildrenToShape, c);
3943 setFlag(ItemIsViewport);
3944 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3945 setFlag(ItemIsViewport,
false);
3947 emit clipChanged(c);
3951
3952
3953
3954
3955
3956
3957
3958
3959void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3964 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3966 QQuickGeometryChange change;
3967 change.setXChange(newGeometry.x() != oldGeometry.x());
3968 change.setYChange(newGeometry.y() != oldGeometry.y());
3969 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3970 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3972 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3973 if (change.matches(listener.gTypes))
3974 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3979 if (change.xChange())
3981 if (change.yChange())
3983 if (change.widthChange())
3985 if (change.heightChange())
3987#if QT_CONFIG(accessibility)
3988 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3989 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3990 QAccessible::updateAccessibility(&ev);
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
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4049QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4051 Q_UNUSED(updatePaintNodeData);
4056QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4057: transformNode(
nullptr)
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4078void QQuickItem::releaseResources()
4082QSGTransformNode *QQuickItemPrivate::createTransformNode()
4084 return new QSGTransformNode;
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097void QQuickItem::updatePolish()
4101#define PRINT_LISTENERS() do
4103 qDebug().nospace() << q_func() << " (" << this
4104 << ") now has the following listeners:";
4105 for (const auto &listener : std::as_const(changeListeners)) {
4106 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4107 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4109}while
4112void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4115 changeListeners.append(ChangeListener(listener, types));
4116 listener->addSourceItem(q);
4118 if (lcChangeListeners().isDebugEnabled())
4122void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4126 const ChangeListener changeListener(listener, types);
4127 const int index = changeListeners.indexOf(changeListener);
4129 changeListeners[index].types = changeListener.types;
4131 changeListeners.append(changeListener);
4132 listener->addSourceItem(q);
4135 if (lcChangeListeners().isDebugEnabled())
4139void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4143 ChangeListener change(listener, types);
4144 changeListeners.removeOne(change);
4145 listener->removeSourceItem(q);
4147 if (lcChangeListeners().isDebugEnabled())
4151void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4152 QQuickGeometryChange types)
4156 ChangeListener change(listener, types);
4157 int index = changeListeners.indexOf(change);
4159 changeListeners[index].gTypes = change.gTypes;
4161 changeListeners.append(change);
4162 listener->addSourceItem(q);
4165 if (lcChangeListeners().isDebugEnabled())
4169void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4170 QQuickGeometryChange types)
4174 ChangeListener change(listener, types);
4175 if (types.noChange()) {
4176 changeListeners.removeOne(change);
4177 listener->removeSourceItem(q);
4179 int index = changeListeners.indexOf(change);
4181 changeListeners[index].gTypes = change.gTypes;
4184 if (lcChangeListeners().isDebugEnabled())
4189
4190
4191
4192
4193
4194
4195void QQuickItem::keyPressEvent(QKeyEvent *event)
4201
4202
4203
4204
4205
4206
4207void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4214
4215
4216
4217
4218
4219
4220void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236void QQuickItem::focusInEvent(QFocusEvent *event)
4239#if QT_CONFIG(accessibility)
4240 if (d->isAccessible && QAccessible::isActive()) {
4241 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4242 QAccessibleEvent ev(acc, QAccessible::Focus);
4243 QAccessible::updateAccessibility(&ev);
4247 d->setLastFocusChangeReason(event->reason());
4251
4252
4253
4254
4255
4256
4257void QQuickItem::focusOutEvent(QFocusEvent *event)
4260 d->setLastFocusChangeReason(event->reason());
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273void QQuickItem::mousePressEvent(QMouseEvent *event)
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4311
4312
4313
4314
4315
4316
4317void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4323
4324
4325
4326void QQuickItem::mouseUngrabEvent()
4332
4333
4334
4335void QQuickItem::touchUngrabEvent()
4340#if QT_CONFIG(wheelevent)
4342
4343
4344
4345
4346
4347
4348void QQuickItem::wheelEvent(QWheelEvent *event)
4355
4356
4357
4358
4359
4360
4361void QQuickItem::touchEvent(QTouchEvent *event)
4367
4368
4369
4370
4371
4372
4373
4374
4375void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4381
4382
4383
4384
4385
4386
4387
4388
4389void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4395
4396
4397
4398
4399
4400
4401
4402
4403void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4408#if QT_CONFIG(quick_draganddrop)
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472void QQuickItem::dropEvent(QDropEvent *event)
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4517
4518
4519
4520
4521
4522
4523
4524QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4526 Q_D(
const QQuickItem);
4531 v = (
bool)(flags() & ItemAcceptsInputMethod);
4534 case Qt::ImAnchorRectangle:
4535 case Qt::ImCursorRectangle:
4537 case Qt::ImCursorPosition:
4538 case Qt::ImSurroundingText:
4539 case Qt::ImCurrentSelection:
4540 case Qt::ImMaximumTextLength:
4541 case Qt::ImAnchorPosition:
4542 case Qt::ImPreferredLanguage:
4543 case Qt::ImReadOnly:
4544 if (d->extra.isAllocated() && d->extra->keyHandler)
4545 v = d->extra->keyHandler->inputMethodQuery(query);
4547 case Qt::ImEnterKeyType:
4548 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4549 v = d->extra->enterKeyAttached->type();
4551 case Qt::ImInputItemClipRectangle:
4552 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4553 QRectF rect = QRectF(0,0, width(), height());
4554 const QQuickItem *par =
this;
4555 while (QQuickItem *parpar = par->parentItem()) {
4556 rect = parpar->mapRectFromItem(par, rect);
4558 rect = rect.intersected(parpar->clipRect());
4561 rect = par->mapRectToScene(rect);
4563 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4565 v = mapRectFromScene(rect);
4576QQuickAnchorLine QQuickItemPrivate::left()
const
4578 Q_Q(
const QQuickItem);
4579 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4582QQuickAnchorLine QQuickItemPrivate::right()
const
4584 Q_Q(
const QQuickItem);
4585 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4588QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4590 Q_Q(
const QQuickItem);
4591 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4594QQuickAnchorLine QQuickItemPrivate::top()
const
4596 Q_Q(
const QQuickItem);
4597 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4600QQuickAnchorLine QQuickItemPrivate::bottom()
const
4602 Q_Q(
const QQuickItem);
4603 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4606QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4608 Q_Q(
const QQuickItem);
4609 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4612QQuickAnchorLine QQuickItemPrivate::baseline()
const
4614 Q_Q(
const QQuickItem);
4615 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640qreal QQuickItem::baselineOffset()
const
4642 Q_D(
const QQuickItem);
4643 return d->baselineOffset;
4646void QQuickItem::setBaselineOffset(qreal offset)
4649 if (offset == d->baselineOffset)
4652 d->baselineOffset = offset;
4654 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4655 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4657 anchor->updateVerticalAnchors();
4660 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4661 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4663 emit baselineOffsetChanged(offset);
4668
4669
4670
4671
4672
4673
4674
4675
4676void QQuickItem::update()
4679 if (!(flags() & ItemHasContents)) {
4681 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4685 d->dirty(QQuickItemPrivate::Content);
4689
4690
4691
4692
4693
4694
4695
4696void QQuickItem::polish()
4699 if (!d->polishScheduled) {
4700 d->polishScheduled =
true;
4702 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4703 bool maybeupdate = p->itemsToPolish.isEmpty();
4704 p->itemsToPolish.append(
this);
4705 if (maybeupdate) d->window->maybeUpdate();
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725void QQuickItem::ensurePolished()
4730#if QT_DEPRECATED_SINCE(6
, 5
)
4731static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4732 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4734 QV4::ExecutionEngine *v4 = args->v4engine();
4735 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4736 v4->throwTypeError();
4740 QV4::Scope scope(v4);
4741 QV4::ScopedValue item(scope, (*args)[0]);
4744 if (!item->isNull()) {
4745 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4747 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4750 if (!(*itemObj) && !item->isNull()) {
4751 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4752 <<
"\" which is neither null nor an Item";
4753 v4->throwTypeError();
4759 if (args->length() == 2) {
4760 QV4::ScopedValue sv(scope, (*args)[1]);
4762 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4763 <<
"\" which is neither a point nor a rect";
4764 v4->throwTypeError();
4767 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4768 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4769 if (v.canConvert<QPointF>()) {
4770 const QPointF p = v.toPointF();
4773 }
else if (v.canConvert<QRectF>()) {
4774 const QRectF r = v.toRectF();
4781 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4782 <<
"\" which is neither a point nor a rect";
4783 v4->throwTypeError();
4787 QV4::ScopedValue vx(scope, (*args)[1]);
4788 QV4::ScopedValue vy(scope, (*args)[2]);
4790 if (!vx->isNumber() || !vy->isNumber()) {
4791 v4->throwTypeError();
4795 *x = vx->asDouble();
4796 *y = vy->asDouble();
4798 if (args->length() > 3) {
4799 QV4::ScopedValue vw(scope, (*args)[3]);
4800 QV4::ScopedValue vh(scope, (*args)[4]);
4801 if (!vw->isNumber() || !vh->isNumber()) {
4802 v4->throwTypeError();
4805 *w = vw->asDouble();
4806 *h = vh->asDouble();
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4833#if QT_DEPRECATED_SINCE(6
, 5
)
4835
4836
4837void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4839 QV4::ExecutionEngine *v4 = args->v4engine();
4840 QV4::Scope scope(v4);
4844 QQuickItem *itemObj;
4845 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4848 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4849 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4851 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4852 args->setReturnValue(rv.asReturnedValue());
4857
4858
4859QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4861 Q_D(
const QQuickItem);
4867 QTransform t = d->itemToWindowTransform();
4868 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4891#if QT_DEPRECATED_SINCE(6
, 5
)
4893
4894
4895void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4897 QV4::ExecutionEngine *v4 = args->v4engine();
4898 QV4::Scope scope(v4);
4902 QQuickItem *itemObj;
4903 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4906 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4907 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4909 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4910 args->setReturnValue(rv.asReturnedValue());
4913static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4915 QV4::ExecutionEngine *v4 = args->v4engine();
4916 if (args->length() != 1 && args->length() != 2) {
4917 v4->throwTypeError();
4921 QV4::Scope scope(v4);
4923 if (args->length() == 1) {
4924 QV4::ScopedValue sv(scope, (*args)[0]);
4926 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4927 <<
"\" which is not a point";
4928 v4->throwTypeError();
4931 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4932 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4933 if (v.canConvert<QPointF>()) {
4934 const QPointF p = v.toPointF();
4938 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4939 <<
"\" which is not a point";
4940 v4->throwTypeError();
4944 QV4::ScopedValue vx(scope, (*args)[0]);
4945 QV4::ScopedValue vy(scope, (*args)[1]);
4947 if (!vx->isNumber() || !vy->isNumber()) {
4948 v4->throwTypeError();
4952 *x = vx->asDouble();
4953 *y = vy->asDouble();
4960
4961
4962
4963
4964
4965
4966
4967
4969
4970
4971void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4973 QV4::ExecutionEngine *v4 = args->v4engine();
4974 QV4::Scope scope(v4);
4977 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4980 QVariant result = mapFromGlobal(QPointF(x, y));
4982 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4983 args->setReturnValue(rv.asReturnedValue());
4988
4989
4990
4991
4992
4993
4994
4995
4997#if QT_DEPRECATED_SINCE(6
, 5
)
4999
5000
5001void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
5003 QV4::ExecutionEngine *v4 = args->v4engine();
5004 QV4::Scope scope(v4);
5007 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
5010 QVariant result = mapToGlobal(QPointF(x, y));
5012 QV4::ScopedObject rv(scope, v4->fromVariant(result));
5013 args->setReturnValue(rv.asReturnedValue());
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043void QQuickItem::forceActiveFocus()
5045 forceActiveFocus(Qt::OtherFocusReason);
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5073void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5075 setFocus(
true, reason);
5076 QQuickItem *parent = parentItem();
5077 QQuickItem *scope =
nullptr;
5079 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5080 parent->setFocus(
true, reason);
5084 parent = parent->parentItem();
5089
5090
5091
5092
5093
5094
5095
5096
5097
5099
5100
5101
5102
5103
5105QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5107 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5111
5112
5113
5114
5115
5116
5117
5119
5120
5121
5122
5123
5124QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5126 const QList<QQuickItem *> children = childItems();
5127 for (
int i = children.size()-1; i >= 0; --i) {
5128 QQuickItem *child = children.at(i);
5130 QPointF point = mapToItem(child, QPointF(x, y));
5131 if (child->isVisible() && child->contains(point))
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178void QQuickItem::dumpItemTree()
const
5180 Q_D(
const QQuickItem);
5184void QQuickItemPrivate::dumpItemTree(
int indent)
const
5186 Q_Q(
const QQuickItem);
5188 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5189 qDebug().nospace().noquote() << indentStr <<
5190#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5191 const_cast<QQuickItem *>(q);
5195 if (extra.isAllocated()) {
5196 for (
const auto handler : extra->pointerHandlers)
5197 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5199 for (
const QQuickItem *ch : childItems) {
5200 auto itemPriv = QQuickItemPrivate::get(ch);
5201 itemPriv->dumpItemTree(indent + 1);
5205QQmlListProperty<QObject> QQuickItemPrivate::resources()
5209 QQmlListProperty<QObject> result;
5210 result.object = q_func();
5211 result.append = QQuickItemPrivate::resources_append;
5212 result.count = QQuickItemPrivate::resources_count;
5213 result.at = QQuickItemPrivate::resources_at;
5214 result.clear = QQuickItemPrivate::resources_clear;
5215 result.removeLast = QQuickItemPrivate::resources_removeLast;
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5233
5234
5235
5236QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5240 QQmlListProperty<QQuickItem> result;
5241 result.object = q_func();
5242 result.append = QQuickItemPrivate::children_append;
5243 result.count = QQuickItemPrivate::children_count;
5244 result.at = QQuickItemPrivate::children_at;
5245 result.clear = QQuickItemPrivate::children_clear;
5246 result.removeLast = QQuickItemPrivate::children_removeLast;
5251
5252
5253
5254
5255
5257
5258
5259
5260QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5262 return QQmlListProperty<QQuickItem>(q_func(),
5264 QQuickItemPrivate::visibleChildren_count,
5265 QQuickItemPrivate::visibleChildren_at);
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5306
5307
5308
5309QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5311 return _states()->statesProperty();
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5343
5344
5345
5346QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5348 return _states()->transitionsProperty();
5351QString QQuickItemPrivate::state()
const
5356 return _stateGroup->state();
5359void QQuickItemPrivate::setState(
const QString &state)
5361 _states()->setState(state);
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386QString QQuickItem::state()
const
5388 Q_D(
const QQuickItem);
5392void QQuickItem::setState(
const QString &state)
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5411
5412
5413
5415
5416
5417QQmlListProperty<QQuickTransform> QQuickItem::transform()
5419 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5420 QQuickItemPrivate::transform_count,
5421 QQuickItemPrivate::transform_at,
5422 QQuickItemPrivate::transform_clear);
5426
5427
5428
5429
5430void QQuickItem::classBegin()
5433 d->componentComplete =
false;
5435 d->_stateGroup->classBegin();
5437 d->_anchors->classBegin();
5438#if QT_CONFIG(quick_shadereffect)
5439 if (d->extra.isAllocated() && d->extra->layer)
5440 d->extra->layer->classBegin();
5445
5446
5447
5448
5449void QQuickItem::componentComplete()
5452#if QT_CONFIG(quick_shadereffect)
5454
5455
5456
5457
5458
5459
5460
5461
5462 QQuickItemLayer *layer = d->extra.isAllocated() ? d->extra->layer :
nullptr;
5464 d->componentComplete =
true;
5466 d->_stateGroup->componentComplete();
5468 d->_anchors->componentComplete();
5469 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5472 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5473 safeArea->updateSafeArea();
5475 if (d->extra.isAllocated()) {
5476#if QT_CONFIG(quick_shadereffect)
5478 layer->componentComplete();
5481 if (d->extra->keyHandler)
5482 d->extra->keyHandler->componentComplete();
5484 if (d->extra->contents)
5485 d->extra->contents->complete();
5488 if (d->window && d->dirtyAttributes) {
5489 d->addToDirtyList();
5490 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5493#if QT_CONFIG(accessibility)
5494 if (d->isAccessible && d->effectiveVisible) {
5495 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5496 QAccessible::updateAccessibility(&ev);
5501QQuickStateGroup *QQuickItemPrivate::_states()
5505 _stateGroup =
new QQuickStateGroup;
5506 if (!componentComplete)
5507 _stateGroup->classBegin();
5508 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5509 q, QQuickItem, SIGNAL(stateChanged(QString)));
5515bool QQuickItemPrivate::customOverlayRequested =
false;
5517void QQuickItemPrivate::requestCustomOverlay()
5519 customOverlayRequested =
true;
5520 customOverlay =
true;
5523QPointF QQuickItemPrivate::computeTransformOrigin()
const
5527 case QQuickItem::TopLeft:
5528 return QPointF(0, 0);
5529 case QQuickItem::Top:
5530 return QPointF(width / 2., 0);
5531 case QQuickItem::TopRight:
5532 return QPointF(width, 0);
5533 case QQuickItem::Left:
5534 return QPointF(0, height / 2.);
5535 case QQuickItem::Center:
5536 return QPointF(width / 2., height / 2.);
5537 case QQuickItem::Right:
5538 return QPointF(width, height / 2.);
5539 case QQuickItem::BottomLeft:
5540 return QPointF(0, height);
5541 case QQuickItem::Bottom:
5542 return QPointF(width / 2., height);
5543 case QQuickItem::BottomRight:
5544 return QPointF(width, height);
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5566#if QT_CONFIG(quick_shadereffect)
5567 if (q == transformedItem) {
5568 if (extra.isAllocated() && extra->layer)
5569 extra->layer->updateMatrix();
5573 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5575 bool childWantsIt =
false;
5576 if (subtreeTransformChangedEnabled) {
5579 const auto children = paintOrderChildItems();
5580 for (QQuickItem *child : children)
5581 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5584 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5585 const bool ret = childWantsIt || thisWantsIt;
5586 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5587 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5588 subtreeTransformChangedEnabled =
false;
5592 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5593 dirty(QQuickItemPrivate::Clip);
5598 QQuickItemPrivate *itemPriv =
this;
5599 while (itemPriv->parentItem) {
5600 auto *parentPriv = QQuickItemPrivate::get(itemPriv->parentItem);
5601 if (parentPriv->eventHandlingChildrenWithinBounds) {
5602 Q_ASSERT(parentPriv->eventHandlingChildrenWithinBoundsSet);
5603 if (itemPriv->parentFullyContains())
5606 parentPriv->eventHandlingChildrenWithinBounds =
false;
5608 itemPriv = parentPriv;
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5631 const QPointF &startPos,
5632 const QVector2D &activeTranslation,
5635 qreal startRotation,
5636 qreal activeRotation)
5639 QVector3D xformOrigin(q->transformOriginPoint());
5640 QMatrix4x4 startMatrix;
5641 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5642 startMatrix.translate(xformOrigin);
5643 startMatrix.scale(
float(startScale));
5644 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5645 startMatrix.translate(-xformOrigin);
5647 const QVector3D centroidParentVector(centroidParentPos);
5649 mat.translate(centroidParentVector);
5650 mat.rotate(
float(activeRotation), 0, 0, 1);
5651 mat.scale(
float(activeScale));
5652 mat.translate(-centroidParentVector);
5653 mat.translate(QVector3D(activeTranslation));
5655 mat = mat * startMatrix;
5657 QPointF xformOriginPoint = q->transformOriginPoint();
5658 QPointF pos = mat.map(xformOriginPoint);
5659 pos -= xformOriginPoint;
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5689 if (maybeHasSubsceneDeliveryAgent) {
5690 QQuickItemPrivate *p =
this;
5692 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5697 maybeHasSubsceneDeliveryAgent =
false;
5700 if (p->extra.isAllocated()) {
5701 if (
auto da = p->extra->subsceneDeliveryAgent)
5704 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5708 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5711 return QQuickWindowPrivate::get(window)->deliveryAgent;
5715QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5717 auto da = deliveryAgent();
5718 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5722
5723
5724
5725
5726
5727
5728
5729QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5735 maybeHasSubsceneDeliveryAgent =
true;
5736 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5737 return extra->subsceneDeliveryAgent;
5738 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5739 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5742 q->setFlag(QQuickItem::ItemIsFocusScope);
5743 return extra->subsceneDeliveryAgent;
5746bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5748 if (!extra.isAllocated() || !extra->keyHandler)
5754 if (e->type() == QEvent::KeyPress)
5755 extra->keyHandler->keyPressed(e, post);
5757 extra->keyHandler->keyReleased(e, post);
5759 return e->isAccepted();
5762void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5765 const auto eventType = event->type();
5766 const bool focusAccepted = setFocusIfNeeded(eventType);
5768 switch (eventType) {
5769 case QEvent::MouseButtonPress:
5770 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5772 case QEvent::MouseButtonRelease:
5773 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5775 case QEvent::MouseButtonDblClick:
5776 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5778#if QT_CONFIG(wheelevent)
5780 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5783 case QEvent::TouchBegin:
5784 case QEvent::TouchUpdate:
5785 case QEvent::TouchEnd:
5786 case QEvent::TouchCancel:
5787 q->touchEvent(
static_cast<QTouchEvent *>(event));
5797void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5801 Q_ASSERT(e->isAccepted());
5802 if (filterKeyEvent(e,
false))
5807 if (e->type() == QEvent::KeyPress)
5808 q->keyPressEvent(e);
5810 q->keyReleaseEvent(e);
5812 if (e->isAccepted())
5815 if (filterKeyEvent(e,
true) || !q->window())
5819 if (e->type() == QEvent::KeyPress &&
5820 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5822 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5823 if (e->key() == Qt::Key_Backtab
5824 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5825 res = QQuickItemPrivate::focusNextPrev(q,
false);
5826 else if (e->key() == Qt::Key_Tab)
5827 res = QQuickItemPrivate::focusNextPrev(q,
true);
5829 e->setAccepted(
true);
5835void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5839 Q_ASSERT(e->isAccepted());
5840 if (extra.isAllocated() && extra->keyHandler) {
5841 extra->keyHandler->inputMethodEvent(e,
false);
5843 if (e->isAccepted())
5849 q->inputMethodEvent(e);
5851 if (e->isAccepted())
5854 if (extra.isAllocated() && extra->keyHandler) {
5857 extra->keyHandler->inputMethodEvent(e,
true);
5862void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5864 if (extra.isAllocated() && extra->keyHandler)
5865 extra->keyHandler->shortcutOverrideEvent(event);
5870bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5872 if (!hasPointerHandlers())
5874 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5875 if (handler->wantsEventPoint(event, point))
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5897 bool delivered =
false;
5898 if (extra.isAllocated()) {
5899 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5900 bool avoidThisHandler =
false;
5901 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5902 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5903 avoidThisHandler =
true;
5904 }
else if (avoidGrabbers) {
5905 for (
auto &p : event->points()) {
5906 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5907 avoidThisHandler =
true;
5912 if (!avoidThisHandler &&
5913 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5914 handler->handlePointerEvent(event);
5922#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5923bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5925bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5928 if (extra.isAllocated() && extra->contextMenu)
5929 return extra->contextMenu->event(event);
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5949 if (change == ItemSceneChange)
5950 emit windowChanged(value.window);
5955
5956
5957
5958void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5960 if (hasActiveFocus())
5961 QGuiApplication::inputMethod()->update(queries);
5966
5967
5968
5969QRectF QQuickItem::boundingRect()
const
5971 Q_D(
const QQuickItem);
5972 return QRectF(0, 0, d->width, d->height);
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996QRectF QQuickItem::clipRect()
const
5998 Q_D(
const QQuickItem);
5999 QRectF ret(0, 0, d->width.valueBypassingBindings(), d->height.valueBypassingBindings());
6000 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
6001 if (QQuickItem *viewport = viewportItem()) {
6004 if (viewport ==
this)
6006 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
6007 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
6008 return mappedViewportRect.intersected(ret);
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025QQuickItem *QQuickItem::viewportItem()
const
6027 if (flags().testFlag(ItemObservesViewport)) {
6028 QQuickItem *par = parentItem();
6030 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
6032 par = par->parentItem();
6035 return (window() ? window()->contentItem() :
nullptr);
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6074 Q_D(
const QQuickItem);
6078void QQuickItem::setTransformOrigin(TransformOrigin origin)
6081 if (origin == d->origin())
6084 d->extra.value().origin = origin;
6085 d->dirty(QQuickItemPrivate::TransformOrigin);
6087 emit transformOriginChanged(d->origin());
6091
6092
6093
6095
6096
6097QPointF QQuickItem::transformOriginPoint()
const
6099 Q_D(
const QQuickItem);
6100 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6101 return d->extra->userTransformOriginPoint;
6102 return d->computeTransformOrigin();
6106
6107
6108void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6111 if (d->extra.value().userTransformOriginPoint == point)
6114 d->extra->userTransformOriginPoint = point;
6115 d->dirty(QQuickItemPrivate::TransformOrigin);
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
6157
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
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
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280qreal QQuickItem::z()
const
6282 Q_D(
const QQuickItem);
6286void QQuickItem::setZ(qreal v)
6292 d->extra.value().z = v;
6294 d->dirty(QQuickItemPrivate::ZValue);
6295 if (d->parentItem) {
6296 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6297 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6302#if QT_CONFIG(quick_shadereffect)
6303 if (d->extra.isAllocated() && d->extra->layer)
6304 d->extra->layer->updateZ();
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
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
6362qreal QQuickItem::rotation()
const
6364 Q_D(
const QQuickItem);
6365 return d->rotation();
6368void QQuickItem::setRotation(qreal r)
6371 if (d->rotation() == r)
6374 d->extra.value().rotation = r;
6376 d->dirty(QQuickItemPrivate::BasicTransform);
6378 d->itemChange(ItemRotationHasChanged, r);
6380 emit rotationChanged();
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
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
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
6464qreal QQuickItem::scale()
const
6466 Q_D(
const QQuickItem);
6470void QQuickItem::setScale(qreal s)
6473 if (d->scale() == s)
6476 d->extra.value().scale = s;
6478 d->dirty(QQuickItemPrivate::BasicTransform);
6480 d->itemChange(ItemScaleHasChanged, s);
6482 emit scaleChanged();
6486
6487
6488
6489
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
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
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
6594
6595
6596
6597
6598
6599qreal QQuickItem::opacity()
const
6601 Q_D(
const QQuickItem);
6602 return d->opacity();
6605void QQuickItem::setOpacity(qreal newOpacity)
6608 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6609 if (d->opacity() == o)
6612 d->extra.value().opacity = o;
6614 d->dirty(QQuickItemPrivate::OpacityValue);
6616 d->itemChange(ItemOpacityHasChanged, o);
6618 emit opacityChanged();
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685bool QQuickItem::isVisible()
const
6687 Q_D(
const QQuickItem);
6688 return d->effectiveVisible;
6691void QQuickItemPrivate::setVisible(
bool visible)
6693 if (visible == explicitVisible)
6696 explicitVisible = visible;
6698 dirty(QQuickItemPrivate::Visible);
6700 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6701 if (childVisibilityChanged && parentItem)
6702 emit parentItem->visibleChildrenChanged();
6705void QQuickItem::setVisible(
bool v)
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760bool QQuickItem::isEnabled()
const
6762 Q_D(
const QQuickItem);
6763 return d->effectiveEnable;
6766void QQuickItem::setEnabled(
bool e)
6769 if (e == d->explicitEnable)
6772 d->explicitEnable = e;
6774 QQuickItem *scope = parentItem();
6775 while (scope && !scope->isFocusScope())
6776 scope = scope->parentItem();
6778 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6781bool QQuickItemPrivate::calcEffectiveVisible()
const
6784 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6787bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6791 if (newEffectiveVisible && !explicitVisible) {
6796 if (newEffectiveVisible == effectiveVisible) {
6801 effectiveVisible = newEffectiveVisible;
6804 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6806 if (
auto agent = deliveryAgentPrivate())
6807 agent->removeGrabber(q,
true,
true,
true);
6810 bool childVisibilityChanged =
false;
6811 for (
int ii = 0; ii < childItems.size(); ++ii)
6812 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6814 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6815#if QT_CONFIG(accessibility)
6817 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6818 QAccessible::updateAccessibility(&ev);
6821 if (!inDestructor) {
6822 emit q->visibleChanged();
6823 if (childVisibilityChanged)
6824 emit q->visibleChildrenChanged();
6830bool QQuickItemPrivate::calcEffectiveEnable()
const
6835 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6838void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6842 if (newEffectiveEnable && !explicitEnable) {
6847 if (newEffectiveEnable == effectiveEnable) {
6852 effectiveEnable = newEffectiveEnable;
6854 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6856 da->removeGrabber(q,
true,
true,
true);
6857 if (scope && !effectiveEnable && activeFocus) {
6858 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6859 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6860 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6864 for (
int ii = 0; ii < childItems.size(); ++ii) {
6865 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6866 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6869 if (scope && effectiveEnable && focus && da) {
6870 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6871 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6872 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6875 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6876#if QT_CONFIG(accessibility)
6878 QAccessible::State changedState;
6879 changedState.disabled =
true;
6880 changedState.focusable =
true;
6881 QAccessibleStateChangeEvent ev(q, changedState);
6882 QAccessible::updateAccessibility(&ev);
6885 emit q->enabledChanged();
6889
6890
6891
6892qreal QQuickItemPrivate::biggestPointerHandlerMargin()
const
6894 if (hasPointerHandlers()) {
6895 if (extra->biggestPointerHandlerMarginCache < 0) {
6896 const auto maxMarginIt = std::max_element(extra->pointerHandlers.constBegin(),
6897 extra->pointerHandlers.constEnd(),
6898 [](
const QQuickPointerHandler *a,
const QQuickPointerHandler *b) {
6899 return a->margin() < b->margin(); });
6900 Q_ASSERT(maxMarginIt != extra->pointerHandlers.constEnd());
6901 extra->biggestPointerHandlerMarginCache = (*maxMarginIt)->margin();
6903 return extra->biggestPointerHandlerMarginCache;
6909
6910
6911
6912
6913
6914
6915QRectF QQuickItemPrivate::eventHandlingBounds(qreal margin)
const
6917 const qreal biggestMargin = margin > 0 ? margin : biggestPointerHandlerMargin();
6918 return QRectF(-biggestMargin, -biggestMargin, width + biggestMargin * 2, height + biggestMargin * 2);
6922
6923
6924
6925bool QQuickItemPrivate::parentFullyContains()
const
6927 Q_Q(
const QQuickItem);
6931 itemToParentTransform(&t);
6932 const auto bounds = eventHandlingBounds();
6933 const auto boundsInParent = t.mapRect(bounds);
6934 const bool ret = parentItem->clipRect().contains(boundsInParent);
6935 qCDebug(lcEffClip) <<
"in parent bounds?" << ret << q << boundsInParent << parentItem << parentItem->clipRect();
6940
6941
6942
6943bool QQuickItemPrivate::effectivelyClipsEventHandlingChildren()
const
6945 Q_Q(
const QQuickItem);
6947 if (flags & QQuickItem::ItemClipsChildrenToShape) {
6948 qCDebug(lcEffClip) << q <<
"result: true because clip is true";
6951 if (!eventHandlingChildrenWithinBoundsSet) {
6953 eventHandlingChildrenWithinBounds =
true;
6954 for (
const auto *child : childItems) {
6955 const auto *childPriv = QQuickItemPrivate::get(child);
6959 if (childPriv->childItems.isEmpty() &&
6960 !(childPriv->hoverEnabled || childPriv->subtreeHoverEnabled || childPriv->touchEnabled ||
6961 childPriv->hasCursor || childPriv->hasCursorHandler || child->acceptedMouseButtons() ||
6962 childPriv->hasPointerHandlers())) {
6963 qCDebug(lcEffClip) << child <<
"doesn't handle pointer events";
6966 if (!childPriv->parentFullyContains()) {
6967 eventHandlingChildrenWithinBounds =
false;
6968 qCDebug(lcEffClip) <<
"child goes outside: giving up" << child;
6971 if (!childPriv->eventHandlingChildrenWithinBoundsSet) {
6972 eventHandlingChildrenWithinBounds = childPriv->effectivelyClipsEventHandlingChildren();
6973 if (!eventHandlingChildrenWithinBounds)
6974 qCDebug(lcEffClip) <<
"child has children that go outside: giving up" << child;
6977#ifdef QT_BUILD_INTERNAL
6978 if (!eventHandlingChildrenWithinBoundsSet && eventHandlingChildrenWithinBounds)
6979 ++eventHandlingChildrenWithinBounds_counter;
6982 eventHandlingChildrenWithinBoundsSet =
true;
6983 qCDebug(lcEffClip) << q << q->clipRect() <<
"result:" <<
static_cast<
bool>(eventHandlingChildrenWithinBounds);
6985 return eventHandlingChildrenWithinBounds;
6988bool QQuickItemPrivate::isTransparentForPositioner()
const
6990 return extra.isAllocated() && extra.value().transparentForPositioner;
6993void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6995 extra.value().transparentForPositioner = transparent;
6999QString QQuickItemPrivate::dirtyToString()
const
7001#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
7003 rv.append(QLatin1Char('|'));
7004 rv.append(QLatin1String(#value)); \
7005}
7032void QQuickItemPrivate::dirty(DirtyType type)
7035 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
7036 dirtyAttributes |= type;
7037 if (window && componentComplete) {
7039 QQuickWindowPrivate::get(window)->dirtyItem(q,
true);
7042 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
7043 transformChanged(q);
7046void QQuickItemPrivate::addToDirtyList()
7051 if (!prevDirtyItem) {
7052 Q_ASSERT(!nextDirtyItem);
7054 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
7055 nextDirtyItem = p->dirtyItemList;
7056 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
7057 prevDirtyItem = &p->dirtyItemList;
7058 p->dirtyItemList = q;
7059 p->dirtyItem(q,
true);
7061 Q_ASSERT(prevDirtyItem);
7064void QQuickItemPrivate::removeFromDirtyList()
7066 if (prevDirtyItem) {
7067 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
7068 *prevDirtyItem = nextDirtyItem;
7069 prevDirtyItem =
nullptr;
7070 nextDirtyItem =
nullptr;
7072 Q_ASSERT(!prevDirtyItem);
7073 Q_ASSERT(!nextDirtyItem);
7076void QQuickItemPrivate::refFromEffectItem(
bool hide)
7078 ++extra.value().effectRefCount;
7079 if (extra->effectRefCount == 1) {
7080 dirty(EffectReference);
7082 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7085 if (++extra->hideRefCount == 1)
7086 dirty(HideReference);
7088 recursiveRefFromEffectItem(1);
7091void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
7096 extra.value().recursiveEffectRefCount += refs;
7097 for (
int ii = 0; ii < childItems.size(); ++ii) {
7098 QQuickItem *child = childItems.at(ii);
7099 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
7103 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
7107void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
7109 Q_ASSERT(extra->effectRefCount);
7110 --extra->effectRefCount;
7111 if (extra->effectRefCount == 0) {
7112 dirty(EffectReference);
7114 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7117 if (--extra->hideRefCount == 0)
7118 dirty(HideReference);
7120 recursiveRefFromEffectItem(-1);
7123void QQuickItemPrivate::setCulled(
bool cull)
7129 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
7130 dirty(HideReference);
7133void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
7137 case QQuickItem::ItemChildAddedChange: {
7138 q->itemChange(change, data);
7144 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
7145 if (!subtreeTransformChangedEnabled) {
7146 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
7147 subtreeTransformChangedEnabled =
true;
7149 enableSubtreeChangeNotificationsForParentHierachy();
7151 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
7154 case QQuickItem::ItemChildRemovedChange: {
7155 q->itemChange(change, data);
7156 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
7159 case QQuickItem::ItemSceneChange:
7160 q->itemChange(change, data);
7162 case QQuickItem::ItemVisibleHasChanged: {
7163 q->itemChange(change, data);
7164 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
7167 case QQuickItem::ItemEnabledHasChanged: {
7168 q->itemChange(change, data);
7169 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
7172 case QQuickItem::ItemParentHasChanged: {
7173 q->itemChange(change, data);
7174 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
7177 case QQuickItem::ItemOpacityHasChanged: {
7178 q->itemChange(change, data);
7179 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
7182 case QQuickItem::ItemActiveFocusHasChanged:
7183 q->itemChange(change, data);
7185 case QQuickItem::ItemRotationHasChanged: {
7186 q->itemChange(change, data);
7187 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7190 case QQuickItem::ItemScaleHasChanged: {
7191 q->itemChange(change, data);
7192 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7195 case QQuickItem::ItemTransformHasChanged: {
7196 q->itemChange(change, data);
7197 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7200 case QQuickItem::ItemAntialiasingHasChanged:
7202 case QQuickItem::ItemDevicePixelRatioHasChanged:
7203 q->itemChange(change, data);
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231bool QQuickItem::smooth()
const
7233 Q_D(
const QQuickItem);
7236void QQuickItem::setSmooth(
bool smooth)
7239 if (d->smooth == smooth)
7243 d->dirty(QQuickItemPrivate::Smooth);
7245 emit smoothChanged(smooth);
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7287bool QQuickItem::activeFocusOnTab()
const
7289 Q_D(
const QQuickItem);
7290 return d->activeFocusOnTab;
7292void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7295 if (d->activeFocusOnTab == activeFocusOnTab)
7299 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7300 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7305 d->activeFocusOnTab = activeFocusOnTab;
7307 emit activeFocusOnTabChanged(activeFocusOnTab);
7311
7312
7313
7314
7315
7316
7317
7318
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329bool QQuickItem::antialiasing()
const
7331 Q_D(
const QQuickItem);
7332 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7335void QQuickItem::setAntialiasing(
bool aa)
7339 if (!d->antialiasingValid) {
7340 d->antialiasingValid =
true;
7341 d->antialiasing = d->implicitAntialiasing;
7344 if (aa == d->antialiasing)
7347 d->antialiasing = aa;
7348 d->dirty(QQuickItemPrivate::Antialiasing);
7350 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7352 emit antialiasingChanged(antialiasing());
7355void QQuickItem::resetAntialiasing()
7358 if (!d->antialiasingValid)
7361 d->antialiasingValid =
false;
7363 if (d->implicitAntialiasing != d->antialiasing)
7364 emit antialiasingChanged(antialiasing());
7367void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7370 bool prev = q->antialiasing();
7371 implicitAntialiasing = antialiasing;
7372 if (componentComplete && (q->antialiasing() != prev))
7373 emit q->antialiasingChanged(q->antialiasing());
7377
7378
7379
7380
7381QQuickItem::Flags QQuickItem::flags()
const
7383 Q_D(
const QQuickItem);
7384 return (QQuickItem::Flags)d->flags;
7388
7389
7390
7391
7392
7393
7394
7395void QQuickItem::setFlag(Flag flag,
bool enabled)
7399 setFlags((Flags)(d->flags | (quint32)flag));
7401 setFlags((Flags)(d->flags & ~(quint32)flag));
7405 if (enabled && flag == ItemObservesViewport)
7406 d->enableSubtreeChangeNotificationsForParentHierachy();
7409void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7413 QQuickItem *par = q->parentItem();
7415 auto parPriv = QQuickItemPrivate::get(par);
7416 if (!parPriv->subtreeTransformChangedEnabled)
7417 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7418 parPriv->subtreeTransformChangedEnabled =
true;
7419 par = par->parentItem();
7424
7425
7426
7427
7428void QQuickItem::setFlags(Flags flags)
7432 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7433 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7434 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7435 flags &= ~ItemIsFocusScope;
7436 }
else if (d->flags & ItemIsFocusScope) {
7437 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7438 flags |= ItemIsFocusScope;
7442 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7443 d->dirty(QQuickItemPrivate::Clip);
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7464
7465
7466
7467
7469
7470
7471
7472
7473qreal QQuickItem::x()
const
7475 Q_D(
const QQuickItem);
7479qreal QQuickItem::y()
const
7481 Q_D(
const QQuickItem);
7486
7487
7488QPointF QQuickItem::position()
const
7490 Q_D(
const QQuickItem);
7491 return QPointF(d->x, d->y);
7494void QQuickItem::setX(qreal v)
7498
7499
7500
7501
7502
7503
7504
7505
7506 d->x.removeBindingUnlessInWrapper();
7510 const qreal oldx = d->x.valueBypassingBindings();
7514 d->x.setValueBypassingBindings(v);
7516 d->dirty(QQuickItemPrivate::Position);
7518 const qreal y = d->y.valueBypassingBindings();
7519 const qreal w = d->width.valueBypassingBindings();
7520 const qreal h = d->height.valueBypassingBindings();
7521 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7524void QQuickItem::setY(qreal v)
7527 d->y.removeBindingUnlessInWrapper();
7531 const qreal oldy = d->y.valueBypassingBindings();
7535 d->y.setValueBypassingBindings(v);
7537 d->dirty(QQuickItemPrivate::Position);
7541 const qreal x = d->x.valueBypassingBindings();
7542 const qreal w = d->width.valueBypassingBindings();
7543 const qreal h = d->height.valueBypassingBindings();
7544 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7548
7549
7550void QQuickItem::setPosition(
const QPointF &pos)
7554 const qreal oldx = d->x.valueBypassingBindings();
7555 const qreal oldy = d->y.valueBypassingBindings();
7557 if (QPointF(oldx, oldy) == pos)
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7573 d->x.setValueBypassingBindings(pos.x());
7574 d->y.setValueBypassingBindings(pos.y());
7576 d->dirty(QQuickItemPrivate::Position);
7578 const qreal w = d->width.valueBypassingBindings();
7579 const qreal h = d->height.valueBypassingBindings();
7580 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7584
7585
7586QBindable<qreal> QQuickItem::bindableX()
7588 return QBindable<qreal>(&d_func()->x);
7591QBindable<qreal> QQuickItem::bindableY()
7593 return QBindable<qreal>(&d_func()->y);
7597
7598
7599
7600
7601qreal QQuickItem::width()
const
7603 Q_D(
const QQuickItem);
7607void QQuickItem::setWidth(qreal w)
7610 d->width.removeBindingUnlessInWrapper();
7614 d->widthValidFlag =
true;
7615 const qreal oldWidth = d->width.valueBypassingBindings();
7619 d->width.setValueBypassingBindings(w);
7621 d->dirty(QQuickItemPrivate::Size);
7623 const qreal x = d->x.valueBypassingBindings();
7624 const qreal y = d->y.valueBypassingBindings();
7625 const qreal h = d->height.valueBypassingBindings();
7626 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7629void QQuickItem::resetWidth()
7632 d->width.takeBinding();
7633 d->widthValidFlag =
false;
7634 setImplicitWidth(implicitWidth());
7637void QQuickItemPrivate::implicitWidthChanged()
7640 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7641 emit q->implicitWidthChanged();
7644qreal QQuickItemPrivate::getImplicitWidth()
const
7646 return implicitWidth;
7649
7650
7651qreal QQuickItem::implicitWidth()
const
7653 Q_D(
const QQuickItem);
7654 return d->getImplicitWidth();
7657QBindable<qreal> QQuickItem::bindableWidth()
7659 return QBindable<qreal>(&d_func()->width);
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
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744void QQuickItem::setImplicitWidth(qreal w)
7747 bool changed = w != d->implicitWidth;
7748 d->implicitWidth = w;
7750 if (d->width.valueBypassingBindings() == w || widthValid()) {
7752 d->implicitWidthChanged();
7753 if (d->width.valueBypassingBindings() == w || widthValid())
7758 const qreal oldWidth = d->width.valueBypassingBindings();
7759 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7761 d->width.setValueBypassingBindings(w);
7763 d->dirty(QQuickItemPrivate::Size);
7765 const qreal x = d->x.valueBypassingBindings();
7766 const qreal y = d->y.valueBypassingBindings();
7767 const qreal width = w;
7768 const qreal height = d->height.valueBypassingBindings();
7769 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7772 d->implicitWidthChanged();
7776
7777
7778bool QQuickItem::widthValid()
const
7780 Q_D(
const QQuickItem);
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7798 return d->widthValid();
7802
7803
7804
7805
7806qreal QQuickItem::height()
const
7808 Q_D(
const QQuickItem);
7812void QQuickItem::setHeight(qreal h)
7818 d->height.removeBindingUnlessInWrapper();
7822 d->heightValidFlag =
true;
7823 const qreal oldHeight = d->height.valueBypassingBindings();
7827 d->height.setValueBypassingBindings(h);
7829 d->dirty(QQuickItemPrivate::Size);
7831 const qreal x = d->x.valueBypassingBindings();
7832 const qreal y = d->y.valueBypassingBindings();
7833 const qreal w = d->width.valueBypassingBindings();
7834 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7837void QQuickItem::resetHeight()
7843 d->height.takeBinding();
7844 d->heightValidFlag =
false;
7845 setImplicitHeight(implicitHeight());
7848void QQuickItemPrivate::implicitHeightChanged()
7851 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7852 emit q->implicitHeightChanged();
7855qreal QQuickItemPrivate::getImplicitHeight()
const
7857 return implicitHeight;
7860qreal QQuickItem::implicitHeight()
const
7862 Q_D(
const QQuickItem);
7863 return d->getImplicitHeight();
7866QBindable<qreal> QQuickItem::bindableHeight()
7868 return QBindable<qreal>(&d_func()->height);
7871void QQuickItem::setImplicitHeight(qreal h)
7874 bool changed = h != d->implicitHeight;
7875 d->implicitHeight = h;
7876 if (d->height.valueBypassingBindings() == h || heightValid()) {
7878 d->implicitHeightChanged();
7879 if (d->height.valueBypassingBindings() == h || heightValid())
7884 const qreal oldHeight = d->height.valueBypassingBindings();
7885 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7887 d->height.setValueBypassingBindings(h);
7889 d->dirty(QQuickItemPrivate::Size);
7891 const qreal x = d->x.valueBypassingBindings();
7892 const qreal y = d->y.valueBypassingBindings();
7893 const qreal width = d->width.valueBypassingBindings();
7894 const qreal height = d->height.valueBypassingBindings();
7895 geometryChange(QRectF(x, y, width, height),
7896 QRectF(x, y, width, oldHeight));
7899 d->implicitHeightChanged();
7903
7904
7905void QQuickItem::setImplicitSize(qreal w, qreal h)
7908 bool wChanged = w != d->implicitWidth;
7909 bool hChanged = h != d->implicitHeight;
7911 d->implicitWidth = w;
7912 d->implicitHeight = h;
7916 qreal width = d->width.valueBypassingBindings();
7917 qreal height = d->height.valueBypassingBindings();
7918 if (width == w || widthValid()) {
7920 d->implicitWidthChanged();
7921 wDone = width == w || widthValid();
7924 if (height == h || heightValid()) {
7926 d->implicitHeightChanged();
7927 hDone = height == h || heightValid();
7933 const qreal oldWidth = width;
7934 const qreal oldHeight = height;
7937 d->width.setValueBypassingBindings(w);
7941 d->height.setValueBypassingBindings(h);
7944 d->dirty(QQuickItemPrivate::Size);
7946 const qreal x = d->x.valueBypassingBindings();
7947 const qreal y = d->y.valueBypassingBindings();
7948 geometryChange(QRectF(x, y, width, height),
7949 QRectF(x, y, oldWidth, oldHeight));
7951 if (!wDone && wChanged)
7952 d->implicitWidthChanged();
7953 if (!hDone && hChanged)
7954 d->implicitHeightChanged();
7958
7959
7960bool QQuickItem::heightValid()
const
7962 Q_D(
const QQuickItem);
7963 return d->heightValid();
7967
7968
7969
7970
7971
7972
7974QSizeF QQuickItem::size()
const
7976 Q_D(
const QQuickItem);
7977 return QSizeF(d->width, d->height);
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991void QQuickItem::setSize(
const QSizeF &size)
7994 d->heightValidFlag =
true;
7995 d->widthValidFlag =
true;
7997 const qreal oldHeight = d->height.valueBypassingBindings();
7998 const qreal oldWidth = d->width.valueBypassingBindings();
8000 if (oldWidth == size.width() && oldHeight == size.height())
8003 d->height.setValueBypassingBindings(size.height());
8004 d->width.setValueBypassingBindings(size.width());
8006 d->dirty(QQuickItemPrivate::Size);
8008 const qreal x = d->x.valueBypassingBindings();
8009 const qreal y = d->y.valueBypassingBindings();
8010 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
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
8078
8079
8080
8081
8082bool QQuickItem::hasActiveFocus()
const
8084 Q_D(
const QQuickItem);
8085 return d->activeFocus;
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
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176bool QQuickItem::hasFocus()
const
8178 Q_D(
const QQuickItem);
8182void QQuickItem::setFocus(
bool focus)
8184 setFocus(focus, Qt::OtherFocusReason);
8187void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8191 QQuickItem *scope = parentItem();
8192 while (scope && !scope->isFocusScope() && scope->parentItem())
8193 scope = scope->parentItem();
8195 if (d->focus == focus && d->activeFocus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8198 bool notifyListeners =
false;
8199 if (d->window || d->parentItem) {
8201 auto da = d->deliveryAgentPrivate();
8204 da->setFocusInScope(scope,
this, reason);
8206 da->clearFocusInScope(scope,
this, reason);
8210 QVarLengthArray<QQuickItem *, 20> changed;
8211 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8212 if (oldSubFocusItem) {
8213 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8214 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8215 changed << oldSubFocusItem;
8216 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8217 QQuickItemPrivate::get(scope)->focus =
false;
8220 d->updateSubFocusItem(scope, focus);
8224 notifyListeners =
true;
8225 emit focusChanged(focus);
8227 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8230 QVarLengthArray<QQuickItem *, 20> changed;
8231 QQuickItem *oldSubFocusItem = d->subFocusItem;
8232 if (!isFocusScope() && oldSubFocusItem) {
8233 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8234 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8235 changed << oldSubFocusItem;
8240 notifyListeners =
true;
8241 emit focusChanged(focus);
8243 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8245 if (notifyListeners)
8246 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8250
8251
8252bool QQuickItem::isFocusScope()
const
8254 return flags() & ItemIsFocusScope;
8258
8259
8260
8261
8262
8263QQuickItem *QQuickItem::scopedFocusItem()
const
8265 Q_D(
const QQuickItem);
8266 if (!isFocusScope())
8269 return d->subFocusItem;
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8287
8288
8289
8290
8291
8292
8293Qt::FocusPolicy QQuickItem::focusPolicy()
const
8295 Q_D(
const QQuickItem);
8296 uint policy = d->focusPolicy;
8297 if (activeFocusOnTab())
8298 policy |= Qt::TabFocus;
8299 return static_cast<Qt::FocusPolicy>(policy);
8303
8304
8305
8306
8307void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8310 if (d->focusPolicy == policy)
8313 d->focusPolicy = policy;
8314 setActiveFocusOnTab(policy & Qt::TabFocus);
8315 emit focusPolicyChanged(policy);
8319
8320
8321
8322
8323
8324
8325
8326bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8328 if (!child || child ==
this)
8330 const QQuickItem *ancestor = child;
8331 while ((ancestor = ancestor->parentItem())) {
8332 if (ancestor ==
this)
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8351 Q_D(
const QQuickItem);
8352 return d->acceptedMouseButtons();
8356
8357
8358
8359
8360
8361
8362
8363
8364void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8367 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8369 buttons &= ~Qt::LeftButton;
8370 if (buttons || d->extra.isAllocated()) {
8371 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8372 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387bool QQuickItem::filtersChildMouseEvents()
const
8389 Q_D(
const QQuickItem);
8390 return d->filtersChildMouseEvents;
8394
8395
8396
8397
8398
8399
8400
8401
8402void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8405 d->filtersChildMouseEvents = filter;
8409
8410
8411bool QQuickItem::isUnderMouse()
const
8413 Q_D(
const QQuickItem);
8420 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8423 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8424 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8428
8429
8430
8431
8432
8433
8434
8435bool QQuickItem::acceptHoverEvents()
const
8437 Q_D(
const QQuickItem);
8438 return d->hoverEnabled;
8442
8443
8444
8445
8446
8447void QQuickItem::setAcceptHoverEvents(
bool enabled)
8454 d->hoverEnabled = enabled;
8460 d->setHasHoverInChild(enabled);
8464 d->dirty(QQuickItemPrivate::Content);
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477bool QQuickItem::acceptTouchEvents()
const
8479 Q_D(
const QQuickItem);
8480 return d->touchEnabled;
8484
8485
8486
8487
8488
8489
8490
8491void QQuickItem::setAcceptTouchEvents(
bool enabled)
8494 d->touchEnabled = enabled;
8497void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8499#if QT_CONFIG(cursor)
8504 if (!hc && subtreeCursorEnabled) {
8505 if (hasCursor || hasCursorHandler)
8507 for (QQuickItem *otherChild : std::as_const(childItems)) {
8508 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8509 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8514 subtreeCursorEnabled = hc;
8515 QQuickItem *parent = q->parentItem();
8517 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8518 parentPrivate->setHasCursorInChild(hc);
8525void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8531 if (!hasHover && subtreeHoverEnabled) {
8534 if (hasEnabledHoverHandlers())
8537 for (QQuickItem *otherChild : std::as_const(childItems)) {
8538 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8539 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8541 if (otherChildPrivate->hasEnabledHoverHandlers())
8546 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8547 subtreeHoverEnabled = hasHover;
8548 QQuickItem *parent = q->parentItem();
8550 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8551 parentPrivate->setHasHoverInChild(hasHover);
8555#if QT_CONFIG(cursor)
8557QWindow *QQuickItemPrivate::renderWindow(QPoint *offset)
const
8559 QWindow *result = QQuickRenderControl::renderWindowFor(window, offset);
8560 return result ? result : window;
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8577QCursor QQuickItem::cursor()
const
8579 Q_D(
const QQuickItem);
8580 return d->extra.isAllocated()
8586
8587
8588
8589
8591void QQuickItem::setCursor(
const QCursor &cursor)
8595 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8596 qCDebug(lcHoverCursor) << oldShape <<
"->" << cursor.shape();
8598 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8599 d->extra.value().cursor = cursor;
8601 QWindow *renderWindow = d->renderWindow();
8602 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8603 renderWindow->setCursor(cursor);
8607 QPointF updateCursorPos;
8608 if (!d->hasCursor) {
8609 d->hasCursor =
true;
8611 QWindow *renderWindow = d->renderWindow();
8612 QPointF pos = renderWindow->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8613 if (contains(mapFromScene(pos)))
8614 updateCursorPos = pos;
8617 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8618 if (!updateCursorPos.isNull())
8619 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8623
8624
8625
8626
8628void QQuickItem::unsetCursor()
8631 qCDebug(lcHoverTrace) <<
"clearing cursor";
8634 d->hasCursor =
false;
8635 d->setHasCursorInChild(d->hasCursorHandler);
8636 if (d->extra.isAllocated())
8637 d->extra->cursor = QCursor();
8640 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8641 if (windowPrivate->cursorItem ==
this) {
8642 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8643 windowPrivate->updateCursor(pos);
8649
8650
8651
8652
8653
8654
8655QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8657 Q_Q(
const QQuickItem);
8660 bool hoverCursorSet =
false;
8661 QCursor hoverCursor;
8662 bool activeCursorSet =
false;
8663 QCursor activeCursor;
8664 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8665 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8666 hoverCursor = hoverHandler->cursorShape();
8667 }
else if (handler->active()) {
8668 activeCursorSet = handler->isCursorShapeExplicitlySet();
8669 activeCursor = handler->cursorShape();
8671 if (activeCursorSet)
8672 return activeCursor;
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8700 if (!hasPointerHandlers())
8702 QQuickPointerHandler* activeHandler =
nullptr;
8703 QQuickPointerHandler* mouseHandler =
nullptr;
8704 QQuickPointerHandler* nonMouseHandler =
nullptr;
8705 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8706 if (!h->isCursorShapeExplicitlySet())
8708 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8713 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8714 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8715 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8717 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8718 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8719 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8721 mouseHandler = hoverHandler;
8724 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8725 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8726 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8728 nonMouseHandler = hoverHandler;
8731 if (!hoverHandler && h->active())
8734 if (activeHandler) {
8735 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8736 return activeHandler;
8742 if (nonMouseHandler) {
8744 const bool beforeTimeout =
8745 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8746 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8747 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8748 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8749 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8750 <<
"choosing cursor according to" << winner << winner->cursorShape();
8753 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8754 return nonMouseHandler;
8757 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8758 return mouseHandler;
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777void QQuickItem::grabMouse()
8782 auto da = d->deliveryAgentPrivate();
8784 auto eventInDelivery = da->eventInDelivery();
8785 if (!eventInDelivery) {
8786 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8789 auto epd = da->mousePointData();
8791 qCDebug(lcPtr) <<
"cannot grab mouse: the event being delivered has no mouse point";
8794 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808void QQuickItem::ungrabMouse()
8813 auto da = d->deliveryAgentPrivate();
8815 auto eventInDelivery = da->eventInDelivery();
8816 if (!eventInDelivery) {
8818 da->removeGrabber(
this);
8821 auto epd = da->mousePointData();
8822 if (epd && eventInDelivery->exclusiveGrabber(epd->eventPoint) ==
this)
8823 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
nullptr);
8827
8828
8829
8830
8831bool QQuickItem::keepMouseGrab()
const
8833 Q_D(
const QQuickItem);
8834 return d->keepMouse;
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853void QQuickItem::setKeepMouseGrab(
bool keep)
8856 d->keepMouse = keep;
8860
8861
8862
8863
8864
8865
8866
8867
8868void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8871 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8872 if (Q_UNLIKELY(!event)) {
8873 qWarning() <<
"cannot grab: no event is currently being delivered";
8876 for (
auto pt : event->points()) {
8877 if (ids.contains(pt.id()))
8878 event->setExclusiveGrabber(pt,
this);
8883
8884
8885
8886void QQuickItem::ungrabTouchPoints()
8891 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8892 da->removeGrabber(
this,
false,
true);
8896
8897
8898
8899
8900
8901bool QQuickItem::keepTouchGrab()
const
8903 Q_D(
const QQuickItem);
8904 return d->keepTouch;
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924void QQuickItem::setKeepTouchGrab(
bool keep)
8927 d->keepTouch = keep;
8931
8932
8933
8934
8935
8936
8937
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949bool QQuickItem::contains(
const QPointF &point)
const
8951 Q_D(
const QQuickItem);
8952 if (d->extra.isAllocated() && d->extra->mask) {
8953 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8954 return quickMask->contains(point - quickMask->position());
8957 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8958 maskContains.invoke(d->extra->mask,
8959 Qt::DirectConnection,
8960 Q_RETURN_ARG(
bool, res),
8961 Q_ARG(QPointF, point));
8965 qreal x = point.x();
8966 qreal y = point.y();
8967 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035QObject *QQuickItem::containmentMask()
const
9037 Q_D(
const QQuickItem);
9038 if (!d->extra.isAllocated())
9040 return d->extra->mask.data();
9043void QQuickItem::setContainmentMask(QObject *mask)
9046 const bool extraDataExists = d->extra.isAllocated();
9048 if (mask ==
static_cast<QObject *>(
this))
9051 if (!extraDataExists && !mask)
9054 if (extraDataExists && d->extra->mask == mask)
9057 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
9060 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9061 maskPrivate->registerAsContainmentMask(
this,
false);
9064 if (!extraDataExists)
9067 int methodIndex = mask->metaObject()->indexOfMethod(
"contains(QPointF)");
9068 if (methodIndex < 0) {
9069 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
9072 d->extra->maskContainsIndex = methodIndex;
9074 d->extra->mask = mask;
9075 quickMask = qobject_cast<QQuickItem *>(mask);
9077 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9078 maskPrivate->registerAsContainmentMask(
this,
true);
9080 emit containmentMaskChanged();
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
9097 QPointF p = mapToScene(point);
9099 const auto *itemWindow = item->window();
9100 const auto *thisWindow = window();
9101 if (thisWindow && itemWindow && itemWindow != thisWindow)
9102 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
9104 p = item->mapFromScene(p);
9110
9111
9112
9113
9114
9115
9116
9117
9118QPointF QQuickItem::mapToScene(
const QPointF &point)
const
9120 Q_D(
const QQuickItem);
9121 return d->itemToWindowTransform().map(point);
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
9143 Q_D(
const QQuickItem);
9145 if (Q_UNLIKELY(d->window ==
nullptr))
9146 return mapToScene(point);
9148 QPoint renderOffset;
9149 QWindow *renderWindow = d->renderWindow(&renderOffset);
9150 return renderWindow->mapToGlobal((mapToScene(point) + renderOffset));
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
9167 Q_D(
const QQuickItem);
9168 QTransform t = d->itemToWindowTransform();
9170 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
9171 return t.mapRect(rect);
9175
9176
9177
9178
9179
9180
9181
9182
9183QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
9185 Q_D(
const QQuickItem);
9186 return d->itemToWindowTransform().mapRect(rect);
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9205 p = item->mapToScene(point);
9206 const auto *itemWindow = item->window();
9207 const auto *thisWindow = window();
9208 if (thisWindow && itemWindow && itemWindow != thisWindow)
9209 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9211 return mapFromScene(p);
9215
9216
9217
9218
9219
9220
9221
9222
9223QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9225 Q_D(
const QQuickItem);
9226 return d->windowToItemTransform().map(point);
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9254 Q_D(
const QQuickItem);
9257 if (Q_LIKELY(d->window)) {
9258 QPoint renderOffset;
9259 QWindow *renderWindow = d->renderWindow();
9260 scenePoint = renderWindow->mapFromGlobal(point) - renderOffset;
9265 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9266 if (
auto sceneTransform = da->sceneTransform())
9267 scenePoint = sceneTransform->map(scenePoint);
9269 return mapFromScene(scenePoint);
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9286 Q_D(
const QQuickItem);
9287 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9288 t *= d->windowToItemTransform();
9289 return t.mapRect(rect);
9293
9294
9295
9296
9297
9298
9299
9300
9301QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9303 Q_D(
const QQuickItem);
9304 return d->windowToItemTransform().mapRect(rect);
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373int QQuickItem::mutabilityGroup()
const
9375 Q_D(
const QQuickItem);
9376 if (d->extra.isAllocated())
9377 return d->extra->mutabilityGroup;
9378 return int(QQuickItem::AutoMutabilityGroup);
9381void QQuickItem::setMutabilityGroup(
int mutabilityGroup)
9385 const int clampedGroup = qBound(
int(AutoMutabilityGroup),
9387 int(DynamicMutabilityGroup));
9388 if (Q_UNLIKELY(clampedGroup != mutabilityGroup)) {
9389 qCDebug(QSG_LOG_RENDERLOOP) <<
"QQuickItem::setMutabilityGroup: Invalid group"
9395 if (clampedGroup ==
this->mutabilityGroup())
9398 d->extra.value().mutabilityGroup = clampedGroup;
9399 d->extra.value().mutabilityGroupSet =
true;
9400 d->dirty(QQuickItemPrivate::Content);
9401 emit mutabilityGroupChanged(clampedGroup);
9405
9406
9407
9410
9411
9412
9415
9416
9417
9420
9421
9422
9425
9426
9427
9430
9431
9432
9435
9436
9437
9440
9441
9442
9445
9446
9447
9450
9451
9452
9455
9456
9457bool QQuickItem::event(QEvent *ev)
9461 switch (ev->type()) {
9463 case QEvent::InputMethodQuery: {
9464 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9465 Qt::InputMethodQueries queries = query->queries();
9466 for (uint i = 0; i < 32; ++i) {
9467 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9469 QVariant v = inputMethodQuery(q);
9470 query->setValue(q, v);
9476 case QEvent::InputMethod:
9477 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9480 case QEvent::TouchBegin:
9481 case QEvent::TouchUpdate:
9482 case QEvent::TouchEnd:
9483 case QEvent::TouchCancel:
9484 case QEvent::MouseButtonPress:
9485 case QEvent::MouseButtonRelease:
9486 case QEvent::MouseButtonDblClick:
9487#if QT_CONFIG(wheelevent)
9490 d->deliverPointerEvent(ev);
9492 case QEvent::StyleAnimationUpdate:
9498 case QEvent::HoverEnter:
9499 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9501 case QEvent::HoverLeave:
9502 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9504 case QEvent::HoverMove:
9505 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9507 case QEvent::KeyPress:
9508 case QEvent::KeyRelease:
9509 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9511 case QEvent::ShortcutOverride:
9512 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9514 case QEvent::FocusIn:
9515 focusInEvent(
static_cast<QFocusEvent*>(ev));
9517 case QEvent::FocusOut:
9518 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9520 case QEvent::MouseMove:
9521 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9523#if QT_CONFIG(quick_draganddrop)
9524 case QEvent::DragEnter:
9525 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9527 case QEvent::DragLeave:
9528 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9530 case QEvent::DragMove:
9531 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9534 dropEvent(
static_cast<QDropEvent*>(ev));
9537#if QT_CONFIG(gestures)
9538 case QEvent::NativeGesture:
9542 case QEvent::LanguageChange:
9543 case QEvent::LocaleChange:
9544 for (QQuickItem *item : std::as_const(d->childItems))
9545 QCoreApplication::sendEvent(item, ev);
9547 case QEvent::WindowActivate:
9548 case QEvent::WindowDeactivate:
9549 if (d->providesPalette())
9550 d->setCurrentColorGroup();
9551 for (QQuickItem *item : std::as_const(d->childItems))
9552 QCoreApplication::sendEvent(item, ev);
9554 case QEvent::ApplicationPaletteChange:
9555 for (QQuickItem *item : std::as_const(d->childItems))
9556 QCoreApplication::sendEvent(item, ev);
9558 case QEvent::ContextMenu:
9560 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9563 return QObject::event(ev);
9569#ifndef QT_NO_DEBUG_STREAM
9571#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9576 QDebugStateSaver saver(debug);
9579 debug <<
"QQuickItem(nullptr)";
9583 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9585 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9589 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9590 if (QQmlContext *context = qmlContext(item)) {
9591 const auto objectId = context->nameForObject(item);
9592 if (!objectId.isEmpty())
9593 debug <<
", id=" << objectId;
9596 if (!item->objectName().isEmpty())
9597 debug <<
", name=" << item->objectName();
9598 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9600 QtDebugUtils::formatQRect(debug, rect);
9601 if (
const qreal z = item->z())
9602 debug <<
", z=" << z;
9603 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9604 debug <<
" \U0001f5bc";
9605 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9613
9614
9615
9616
9617
9618
9619
9621bool QQuickItem::isTextureProvider()
const
9623#if QT_CONFIG(quick_shadereffect)
9624 Q_D(
const QQuickItem);
9625 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9626 d->extra->layer->effectSource()->isTextureProvider() :
false;
9633
9634
9635
9636
9637
9638
9639
9641QSGTextureProvider *QQuickItem::textureProvider()
const
9643#if QT_CONFIG(quick_shadereffect)
9644 Q_D(
const QQuickItem);
9645 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9646 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9694#if QT_CONFIG(quick_shadereffect)
9696
9697
9698
9699QQuickItemLayer *QQuickItemPrivate::layer()
const
9701 if (!extra.isAllocated() || !extra->layer) {
9702 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9703 if (!componentComplete)
9704 extra->layer->classBegin();
9706 return extra->layer;
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9730 QList<QEventPoint> touchPoints;
9731 QEventPoint::States eventStates;
9733 bool anyPressOrReleaseInside =
false;
9734 bool anyGrabber =
false;
9735 for (
auto &p : event->points()) {
9740 auto pointGrabber = event->exclusiveGrabber(p);
9741 bool isGrabber = (pointGrabber == q);
9742 if (!isGrabber && pointGrabber && isFiltering) {
9743 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9744 if (handlerGrabber && handlerGrabber->parentItem() == q)
9751 const auto localPos = q->mapFromScene(p.scenePosition());
9752 bool isInside = q->contains(localPos);
9753 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9755 if (isFiltering && !pointGrabber) {
9756 const auto pg = event->passiveGrabbers(p);
9757 if (!pg.isEmpty()) {
9761 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9763 pointGrabber = handler->parentItem();
9768 bool grabberIsChild =
false;
9769 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9770 while (isFiltering && parent) {
9772 grabberIsChild =
true;
9775 parent = parent->parentItem();
9778 bool filterRelevant = isFiltering && grabberIsChild;
9779 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9781 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9782 anyPressOrReleaseInside =
true;
9783 QEventPoint pCopy(p);
9784 eventStates |= p.state();
9785 if (p.state() == QEventPoint::State::Released)
9786 QMutableEventPoint::detach(pCopy);
9787 QMutableEventPoint::setPosition(pCopy, localPos);
9788 touchPoints.append(std::move(pCopy));
9793 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9794 *localized = QMutableTouchEvent(QEvent::None);
9799 QEvent::Type eventType = event->type();
9800 switch (eventStates) {
9801 case QEventPoint::State::Pressed:
9802 eventType = QEvent::TouchBegin;
9804 case QEventPoint::State::Released:
9805 eventType = QEvent::TouchEnd;
9808 eventType = QEvent::TouchUpdate;
9812 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9814 ret.setTimestamp(event->timestamp());
9819bool QQuickItemPrivate::hasPointerHandlers()
const
9821 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9824bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9826 if (!hasPointerHandlers())
9828 for (QQuickPointerHandler *h : extra->pointerHandlers)
9829 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9834void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9840 extra.value().acceptedMouseButtons = Qt::AllButtons;
9841 auto &handlers = extra.value().pointerHandlers;
9842 if (!handlers.contains(h))
9843 handlers.prepend(h);
9844 auto &res = extra.value().resourcesList;
9845 if (!res.contains(h)) {
9847 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9848 _q_resourceObjectDeleted(o);
9853void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9857 auto &handlers = extra.value().pointerHandlers;
9858 handlers.removeOne(h);
9859 auto &res = extra.value().resourcesList;
9861 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9862 if (handlers.isEmpty())
9863 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9867
9868
9869
9870QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9872 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9873 extra.value().contextMenu = menu;
9877QtPrivate::QQuickAttachedPropertyPropagator *QQuickItemPrivate::attachedPropertyPropagator_parent(
9878 const QMetaObject *attachedType)
9881 qCDebug(lcAttachedPropertyPropagator).noquote() <<
"- attachedPropertyPropagator_parent called on"
9882 << q <<
"with attachedType" << attachedType->metaType().name();
9884 QQuickItem *parent = q->parentItem();
9885 if (
auto *attached = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(attachedType, parent)) {
9886 qCDebug(lcAttachedPropertyPropagator).noquote() <<
" - parent item has attached object"
9887 << attached <<
"- returning";
9894#if QT_CONFIG(quick_shadereffect)
9895QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9901 , m_componentComplete(
true)
9902 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9903 , m_format(QQuickShaderEffectSource::RGBA8)
9905 , m_effectComponent(
nullptr)
9907 , m_effectSource(
nullptr)
9908 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9913QQuickItemLayer::~QQuickItemLayer()
9915 delete m_effectSource;
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933void QQuickItemLayer::setEnabled(
bool e)
9938 if (m_componentComplete) {
9945 emit enabledChanged(e);
9948void QQuickItemLayer::classBegin()
9950 Q_ASSERT(!m_effectSource);
9951 Q_ASSERT(!m_effect);
9952 m_componentComplete =
false;
9955void QQuickItemLayer::componentComplete()
9957 Q_ASSERT(!m_componentComplete);
9958 m_componentComplete =
true;
9963void QQuickItemLayer::activate()
9965 Q_ASSERT(!m_effectSource);
9966 m_effectSource =
new QQuickShaderEffectSource();
9967 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9969 QQuickItem *parentItem = m_item->parentItem();
9971 m_effectSource->setParentItem(parentItem);
9972 m_effectSource->stackAfter(m_item);
9975 m_effectSource->setSourceItem(m_item);
9976 m_effectSource->setHideSource(
true);
9977 m_effectSource->setSmooth(m_smooth);
9978 m_effectSource->setLive(m_live);
9979 m_effectSource->setTextureSize(m_size);
9980 m_effectSource->setSourceRect(m_sourceRect);
9981 m_effectSource->setMipmap(m_mipmap);
9982 m_effectSource->setWrapMode(m_wrapMode);
9983 m_effectSource->setFormat(m_format);
9984 m_effectSource->setTextureMirroring(m_textureMirroring);
9985 m_effectSource->setSamples(m_samples);
9987 if (m_effectComponent)
9990 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9997 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9998 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
10001void QQuickItemLayer::deactivate()
10003 Q_ASSERT(m_effectSource);
10005 if (m_effectComponent)
10006 deactivateEffect();
10008 delete m_effectSource;
10009 m_effectSource =
nullptr;
10011 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
10012 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
10015void QQuickItemLayer::activateEffect()
10017 Q_ASSERT(m_effectSource);
10018 Q_ASSERT(m_effectComponent);
10019 Q_ASSERT(!m_effect);
10021 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
10022 m_effect = qobject_cast<QQuickItem *>(created);
10024 qWarning(
"Item: layer.effect is not a QML Item.");
10025 m_effectComponent->completeCreate();
10029 QQuickItem *parentItem = m_item->parentItem();
10031 m_effect->setParentItem(parentItem);
10032 m_effect->stackAfter(m_effectSource);
10034 m_effect->setVisible(m_item->isVisible());
10035 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
10036 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
10037 m_effectComponent->completeCreate();
10040void QQuickItemLayer::deactivateEffect()
10042 Q_ASSERT(m_effectSource);
10043 Q_ASSERT(m_effectComponent);
10046 m_effect =
nullptr;
10051
10052
10053
10054
10055
10056
10057
10058
10059
10061void QQuickItemLayer::setEffect(QQmlComponent *component)
10063 if (component == m_effectComponent)
10066 bool updateNeeded =
false;
10067 if (m_effectSource && m_effectComponent) {
10068 deactivateEffect();
10069 updateNeeded =
true;
10072 m_effectComponent = component;
10074 if (m_effectSource && m_effectComponent) {
10076 updateNeeded =
true;
10079 if (updateNeeded) {
10084 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
10087 emit effectChanged(component);
10092
10093
10094
10095
10096
10097
10098
10099
10100
10102void QQuickItemLayer::setMipmap(
bool mipmap)
10104 if (mipmap == m_mipmap)
10108 if (m_effectSource)
10109 m_effectSource->setMipmap(m_mipmap);
10111 emit mipmapChanged(mipmap);
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10132void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
10138 if (m_effectSource)
10139 m_effectSource->setFormat(m_format);
10141 emit formatChanged(m_format);
10146
10147
10148
10149
10150
10151
10152
10153
10154
10156void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
10158 if (sourceRect == m_sourceRect)
10160 m_sourceRect = sourceRect;
10162 if (m_effectSource)
10163 m_effectSource->setSourceRect(m_sourceRect);
10165 emit sourceRectChanged(sourceRect);
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10180void QQuickItemLayer::setSmooth(
bool s)
10186 if (m_effectSource)
10187 m_effectSource->setSmooth(m_smooth);
10189 emit smoothChanged(s);
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10204void QQuickItemLayer::setLive(
bool live)
10206 if (m_live == live)
10210 if (m_effectSource)
10211 m_effectSource->setLive(m_live);
10213 emit liveChanged(live);
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10229void QQuickItemLayer::setSize(
const QSize &size)
10231 if (size == m_size)
10235 if (m_effectSource)
10236 m_effectSource->setTextureSize(size);
10238 emit sizeChanged(size);
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10259void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
10261 if (mode == m_wrapMode)
10265 if (m_effectSource)
10266 m_effectSource->setWrapMode(m_wrapMode);
10268 emit wrapModeChanged(mode);
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10286void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
10288 if (mirroring == m_textureMirroring)
10290 m_textureMirroring = mirroring;
10292 if (m_effectSource)
10293 m_effectSource->setTextureMirroring(m_textureMirroring);
10295 emit textureMirroringChanged(mirroring);
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10323void QQuickItemLayer::setSamples(
int count)
10325 if (m_samples == count)
10330 if (m_effectSource)
10331 m_effectSource->setSamples(m_samples);
10333 emit samplesChanged(count);
10337
10338
10339
10340
10341
10342
10343
10344
10345
10347void QQuickItemLayer::setName(
const QByteArray &name) {
10348 if (m_name == name)
10351 m_effect->setProperty(m_name, QVariant());
10352 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10355 emit nameChanged(name);
10358void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10364void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10369void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10372 Q_ASSERT(item == m_item);
10373 Q_ASSERT(parent != m_effectSource);
10374 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10376 m_effectSource->setParentItem(parent);
10378 m_effectSource->stackAfter(m_item);
10381 m_effect->setParentItem(parent);
10383 m_effect->stackAfter(m_effectSource);
10387void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10389 m_effectSource->stackAfter(m_item);
10391 m_effect->stackAfter(m_effectSource);
10394void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10396 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10399 l->setVisible(m_item->isVisible());
10402void QQuickItemLayer::updateZ()
10404 if (!m_componentComplete || !m_enabled)
10406 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10409 l->setZ(m_item->z());
10412void QQuickItemLayer::updateOpacity()
10414 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10417 l->setOpacity(m_item->opacity());
10420void QQuickItemLayer::updateGeometry()
10422 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10427 QRectF bounds = m_item->QQuickItem::boundingRect();
10428 l->setSize(bounds.size());
10429 l->setPosition(bounds.topLeft() + m_item->position());
10432void QQuickItemLayer::updateMatrix()
10436 if (!m_componentComplete || !m_enabled)
10438 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10441 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10442 l->setScale(m_item->scale());
10443 l->setRotation(m_item->rotation());
10444 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10445 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10446 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10447 ld->dirty(QQuickItemPrivate::Transform);
10451QQuickItemPrivate::ExtraData::ExtraData()
10452: z(0), scale(1), rotation(0), opacity(1), biggestPointerHandlerMarginCache(-1),
10453 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10454 enterKeyAttached(
nullptr),
10455 keyHandler(
nullptr), contextMenu(
nullptr),
10456#if QT_CONFIG(quick_shadereffect)
10459 effectRefCount(0), hideRefCount(0),
10460 recursiveEffectRefCount(0),
10461 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10462 origin(QQuickItem::Center),
10463 transparentForPositioner(
false),
10464 mutabilityGroup(uint(QQuickItem::AutoMutabilityGroup)),
10465 mutabilityGroupSet(
false)
10467#ifdef QT_BUILD_INTERNAL
10468 ++QQuickItemPrivate::itemExtra_counter;
10473#if QT_CONFIG(accessibility)
10474QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10476 auto role = QAccessible::NoRole;
10477 if (!inDestructor) {
10478 Q_Q(
const QQuickItem);
10479 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10480 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10481 role = accessibleAttached->role();
10482 if (role == QAccessible::NoRole)
10483 role = accessibleRole();
10488QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10490 return QAccessible::NoRole;
10499 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10512 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10513 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10514 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10515 QV4::QObjectWrapper::markWrapper(child, markStack);
10517 QObjectWrapper::markObjects(that, markStack);
10520quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10522 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10527 QDebugStateSaver stateSaver(debug);
10528 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10533QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10534{
return mapFromItem(item, QPointF(x, y) ); }
10537QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10538{
return mapRectFromItem(item, rect); }
10541QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10542{
return mapFromItem(item, QRectF(x, y, width, height)); }
10545QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10546{
return mapToItem(item, QPointF(x, y)); }
10549QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10550{
return mapRectToItem(item, rect); }
10553QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10554{
return mapToItem(item, QRectF(x, y, width, height)); }
10557QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10558{
return mapToGlobal(QPointF(x, y)); }
10561QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10562{
return mapFromGlobal(QPointF(x, y)); }
10565QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10568bool QQuickItemChangeListener::baseDeleted(
const QObject *caller)
const
10570 if (
auto ptr =
dynamic_cast<
const QObjectPrivate *>(
this))
10571 return ptr->q_ptr != caller && QQmlData::wasDeleted(ptr);
10576QString QQuickItemChangeListener::debugName()
const
10578 return QStringLiteral(
"QQuickItemChangeListener(0x%1)").arg(quintptr(
this), 0, 16);
10584#include <moc_qquickitem.cpp>
10586#include "moc_qquickitem_p.cpp"