8#include <QtQml/qjsengine.h>
14#include <QtQml/qqmlengine.h>
15#include <QtQml/qqmlcomponent.h>
16#include <QtQml/qqmlinfo.h>
17#include <QtGui/qpen.h>
18#include <QtGui/qguiapplication.h>
19#include <QtGui/qstylehints.h>
20#include <QtGui/private/qeventpoint_p.h>
21#include <QtGui/private/qguiapplication_p.h>
22#include <QtGui/private/qpointingdevice_p.h>
23#include <QtGui/qinputmethod.h>
24#include <QtCore/qcoreevent.h>
25#include <QtCore/private/qnumeric_p.h>
26#include <QtGui/qpa/qplatformtheme.h>
27#include <QtCore/qloggingcategory.h>
28#include <QtCore/private/qduplicatetracker_p.h>
30#include <private/qqmlglobal_p.h>
31#include <private/qqmlengine_p.h>
32#include <QtQuick/private/qquickstategroup_p.h>
33#include <private/qqmlopenmetaobject_p.h>
34#include <QtQuick/private/qquickstate_p.h>
35#include <private/qquickitem_p.h>
36#include <QtQuick/private/qquickaccessibleattached_p.h>
37#include <QtQuick/private/qquickhoverhandler_p.h>
38#include <QtQuick/private/qquickpointerhandler_p.h>
39#include <QtQuick/private/qquickpointerhandler_p_p.h>
41#include <private/qv4engine_p.h>
42#include <private/qv4object_p.h>
43#include <private/qv4qobjectwrapper_p.h>
44#include <private/qdebug_p.h>
45#include <private/qqmlvaluetypewrapper_p.h>
48# include <QtGui/qcursor.h>
51#include <QtCore/qpointer.h>
61Q_LOGGING_CATEGORY(lcVP,
"qt.quick.viewport")
62Q_STATIC_LOGGING_CATEGORY(lcChangeListeners,
"qt.quick.item.changelisteners")
65static const quint64 kCursorOverrideTimeout = 100;
67void debugFocusTree(QQuickItem *item, QQuickItem *scope =
nullptr,
int depth = 1)
69 if (lcFocus().isEnabled(QtDebugMsg)) {
71 << QByteArray(depth,
'\t').constData()
72 << (scope && QQuickItemPrivate::get(scope)->subFocusItem == item ?
'*' :
' ')
74 << item->hasActiveFocus()
75 << item->isFocusScope()
77 const auto childItems = item->childItems();
78 for (QQuickItem *child : childItems) {
81 item->isFocusScope() || !scope ? item : scope,
82 item->isFocusScope() || !scope ? depth + 1 : depth);
89 QQuickItemPrivate *d = QQuickItemPrivate::get(item);
90 if (d->subFocusItem && d->window && d->flags & QQuickItem::ItemIsFocusScope)
91 d->deliveryAgentPrivate()->clearFocusInScope(item, d->subFocusItem, reason);
92 item->forceActiveFocus(reason);
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118QQuickTransformPrivate::QQuickTransformPrivate()
122QQuickTransform::QQuickTransform(QObject *parent)
123: QObject(*(
new QQuickTransformPrivate), parent)
127QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent)
132QQuickTransform::~QQuickTransform()
134 Q_D(QQuickTransform);
135 for (
int ii = 0; ii < d->items.size(); ++ii) {
136 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
137 p->transforms.removeOne(
this);
138 p->dirty(QQuickItemPrivate::Transform);
142void QQuickTransform::update()
144 Q_D(QQuickTransform);
145 for (
int ii = 0; ii < d->items.size(); ++ii) {
146 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
147 p->dirty(QQuickItemPrivate::Transform);
151QQuickContents::QQuickContents(QQuickItem *item)
156QQuickContents::~QQuickContents()
158 QList<QQuickItem *> children = m_item->childItems();
159 for (
int i = 0; i < children.size(); ++i) {
160 QQuickItem *child = children.at(i);
161 QQuickItemPrivate::get(child)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
165bool QQuickContents::calcHeight(QQuickItem *changed)
167 qreal oldy = m_contents.y();
168 qreal oldheight = m_contents.height();
172 qreal bottom = oldy + oldheight;
173 qreal y = changed->y();
174 if (y + changed->height() > bottom)
175 bottom = y + changed->height();
178 m_contents.setY(top);
179 m_contents.setHeight(bottom - top);
181 qreal top = std::numeric_limits<qreal>::max();
182 qreal bottom = -std::numeric_limits<qreal>::max();
183 QList<QQuickItem *> children = m_item->childItems();
184 for (
int i = 0; i < children.size(); ++i) {
185 QQuickItem *child = children.at(i);
186 qreal y = child->y();
187 if (y + child->height() > bottom)
188 bottom = y + child->height();
192 if (!children.isEmpty())
193 m_contents.setY(top);
194 m_contents.setHeight(qMax(bottom - top, qreal(0.0)));
197 return (m_contents.height() != oldheight || m_contents.y() != oldy);
200bool QQuickContents::calcWidth(QQuickItem *changed)
202 qreal oldx = m_contents.x();
203 qreal oldwidth = m_contents.width();
207 qreal right = oldx + oldwidth;
208 qreal x = changed->x();
209 if (x + changed->width() > right)
210 right = x + changed->width();
213 m_contents.setX(left);
214 m_contents.setWidth(right - left);
216 qreal left = std::numeric_limits<qreal>::max();
217 qreal right = -std::numeric_limits<qreal>::max();
218 QList<QQuickItem *> children = m_item->childItems();
219 for (
int i = 0; i < children.size(); ++i) {
220 QQuickItem *child = children.at(i);
221 qreal x = child->x();
222 if (x + child->width() > right)
223 right = x + child->width();
227 if (!children.isEmpty())
228 m_contents.setX(left);
229 m_contents.setWidth(qMax(right - left, qreal(0.0)));
232 return (m_contents.width() != oldwidth || m_contents.x() != oldx);
235void QQuickContents::complete()
237 QQuickItemPrivate::get(m_item)->addItemChangeListener(
this, QQuickItemPrivate::Children);
239 QList<QQuickItem *> children = m_item->childItems();
240 for (
int i = 0; i < children.size(); ++i) {
241 QQuickItem *child = children.at(i);
242 QQuickItemPrivate::get(child)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
248void QQuickContents::updateRect()
250 QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF());
253void QQuickContents::itemGeometryChanged(QQuickItem *changed, QQuickGeometryChange change,
const QRectF &)
256 bool wChanged =
false;
257 bool hChanged =
false;
259 if (change.horizontalChange())
260 wChanged = calcWidth();
261 if (change.verticalChange())
262 hChanged = calcHeight();
263 if (wChanged || hChanged)
267void QQuickContents::itemDestroyed(QQuickItem *item)
270 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
274void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item)
277 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
281void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item)
284 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
288QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item)
289: m_processPost(
false), m_next(
nullptr)
291 QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):
nullptr;
293 m_next = p->extra.value().keyHandler;
294 p->extra->keyHandler =
this;
298QQuickItemKeyFilter::~QQuickItemKeyFilter()
302void QQuickItemKeyFilter::keyPressed(QKeyEvent *event,
bool post)
304 if (m_next) m_next->keyPressed(event, post);
307void QQuickItemKeyFilter::keyReleased(QKeyEvent *event,
bool post)
309 if (m_next) m_next->keyReleased(event, post);
313void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event,
bool post)
316 m_next->inputMethodEvent(event, post);
321QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query)
const
323 if (m_next)
return m_next->inputMethodQuery(query);
328void QQuickItemKeyFilter::shortcutOverrideEvent(QKeyEvent *event)
331 m_next->shortcutOverrideEvent(event);
336void QQuickItemKeyFilter::componentComplete()
338 if (m_next) m_next->componentComplete();
341
342
343
344
345
346
347
348
349
350
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
385
386
387
388
389
392
393
394
395
396
399
400
401
402
403
406
407
408
409
410
413
414
415
416
417
420
421
422
423
424
426QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent)
427: QObject(*(
new QQuickKeyNavigationAttachedPrivate), parent),
428 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
430 m_processPost =
true;
433QQuickKeyNavigationAttached *
434QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
436 return new QQuickKeyNavigationAttached(obj);
439QQuickItem *QQuickKeyNavigationAttached::left()
const
441 Q_D(
const QQuickKeyNavigationAttached);
445void QQuickKeyNavigationAttached::setLeft(QQuickItem *i)
447 Q_D(QQuickKeyNavigationAttached);
448 if (d->leftSet && d->left == i)
450 d->leftSet = d->left != i;
452 QQuickKeyNavigationAttached* other =
453 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
454 if (other && !other->d_func()->rightSet){
455 other->d_func()->right = qobject_cast<QQuickItem*>(parent());
456 emit other->rightChanged();
461QQuickItem *QQuickKeyNavigationAttached::right()
const
463 Q_D(
const QQuickKeyNavigationAttached);
467void QQuickKeyNavigationAttached::setRight(QQuickItem *i)
469 Q_D(QQuickKeyNavigationAttached);
470 if (d->rightSet && d->right == i)
472 d->rightSet = d->right != i;
474 QQuickKeyNavigationAttached* other =
475 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
476 if (other && !other->d_func()->leftSet){
477 other->d_func()->left = qobject_cast<QQuickItem*>(parent());
478 emit other->leftChanged();
483QQuickItem *QQuickKeyNavigationAttached::up()
const
485 Q_D(
const QQuickKeyNavigationAttached);
489void QQuickKeyNavigationAttached::setUp(QQuickItem *i)
491 Q_D(QQuickKeyNavigationAttached);
492 if (d->upSet && d->up == i)
494 d->upSet = d->up != i;
496 QQuickKeyNavigationAttached* other =
497 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
498 if (other && !other->d_func()->downSet){
499 other->d_func()->down = qobject_cast<QQuickItem*>(parent());
500 emit other->downChanged();
505QQuickItem *QQuickKeyNavigationAttached::down()
const
507 Q_D(
const QQuickKeyNavigationAttached);
511void QQuickKeyNavigationAttached::setDown(QQuickItem *i)
513 Q_D(QQuickKeyNavigationAttached);
514 if (d->downSet && d->down == i)
516 d->downSet = d->down != i;
518 QQuickKeyNavigationAttached* other =
519 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
520 if (other && !other->d_func()->upSet) {
521 other->d_func()->up = qobject_cast<QQuickItem*>(parent());
522 emit other->upChanged();
527QQuickItem *QQuickKeyNavigationAttached::tab()
const
529 Q_D(
const QQuickKeyNavigationAttached);
533void QQuickKeyNavigationAttached::setTab(QQuickItem *i)
535 Q_D(QQuickKeyNavigationAttached);
536 if (d->tabSet && d->tab == i)
538 d->tabSet = d->tab != i;
540 QQuickKeyNavigationAttached* other =
541 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
542 if (other && !other->d_func()->backtabSet) {
543 other->d_func()->backtab = qobject_cast<QQuickItem*>(parent());
544 emit other->backtabChanged();
549QQuickItem *QQuickKeyNavigationAttached::backtab()
const
551 Q_D(
const QQuickKeyNavigationAttached);
555void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i)
557 Q_D(QQuickKeyNavigationAttached);
558 if (d->backtabSet && d->backtab == i)
560 d->backtabSet = d->backtab != i;
562 QQuickKeyNavigationAttached* other =
563 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
564 if (other && !other->d_func()->tabSet) {
565 other->d_func()->tab = qobject_cast<QQuickItem*>(parent());
566 emit other->tabChanged();
568 emit backtabChanged();
572
573
574
575
576
577
578
579
580
581
582
583
584QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority()
const
586 return m_processPost ? AfterItem : BeforeItem;
589void QQuickKeyNavigationAttached::setPriority(Priority order)
591 bool processPost = order == AfterItem;
592 if (processPost != m_processPost) {
593 m_processPost = processPost;
594 emit priorityChanged();
598void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event,
bool post)
600 Q_D(QQuickKeyNavigationAttached);
603 if (post != m_processPost) {
604 QQuickItemKeyFilter::keyPressed(event, post);
609 switch (event->key()) {
611 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
612 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
613 QQuickItem* leftItem = mirror ? d->right : d->left;
615 setFocusNavigation(leftItem, mirror ?
"right" :
"left", mirror ? Qt::TabFocusReason : Qt::BacktabFocusReason);
620 case Qt::Key_Right: {
621 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
622 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
623 QQuickItem* rightItem = mirror ? d->left : d->right;
625 setFocusNavigation(rightItem, mirror ?
"left" :
"right", mirror ? Qt::BacktabFocusReason : Qt::TabFocusReason);
632 setFocusNavigation(d->up,
"up", Qt::BacktabFocusReason);
638 setFocusNavigation(d->down,
"down", Qt::TabFocusReason);
644 setFocusNavigation(d->tab,
"tab", Qt::TabFocusReason);
648 case Qt::Key_Backtab:
650 setFocusNavigation(d->backtab,
"backtab", Qt::BacktabFocusReason);
658 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
661void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event,
bool post)
663 Q_D(QQuickKeyNavigationAttached);
666 if (post != m_processPost) {
667 QQuickItemKeyFilter::keyReleased(event, post);
672 switch (event->key()) {
674 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
675 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
676 if (mirror ? d->right : d->left)
680 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
681 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
682 if (mirror ? d->left : d->right)
700 case Qt::Key_Backtab:
709 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
712void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem,
const char *dir,
713 Qt::FocusReason reason)
715 QQuickItem *initialItem = currentItem;
716 bool isNextItem =
false;
717 QVector<QQuickItem *> visitedItems;
720 if (currentItem->isVisible() && currentItem->isEnabled()) {
721 currentItem->forceActiveFocus(reason);
724 qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(currentItem,
false);
726 QQuickItem *tempItem = qvariant_cast<QQuickItem*>(attached->property(dir));
728 visitedItems.append(currentItem);
729 currentItem = tempItem;
735 while (currentItem != initialItem && isNextItem && !visitedItems.contains(currentItem));
744 { Qt::Key_Left,
"leftPressed" },
745 { Qt::Key_Right,
"rightPressed" },
746 { Qt::Key_Up,
"upPressed" },
747 { Qt::Key_Down,
"downPressed" },
748 { Qt::Key_Tab,
"tabPressed" },
749 { Qt::Key_Backtab,
"backtabPressed" },
750 { Qt::Key_Asterisk,
"asteriskPressed" },
751 { Qt::Key_NumberSign,
"numberSignPressed" },
752 { Qt::Key_Escape,
"escapePressed" },
753 { Qt::Key_Return,
"returnPressed" },
754 { Qt::Key_Enter,
"enterPressed" },
755 { Qt::Key_Delete,
"deletePressed" },
756 { Qt::Key_Space,
"spacePressed" },
757 { Qt::Key_Back,
"backPressed" },
758 { Qt::Key_Cancel,
"cancelPressed" },
759 { Qt::Key_Select,
"selectPressed" },
760 { Qt::Key_Yes,
"yesPressed" },
761 { Qt::Key_No,
"noPressed" },
762 { Qt::Key_Context1,
"context1Pressed" },
763 { Qt::Key_Context2,
"context2Pressed" },
764 { Qt::Key_Context3,
"context3Pressed" },
765 { Qt::Key_Context4,
"context4Pressed" },
766 { Qt::Key_Call,
"callPressed" },
767 { Qt::Key_Hangup,
"hangupPressed" },
768 { Qt::Key_Flip,
"flipPressed" },
769 { Qt::Key_Menu,
"menuPressed" },
770 { Qt::Key_VolumeUp,
"volumeUpPressed" },
771 { Qt::Key_VolumeDown,
"volumeDownPressed" },
775QByteArray QQuickKeysAttached::keyToSignal(
int key)
777 QByteArray keySignal;
778 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
779 keySignal =
"digit0Pressed";
780 keySignal[5] =
'0' + (key - Qt::Key_0);
783 while (sigMap[i].key && sigMap[i].key != key)
785 keySignal = sigMap[i].sig;
790bool QQuickKeysAttached::isConnected(
const char *signalName)
const
792 Q_D(
const QQuickKeysAttached);
793 int signal_index = d->signalIndex(signalName);
794 return d->isSignalConnected(signal_index);
798
799
800
801
802
803
804
805
806
807
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
863
864
865
866
867
870
871
872
873
874
875
876
877
878
879
880
881
882
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
915
916
917
918
919
922
923
924
925
926
929
930
931
932
933
934
935
936
937
938
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
967
968
969
970
971
974
975
976
977
978
981
982
983
984
985
988
989
990
991
992
995
996
997
998
999
1002
1003
1004
1005
1006
1009
1010
1011
1012
1013
1016
1017
1018
1019
1020
1023
1024
1025
1026
1027
1030
1031
1032
1033
1034
1037
1038
1039
1040
1041
1044
1045
1046
1047
1048
1051
1052
1053
1054
1055
1058
1059
1060
1061
1062
1065
1066
1067
1068
1069
1072
1073
1074
1075
1076
1079
1080
1081
1082
1083
1086
1087
1088
1089
1090
1093
1094
1095
1096
1097
1100
1101
1102
1103
1104
1107
1108
1109
1110
1111
1114
1115
1116
1117
1118
1121
1122
1123
1124
1125
1128
1129
1130
1131
1132
1135
1136
1137
1138
1139
1142
1143
1144
1145
1146
1149
1150
1151
1152
1153
1156
1157
1158
1159
1160
1163
1164
1165
1166
1167
1170
1171
1172
1173
1174
1177
1178
1179
1180
1181
1184
1185
1186
1187
1188
1191
1192
1193
1194
1195
1198
1199
1200
1201
1202
1205
1206
1207
1208
1209
1212
1213
1214
1215
1216
1219
1220
1221
1222
1223
1225QQuickKeysAttached::QQuickKeysAttached(QObject *parent)
1226: QObject(*(
new QQuickKeysAttachedPrivate), parent),
1227 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
1229 Q_D(QQuickKeysAttached);
1230 m_processPost =
false;
1231 d->item = qmlobject_cast<QQuickItem*>(parent);
1232 if (d->item != parent)
1233 qWarning() <<
"Could not attach Keys property to: " << parent <<
" is not an Item";
1236QQuickKeysAttached::~QQuickKeysAttached()
1240QQuickKeysAttached::Priority QQuickKeysAttached::priority()
const
1242 return m_processPost ? AfterItem : BeforeItem;
1245void QQuickKeysAttached::setPriority(Priority order)
1247 bool processPost = order == AfterItem;
1248 if (processPost != m_processPost) {
1249 m_processPost = processPost;
1250 emit priorityChanged();
1254void QQuickKeysAttached::componentComplete()
1257 Q_D(QQuickKeysAttached);
1259 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1260 QQuickItem *targetItem = d->targets.at(ii);
1261 if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1262 d->item->setFlag(QQuickItem::ItemAcceptsInputMethod);
1270void QQuickKeysAttached::keyPressed(QKeyEvent *event,
bool post)
1272 Q_D(QQuickKeysAttached);
1273 if (post != m_processPost || !d->enabled || d->inPress) {
1275 QQuickItemKeyFilter::keyPressed(event, post);
1280 if (d->item && d->item->window()) {
1282 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1283 QQuickItem *i = d->targets.at(ii);
1284 if (i && i->isVisible()) {
1286 QCoreApplication::sendEvent(i, event);
1287 if (event->isAccepted()) {
1296 QQuickKeyEvent &ke = d->theKeyEvent;
1298 QByteArray keySignal = keyToSignal(event->key());
1299 if (!keySignal.isEmpty()) {
1300 keySignal +=
"(QQuickKeyEvent*)";
1301 if (isConnected(keySignal)) {
1303 ke.setAccepted(
true);
1304 int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal);
1305 metaObject()->method(idx).invoke(
this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke));
1308 if (!ke.isAccepted())
1310 event->setAccepted(ke.isAccepted());
1312 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
1315void QQuickKeysAttached::keyReleased(QKeyEvent *event,
bool post)
1317 Q_D(QQuickKeysAttached);
1318 if (post != m_processPost || !d->enabled || d->inRelease) {
1320 QQuickItemKeyFilter::keyReleased(event, post);
1324 if (d->item && d->item->window()) {
1325 d->inRelease =
true;
1326 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1327 QQuickItem *i = d->targets.at(ii);
1328 if (i && i->isVisible()) {
1330 QCoreApplication::sendEvent(i, event);
1331 if (event->isAccepted()) {
1332 d->inRelease =
false;
1337 d->inRelease =
false;
1340 QQuickKeyEvent &ke = d->theKeyEvent;
1343 event->setAccepted(ke.isAccepted());
1345 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
1349void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event,
bool post)
1351 Q_D(QQuickKeysAttached);
1352 if (post == m_processPost && d->item && !d->inIM && d->item->window()) {
1354 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1355 QQuickItem *targetItem = d->targets.at(ii);
1356 if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1357 QCoreApplication::sendEvent(targetItem, event);
1358 if (event->isAccepted()) {
1359 d->imeItem = targetItem;
1367 QQuickItemKeyFilter::inputMethodEvent(event, post);
1370QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query)
const
1372 Q_D(
const QQuickKeysAttached);
1374 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1375 QQuickItem *i = d->targets.at(ii);
1376 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) {
1378 QVariant v = i->inputMethodQuery(query);
1379 if (v.userType() == QMetaType::QRectF)
1380 v = d->item->mapRectFromItem(i, v.toRectF());
1385 return QQuickItemKeyFilter::inputMethodQuery(query);
1389void QQuickKeysAttached::shortcutOverrideEvent(QKeyEvent *event)
1391 Q_D(QQuickKeysAttached);
1392 QQuickKeyEvent &keyEvent = d->theKeyEvent;
1393 keyEvent.reset(*event);
1394 emit shortcutOverride(&keyEvent);
1396 event->setAccepted(keyEvent.isAccepted());
1399QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
1401 return new QQuickKeysAttached(obj);
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
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
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1471
1472
1473
1474
1475
1476
1477
1480QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1482 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1483 itemPrivate = QQuickItemPrivate::get(item);
1484 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1485 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1488 itemPrivate->extra.value().layoutDirectionAttached =
this;
1490 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1493QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1495 return new QQuickLayoutMirroringAttached(object);
1498bool QQuickLayoutMirroringAttached::enabled()
const
1500 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1503void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1508 itemPrivate->isMirrorImplicit =
false;
1509 if (enabled != itemPrivate->effectiveLayoutMirror) {
1510 itemPrivate->setLayoutMirror(enabled);
1511 if (itemPrivate->inheritMirrorFromItem)
1512 itemPrivate->resolveLayoutMirror();
1516void QQuickLayoutMirroringAttached::resetEnabled()
1518 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1519 itemPrivate->isMirrorImplicit =
true;
1520 itemPrivate->resolveLayoutMirror();
1524bool QQuickLayoutMirroringAttached::childrenInherit()
const
1526 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1529void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1530 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1531 itemPrivate->inheritMirrorFromItem = childrenInherit;
1532 itemPrivate->resolveLayoutMirror();
1533 childrenInheritChanged();
1537void QQuickItemPrivate::resolveLayoutMirror()
1540 if (QQuickItem *parentItem = q->parentItem()) {
1541 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1542 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1544 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1548void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1550 inherit = inherit || inheritMirrorFromItem;
1551 if (!isMirrorImplicit && inheritMirrorFromItem)
1552 mirror = effectiveLayoutMirror;
1553 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1556 inheritMirrorFromParent = inherit;
1557 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1559 if (isMirrorImplicit)
1560 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1561 for (
int i = 0; i < childItems.size(); ++i) {
1562 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1563 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1564 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1569void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1571 if (mirror != effectiveLayoutMirror) {
1572 effectiveLayoutMirror = mirror;
1574 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1575 anchor_d->fillChanged();
1576 anchor_d->centerInChanged();
1577 anchor_d->updateHorizontalAnchors();
1580 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1581 emit extra->layoutDirectionAttached->enabledChanged();
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1633QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1634 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1636 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1637 itemPrivate = QQuickItemPrivate::get(item);
1638 itemPrivate->extra.value().enterKeyAttached =
this;
1640 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1643QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1645 return new QQuickEnterKeyAttached(object);
1648Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1653void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1655 if (keyType != type) {
1658 if (itemPrivate && itemPrivate->activeFocus)
1659 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1665void QQuickItemPrivate::setAccessible()
1667 isAccessible =
true;
1671
1672
1673
1674
1675void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1680 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1682 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1684 if (oldSubFocusItem) {
1685 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1686 while (sfi && sfi != scope) {
1687 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1688 sfi = sfi->parentItem();
1693 scopePrivate->subFocusItem = q;
1694 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1695 while (sfi && sfi != scope) {
1696 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1697 sfi = sfi->parentItem();
1700 scopePrivate->subFocusItem =
nullptr;
1705bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1708 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1709 Qt::FocusPolicy policy = Qt::ClickFocus;
1711 switch (eventType) {
1712 case QEvent::MouseButtonPress:
1713 case QEvent::MouseButtonDblClick:
1714 case QEvent::TouchBegin:
1715 if (setFocusOnRelease)
1718 case QEvent::MouseButtonRelease:
1719 case QEvent::TouchEnd:
1720 if (!setFocusOnRelease)
1724 policy = Qt::WheelFocus;
1730 if ((focusPolicy & policy) == policy) {
1731 setActiveFocus(q, Qt::MouseFocusReason);
1738Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1740 return static_cast<Qt::FocusReason>(focusReason);
1743bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1745 if (focusReason == reason)
1748 focusReason = reason;
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2141
2142
2143
2144
2145
2146
2147
2148
2149
2152
2153
2154
2157
2158
2159
2162
2163
2164
2167
2168
2169
2172
2173
2174
2175
2176
2177
2178
2181
2182
2183
2184
2185
2186
2189
2190
2191
2192
2193
2196
2197
2198
2199
2200
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2221
2222
2223
2226
2227
2228
2231
2232
2233
2236
2237
2238
2241
2242
2243
2246
2247
2248
2251
2252
2253
2256
2257
2258
2261
2262
2263
2266
2267
2268
2271
2272
2273
2276
2277
2278
2281
2282
2283
2286
2287
2288
2291
2292
2293
2296
2297
2298
2301
2302
2303
2306
2307
2308
2311
2312
2313
2316
2317
2318
2321
2322
2323
2326
2327
2328
2331
2332
2333
2336
2337
2338
2341
2342
2343
2346
2347
2348
2351
2352
2353
2354
2355
2356
2357
2358QQuickItem::QQuickItem(QQuickItem* parent)
2359: QObject(*(
new QQuickItemPrivate), parent)
2366
2367QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2368: QObject(dd, parent)
2375
2376
2377QQuickItem::~QQuickItem()
2380 d->inDestructor =
true;
2382 if (d->windowRefCount > 1)
2383 d->windowRefCount = 1;
2385 setParentItem(
nullptr);
2389 for (QQuickItem *child : std::as_const(d->childItems))
2390 child->setParentItem(
nullptr);
2391 d->childItems.clear();
2393 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2394 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2396 anchor->clearItem(
this);
2399
2400
2401
2402 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2403 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2404 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2407 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2408 d->changeListeners.clear();
2411
2412
2413
2414
2415 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2416 QQuickTransform *t = d->transforms.at(ii);
2417 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2418 tp->items.removeOne(
this);
2421 if (d->extra.isAllocated()) {
2422 delete d->extra->contents; d->extra->contents =
nullptr;
2423#if QT_CONFIG(quick_shadereffect)
2424 delete d->extra->layer; d->extra->layer =
nullptr;
2428 delete d->_anchors; d->_anchors =
nullptr;
2429 delete d->_stateGroup; d->_stateGroup =
nullptr;
2431 d->isQuickItem =
false;
2435
2436
2437bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2439 if (!item->window())
2442 if (item == item->window()->contentItem())
2445 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2446 if (tabFocus == Qt::NoTabFocus)
2448 if (tabFocus == Qt::TabFocusAllControls)
2451 QVariant editable = item->property(
"editable");
2452 if (editable.isValid())
2453 return editable.toBool();
2455 QVariant readonly = item->property(
"readOnly");
2456 if (readonly.isValid())
2457 return !readonly.toBool() && item->property(
"text").isValid();
2459#if QT_CONFIG(accessibility)
2460 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2461 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2463 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2464 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2465 return iface->state().editable;
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2484 QQuickWindow *window = item->window();
2485 const bool wrap = !window || window->isTopLevel();
2487 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2492 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2494 if (!wrap && !next) {
2498 Q_ASSERT(window->parent());
2501 qt_window_private(window->parent())->setFocusToTarget(
2502 forward ? QWindowPrivate::FocusTarget::Next
2503 : QWindowPrivate::FocusTarget::Prev,
2505 window->parent()->requestActivate();
2509 next->forceActiveFocus(reason);
2514QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2517 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2520 const QList<QQuickItem *> &children = item->childItems();
2521 const int count = children.size();
2522 if (start < 0 || start >= count) {
2523 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2526 while (start < count) {
2527 QQuickItem *child = children.at(start);
2528 if (!child->d_func()->isTabFence)
2535QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2538 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2541 const QList<QQuickItem *> &children = item->childItems();
2542 const int count = children.size();
2545 if (start < 0 || start >= count) {
2546 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2549 while (start >= 0) {
2550 QQuickItem *child = children.at(start);
2551 if (!child->d_func()->isTabFence)
2558QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2561 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2563 if (!item->window())
2565 const QQuickItem *
const contentItem = item->window()->contentItem();
2569 QQuickItem *from =
nullptr;
2570 bool isTabFence = item->d_func()->isTabFence;
2573 from = item->parentItem();
2575 if (!item->childItems().isEmpty())
2576 from = item->d_func()->childItems.constFirst();
2577 else if (!isTabFence)
2578 from = item->parentItem();
2582 QQuickItem *startItem = item;
2583 QQuickItem *originalStartItem = startItem;
2588 while (startItem && !startItem->isVisible()) {
2589 startItem = startItem->parentItem();
2594 QQuickItem *firstFromItem = from;
2595 QQuickItem *current = item;
2596 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2597 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2598 QDuplicateTracker<QQuickItem *> cycleDetector;
2600 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2601 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2603 QQuickItem *last = current;
2605 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2606 QQuickItem *firstChild =
nullptr;
2607 QQuickItem *lastChild =
nullptr;
2609 firstChild = nextTabChildItem(current, 0);
2611 hasChildren =
false;
2613 lastChild = prevTabChildItem(current, -1);
2615 isTabFence = current->d_func()->isTabFence;
2616 if (isTabFence && !hasChildren)
2620 if (hasChildren && from == current->parentItem()) {
2622 current = firstChild;
2624 current = lastChild;
2625 if (!current->childItems().isEmpty())
2628 }
else if (hasChildren && forward && from != lastChild) {
2630 int nextChild = current->childItems().indexOf(from) + 1;
2631 current = nextTabChildItem(current, nextChild);
2632 }
else if (hasChildren && !forward && from != firstChild) {
2634 int prevChild = current->childItems().indexOf(from) - 1;
2635 current = prevTabChildItem(current, prevChild);
2636 if (!current->childItems().isEmpty())
2639 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2643 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2644 if (last != firstSibling
2645 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2649 }
else if (hasChildren) {
2651 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2652 <<
"Focus chain about to wrap but wrapping was set to false."
2659 current = firstChild;
2661 current = lastChild;
2662 if (!current->childItems().isEmpty())
2674 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2675 (!skip && cycleDetector.hasSeen(current))) {
2677 if (item == contentItem) {
2678 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2681 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2685 if (!firstFromItem) {
2686 if (startItem->d_func()->isTabFence) {
2687 if (current == startItem)
2688 firstFromItem = from;
2690 startItem = current;
2691 firstFromItem = from;
2694 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2695 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2701
2702
2703
2704
2705
2706
2707
2708
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724QQuickItem *QQuickItem::parentItem()
const
2726 Q_D(
const QQuickItem);
2727 return d->parentItem;
2730void QQuickItem::setParentItem(QQuickItem *parentItem)
2733 if (parentItem == d->parentItem)
2737 QQuickItem *itemAncestor = parentItem;
2738 while (itemAncestor !=
nullptr) {
2739 if (Q_UNLIKELY(itemAncestor ==
this)) {
2740 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2743 itemAncestor = itemAncestor->parentItem();
2745 auto engine = qmlEngine(
this);
2747 QV4::ExecutionEngine *v4 = engine->handle();
2748 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2749 QV4::QObjectWrapper::markWrapper(
this, ms);
2754 d->removeFromDirtyList();
2756 QQuickItem *oldParentItem = d->parentItem;
2757 QQuickItem *scopeFocusedItem =
nullptr;
2759 if (oldParentItem) {
2760 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2762 QQuickItem *scopeItem =
nullptr;
2764 if (hasFocus() || op->subFocusItem ==
this)
2765 scopeFocusedItem =
this;
2766 else if (!isFocusScope() && d->subFocusItem)
2767 scopeFocusedItem = d->subFocusItem;
2769 if (scopeFocusedItem) {
2770 scopeItem = oldParentItem;
2771 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2772 scopeItem = scopeItem->parentItem();
2774 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2775 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2776 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2778 if (scopeFocusedItem !=
this)
2779 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2781 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2785 const bool wasVisible = isVisible();
2786 op->removeChild(
this);
2787 if (wasVisible && !op->inDestructor)
2788 emit oldParentItem->visibleChildrenChanged();
2789 }
else if (d->window) {
2790 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2793 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2794 bool alreadyAddedChild =
false;
2795 if (d->window == parentWindow) {
2797 d->parentItem = parentItem;
2799 auto oldParentItem = d->parentItem;
2800 d->parentItem = parentItem;
2801 if (d->parentItem) {
2802 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2803 alreadyAddedChild =
true;
2811 if (!oldParentItem && d->window) {
2812 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2816 d->refWindow(parentWindow);
2819 d->dirty(QQuickItemPrivate::ParentChanged);
2821 if (d->parentItem && !alreadyAddedChild)
2822 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2823 else if (d->window && !alreadyAddedChild)
2824 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2826 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2827 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2829 if (d->parentItem) {
2830 if (!scopeFocusedItem) {
2832 scopeFocusedItem =
this;
2833 else if (!isFocusScope() && d->subFocusItem)
2834 scopeFocusedItem = d->subFocusItem;
2837 if (scopeFocusedItem) {
2839 QQuickItem *scopeItem = d->parentItem;
2840 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2841 scopeItem = scopeItem->parentItem();
2843 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2844 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2845 if (scopeFocusedItem !=
this)
2846 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2847 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2848 emit scopeFocusedItem->focusChanged(
false);
2851 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2852 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2853 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2856 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2863 d->resolveLayoutMirror();
2865 d->itemChange(ItemParentHasChanged, d->parentItem);
2867 if (!d->inDestructor)
2868 emit parentChanged(d->parentItem);
2869 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2870 emit d->parentItem->visibleChildrenChanged();
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890void QQuickItem::stackBefore(
const QQuickItem *sibling)
2893 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2894 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2895 <<
this <<
" before " << sibling <<
", which must be a sibling";
2899 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2901 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2902 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2904 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2906 if (myIndex == siblingIndex - 1)
2909 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2911 parentPrivate->markSortedChildrenDirty(
this);
2912 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2914 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2915 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935void QQuickItem::stackAfter(
const QQuickItem *sibling)
2938 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2939 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2940 <<
this <<
" after " << sibling <<
", which must be a sibling";
2944 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2946 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2947 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2949 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2951 if (myIndex == siblingIndex + 1)
2954 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2956 parentPrivate->markSortedChildrenDirty(
this);
2957 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2959 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2960 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2964
2965
2968
2969
2970
2971
2972
2973
2974QQuickWindow *QQuickItem::window()
const
2976 Q_D(
const QQuickItem);
2982 return lhs->z() < rhs->z();
2985QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
2987 if (sortedChildItems)
2988 return *sortedChildItems;
2993 for (
int i = 0; i < childItems.size(); ++i) {
2994 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3000 sortedChildItems =
new QList<QQuickItem*>(childItems);
3001 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3002 return *sortedChildItems;
3005 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3010void QQuickItemPrivate::addChild(QQuickItem *child)
3014 Q_ASSERT(!childItems.contains(child));
3016 childItems.append(child);
3018 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3020#if QT_CONFIG(cursor)
3023 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3024 setHasCursorInChild(
true);
3027 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3028 setHasHoverInChild(
true);
3030 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3031 markSortedChildrenDirty(child);
3032 dirty(QQuickItemPrivate::ChildrenChanged);
3034 itemChange(QQuickItem::ItemChildAddedChange, child);
3036 emit q->childrenChanged();
3039void QQuickItemPrivate::removeChild(QQuickItem *child)
3044 if (!inDestructor) {
3046 Q_ASSERT(childItems.contains(child));
3047 childItems.removeOne(child);
3048 Q_ASSERT(!childItems.contains(child));
3051 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3053#if QT_CONFIG(cursor)
3055 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3056 setHasCursorInChild(
false);
3059 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3060 setHasHoverInChild(
false);
3062 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3063 if (!inDestructor) {
3064 markSortedChildrenDirty(child);
3065 dirty(QQuickItemPrivate::ChildrenChanged);
3068 itemChange(QQuickItem::ItemChildRemovedChange, child);
3071 emit q->childrenChanged();
3074void QQuickItemPrivate::refWindow(QQuickWindow *c)
3086 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3088 if (++windowRefCount > 1) {
3090 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3094 Q_ASSERT(window ==
nullptr);
3097 if (polishScheduled)
3098 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3101 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3103 for (
int ii = 0; ii < childItems.size(); ++ii) {
3104 QQuickItem *child = childItems.at(ii);
3105 QQuickItemPrivate::get(child)->refWindow(c);
3110 if (extra.isAllocated() && extra->screenAttached)
3111 extra->screenAttached->windowChanged(c);
3112 itemChange(QQuickItem::ItemSceneChange, c);
3115void QQuickItemPrivate::derefWindow()
3118 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3123 if (--windowRefCount > 0)
3126 q->releaseResources();
3127 removeFromDirtyList();
3128 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3129 if (polishScheduled)
3130 c->itemsToPolish.removeOne(q);
3131#if QT_CONFIG(cursor)
3132 if (c->cursorItem == q) {
3133 c->cursorItem =
nullptr;
3134 window->unsetCursor();
3137 if (itemNodeInstance)
3138 c->cleanup(itemNodeInstance);
3140 c->parentlessItems.remove(q);
3144 itemNodeInstance =
nullptr;
3146 if (extra.isAllocated()) {
3147 extra->opacityNode =
nullptr;
3148 extra->clipNode =
nullptr;
3149 extra->rootNode =
nullptr;
3152 paintNode =
nullptr;
3154 for (
int ii = 0; ii < childItems.size(); ++ii) {
3155 if (QQuickItem *child = childItems.at(ii))
3156 QQuickItemPrivate::get(child)->derefWindow();
3161 if (extra.isAllocated() && extra->screenAttached)
3162 extra->screenAttached->windowChanged(
nullptr);
3163 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3168
3169
3170QTransform QQuickItemPrivate::windowToItemTransform()
const
3173 return itemToWindowTransform().inverted();
3177
3178
3179QTransform QQuickItemPrivate::itemToWindowTransform()
const
3182 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3183 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3184 itemToParentTransform(&rv);
3189
3190
3191void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3194
3195
3196
3197
3198
3200 qreal x =
this->x.valueBypassingBindings();
3201 qreal y =
this->y.valueBypassingBindings();
3205 if (!transforms.isEmpty()) {
3207 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3208 transforms.at(ii)->applyTo(&m);
3209 *t = m.toTransform();
3212 if (scale() != 1. || rotation() != 0.) {
3213 QPointF tp = computeTransformOrigin();
3214 t->translate(tp.x(), tp.y());
3215 t->scale(scale(), scale());
3216 t->rotate(rotation());
3217 t->translate(-tp.x(), -tp.y());
3222
3223
3224
3225
3226
3227
3228
3229
3230bool QQuickItem::isComponentComplete()
const
3232 Q_D(
const QQuickItem);
3233 return d->componentComplete;
3236QQuickItemPrivate::QQuickItemPrivate()
3238 , _stateGroup(
nullptr)
3240 , widthValidFlag(
false)
3241 , heightValidFlag(
false)
3242 , componentComplete(
true)
3245 , hoverEnabled(
false)
3247 , antialiasing(
false)
3249 , activeFocus(
false)
3250 , notifiedFocus(
false)
3251 , notifiedActiveFocus(
false)
3252 , filtersChildMouseEvents(
false)
3253 , explicitVisible(
true)
3254 , effectiveVisible(
true)
3255 , explicitEnable(
true)
3256 , effectiveEnable(
true)
3257 , polishScheduled(
false)
3258 , inheritedLayoutMirror(
false)
3259 , effectiveLayoutMirror(
false)
3260 , isMirrorImplicit(
true)
3261 , inheritMirrorFromParent(
false)
3262 , inheritMirrorFromItem(
false)
3263 , isAccessible(
false)
3266 , subtreeCursorEnabled(
false)
3267 , subtreeHoverEnabled(
false)
3268 , activeFocusOnTab(
false)
3269 , implicitAntialiasing(
false)
3270 , antialiasingValid(
false)
3272 , replayingPressEvent(
false)
3273 , touchEnabled(
false)
3274 , hasCursorHandler(
false)
3275 , maybeHasSubsceneDeliveryAgent(
true)
3276 , subtreeTransformChangedEnabled(
true)
3277 , inDestructor(
false)
3278 , focusReason(Qt::OtherFocusReason)
3279 , focusPolicy(Qt::NoFocus)
3280 , dirtyAttributes(0)
3281 , nextDirtyItem(
nullptr)
3282 , prevDirtyItem(
nullptr)
3285 , parentItem(
nullptr)
3286 , sortedChildItems(&childItems)
3287 , subFocusItem(
nullptr)
3295 , itemNodeInstance(
nullptr)
3296 , paintNode(
nullptr)
3297 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3301QQuickItemPrivate::~QQuickItemPrivate()
3303 if (sortedChildItems != &childItems)
3304 delete sortedChildItems;
3307void QQuickItemPrivate::init(QQuickItem *parent)
3313 baselineOffset = 0.0;
3316 q->setParentItem(parent);
3317 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3318 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3322QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3327void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3329 szPolicy.setHorizontalPolicy(horizontalPolicy);
3330 szPolicy.setVerticalPolicy(verticalPolicy);
3333void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3338 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3340 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3341 item->setParentItem(that);
3342 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3343 if (pointerHandler->parent() != that) {
3344 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3345 pointerHandler->setParent(that);
3347 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3350 resources_append(prop, o);
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3389qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3391 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3392 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3393 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3394 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3396 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3399QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3401 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3402 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3403 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3404 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3406 qsizetype resourcesCount = resources_count(&resourcesProperty);
3407 if (i < resourcesCount)
3408 return resources_at(&resourcesProperty, i);
3409 const qsizetype j = i - resourcesCount;
3410 if (j < children_count(&childrenProperty))
3411 return children_at(&childrenProperty, j);
3415void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3417 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3418 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3419 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3420 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3422 resources_clear(&resourcesProperty);
3423 children_clear(&childrenProperty);
3426void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3428 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3429 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3431 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3432 if (children_count(&childrenProperty) > 0) {
3433 children_removeLast(&childrenProperty);
3437 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3438 if (resources_count(&resourcesProperty) > 0)
3439 resources_removeLast(&resourcesProperty);
3442QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3444 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3445 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3448void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3450 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3451 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3452 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3453 quickItemPrivate->extra.value().resourcesList.append(object);
3454 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3455 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3459qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3461 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3462 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3465void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3467 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3468 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3469 if (quickItemPrivate->extra.isAllocated()) {
3470 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3471 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3472 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3474 quickItemPrivate->extra->resourcesList.clear();
3478void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3480 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3481 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3482 if (quickItemPrivate->extra.isAllocated()) {
3483 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3484 if (resources->isEmpty())
3487 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3488 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3489 resources->removeLast();
3493QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3495 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3496 if (index >= p->childItems.size() || index < 0)
3499 return p->childItems.at(index);
3502void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3507 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3508 if (o->parentItem() == that)
3509 o->setParentItem(
nullptr);
3511 o->setParentItem(that);
3514qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3516 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3517 return p->childItems.size();
3520void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3522 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3523 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3524 while (!p->childItems.isEmpty())
3525 p->childItems.at(0)->setParentItem(
nullptr);
3528void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3530 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3531 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3532 if (!p->childItems.isEmpty())
3533 p->childItems.last()->setParentItem(
nullptr);
3536qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3538 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3539 qsizetype visibleCount = 0;
3540 qsizetype c = p->childItems.size();
3542 if (p->childItems.at(c)->isVisible()) visibleCount++;
3545 return visibleCount;
3548QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3550 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3551 const qsizetype childCount = p->childItems.size();
3552 if (index >= childCount || index < 0)
3555 qsizetype visibleCount = -1;
3556 for (qsizetype i = 0; i < childCount; i++) {
3557 if (p->childItems.at(i)->isVisible()) visibleCount++;
3558 if (visibleCount == index)
return p->childItems.at(i);
3563qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3565 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3566 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3568 return p->transforms.size();
3571void QQuickTransform::appendToItem(QQuickItem *item)
3573 Q_D(QQuickTransform);
3577 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3579 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3580 p->transforms.removeOne(
this);
3581 p->transforms.append(
this);
3583 p->transforms.append(
this);
3584 d->items.append(item);
3587 p->dirty(QQuickItemPrivate::Transform);
3590void QQuickTransform::prependToItem(QQuickItem *item)
3592 Q_D(QQuickTransform);
3596 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3598 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3599 p->transforms.removeOne(
this);
3600 p->transforms.prepend(
this);
3602 p->transforms.prepend(
this);
3603 d->items.append(item);
3606 p->dirty(QQuickItemPrivate::Transform);
3609void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3614 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3615 transform->appendToItem(that);
3618QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3620 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3621 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3623 if (idx < 0 || idx >= p->transforms.size())
3626 return p->transforms.at(idx);
3629void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3631 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3632 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3634 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3635 QQuickTransform *t = p->transforms.at(ii);
3636 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3637 tp->items.removeOne(that);
3640 p->transforms.clear();
3642 p->dirty(QQuickItemPrivate::Transform);
3645void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3647 if (extra.isAllocated() && extra->resourcesList.contains(object))
3648 extra->resourcesList.removeAll(object);
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745QQuickAnchors *QQuickItemPrivate::anchors()
const
3748 Q_Q(
const QQuickItem);
3749 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3750 if (!componentComplete)
3751 _anchors->classBegin();
3756void QQuickItemPrivate::siblingOrderChanged()
3759 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3762QQmlListProperty<QObject> QQuickItemPrivate::data()
3766 QQmlListProperty<QObject> result;
3767 result.object = q_func();
3768 result.append = QQuickItemPrivate::data_append;
3769 result.count = QQuickItemPrivate::data_count;
3770 result.at = QQuickItemPrivate::data_at;
3771 result.clear = QQuickItemPrivate::data_clear;
3772 result.removeLast = QQuickItemPrivate::data_removeLast;
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807QRectF QQuickItem::childrenRect()
3810 if (!d->extra.isAllocated() || !d->extra->contents) {
3811 d->extra.value().contents =
new QQuickContents(
this);
3812 if (d->componentComplete)
3813 d->extra->contents->complete();
3815 return d->extra->contents->rectF();
3819
3820
3821QList<QQuickItem *> QQuickItem::childItems()
const
3823 Q_D(
const QQuickItem);
3824 return d->childItems;
3828
3829
3830
3831
3832
3833
3834
3835
3836
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855bool QQuickItem::clip()
const
3857 return flags() & ItemClipsChildrenToShape;
3860void QQuickItem::setClip(
bool c)
3865 setFlag(ItemClipsChildrenToShape, c);
3867 setFlag(ItemIsViewport);
3868 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3869 setFlag(ItemIsViewport,
false);
3871 emit clipChanged(c);
3875
3876
3877
3878
3879
3880
3881
3882
3883void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3888 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3890 QQuickGeometryChange change;
3891 change.setXChange(newGeometry.x() != oldGeometry.x());
3892 change.setYChange(newGeometry.y() != oldGeometry.y());
3893 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3894 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3896 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3897 if (change.matches(listener.gTypes))
3898 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3903 if (change.xChange())
3905 if (change.yChange())
3907 if (change.widthChange())
3909 if (change.heightChange())
3911#if QT_CONFIG(accessibility)
3912 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3913 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3914 QAccessible::updateAccessibility(&ev);
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3973QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
3975 Q_UNUSED(updatePaintNodeData);
3980QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
3981: transformNode(
nullptr)
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4002void QQuickItem::releaseResources()
4006QSGTransformNode *QQuickItemPrivate::createTransformNode()
4008 return new QSGTransformNode;
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021void QQuickItem::updatePolish()
4025#define PRINT_LISTENERS() do
4027 qDebug().nospace() << q_func() << " (" << this
4028 << ") now has the following listeners:";
4029 for (const auto &listener : std::as_const(changeListeners)) {
4030 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4031 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4033}while
4036void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4038 changeListeners.append(ChangeListener(listener, types));
4040 if (lcChangeListeners().isDebugEnabled())
4044void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4046 const ChangeListener changeListener(listener, types);
4047 const int index = changeListeners.indexOf(changeListener);
4049 changeListeners[index].types = changeListener.types;
4051 changeListeners.append(changeListener);
4053 if (lcChangeListeners().isDebugEnabled())
4057void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4059 ChangeListener change(listener, types);
4060 changeListeners.removeOne(change);
4062 if (lcChangeListeners().isDebugEnabled())
4066void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4067 QQuickGeometryChange types)
4069 ChangeListener change(listener, types);
4070 int index = changeListeners.indexOf(change);
4072 changeListeners[index].gTypes = change.gTypes;
4074 changeListeners.append(change);
4076 if (lcChangeListeners().isDebugEnabled())
4080void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4081 QQuickGeometryChange types)
4083 ChangeListener change(listener, types);
4084 if (types.noChange()) {
4085 changeListeners.removeOne(change);
4087 int index = changeListeners.indexOf(change);
4089 changeListeners[index].gTypes = change.gTypes;
4092 if (lcChangeListeners().isDebugEnabled())
4097
4098
4099
4100
4101
4102
4103void QQuickItem::keyPressEvent(QKeyEvent *event)
4109
4110
4111
4112
4113
4114
4115void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4122
4123
4124
4125
4126
4127
4128void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144void QQuickItem::focusInEvent(QFocusEvent *event)
4147#if QT_CONFIG(accessibility)
4148 if (QAccessible::isActive()) {
4149 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4150 QAccessibleEvent ev(acc, QAccessible::Focus);
4151 QAccessible::updateAccessibility(&ev);
4155 d->setLastFocusChangeReason(event->reason());
4159
4160
4161
4162
4163
4164
4165void QQuickItem::focusOutEvent(QFocusEvent *event)
4168 d->setLastFocusChangeReason(event->reason());
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181void QQuickItem::mousePressEvent(QMouseEvent *event)
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4219
4220
4221
4222
4223
4224
4225void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4231
4232
4233
4234void QQuickItem::mouseUngrabEvent()
4240
4241
4242
4243void QQuickItem::touchUngrabEvent()
4248#if QT_CONFIG(wheelevent)
4250
4251
4252
4253
4254
4255
4256void QQuickItem::wheelEvent(QWheelEvent *event)
4263
4264
4265
4266
4267
4268
4269void QQuickItem::touchEvent(QTouchEvent *event)
4275
4276
4277
4278
4279
4280
4281
4282
4283void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4289
4290
4291
4292
4293
4294
4295
4296
4297void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4303
4304
4305
4306
4307
4308
4309
4310
4311void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4316#if QT_CONFIG(quick_draganddrop)
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380void QQuickItem::dropEvent(QDropEvent *event)
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4425
4426
4427
4428
4429
4430
4431
4432QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4434 Q_D(
const QQuickItem);
4439 v = (
bool)(flags() & ItemAcceptsInputMethod);
4442 case Qt::ImAnchorRectangle:
4443 case Qt::ImCursorRectangle:
4445 case Qt::ImCursorPosition:
4446 case Qt::ImSurroundingText:
4447 case Qt::ImCurrentSelection:
4448 case Qt::ImMaximumTextLength:
4449 case Qt::ImAnchorPosition:
4450 case Qt::ImPreferredLanguage:
4451 case Qt::ImReadOnly:
4452 if (d->extra.isAllocated() && d->extra->keyHandler)
4453 v = d->extra->keyHandler->inputMethodQuery(query);
4455 case Qt::ImEnterKeyType:
4456 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4457 v = d->extra->enterKeyAttached->type();
4459 case Qt::ImInputItemClipRectangle:
4460 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4461 QRectF rect = QRectF(0,0, width(), height());
4462 const QQuickItem *par =
this;
4463 while (QQuickItem *parpar = par->parentItem()) {
4464 rect = parpar->mapRectFromItem(par, rect);
4466 rect = rect.intersected(parpar->clipRect());
4469 rect = par->mapRectToScene(rect);
4471 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4473 v = mapRectFromScene(rect);
4484QQuickAnchorLine QQuickItemPrivate::left()
const
4486 Q_Q(
const QQuickItem);
4487 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4490QQuickAnchorLine QQuickItemPrivate::right()
const
4492 Q_Q(
const QQuickItem);
4493 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4496QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4498 Q_Q(
const QQuickItem);
4499 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4502QQuickAnchorLine QQuickItemPrivate::top()
const
4504 Q_Q(
const QQuickItem);
4505 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4508QQuickAnchorLine QQuickItemPrivate::bottom()
const
4510 Q_Q(
const QQuickItem);
4511 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4514QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4516 Q_Q(
const QQuickItem);
4517 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4520QQuickAnchorLine QQuickItemPrivate::baseline()
const
4522 Q_Q(
const QQuickItem);
4523 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548qreal QQuickItem::baselineOffset()
const
4550 Q_D(
const QQuickItem);
4551 return d->baselineOffset;
4554void QQuickItem::setBaselineOffset(qreal offset)
4557 if (offset == d->baselineOffset)
4560 d->baselineOffset = offset;
4562 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4563 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4565 anchor->updateVerticalAnchors();
4568 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4569 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4571 emit baselineOffsetChanged(offset);
4576
4577
4578
4579
4580
4581
4582
4583
4584void QQuickItem::update()
4587 if (!(flags() & ItemHasContents)) {
4589 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4593 d->dirty(QQuickItemPrivate::Content);
4597
4598
4599
4600
4601
4602
4603
4604void QQuickItem::polish()
4607 if (!d->polishScheduled) {
4608 d->polishScheduled =
true;
4610 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4611 bool maybeupdate = p->itemsToPolish.isEmpty();
4612 p->itemsToPolish.append(
this);
4613 if (maybeupdate) d->window->maybeUpdate();
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633void QQuickItem::ensurePolished()
4638#if QT_DEPRECATED_SINCE(6
, 5
)
4639static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4640 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4642 QV4::ExecutionEngine *v4 = args->v4engine();
4643 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4644 v4->throwTypeError();
4648 QV4::Scope scope(v4);
4649 QV4::ScopedValue item(scope, (*args)[0]);
4652 if (!item->isNull()) {
4653 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4655 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4658 if (!(*itemObj) && !item->isNull()) {
4659 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4660 <<
"\" which is neither null nor an Item";
4661 v4->throwTypeError();
4667 if (args->length() == 2) {
4668 QV4::ScopedValue sv(scope, (*args)[1]);
4670 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4671 <<
"\" which is neither a point nor a rect";
4672 v4->throwTypeError();
4675 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4676 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4677 if (v.canConvert<QPointF>()) {
4678 const QPointF p = v.toPointF();
4681 }
else if (v.canConvert<QRectF>()) {
4682 const QRectF r = v.toRectF();
4689 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4690 <<
"\" which is neither a point nor a rect";
4691 v4->throwTypeError();
4695 QV4::ScopedValue vx(scope, (*args)[1]);
4696 QV4::ScopedValue vy(scope, (*args)[2]);
4698 if (!vx->isNumber() || !vy->isNumber()) {
4699 v4->throwTypeError();
4703 *x = vx->asDouble();
4704 *y = vy->asDouble();
4706 if (args->length() > 3) {
4707 QV4::ScopedValue vw(scope, (*args)[3]);
4708 QV4::ScopedValue vh(scope, (*args)[4]);
4709 if (!vw->isNumber() || !vh->isNumber()) {
4710 v4->throwTypeError();
4713 *w = vw->asDouble();
4714 *h = vh->asDouble();
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4741#if QT_DEPRECATED_SINCE(6
, 5
)
4743
4744
4745void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4747 QV4::ExecutionEngine *v4 = args->v4engine();
4748 QV4::Scope scope(v4);
4752 QQuickItem *itemObj;
4753 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4756 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4757 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4759 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4760 args->setReturnValue(rv.asReturnedValue());
4765
4766
4767QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4769 Q_D(
const QQuickItem);
4775 QTransform t = d->itemToWindowTransform();
4776 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4799#if QT_DEPRECATED_SINCE(6
, 5
)
4801
4802
4803void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4805 QV4::ExecutionEngine *v4 = args->v4engine();
4806 QV4::Scope scope(v4);
4810 QQuickItem *itemObj;
4811 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4814 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4815 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4817 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4818 args->setReturnValue(rv.asReturnedValue());
4821static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4823 QV4::ExecutionEngine *v4 = args->v4engine();
4824 if (args->length() != 1 && args->length() != 2) {
4825 v4->throwTypeError();
4829 QV4::Scope scope(v4);
4831 if (args->length() == 1) {
4832 QV4::ScopedValue sv(scope, (*args)[0]);
4834 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4835 <<
"\" which is not a point";
4836 v4->throwTypeError();
4839 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4840 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4841 if (v.canConvert<QPointF>()) {
4842 const QPointF p = v.toPointF();
4846 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4847 <<
"\" which is not a point";
4848 v4->throwTypeError();
4852 QV4::ScopedValue vx(scope, (*args)[0]);
4853 QV4::ScopedValue vy(scope, (*args)[1]);
4855 if (!vx->isNumber() || !vy->isNumber()) {
4856 v4->throwTypeError();
4860 *x = vx->asDouble();
4861 *y = vy->asDouble();
4868
4869
4870
4871
4872
4873
4874
4875
4877
4878
4879void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4881 QV4::ExecutionEngine *v4 = args->v4engine();
4882 QV4::Scope scope(v4);
4885 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4888 QVariant result = mapFromGlobal(QPointF(x, y));
4890 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4891 args->setReturnValue(rv.asReturnedValue());
4896
4897
4898
4899
4900
4901
4902
4903
4905#if QT_DEPRECATED_SINCE(6
, 5
)
4907
4908
4909void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4911 QV4::ExecutionEngine *v4 = args->v4engine();
4912 QV4::Scope scope(v4);
4915 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4918 QVariant result = mapToGlobal(QPointF(x, y));
4920 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4921 args->setReturnValue(rv.asReturnedValue());
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951void QQuickItem::forceActiveFocus()
4953 forceActiveFocus(Qt::OtherFocusReason);
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4981void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
4983 setFocus(
true, reason);
4984 QQuickItem *parent = parentItem();
4985 QQuickItem *scope =
nullptr;
4987 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
4988 parent->setFocus(
true, reason);
4992 parent = parent->parentItem();
4997
4998
4999
5000
5001
5002
5003
5004
5005
5007
5008
5009
5010
5011
5013QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5015 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5019
5020
5021
5022
5023
5024
5025
5027
5028
5029
5030
5031
5032QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5034 const QList<QQuickItem *> children = childItems();
5035 for (
int i = children.size()-1; i >= 0; --i) {
5036 QQuickItem *child = children.at(i);
5038 QPointF point = mapToItem(child, QPointF(x, y));
5039 if (child->isVisible() && child->contains(point))
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086void QQuickItem::dumpItemTree()
const
5088 Q_D(
const QQuickItem);
5092void QQuickItemPrivate::dumpItemTree(
int indent)
const
5094 Q_Q(
const QQuickItem);
5096 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5097 qDebug().nospace().noquote() << indentStr <<
5098#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5099 const_cast<QQuickItem *>(q);
5103 if (extra.isAllocated()) {
5104 for (
const auto handler : extra->pointerHandlers)
5105 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5107 for (
const QQuickItem *ch : childItems) {
5108 auto itemPriv = QQuickItemPrivate::get(ch);
5109 itemPriv->dumpItemTree(indent + 1);
5113QQmlListProperty<QObject> QQuickItemPrivate::resources()
5117 QQmlListProperty<QObject> result;
5118 result.object = q_func();
5119 result.append = QQuickItemPrivate::resources_append;
5120 result.count = QQuickItemPrivate::resources_count;
5121 result.at = QQuickItemPrivate::resources_at;
5122 result.clear = QQuickItemPrivate::resources_clear;
5123 result.removeLast = QQuickItemPrivate::resources_removeLast;
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5141
5142
5143
5144QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5148 QQmlListProperty<QQuickItem> result;
5149 result.object = q_func();
5150 result.append = QQuickItemPrivate::children_append;
5151 result.count = QQuickItemPrivate::children_count;
5152 result.at = QQuickItemPrivate::children_at;
5153 result.clear = QQuickItemPrivate::children_clear;
5154 result.removeLast = QQuickItemPrivate::children_removeLast;
5159
5160
5161
5162
5163
5165
5166
5167
5168QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5170 return QQmlListProperty<QQuickItem>(q_func(),
5172 QQuickItemPrivate::visibleChildren_count,
5173 QQuickItemPrivate::visibleChildren_at);
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5214
5215
5216
5217QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5219 return _states()->statesProperty();
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5251
5252
5253
5254QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5256 return _states()->transitionsProperty();
5259QString QQuickItemPrivate::state()
const
5264 return _stateGroup->state();
5267void QQuickItemPrivate::setState(
const QString &state)
5269 _states()->setState(state);
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294QString QQuickItem::state()
const
5296 Q_D(
const QQuickItem);
5300void QQuickItem::setState(
const QString &state)
5307
5308
5309
5310
5311
5313
5314
5315
5317
5318
5319QQmlListProperty<QQuickTransform> QQuickItem::transform()
5321 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5322 QQuickItemPrivate::transform_count,
5323 QQuickItemPrivate::transform_at,
5324 QQuickItemPrivate::transform_clear);
5328
5329
5330
5331
5332void QQuickItem::classBegin()
5335 d->componentComplete =
false;
5337 d->_stateGroup->classBegin();
5339 d->_anchors->classBegin();
5340#if QT_CONFIG(quick_shadereffect)
5341 if (d->extra.isAllocated() && d->extra->layer)
5342 d->extra->layer->classBegin();
5347
5348
5349
5350
5351void QQuickItem::componentComplete()
5354 d->componentComplete =
true;
5356 d->_stateGroup->componentComplete();
5358 d->_anchors->componentComplete();
5359 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5362 if (d->extra.isAllocated()) {
5363#if QT_CONFIG(quick_shadereffect)
5364 if (d->extra->layer)
5365 d->extra->layer->componentComplete();
5368 if (d->extra->keyHandler)
5369 d->extra->keyHandler->componentComplete();
5371 if (d->extra->contents)
5372 d->extra->contents->complete();
5375 if (d->window && d->dirtyAttributes) {
5376 d->addToDirtyList();
5377 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5380#if QT_CONFIG(accessibility)
5381 if (d->isAccessible && d->effectiveVisible) {
5382 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5383 QAccessible::updateAccessibility(&ev);
5388QQuickStateGroup *QQuickItemPrivate::_states()
5392 _stateGroup =
new QQuickStateGroup;
5393 if (!componentComplete)
5394 _stateGroup->classBegin();
5395 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5396 q, QQuickItem, SIGNAL(stateChanged(QString)));
5402QPointF QQuickItemPrivate::computeTransformOrigin()
const
5406 case QQuickItem::TopLeft:
5407 return QPointF(0, 0);
5408 case QQuickItem::Top:
5409 return QPointF(width / 2., 0);
5410 case QQuickItem::TopRight:
5411 return QPointF(width, 0);
5412 case QQuickItem::Left:
5413 return QPointF(0, height / 2.);
5414 case QQuickItem::Center:
5415 return QPointF(width / 2., height / 2.);
5416 case QQuickItem::Right:
5417 return QPointF(width, height / 2.);
5418 case QQuickItem::BottomLeft:
5419 return QPointF(0, height);
5420 case QQuickItem::Bottom:
5421 return QPointF(width / 2., height);
5422 case QQuickItem::BottomRight:
5423 return QPointF(width, height);
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5445 bool childWantsIt =
false;
5446 if (subtreeTransformChangedEnabled) {
5449 const auto children = paintOrderChildItems();
5450 for (QQuickItem *child : children)
5451 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5454#if QT_CONFIG(quick_shadereffect)
5455 if (q == transformedItem) {
5456 if (extra.isAllocated() && extra->layer)
5457 extra->layer->updateMatrix();
5460 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5461 const bool ret = childWantsIt || thisWantsIt;
5462 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5463 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5464 subtreeTransformChangedEnabled =
false;
5468 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5469 dirty(QQuickItemPrivate::Clip);
5471 itemChange(QQuickItem::ItemTransformHasChanged,
true);
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5493 const QPointF &startPos,
5494 const QVector2D &activeTranslation,
5497 qreal startRotation,
5498 qreal activeRotation)
5501 QVector3D xformOrigin(q->transformOriginPoint());
5502 QMatrix4x4 startMatrix;
5503 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5504 startMatrix.translate(xformOrigin);
5505 startMatrix.scale(
float(startScale));
5506 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5507 startMatrix.translate(-xformOrigin);
5509 const QVector3D centroidParentVector(centroidParentPos);
5511 mat.translate(centroidParentVector);
5512 mat.rotate(
float(activeRotation), 0, 0, 1);
5513 mat.scale(
float(activeScale));
5514 mat.translate(-centroidParentVector);
5515 mat.translate(QVector3D(activeTranslation));
5517 mat = mat * startMatrix;
5519 QPointF xformOriginPoint = q->transformOriginPoint();
5520 QPointF pos = mat.map(xformOriginPoint);
5521 pos -= xformOriginPoint;
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5551 if (maybeHasSubsceneDeliveryAgent) {
5552 QQuickItemPrivate *p =
this;
5554 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5559 maybeHasSubsceneDeliveryAgent =
false;
5562 if (p->extra.isAllocated()) {
5563 if (
auto da = p->extra->subsceneDeliveryAgent)
5566 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5570 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5573 return QQuickWindowPrivate::get(window)->deliveryAgent;
5577QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5579 auto da = deliveryAgent();
5580 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5584
5585
5586
5587
5588
5589
5590
5591QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5597 maybeHasSubsceneDeliveryAgent =
true;
5598 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5599 return extra->subsceneDeliveryAgent;
5600 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5601 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5604 q->setFlag(QQuickItem::ItemIsFocusScope);
5605 return extra->subsceneDeliveryAgent;
5608bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5610 if (!extra.isAllocated() || !extra->keyHandler)
5616 if (e->type() == QEvent::KeyPress)
5617 extra->keyHandler->keyPressed(e, post);
5619 extra->keyHandler->keyReleased(e, post);
5621 return e->isAccepted();
5624void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5627 const auto eventType = event->type();
5628 const bool focusAccepted = setFocusIfNeeded(eventType);
5630 switch (eventType) {
5631 case QEvent::MouseButtonPress:
5632 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5634 case QEvent::MouseButtonRelease:
5635 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5637 case QEvent::MouseButtonDblClick:
5638 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5640#if QT_CONFIG(wheelevent)
5642 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5645 case QEvent::TouchBegin:
5646 case QEvent::TouchUpdate:
5647 case QEvent::TouchEnd:
5648 case QEvent::TouchCancel:
5649 q->touchEvent(
static_cast<QTouchEvent *>(event));
5659void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5663 Q_ASSERT(e->isAccepted());
5664 if (filterKeyEvent(e,
false))
5669 if (e->type() == QEvent::KeyPress)
5670 q->keyPressEvent(e);
5672 q->keyReleaseEvent(e);
5674 if (e->isAccepted())
5677 if (filterKeyEvent(e,
true) || !q->window())
5681 if (e->type() == QEvent::KeyPress &&
5682 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5684 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5685 if (e->key() == Qt::Key_Backtab
5686 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5687 res = QQuickItemPrivate::focusNextPrev(q,
false);
5688 else if (e->key() == Qt::Key_Tab)
5689 res = QQuickItemPrivate::focusNextPrev(q,
true);
5691 e->setAccepted(
true);
5697void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5701 Q_ASSERT(e->isAccepted());
5702 if (extra.isAllocated() && extra->keyHandler) {
5703 extra->keyHandler->inputMethodEvent(e,
false);
5705 if (e->isAccepted())
5711 q->inputMethodEvent(e);
5713 if (e->isAccepted())
5716 if (extra.isAllocated() && extra->keyHandler) {
5719 extra->keyHandler->inputMethodEvent(e,
true);
5724void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5726 if (extra.isAllocated() && extra->keyHandler)
5727 extra->keyHandler->shortcutOverrideEvent(event);
5732bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5734 if (!hasPointerHandlers())
5736 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5737 if (handler->wantsEventPoint(event, point))
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5755 bool delivered =
false;
5756 if (extra.isAllocated()) {
5757 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5758 bool avoidThisHandler =
false;
5759 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5760 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5761 avoidThisHandler =
true;
5762 }
else if (avoidGrabbers) {
5763 for (
auto &p : event->points()) {
5764 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5765 avoidThisHandler =
true;
5770 if (!avoidThisHandler &&
5771 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5772 handler->handlePointerEvent(event);
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5795 if (change == ItemSceneChange)
5796 emit windowChanged(value.window);
5801
5802
5803
5804void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5806 if (hasActiveFocus())
5807 QGuiApplication::inputMethod()->update(queries);
5812
5813
5814
5815QRectF QQuickItem::boundingRect()
const
5817 Q_D(
const QQuickItem);
5818 return QRectF(0, 0, d->width, d->height);
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842QRectF QQuickItem::clipRect()
const
5844 Q_D(
const QQuickItem);
5845 QRectF ret(0, 0, d->width, d->height);
5846 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5847 if (QQuickItem *viewport = viewportItem()) {
5850 if (viewport ==
this)
5852 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5853 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5854 return mappedViewportRect.intersected(ret);
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871QQuickItem *QQuickItem::viewportItem()
const
5873 if (flags().testFlag(ItemObservesViewport)) {
5874 QQuickItem *par = parentItem();
5876 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
5878 par = par->parentItem();
5881 return (window() ? window()->contentItem() :
nullptr);
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5906
5907
5908
5909
5910
5911
5912
5913
5914QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
5916 Q_D(
const QQuickItem);
5920void QQuickItem::setTransformOrigin(TransformOrigin origin)
5923 if (origin == d->origin())
5926 d->extra.value().origin = origin;
5927 d->dirty(QQuickItemPrivate::TransformOrigin);
5929 emit transformOriginChanged(d->origin());
5933
5934
5935
5937
5938
5939QPointF QQuickItem::transformOriginPoint()
const
5941 Q_D(
const QQuickItem);
5942 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
5943 return d->extra->userTransformOriginPoint;
5944 return d->computeTransformOrigin();
5948
5949
5950void QQuickItem::setTransformOriginPoint(
const QPointF &point)
5953 if (d->extra.value().userTransformOriginPoint == point)
5956 d->extra->userTransformOriginPoint = point;
5957 d->dirty(QQuickItemPrivate::TransformOrigin);
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114qreal QQuickItem::z()
const
6116 Q_D(
const QQuickItem);
6120void QQuickItem::setZ(qreal v)
6126 d->extra.value().z = v;
6128 d->dirty(QQuickItemPrivate::ZValue);
6129 if (d->parentItem) {
6130 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6131 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6136#if QT_CONFIG(quick_shadereffect)
6137 if (d->extra.isAllocated() && d->extra->layer)
6138 d->extra->layer->updateZ();
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
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
6194qreal QQuickItem::rotation()
const
6196 Q_D(
const QQuickItem);
6197 return d->rotation();
6200void QQuickItem::setRotation(qreal r)
6203 if (d->rotation() == r)
6206 d->extra.value().rotation = r;
6208 d->dirty(QQuickItemPrivate::BasicTransform);
6210 d->itemChange(ItemRotationHasChanged, r);
6212 emit rotationChanged();
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
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294qreal QQuickItem::scale()
const
6296 Q_D(
const QQuickItem);
6300void QQuickItem::setScale(qreal s)
6303 if (d->scale() == s)
6306 d->extra.value().scale = s;
6308 d->dirty(QQuickItemPrivate::BasicTransform);
6310 d->itemChange(ItemScaleHasChanged, s);
6312 emit scaleChanged();
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425qreal QQuickItem::opacity()
const
6427 Q_D(
const QQuickItem);
6428 return d->opacity();
6431void QQuickItem::setOpacity(qreal newOpacity)
6434 qreal o = qBound<qreal>(0, newOpacity, 1);
6435 if (d->opacity() == o)
6438 d->extra.value().opacity = o;
6440 d->dirty(QQuickItemPrivate::OpacityValue);
6442 d->itemChange(ItemOpacityHasChanged, o);
6444 emit opacityChanged();
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
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
6511bool QQuickItem::isVisible()
const
6513 Q_D(
const QQuickItem);
6514 return d->effectiveVisible;
6517void QQuickItemPrivate::setVisible(
bool visible)
6519 if (visible == explicitVisible)
6522 explicitVisible = visible;
6524 dirty(QQuickItemPrivate::Visible);
6526 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6527 if (childVisibilityChanged && parentItem)
6528 emit parentItem->visibleChildrenChanged();
6531void QQuickItem::setVisible(
bool v)
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578bool QQuickItem::isEnabled()
const
6580 Q_D(
const QQuickItem);
6581 return d->effectiveEnable;
6584void QQuickItem::setEnabled(
bool e)
6587 if (e == d->explicitEnable)
6590 d->explicitEnable = e;
6592 QQuickItem *scope = parentItem();
6593 while (scope && !scope->isFocusScope())
6594 scope = scope->parentItem();
6596 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6599bool QQuickItemPrivate::calcEffectiveVisible()
const
6602 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6605bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6609 if (newEffectiveVisible && !explicitVisible) {
6614 if (newEffectiveVisible == effectiveVisible) {
6619 effectiveVisible = newEffectiveVisible;
6622 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6624 if (
auto agent = deliveryAgentPrivate())
6625 agent->removeGrabber(q,
true,
true,
true);
6628 bool childVisibilityChanged =
false;
6629 for (
int ii = 0; ii < childItems.size(); ++ii)
6630 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6632 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6633#if QT_CONFIG(accessibility)
6635 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6636 QAccessible::updateAccessibility(&ev);
6639 if (!inDestructor) {
6640 emit q->visibleChanged();
6641 if (childVisibilityChanged)
6642 emit q->visibleChildrenChanged();
6648bool QQuickItemPrivate::calcEffectiveEnable()
const
6653 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6656void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6660 if (newEffectiveEnable && !explicitEnable) {
6665 if (newEffectiveEnable == effectiveEnable) {
6670 effectiveEnable = newEffectiveEnable;
6672 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6674 da->removeGrabber(q,
true,
true,
true);
6675 if (scope && !effectiveEnable && activeFocus) {
6676 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6677 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6678 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6682 for (
int ii = 0; ii < childItems.size(); ++ii) {
6683 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6684 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6687 if (scope && effectiveEnable && focus && da) {
6688 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6689 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6690 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6693 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6694#if QT_CONFIG(accessibility)
6696 QAccessible::State changedState;
6697 changedState.disabled =
true;
6698 changedState.focusable =
true;
6699 QAccessibleStateChangeEvent ev(q, changedState);
6700 QAccessible::updateAccessibility(&ev);
6703 emit q->enabledChanged();
6706bool QQuickItemPrivate::isTransparentForPositioner()
const
6708 return extra.isAllocated() && extra.value().transparentForPositioner;
6711void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6713 extra.value().transparentForPositioner = transparent;
6717QString QQuickItemPrivate::dirtyToString()
const
6719#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6721 rv.append(QLatin1Char('|'));
6722 rv.append(QLatin1String(#value)); \
6723}
6750void QQuickItemPrivate::dirty(DirtyType type)
6753 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6754 dirtyAttributes |= type;
6755 if (window && componentComplete) {
6757 QQuickWindowPrivate::get(window)->dirtyItem(q);
6760 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6761 transformChanged(q);
6764void QQuickItemPrivate::addToDirtyList()
6769 if (!prevDirtyItem) {
6770 Q_ASSERT(!nextDirtyItem);
6772 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
6773 nextDirtyItem = p->dirtyItemList;
6774 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
6775 prevDirtyItem = &p->dirtyItemList;
6776 p->dirtyItemList = q;
6779 Q_ASSERT(prevDirtyItem);
6782void QQuickItemPrivate::removeFromDirtyList()
6784 if (prevDirtyItem) {
6785 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
6786 *prevDirtyItem = nextDirtyItem;
6787 prevDirtyItem =
nullptr;
6788 nextDirtyItem =
nullptr;
6790 Q_ASSERT(!prevDirtyItem);
6791 Q_ASSERT(!nextDirtyItem);
6794void QQuickItemPrivate::refFromEffectItem(
bool hide)
6796 ++extra.value().effectRefCount;
6797 if (extra->effectRefCount == 1) {
6798 dirty(EffectReference);
6800 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6803 if (++extra->hideRefCount == 1)
6804 dirty(HideReference);
6806 recursiveRefFromEffectItem(1);
6809void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
6814 extra.value().recursiveEffectRefCount += refs;
6815 for (
int ii = 0; ii < childItems.size(); ++ii) {
6816 QQuickItem *child = childItems.at(ii);
6817 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
6821 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
6825void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
6827 Q_ASSERT(extra->effectRefCount);
6828 --extra->effectRefCount;
6829 if (extra->effectRefCount == 0) {
6830 dirty(EffectReference);
6832 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6835 if (--extra->hideRefCount == 0)
6836 dirty(HideReference);
6838 recursiveRefFromEffectItem(-1);
6841void QQuickItemPrivate::setCulled(
bool cull)
6847 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
6848 dirty(HideReference);
6851void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
6855 case QQuickItem::ItemChildAddedChange: {
6856 q->itemChange(change, data);
6862 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
6863 if (!subtreeTransformChangedEnabled) {
6864 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
6865 subtreeTransformChangedEnabled =
true;
6867 enableSubtreeChangeNotificationsForParentHierachy();
6869 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
6872 case QQuickItem::ItemChildRemovedChange: {
6873 q->itemChange(change, data);
6874 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
6877 case QQuickItem::ItemSceneChange:
6878 q->itemChange(change, data);
6880 case QQuickItem::ItemVisibleHasChanged: {
6881 q->itemChange(change, data);
6882 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
6885 case QQuickItem::ItemEnabledHasChanged: {
6886 q->itemChange(change, data);
6887 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
6890 case QQuickItem::ItemParentHasChanged: {
6891 q->itemChange(change, data);
6892 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
6895 case QQuickItem::ItemOpacityHasChanged: {
6896 q->itemChange(change, data);
6897 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
6900 case QQuickItem::ItemActiveFocusHasChanged:
6901 q->itemChange(change, data);
6903 case QQuickItem::ItemRotationHasChanged: {
6904 q->itemChange(change, data);
6905 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
6908 case QQuickItem::ItemScaleHasChanged: {
6909 q->itemChange(change, data);
6910 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
6913 case QQuickItem::ItemTransformHasChanged: {
6914 q->itemChange(change, data);
6915 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q);
6918 case QQuickItem::ItemAntialiasingHasChanged:
6920 case QQuickItem::ItemDevicePixelRatioHasChanged:
6921 q->itemChange(change, data);
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949bool QQuickItem::smooth()
const
6951 Q_D(
const QQuickItem);
6954void QQuickItem::setSmooth(
bool smooth)
6957 if (d->smooth == smooth)
6961 d->dirty(QQuickItemPrivate::Smooth);
6963 emit smoothChanged(smooth);
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7005bool QQuickItem::activeFocusOnTab()
const
7007 Q_D(
const QQuickItem);
7008 return d->activeFocusOnTab;
7010void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7013 if (d->activeFocusOnTab == activeFocusOnTab)
7017 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7018 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7023 d->activeFocusOnTab = activeFocusOnTab;
7025 emit activeFocusOnTabChanged(activeFocusOnTab);
7029
7030
7031
7032
7033
7034
7035
7036
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047bool QQuickItem::antialiasing()
const
7049 Q_D(
const QQuickItem);
7050 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7053void QQuickItem::setAntialiasing(
bool aa)
7057 if (!d->antialiasingValid) {
7058 d->antialiasingValid =
true;
7059 d->antialiasing = d->implicitAntialiasing;
7062 if (aa == d->antialiasing)
7065 d->antialiasing = aa;
7066 d->dirty(QQuickItemPrivate::Antialiasing);
7068 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7070 emit antialiasingChanged(antialiasing());
7073void QQuickItem::resetAntialiasing()
7076 if (!d->antialiasingValid)
7079 d->antialiasingValid =
false;
7081 if (d->implicitAntialiasing != d->antialiasing)
7082 emit antialiasingChanged(antialiasing());
7085void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7088 bool prev = q->antialiasing();
7089 implicitAntialiasing = antialiasing;
7090 if (componentComplete && (q->antialiasing() != prev))
7091 emit q->antialiasingChanged(q->antialiasing());
7095
7096
7097
7098
7099QQuickItem::Flags QQuickItem::flags()
const
7101 Q_D(
const QQuickItem);
7102 return (QQuickItem::Flags)d->flags;
7106
7107
7108
7109
7110
7111
7112
7113void QQuickItem::setFlag(Flag flag,
bool enabled)
7117 setFlags((Flags)(d->flags | (quint32)flag));
7119 setFlags((Flags)(d->flags & ~(quint32)flag));
7123 if (enabled && flag == ItemObservesViewport)
7124 d->enableSubtreeChangeNotificationsForParentHierachy();
7127void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7131 QQuickItem *par = q->parentItem();
7133 auto parPriv = QQuickItemPrivate::get(par);
7134 if (!parPriv->subtreeTransformChangedEnabled)
7135 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7136 parPriv->subtreeTransformChangedEnabled =
true;
7137 par = par->parentItem();
7142
7143
7144
7145
7146void QQuickItem::setFlags(Flags flags)
7150 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7151 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7152 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7153 flags &= ~ItemIsFocusScope;
7154 }
else if (d->flags & ItemIsFocusScope) {
7155 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7156 flags |= ItemIsFocusScope;
7160 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7161 d->dirty(QQuickItemPrivate::Clip);
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7182
7183
7184
7185
7187
7188
7189
7190
7191qreal QQuickItem::x()
const
7193 Q_D(
const QQuickItem);
7197qreal QQuickItem::y()
const
7199 Q_D(
const QQuickItem);
7204
7205
7206QPointF QQuickItem::position()
const
7208 Q_D(
const QQuickItem);
7209 return QPointF(d->x, d->y);
7212void QQuickItem::setX(qreal v)
7216
7217
7218
7219
7220
7221
7222
7223
7224 d->x.removeBindingUnlessInWrapper();
7228 const qreal oldx = d->x.valueBypassingBindings();
7232 d->x.setValueBypassingBindings(v);
7234 d->dirty(QQuickItemPrivate::Position);
7236 const qreal y = d->y.valueBypassingBindings();
7237 const qreal w = d->width.valueBypassingBindings();
7238 const qreal h = d->height.valueBypassingBindings();
7239 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7242void QQuickItem::setY(qreal v)
7245 d->y.removeBindingUnlessInWrapper();
7249 const qreal oldy = d->y.valueBypassingBindings();
7253 d->y.setValueBypassingBindings(v);
7255 d->dirty(QQuickItemPrivate::Position);
7259 const qreal x = d->x.valueBypassingBindings();
7260 const qreal w = d->width.valueBypassingBindings();
7261 const qreal h = d->height.valueBypassingBindings();
7262 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7266
7267
7268void QQuickItem::setPosition(
const QPointF &pos)
7272 const qreal oldx = d->x.valueBypassingBindings();
7273 const qreal oldy = d->y.valueBypassingBindings();
7275 if (QPointF(oldx, oldy) == pos)
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7291 d->x.setValueBypassingBindings(pos.x());
7292 d->y.setValueBypassingBindings(pos.y());
7294 d->dirty(QQuickItemPrivate::Position);
7296 const qreal w = d->width.valueBypassingBindings();
7297 const qreal h = d->height.valueBypassingBindings();
7298 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7302
7303
7304QBindable<qreal> QQuickItem::bindableX()
7306 return QBindable<qreal>(&d_func()->x);
7309QBindable<qreal> QQuickItem::bindableY()
7311 return QBindable<qreal>(&d_func()->y);
7315
7316
7317
7318
7319qreal QQuickItem::width()
const
7321 Q_D(
const QQuickItem);
7325void QQuickItem::setWidth(qreal w)
7328 d->width.removeBindingUnlessInWrapper();
7332 d->widthValidFlag =
true;
7333 const qreal oldWidth = d->width.valueBypassingBindings();
7337 d->width.setValueBypassingBindings(w);
7339 d->dirty(QQuickItemPrivate::Size);
7341 const qreal x = d->x.valueBypassingBindings();
7342 const qreal y = d->y.valueBypassingBindings();
7343 const qreal h = d->height.valueBypassingBindings();
7344 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7347void QQuickItem::resetWidth()
7350 d->width.takeBinding();
7351 d->widthValidFlag =
false;
7352 setImplicitWidth(implicitWidth());
7355void QQuickItemPrivate::implicitWidthChanged()
7358 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7359 emit q->implicitWidthChanged();
7362qreal QQuickItemPrivate::getImplicitWidth()
const
7364 return implicitWidth;
7367
7368
7369qreal QQuickItem::implicitWidth()
const
7371 Q_D(
const QQuickItem);
7372 return d->getImplicitWidth();
7375QBindable<qreal> QQuickItem::bindableWidth()
7377 return QBindable<qreal>(&d_func()->width);
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462void QQuickItem::setImplicitWidth(qreal w)
7465 bool changed = w != d->implicitWidth;
7466 d->implicitWidth = w;
7468 if (d->width.valueBypassingBindings() == w || widthValid()) {
7470 d->implicitWidthChanged();
7471 if (d->width.valueBypassingBindings() == w || widthValid())
7476 const qreal oldWidth = d->width.valueBypassingBindings();
7477 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7479 d->width.setValueBypassingBindings(w);
7481 d->dirty(QQuickItemPrivate::Size);
7483 const qreal x = d->x.valueBypassingBindings();
7484 const qreal y = d->y.valueBypassingBindings();
7485 const qreal width = w;
7486 const qreal height = d->height.valueBypassingBindings();
7487 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7490 d->implicitWidthChanged();
7494
7495
7496bool QQuickItem::widthValid()
const
7498 Q_D(
const QQuickItem);
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7516 return d->widthValid();
7520
7521
7522
7523
7524qreal QQuickItem::height()
const
7526 Q_D(
const QQuickItem);
7530void QQuickItem::setHeight(qreal h)
7536 d->height.removeBindingUnlessInWrapper();
7540 d->heightValidFlag =
true;
7541 const qreal oldHeight = d->height.valueBypassingBindings();
7545 d->height.setValueBypassingBindings(h);
7547 d->dirty(QQuickItemPrivate::Size);
7549 const qreal x = d->x.valueBypassingBindings();
7550 const qreal y = d->y.valueBypassingBindings();
7551 const qreal w = d->width.valueBypassingBindings();
7552 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7555void QQuickItem::resetHeight()
7561 d->height.takeBinding();
7562 d->heightValidFlag =
false;
7563 setImplicitHeight(implicitHeight());
7566void QQuickItemPrivate::implicitHeightChanged()
7569 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7570 emit q->implicitHeightChanged();
7573qreal QQuickItemPrivate::getImplicitHeight()
const
7575 return implicitHeight;
7578qreal QQuickItem::implicitHeight()
const
7580 Q_D(
const QQuickItem);
7581 return d->getImplicitHeight();
7584QBindable<qreal> QQuickItem::bindableHeight()
7586 return QBindable<qreal>(&d_func()->height);
7589void QQuickItem::setImplicitHeight(qreal h)
7592 bool changed = h != d->implicitHeight;
7593 d->implicitHeight = h;
7594 if (d->height.valueBypassingBindings() == h || heightValid()) {
7596 d->implicitHeightChanged();
7597 if (d->height.valueBypassingBindings() == h || heightValid())
7602 const qreal oldHeight = d->height.valueBypassingBindings();
7603 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7605 d->height.setValueBypassingBindings(h);
7607 d->dirty(QQuickItemPrivate::Size);
7609 const qreal x = d->x.valueBypassingBindings();
7610 const qreal y = d->y.valueBypassingBindings();
7611 const qreal width = d->width.valueBypassingBindings();
7612 const qreal height = d->height.valueBypassingBindings();
7613 geometryChange(QRectF(x, y, width, height),
7614 QRectF(x, y, width, oldHeight));
7617 d->implicitHeightChanged();
7621
7622
7623void QQuickItem::setImplicitSize(qreal w, qreal h)
7626 bool wChanged = w != d->implicitWidth;
7627 bool hChanged = h != d->implicitHeight;
7629 d->implicitWidth = w;
7630 d->implicitHeight = h;
7634 qreal width = d->width.valueBypassingBindings();
7635 qreal height = d->height.valueBypassingBindings();
7636 if (width == w || widthValid()) {
7638 d->implicitWidthChanged();
7639 wDone = width == w || widthValid();
7642 if (height == h || heightValid()) {
7644 d->implicitHeightChanged();
7645 hDone = height == h || heightValid();
7651 const qreal oldWidth = width;
7652 const qreal oldHeight = height;
7655 d->width.setValueBypassingBindings(w);
7659 d->height.setValueBypassingBindings(h);
7662 d->dirty(QQuickItemPrivate::Size);
7664 const qreal x = d->x.valueBypassingBindings();
7665 const qreal y = d->y.valueBypassingBindings();
7666 geometryChange(QRectF(x, y, width, height),
7667 QRectF(x, y, oldWidth, oldHeight));
7669 if (!wDone && wChanged)
7670 d->implicitWidthChanged();
7671 if (!hDone && hChanged)
7672 d->implicitHeightChanged();
7676
7677
7678bool QQuickItem::heightValid()
const
7680 Q_D(
const QQuickItem);
7681 return d->heightValid();
7685
7686
7687
7688
7689
7690
7692QSizeF QQuickItem::size()
const
7694 Q_D(
const QQuickItem);
7695 return QSizeF(d->width, d->height);
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709void QQuickItem::setSize(
const QSizeF &size)
7712 d->heightValidFlag =
true;
7713 d->widthValidFlag =
true;
7715 const qreal oldHeight = d->height.valueBypassingBindings();
7716 const qreal oldWidth = d->width.valueBypassingBindings();
7718 if (oldWidth == size.width() && oldHeight == size.height())
7721 d->height.setValueBypassingBindings(size.height());
7722 d->width.setValueBypassingBindings(size.width());
7724 d->dirty(QQuickItemPrivate::Size);
7726 const qreal x = d->x.valueBypassingBindings();
7727 const qreal y = d->y.valueBypassingBindings();
7728 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800bool QQuickItem::hasActiveFocus()
const
7802 Q_D(
const QQuickItem);
7803 return d->activeFocus;
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894bool QQuickItem::hasFocus()
const
7896 Q_D(
const QQuickItem);
7900void QQuickItem::setFocus(
bool focus)
7902 setFocus(focus, Qt::OtherFocusReason);
7905void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
7909 QQuickItem *scope = parentItem();
7910 while (scope && !scope->isFocusScope() && scope->parentItem())
7911 scope = scope->parentItem();
7913 if (d->focus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
7916 bool notifyListeners =
false;
7917 if (d->window || d->parentItem) {
7919 auto da = d->deliveryAgentPrivate();
7922 da->setFocusInScope(scope,
this, reason);
7924 da->clearFocusInScope(scope,
this, reason);
7928 QVarLengthArray<QQuickItem *, 20> changed;
7929 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
7930 if (oldSubFocusItem) {
7931 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
7932 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
7933 changed << oldSubFocusItem;
7934 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
7935 QQuickItemPrivate::get(scope)->focus =
false;
7938 d->updateSubFocusItem(scope, focus);
7942 notifyListeners =
true;
7943 emit focusChanged(focus);
7945 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
7948 QVarLengthArray<QQuickItem *, 20> changed;
7949 QQuickItem *oldSubFocusItem = d->subFocusItem;
7950 if (!isFocusScope() && oldSubFocusItem) {
7951 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
7952 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
7953 changed << oldSubFocusItem;
7958 notifyListeners =
true;
7959 emit focusChanged(focus);
7961 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
7963 if (notifyListeners)
7964 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
7968
7969
7970bool QQuickItem::isFocusScope()
const
7972 return flags() & ItemIsFocusScope;
7976
7977
7978
7979
7980
7981QQuickItem *QQuickItem::scopedFocusItem()
const
7983 Q_D(
const QQuickItem);
7984 if (!isFocusScope())
7987 return d->subFocusItem;
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8005
8006
8007
8008
8009
8010
8011Qt::FocusPolicy QQuickItem::focusPolicy()
const
8013 Q_D(
const QQuickItem);
8014 uint policy = d->focusPolicy;
8015 if (activeFocusOnTab())
8016 policy |= Qt::TabFocus;
8017 return static_cast<Qt::FocusPolicy>(policy);
8021
8022
8023
8024
8025void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8028 if (d->focusPolicy == policy)
8031 d->focusPolicy = policy;
8032 setActiveFocusOnTab(policy & Qt::TabFocus);
8033 emit focusPolicyChanged(policy);
8037
8038
8039
8040
8041
8042
8043
8044bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8046 if (!child || child ==
this)
8048 const QQuickItem *ancestor = child;
8049 while ((ancestor = ancestor->parentItem())) {
8050 if (ancestor ==
this)
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8069 Q_D(
const QQuickItem);
8070 return d->acceptedMouseButtons();
8074
8075
8076
8077
8078
8079
8080
8081
8082void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8085 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8087 buttons &= ~Qt::LeftButton;
8088 if (buttons || d->extra.isAllocated()) {
8089 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8090 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105bool QQuickItem::filtersChildMouseEvents()
const
8107 Q_D(
const QQuickItem);
8108 return d->filtersChildMouseEvents;
8112
8113
8114
8115
8116
8117
8118
8119
8120void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8123 d->filtersChildMouseEvents = filter;
8127
8128
8129bool QQuickItem::isUnderMouse()
const
8131 Q_D(
const QQuickItem);
8138 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8141 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8142 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8146
8147
8148
8149
8150
8151
8152
8153bool QQuickItem::acceptHoverEvents()
const
8155 Q_D(
const QQuickItem);
8156 return d->hoverEnabled;
8160
8161
8162
8163
8164
8165void QQuickItem::setAcceptHoverEvents(
bool enabled)
8168 d->hoverEnabled = enabled;
8169 d->setHasHoverInChild(enabled);
8173 d->dirty(QQuickItemPrivate::Content);
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186bool QQuickItem::acceptTouchEvents()
const
8188 Q_D(
const QQuickItem);
8189 return d->touchEnabled;
8193
8194
8195
8196
8197
8198
8199
8200void QQuickItem::setAcceptTouchEvents(
bool enabled)
8203 d->touchEnabled = enabled;
8206void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8208#if QT_CONFIG(cursor)
8213 if (!hc && subtreeCursorEnabled) {
8216 for (QQuickItem *otherChild : std::as_const(childItems)) {
8217 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8218 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8223 subtreeCursorEnabled = hc;
8224 QQuickItem *parent = q->parentItem();
8226 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8227 parentPrivate->setHasCursorInChild(hc);
8234void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8240 if (!hasHover && subtreeHoverEnabled) {
8243 if (hasEnabledHoverHandlers())
8246 for (QQuickItem *otherChild : std::as_const(childItems)) {
8247 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8248 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8250 if (otherChildPrivate->hasEnabledHoverHandlers())
8255 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8256 subtreeHoverEnabled = hasHover;
8257 QQuickItem *parent = q->parentItem();
8259 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8260 parentPrivate->setHasHoverInChild(hasHover);
8264#if QT_CONFIG(cursor)
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8280QCursor QQuickItem::cursor()
const
8282 Q_D(
const QQuickItem);
8283 return d->extra.isAllocated()
8289
8290
8291
8292
8294void QQuickItem::setCursor(
const QCursor &cursor)
8298 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8299 qCDebug(lcHoverTrace) << oldShape <<
"->" << cursor.shape();
8301 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8302 d->extra.value().cursor = cursor;
8304 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8305 QWindow *window = renderWindow ? renderWindow : d->window;
8306 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8307 window->setCursor(cursor);
8311 QPointF updateCursorPos;
8312 if (!d->hasCursor) {
8313 d->hasCursor =
true;
8315 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8316 QWindow *window = renderWindow ? renderWindow : d->window;
8317 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8318 if (contains(mapFromScene(pos)))
8319 updateCursorPos = pos;
8322 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8323 if (!updateCursorPos.isNull())
8324 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8328
8329
8330
8331
8333void QQuickItem::unsetCursor()
8336 qCDebug(lcHoverTrace) <<
"clearing cursor";
8339 d->hasCursor =
false;
8340 d->setHasCursorInChild(d->hasCursorHandler);
8341 if (d->extra.isAllocated())
8342 d->extra->cursor = QCursor();
8345 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8346 if (windowPrivate->cursorItem ==
this) {
8347 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8348 windowPrivate->updateCursor(pos);
8354
8355
8356
8357
8358
8359
8360QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8362 Q_Q(
const QQuickItem);
8365 bool hoverCursorSet =
false;
8366 QCursor hoverCursor;
8367 bool activeCursorSet =
false;
8368 QCursor activeCursor;
8369 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8370 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8371 hoverCursor = hoverHandler->cursorShape();
8372 }
else if (handler->active()) {
8373 activeCursorSet = handler->isCursorShapeExplicitlySet();
8374 activeCursor = handler->cursorShape();
8376 if (activeCursorSet)
8377 return activeCursor;
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8405 if (!hasPointerHandlers())
8407 QQuickPointerHandler* activeHandler =
nullptr;
8408 QQuickPointerHandler* mouseHandler =
nullptr;
8409 QQuickPointerHandler* nonMouseHandler =
nullptr;
8410 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8411 if (!h->isCursorShapeExplicitlySet())
8413 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8418 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8419 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8420 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8422 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8423 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8424 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8426 mouseHandler = hoverHandler;
8429 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8430 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8431 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8433 nonMouseHandler = hoverHandler;
8436 if (!hoverHandler && h->active())
8439 if (activeHandler) {
8440 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8441 return activeHandler;
8447 if (nonMouseHandler) {
8449 const bool beforeTimeout =
8450 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8451 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8452 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8453 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8454 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8455 <<
"choosing cursor according to" << winner << winner->cursorShape();
8458 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8459 return nonMouseHandler;
8462 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8463 return mouseHandler;
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482void QQuickItem::grabMouse()
8487 auto da = d->deliveryAgentPrivate();
8489 auto eventInDelivery = da->eventInDelivery();
8490 if (!eventInDelivery) {
8491 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8494 auto epd = da->mousePointData();
8495 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509void QQuickItem::ungrabMouse()
8514 auto da = d->deliveryAgentPrivate();
8516 auto eventInDelivery = da->eventInDelivery();
8517 if (!eventInDelivery) {
8519 da->removeGrabber(
this);
8522 const auto &eventPoint = da->mousePointData()->eventPoint;
8523 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8524 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8528
8529
8530
8531
8532bool QQuickItem::keepMouseGrab()
const
8534 Q_D(
const QQuickItem);
8535 return d->keepMouse;
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554void QQuickItem::setKeepMouseGrab(
bool keep)
8557 d->keepMouse = keep;
8561
8562
8563
8564
8565
8566
8567
8568
8569void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8572 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8573 if (Q_UNLIKELY(!event)) {
8574 qWarning() <<
"cannot grab: no event is currently being delivered";
8577 for (
auto pt : event->points()) {
8578 if (ids.contains(pt.id()))
8579 event->setExclusiveGrabber(pt,
this);
8584
8585
8586
8587void QQuickItem::ungrabTouchPoints()
8592 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8593 da->removeGrabber(
this,
false,
true);
8597
8598
8599
8600
8601
8602bool QQuickItem::keepTouchGrab()
const
8604 Q_D(
const QQuickItem);
8605 return d->keepTouch;
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625void QQuickItem::setKeepTouchGrab(
bool keep)
8628 d->keepTouch = keep;
8632
8633
8634
8635
8636
8637
8638
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650bool QQuickItem::contains(
const QPointF &point)
const
8652 Q_D(
const QQuickItem);
8653 if (d->extra.isAllocated() && d->extra->mask) {
8654 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8655 return quickMask->contains(point - quickMask->position());
8658 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8659 maskContains.invoke(d->extra->mask,
8660 Qt::DirectConnection,
8661 Q_RETURN_ARG(
bool, res),
8662 Q_ARG(QPointF, point));
8666 qreal x = point.x();
8667 qreal y = point.y();
8668 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734QObject *QQuickItem::containmentMask()
const
8736 Q_D(
const QQuickItem);
8737 if (!d->extra.isAllocated())
8739 return d->extra->mask.data();
8742void QQuickItem::setContainmentMask(QObject *mask)
8745 const bool extraDataExists = d->extra.isAllocated();
8747 if (mask ==
static_cast<QObject *>(
this))
8750 if (!extraDataExists && !mask)
8753 if (extraDataExists && d->extra->mask == mask)
8756 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8759 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8760 maskPrivate->registerAsContainmentMask(
this,
false);
8763 if (!extraDataExists)
8766 int methodIndex = mask->metaObject()->indexOfMethod(QByteArrayLiteral(
"contains(QPointF)"));
8767 if (methodIndex < 0) {
8768 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
8771 d->extra->maskContainsIndex = methodIndex;
8773 d->extra->mask = mask;
8774 quickMask = qobject_cast<QQuickItem *>(mask);
8776 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8777 maskPrivate->registerAsContainmentMask(
this,
true);
8779 emit containmentMaskChanged();
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
8796 QPointF p = mapToScene(point);
8798 const auto *itemWindow = item->window();
8799 const auto *thisWindow = window();
8800 if (thisWindow && itemWindow && itemWindow != thisWindow)
8801 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
8803 p = item->mapFromScene(p);
8809
8810
8811
8812
8813
8814
8815
8816
8817QPointF QQuickItem::mapToScene(
const QPointF &point)
const
8819 Q_D(
const QQuickItem);
8820 return d->itemToWindowTransform().map(point);
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
8842 Q_D(
const QQuickItem);
8844 if (Q_UNLIKELY(d->window ==
nullptr))
8845 return mapToScene(point);
8847 QPoint renderOffset;
8848 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
8849 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
8850 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
8867 Q_D(
const QQuickItem);
8868 QTransform t = d->itemToWindowTransform();
8870 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
8871 return t.mapRect(rect);
8875
8876
8877
8878
8879
8880
8881
8882
8883QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
8885 Q_D(
const QQuickItem);
8886 return d->itemToWindowTransform().mapRect(rect);
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
8905 p = item->mapToScene(point);
8906 const auto *itemWindow = item->window();
8907 const auto *thisWindow = window();
8908 if (thisWindow && itemWindow && itemWindow != thisWindow)
8909 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
8911 return mapFromScene(p);
8915
8916
8917
8918
8919
8920
8921
8922
8923QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
8925 Q_D(
const QQuickItem);
8926 return d->windowToItemTransform().map(point);
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
8954 Q_D(
const QQuickItem);
8957 if (Q_LIKELY(d->window)) {
8958 QPoint renderOffset;
8959 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
8960 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
8961 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
8966 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
8967 if (
auto sceneTransform = da->sceneTransform())
8968 scenePoint = sceneTransform->map(scenePoint);
8970 return mapFromScene(scenePoint);
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
8987 Q_D(
const QQuickItem);
8988 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
8989 t *= d->windowToItemTransform();
8990 return t.mapRect(rect);
8994
8995
8996
8997
8998
8999
9000
9001
9002QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9004 Q_D(
const QQuickItem);
9005 return d->windowToItemTransform().mapRect(rect);
9009
9010
9011
9014
9015
9016
9019
9020
9021
9024
9025
9026
9029
9030
9031
9034
9035
9036
9039
9040
9041
9044
9045
9046
9049
9050
9051
9054
9055
9056
9059
9060
9061bool QQuickItem::event(QEvent *ev)
9065 switch (ev->type()) {
9067 case QEvent::InputMethodQuery: {
9068 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9069 Qt::InputMethodQueries queries = query->queries();
9070 for (uint i = 0; i < 32; ++i) {
9071 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9073 QVariant v = inputMethodQuery(q);
9074 query->setValue(q, v);
9080 case QEvent::InputMethod:
9081 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9084 case QEvent::TouchBegin:
9085 case QEvent::TouchUpdate:
9086 case QEvent::TouchEnd:
9087 case QEvent::TouchCancel:
9088 case QEvent::MouseButtonPress:
9089 case QEvent::MouseButtonRelease:
9090 case QEvent::MouseButtonDblClick:
9091#if QT_CONFIG(wheelevent)
9094 d->deliverPointerEvent(ev);
9096 case QEvent::StyleAnimationUpdate:
9102 case QEvent::HoverEnter:
9103 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9105 case QEvent::HoverLeave:
9106 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9108 case QEvent::HoverMove:
9109 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9111 case QEvent::KeyPress:
9112 case QEvent::KeyRelease:
9113 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9115 case QEvent::ShortcutOverride:
9116 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9118 case QEvent::FocusIn:
9119 focusInEvent(
static_cast<QFocusEvent*>(ev));
9121 case QEvent::FocusOut:
9122 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9124 case QEvent::MouseMove:
9125 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9127#if QT_CONFIG(quick_draganddrop)
9128 case QEvent::DragEnter:
9129 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9131 case QEvent::DragLeave:
9132 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9134 case QEvent::DragMove:
9135 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9138 dropEvent(
static_cast<QDropEvent*>(ev));
9141#if QT_CONFIG(gestures)
9142 case QEvent::NativeGesture:
9146 case QEvent::LanguageChange:
9147 case QEvent::LocaleChange:
9148 for (QQuickItem *item : std::as_const(d->childItems))
9149 QCoreApplication::sendEvent(item, ev);
9151 case QEvent::WindowActivate:
9152 case QEvent::WindowDeactivate:
9153 if (d->providesPalette())
9154 d->setCurrentColorGroup();
9155 for (QQuickItem *item : std::as_const(d->childItems))
9156 QCoreApplication::sendEvent(item, ev);
9158 case QEvent::ApplicationPaletteChange:
9159 for (QQuickItem *item : std::as_const(d->childItems))
9160 QCoreApplication::sendEvent(item, ev);
9163 return QObject::event(ev);
9169#ifndef QT_NO_DEBUG_STREAM
9171#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9176 QDebugStateSaver saver(debug);
9179 debug <<
"QQuickItem(nullptr)";
9183 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9185 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9189 if (item->isComponentComplete()) {
9190 if (QQmlContext *context = qmlContext(item)) {
9191 const auto objectId = context->nameForObject(item);
9192 if (!objectId.isEmpty())
9193 debug <<
", id=" << objectId;
9196 if (!item->objectName().isEmpty())
9197 debug <<
", name=" << item->objectName();
9198 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9200 QtDebugUtils::formatQRect(debug, rect);
9201 if (
const qreal z = item->z())
9202 debug <<
", z=" << z;
9203 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9204 debug <<
" \U0001f5bc";
9205 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9213
9214
9215
9216
9217
9218
9219
9221bool QQuickItem::isTextureProvider()
const
9223#if QT_CONFIG(quick_shadereffect)
9224 Q_D(
const QQuickItem);
9225 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9226 d->extra->layer->effectSource()->isTextureProvider() :
false;
9233
9234
9235
9236
9237
9238
9239
9241QSGTextureProvider *QQuickItem::textureProvider()
const
9243#if QT_CONFIG(quick_shadereffect)
9244 Q_D(
const QQuickItem);
9245 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9246 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9294#if QT_CONFIG(quick_shadereffect)
9296
9297
9298
9299QQuickItemLayer *QQuickItemPrivate::layer()
const
9301 if (!extra.isAllocated() || !extra->layer) {
9302 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9303 if (!componentComplete)
9304 extra->layer->classBegin();
9306 return extra->layer;
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9330 QList<QEventPoint> touchPoints;
9331 QEventPoint::States eventStates;
9333 bool anyPressOrReleaseInside =
false;
9334 bool anyGrabber =
false;
9335 for (
auto &p : event->points()) {
9340 auto pointGrabber = event->exclusiveGrabber(p);
9341 bool isGrabber = (pointGrabber == q);
9342 if (!isGrabber && pointGrabber && isFiltering) {
9343 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9344 if (handlerGrabber && handlerGrabber->parentItem() == q)
9351 const auto localPos = q->mapFromScene(p.scenePosition());
9352 bool isInside = q->contains(localPos);
9353 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9355 if (isFiltering && !pointGrabber) {
9356 const auto pg = event->passiveGrabbers(p);
9357 if (!pg.isEmpty()) {
9361 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9363 pointGrabber = handler->parentItem();
9368 bool grabberIsChild =
false;
9369 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9370 while (isFiltering && parent) {
9372 grabberIsChild =
true;
9375 parent = parent->parentItem();
9378 bool filterRelevant = isFiltering && grabberIsChild;
9379 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9381 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9382 anyPressOrReleaseInside =
true;
9383 QEventPoint pCopy(p);
9384 eventStates |= p.state();
9385 if (p.state() == QEventPoint::State::Released)
9386 QMutableEventPoint::detach(pCopy);
9387 QMutableEventPoint::setPosition(pCopy, localPos);
9388 touchPoints.append(std::move(pCopy));
9393 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9394 *localized = QMutableTouchEvent(QEvent::None);
9399 QEvent::Type eventType = event->type();
9400 switch (eventStates) {
9401 case QEventPoint::State::Pressed:
9402 eventType = QEvent::TouchBegin;
9404 case QEventPoint::State::Released:
9405 eventType = QEvent::TouchEnd;
9408 eventType = QEvent::TouchUpdate;
9412 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9414 ret.setTimestamp(event->timestamp());
9419bool QQuickItemPrivate::hasPointerHandlers()
const
9421 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9424bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9426 if (!hasPointerHandlers())
9428 for (QQuickPointerHandler *h : extra->pointerHandlers)
9429 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9434void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9440 extra.value().acceptedMouseButtons = Qt::AllButtons;
9441 auto &handlers = extra.value().pointerHandlers;
9442 if (!handlers.contains(h))
9443 handlers.prepend(h);
9444 auto &res = extra.value().resourcesList;
9445 if (!res.contains(h)) {
9447 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9448 _q_resourceObjectDeleted(o);
9453void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9457 auto &handlers = extra.value().pointerHandlers;
9458 handlers.removeOne(h);
9459 auto &res = extra.value().resourcesList;
9461 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9462 if (handlers.isEmpty())
9463 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9466#if QT_CONFIG(quick_shadereffect)
9467QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9473 , m_componentComplete(
true)
9474 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9475 , m_format(QQuickShaderEffectSource::RGBA8)
9477 , m_effectComponent(
nullptr)
9479 , m_effectSource(
nullptr)
9480 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9485QQuickItemLayer::~QQuickItemLayer()
9487 delete m_effectSource;
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505void QQuickItemLayer::setEnabled(
bool e)
9510 if (m_componentComplete) {
9517 emit enabledChanged(e);
9520void QQuickItemLayer::classBegin()
9522 Q_ASSERT(!m_effectSource);
9523 Q_ASSERT(!m_effect);
9524 m_componentComplete =
false;
9527void QQuickItemLayer::componentComplete()
9529 Q_ASSERT(!m_componentComplete);
9530 m_componentComplete =
true;
9535void QQuickItemLayer::activate()
9537 Q_ASSERT(!m_effectSource);
9538 m_effectSource =
new QQuickShaderEffectSource();
9539 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9541 QQuickItem *parentItem = m_item->parentItem();
9543 m_effectSource->setParentItem(parentItem);
9544 m_effectSource->stackAfter(m_item);
9547 m_effectSource->setSourceItem(m_item);
9548 m_effectSource->setHideSource(
true);
9549 m_effectSource->setSmooth(m_smooth);
9550 m_effectSource->setLive(m_live);
9551 m_effectSource->setTextureSize(m_size);
9552 m_effectSource->setSourceRect(m_sourceRect);
9553 m_effectSource->setMipmap(m_mipmap);
9554 m_effectSource->setWrapMode(m_wrapMode);
9555 m_effectSource->setFormat(m_format);
9556 m_effectSource->setTextureMirroring(m_textureMirroring);
9557 m_effectSource->setSamples(m_samples);
9559 if (m_effectComponent)
9562 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9569 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9570 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9573void QQuickItemLayer::deactivate()
9575 Q_ASSERT(m_effectSource);
9577 if (m_effectComponent)
9580 delete m_effectSource;
9581 m_effectSource =
nullptr;
9583 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9584 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9587void QQuickItemLayer::activateEffect()
9589 Q_ASSERT(m_effectSource);
9590 Q_ASSERT(m_effectComponent);
9591 Q_ASSERT(!m_effect);
9593 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9594 m_effect = qobject_cast<QQuickItem *>(created);
9596 qWarning(
"Item: layer.effect is not a QML Item.");
9597 m_effectComponent->completeCreate();
9601 QQuickItem *parentItem = m_item->parentItem();
9603 m_effect->setParentItem(parentItem);
9604 m_effect->stackAfter(m_effectSource);
9606 m_effect->setVisible(m_item->isVisible());
9607 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9608 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9609 m_effectComponent->completeCreate();
9612void QQuickItemLayer::deactivateEffect()
9614 Q_ASSERT(m_effectSource);
9615 Q_ASSERT(m_effectComponent);
9623
9624
9625
9626
9627
9628
9629
9630
9631
9633void QQuickItemLayer::setEffect(QQmlComponent *component)
9635 if (component == m_effectComponent)
9638 bool updateNeeded =
false;
9639 if (m_effectSource && m_effectComponent) {
9641 updateNeeded =
true;
9644 m_effectComponent = component;
9646 if (m_effectSource && m_effectComponent) {
9648 updateNeeded =
true;
9656 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9659 emit effectChanged(component);
9664
9665
9666
9667
9668
9669
9670
9671
9672
9674void QQuickItemLayer::setMipmap(
bool mipmap)
9676 if (mipmap == m_mipmap)
9681 m_effectSource->setMipmap(m_mipmap);
9683 emit mipmapChanged(mipmap);
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9704void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9711 m_effectSource->setFormat(m_format);
9713 emit formatChanged(m_format);
9718
9719
9720
9721
9722
9723
9724
9725
9726
9728void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
9730 if (sourceRect == m_sourceRect)
9732 m_sourceRect = sourceRect;
9735 m_effectSource->setSourceRect(m_sourceRect);
9737 emit sourceRectChanged(sourceRect);
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9752void QQuickItemLayer::setSmooth(
bool s)
9759 m_effectSource->setSmooth(m_smooth);
9761 emit smoothChanged(s);
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9776void QQuickItemLayer::setLive(
bool live)
9783 m_effectSource->setLive(m_live);
9785 emit liveChanged(live);
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9801void QQuickItemLayer::setSize(
const QSize &size)
9808 m_effectSource->setTextureSize(size);
9810 emit sizeChanged(size);
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9831void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
9833 if (mode == m_wrapMode)
9838 m_effectSource->setWrapMode(m_wrapMode);
9840 emit wrapModeChanged(mode);
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9858void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
9860 if (mirroring == m_textureMirroring)
9862 m_textureMirroring = mirroring;
9865 m_effectSource->setTextureMirroring(m_textureMirroring);
9867 emit textureMirroringChanged(mirroring);
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9895void QQuickItemLayer::setSamples(
int count)
9897 if (m_samples == count)
9903 m_effectSource->setSamples(m_samples);
9905 emit samplesChanged(count);
9909
9910
9911
9912
9913
9914
9915
9916
9917
9919void QQuickItemLayer::setName(
const QByteArray &name) {
9923 m_effect->setProperty(m_name, QVariant());
9924 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
9927 emit nameChanged(name);
9930void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
9936void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
9941void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
9944 Q_ASSERT(item == m_item);
9945 Q_ASSERT(parent != m_effectSource);
9946 Q_ASSERT(parent ==
nullptr || parent != m_effect);
9948 m_effectSource->setParentItem(parent);
9950 m_effectSource->stackAfter(m_item);
9953 m_effect->setParentItem(parent);
9955 m_effect->stackAfter(m_effectSource);
9959void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
9961 m_effectSource->stackAfter(m_item);
9963 m_effect->stackAfter(m_effectSource);
9966void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
9968 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
9971 l->setVisible(m_item->isVisible());
9974void QQuickItemLayer::updateZ()
9976 if (!m_componentComplete || !m_enabled)
9978 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
9981 l->setZ(m_item->z());
9984void QQuickItemLayer::updateOpacity()
9986 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
9989 l->setOpacity(m_item->opacity());
9992void QQuickItemLayer::updateGeometry()
9994 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
9999 QRectF bounds = m_item->QQuickItem::boundingRect();
10000 l->setSize(bounds.size());
10001 l->setPosition(bounds.topLeft() + m_item->position());
10004void QQuickItemLayer::updateMatrix()
10008 if (!m_componentComplete || !m_enabled)
10010 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10013 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10014 l->setScale(m_item->scale());
10015 l->setRotation(m_item->rotation());
10016 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10017 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10018 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10019 ld->dirty(QQuickItemPrivate::Transform);
10023QQuickItemPrivate::ExtraData::ExtraData()
10024: z(0), scale(1), rotation(0), opacity(1),
10025 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10026 enterKeyAttached(
nullptr),
10027 keyHandler(
nullptr),
10028#if QT_CONFIG(quick_shadereffect)
10031 effectRefCount(0), hideRefCount(0),
10032 recursiveEffectRefCount(0),
10033 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10034 origin(QQuickItem::Center),
10035 transparentForPositioner(
false)
10040#if QT_CONFIG(accessibility)
10041QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10043 Q_Q(
const QQuickItem);
10044 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10045 auto role = QAccessible::NoRole;
10046 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10047 role = accessibleAttached->role();
10048 if (role == QAccessible::NoRole)
10049 role = accessibleRole();
10053QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10055 return QAccessible::NoRole;
10064 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10077 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10078 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10079 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10080 QV4::QObjectWrapper::markWrapper(child, markStack);
10082 QObjectWrapper::markObjects(that, markStack);
10085quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10087 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10092 QDebugStateSaver stateSaver(debug);
10093 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10098QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10099{
return mapFromItem(item, QPointF(x, y) ); }
10102QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10103{
return mapRectFromItem(item, rect); }
10106QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10107{
return mapFromItem(item, QRectF(x, y, width, height)); }
10110QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10111{
return mapToItem(item, QPointF(x, y)); }
10114QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10115{
return mapRectToItem(item, rect); }
10118QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10119{
return mapToItem(item, QRectF(x, y, width, height)); }
10122QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10123{
return mapToGlobal(QPointF(x, y)); }
10126QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10127{
return mapFromGlobal(QPointF(x, y)); }
10130QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10134#include <moc_qquickitem.cpp>
10136#include "moc_qquickitem_p.cpp"
QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
#define PRINT_LISTENERS()
QDebug operator<<(QDebug debug, const QQuickItem *item)
static bool itemZOrder_sort(QQuickItem *lhs, QQuickItem *rhs)
#define DIRTY_TO_STRING(value)
void debugFocusTree(QQuickItem *item, QQuickItem *scope=nullptr, int depth=1)
DEFINE_OBJECT_VTABLE(QQuickItemWrapper)
static void setActiveFocus(QQuickItem *item, Qt::FocusReason reason)
static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack)