9#include <QtQml/qjsengine.h>
16#include <QtQml/qqmlengine.h>
17#include <QtQml/qqmlcomponent.h>
18#include <QtQml/qqmlinfo.h>
19#include <QtGui/qpen.h>
20#include <QtGui/qguiapplication.h>
21#include <QtGui/qstylehints.h>
22#include <QtGui/private/qeventpoint_p.h>
23#include <QtGui/private/qguiapplication_p.h>
24#include <QtGui/private/qpointingdevice_p.h>
25#include <QtGui/qinputmethod.h>
26#include <QtCore/qcoreevent.h>
27#include <QtCore/private/qnumeric_p.h>
28#include <QtGui/qpa/qplatformtheme.h>
29#include <QtCore/qloggingcategory.h>
30#include <QtCore/private/qduplicatetracker_p.h>
32#include <private/qqmlglobal_p.h>
33#include <private/qqmlengine_p.h>
34#include <QtQuick/private/qquickstategroup_p.h>
35#include <private/qqmlopenmetaobject_p.h>
36#include <QtQuick/private/qquickstate_p.h>
37#include <private/qquickitem_p.h>
38#include <QtQuick/private/qquickaccessibleattached_p.h>
39#include <QtQuick/private/qquickhoverhandler_p.h>
40#include <QtQuick/private/qquickpointerhandler_p.h>
41#include <QtQuick/private/qquickpointerhandler_p_p.h>
43#include <private/qv4engine_p.h>
44#include <private/qv4object_p.h>
45#include <private/qv4qobjectwrapper_p.h>
46#include <private/qdebug_p.h>
47#include <private/qqmlvaluetypewrapper_p.h>
50# include <QtGui/qcursor.h>
53#if QT_CONFIG(accessibility)
54# include <private/qaccessiblecache_p.h>
57#include <QtCore/qpointer.h>
67Q_LOGGING_CATEGORY(lcVP,
"qt.quick.viewport")
68Q_STATIC_LOGGING_CATEGORY(lcChangeListeners,
"qt.quick.item.changelisteners")
71static const quint64 kCursorOverrideTimeout = 100;
73void debugFocusTree(QQuickItem *item, QQuickItem *scope =
nullptr,
int depth = 1)
75 if (lcFocus().isEnabled(QtDebugMsg)) {
77 << QByteArray(depth,
'\t').constData()
78 << (scope && QQuickItemPrivate::get(scope)->subFocusItem == item ?
'*' :
' ')
80 << item->hasActiveFocus()
81 << item->isFocusScope()
83 const auto childItems = item->childItems();
84 for (QQuickItem *child : childItems) {
87 item->isFocusScope() || !scope ? item : scope,
88 item->isFocusScope() || !scope ? depth + 1 : depth);
95 QQuickItemPrivate *d = QQuickItemPrivate::get(item);
96 if (d->subFocusItem && d->window && d->flags & QQuickItem::ItemIsFocusScope)
97 d->deliveryAgentPrivate()->clearFocusInScope(item, d->subFocusItem, reason);
98 item->forceActiveFocus(reason);
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125QQuickTransformPrivate::QQuickTransformPrivate()
129QQuickTransform::QQuickTransform(QObject *parent)
130: QObject(*(
new QQuickTransformPrivate), parent)
134QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent)
139QQuickTransform::~QQuickTransform()
141 Q_D(QQuickTransform);
142 for (
int ii = 0; ii < d->items.size(); ++ii) {
143 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
144 p->transforms.removeOne(
this);
145 p->dirty(QQuickItemPrivate::Transform);
149void QQuickTransform::update()
151 Q_D(QQuickTransform);
152 for (
int ii = 0; ii < d->items.size(); ++ii) {
153 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
154 p->dirty(QQuickItemPrivate::Transform);
158QQuickContents::QQuickContents(QQuickItem *item)
163QQuickContents::~QQuickContents()
166 QList<QQuickItem *> children = m_item->childItems();
167 for (
int i = 0; i < children.size(); ++i) {
168 QQuickItem *child = children.at(i);
169 QQuickItemPrivate::get(child)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
173bool QQuickContents::calcHeight(QQuickItem *changed)
175 qreal oldy = m_contents.y();
176 qreal oldheight = m_contents.height();
180 qreal bottom = oldy + oldheight;
181 qreal y = changed->y();
182 if (y + changed->height() > bottom)
183 bottom = y + changed->height();
186 m_contents.setY(top);
187 m_contents.setHeight(bottom - top);
189 qreal top = std::numeric_limits<qreal>::max();
190 qreal bottom = -std::numeric_limits<qreal>::max();
191 QList<QQuickItem *> children = m_item->childItems();
192 for (
int i = 0; i < children.size(); ++i) {
193 QQuickItem *child = children.at(i);
194 qreal y = child->y();
195 if (y + child->height() > bottom)
196 bottom = y + child->height();
200 if (!children.isEmpty())
201 m_contents.setY(top);
202 m_contents.setHeight(qMax(bottom - top, qreal(0.0)));
205 return (m_contents.height() != oldheight || m_contents.y() != oldy);
208bool QQuickContents::calcWidth(QQuickItem *changed)
210 qreal oldx = m_contents.x();
211 qreal oldwidth = m_contents.width();
215 qreal right = oldx + oldwidth;
216 qreal x = changed->x();
217 if (x + changed->width() > right)
218 right = x + changed->width();
221 m_contents.setX(left);
222 m_contents.setWidth(right - left);
224 qreal left = std::numeric_limits<qreal>::max();
225 qreal right = -std::numeric_limits<qreal>::max();
226 QList<QQuickItem *> children = m_item->childItems();
227 for (
int i = 0; i < children.size(); ++i) {
228 QQuickItem *child = children.at(i);
229 qreal x = child->x();
230 if (x + child->width() > right)
231 right = x + child->width();
235 if (!children.isEmpty())
236 m_contents.setX(left);
237 m_contents.setWidth(qMax(right - left, qreal(0.0)));
240 return (m_contents.width() != oldwidth || m_contents.x() != oldx);
243void QQuickContents::complete()
245 QQuickItemPrivate::get(m_item)->addItemChangeListener(
this, QQuickItemPrivate::Children);
247 QList<QQuickItem *> children = m_item->childItems();
248 for (
int i = 0; i < children.size(); ++i) {
249 QQuickItem *child = children.at(i);
250 QQuickItemPrivate::get(child)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
256void QQuickContents::updateRect()
258 QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF());
261void QQuickContents::itemGeometryChanged(QQuickItem *changed, QQuickGeometryChange change,
const QRectF &)
264 bool wChanged =
false;
265 bool hChanged =
false;
267 if (change.horizontalChange())
268 wChanged = calcWidth();
269 if (change.verticalChange())
270 hChanged = calcHeight();
271 if (wChanged || hChanged)
275void QQuickContents::itemDestroyed(QQuickItem *item)
278 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
282void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item)
285 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
289void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item)
292 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
296QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item)
297: m_processPost(
false), m_next(
nullptr)
299 QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):
nullptr;
301 m_next = p->extra.value().keyHandler;
302 p->extra->keyHandler =
this;
306QQuickItemKeyFilter::~QQuickItemKeyFilter()
310void QQuickItemKeyFilter::keyPressed(QKeyEvent *event,
bool post)
312 if (m_next) m_next->keyPressed(event, post);
315void QQuickItemKeyFilter::keyReleased(QKeyEvent *event,
bool post)
317 if (m_next) m_next->keyReleased(event, post);
321void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event,
bool post)
324 m_next->inputMethodEvent(event, post);
329QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query)
const
331 if (m_next)
return m_next->inputMethodQuery(query);
336void QQuickItemKeyFilter::shortcutOverrideEvent(QKeyEvent *event)
339 m_next->shortcutOverrideEvent(event);
344void QQuickItemKeyFilter::componentComplete()
346 if (m_next) m_next->componentComplete();
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
383
384
385
386
387
388
389
390
393
394
395
396
397
400
401
402
403
404
407
408
409
410
411
414
415
416
417
418
421
422
423
424
425
428
429
430
431
432
434QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent)
435: QObject(*(
new QQuickKeyNavigationAttachedPrivate), parent),
436 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
438 m_processPost =
true;
441QQuickKeyNavigationAttached *
442QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
444 return new QQuickKeyNavigationAttached(obj);
447QQuickItem *QQuickKeyNavigationAttached::left()
const
449 Q_D(
const QQuickKeyNavigationAttached);
453void QQuickKeyNavigationAttached::setLeft(QQuickItem *i)
455 Q_D(QQuickKeyNavigationAttached);
456 if (d->leftSet && d->left == i)
458 d->leftSet = d->left != i;
460 QQuickKeyNavigationAttached* other =
461 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
462 if (other && !other->d_func()->rightSet){
463 other->d_func()->right = qobject_cast<QQuickItem*>(parent());
464 emit other->rightChanged();
469QQuickItem *QQuickKeyNavigationAttached::right()
const
471 Q_D(
const QQuickKeyNavigationAttached);
475void QQuickKeyNavigationAttached::setRight(QQuickItem *i)
477 Q_D(QQuickKeyNavigationAttached);
478 if (d->rightSet && d->right == i)
480 d->rightSet = d->right != i;
482 QQuickKeyNavigationAttached* other =
483 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
484 if (other && !other->d_func()->leftSet){
485 other->d_func()->left = qobject_cast<QQuickItem*>(parent());
486 emit other->leftChanged();
491QQuickItem *QQuickKeyNavigationAttached::up()
const
493 Q_D(
const QQuickKeyNavigationAttached);
497void QQuickKeyNavigationAttached::setUp(QQuickItem *i)
499 Q_D(QQuickKeyNavigationAttached);
500 if (d->upSet && d->up == i)
502 d->upSet = d->up != i;
504 QQuickKeyNavigationAttached* other =
505 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
506 if (other && !other->d_func()->downSet){
507 other->d_func()->down = qobject_cast<QQuickItem*>(parent());
508 emit other->downChanged();
513QQuickItem *QQuickKeyNavigationAttached::down()
const
515 Q_D(
const QQuickKeyNavigationAttached);
519void QQuickKeyNavigationAttached::setDown(QQuickItem *i)
521 Q_D(QQuickKeyNavigationAttached);
522 if (d->downSet && d->down == i)
524 d->downSet = d->down != i;
526 QQuickKeyNavigationAttached* other =
527 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
528 if (other && !other->d_func()->upSet) {
529 other->d_func()->up = qobject_cast<QQuickItem*>(parent());
530 emit other->upChanged();
535QQuickItem *QQuickKeyNavigationAttached::tab()
const
537 Q_D(
const QQuickKeyNavigationAttached);
541void QQuickKeyNavigationAttached::setTab(QQuickItem *i)
543 Q_D(QQuickKeyNavigationAttached);
544 if (d->tabSet && d->tab == i)
546 d->tabSet = d->tab != i;
548 QQuickKeyNavigationAttached* other =
549 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
550 if (other && !other->d_func()->backtabSet) {
551 other->d_func()->backtab = qobject_cast<QQuickItem*>(parent());
552 emit other->backtabChanged();
557QQuickItem *QQuickKeyNavigationAttached::backtab()
const
559 Q_D(
const QQuickKeyNavigationAttached);
563void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i)
565 Q_D(QQuickKeyNavigationAttached);
566 if (d->backtabSet && d->backtab == i)
568 d->backtabSet = d->backtab != i;
570 QQuickKeyNavigationAttached* other =
571 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
572 if (other && !other->d_func()->tabSet) {
573 other->d_func()->tab = qobject_cast<QQuickItem*>(parent());
574 emit other->tabChanged();
576 emit backtabChanged();
580
581
582
583
584
585
586
587
588
589
590
591
592QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority()
const
594 return m_processPost ? AfterItem : BeforeItem;
597void QQuickKeyNavigationAttached::setPriority(Priority order)
599 bool processPost = order == AfterItem;
600 if (processPost != m_processPost) {
601 m_processPost = processPost;
602 emit priorityChanged();
606void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event,
bool post)
608 Q_D(QQuickKeyNavigationAttached);
611 if (post != m_processPost) {
612 QQuickItemKeyFilter::keyPressed(event, post);
617 switch (event->key()) {
619 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
620 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
621 QQuickItem* leftItem = mirror ? d->right : d->left;
623 setFocusNavigation(leftItem, mirror ?
"right" :
"left", mirror ? Qt::TabFocusReason : Qt::BacktabFocusReason);
628 case Qt::Key_Right: {
629 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
630 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
631 QQuickItem* rightItem = mirror ? d->left : d->right;
633 setFocusNavigation(rightItem, mirror ?
"left" :
"right", mirror ? Qt::BacktabFocusReason : Qt::TabFocusReason);
640 setFocusNavigation(d->up,
"up", Qt::BacktabFocusReason);
646 setFocusNavigation(d->down,
"down", Qt::TabFocusReason);
652 setFocusNavigation(d->tab,
"tab", Qt::TabFocusReason);
656 case Qt::Key_Backtab:
658 setFocusNavigation(d->backtab,
"backtab", Qt::BacktabFocusReason);
666 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
669void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event,
bool post)
671 Q_D(QQuickKeyNavigationAttached);
674 if (post != m_processPost) {
675 QQuickItemKeyFilter::keyReleased(event, post);
680 switch (event->key()) {
682 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
683 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
684 if (mirror ? d->right : d->left)
688 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
689 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
690 if (mirror ? d->left : d->right)
708 case Qt::Key_Backtab:
717 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
720void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem,
const char *dir,
721 Qt::FocusReason reason)
723 QQuickItem *initialItem = currentItem;
724 bool isNextItem =
false;
725 QVector<QQuickItem *> visitedItems;
728 if (currentItem->isVisible() && currentItem->isEnabled()) {
729 currentItem->forceActiveFocus(reason);
732 qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(currentItem,
false);
734 QQuickItem *tempItem = qvariant_cast<QQuickItem*>(attached->property(dir));
736 visitedItems.append(currentItem);
737 currentItem = tempItem;
743 while (currentItem != initialItem && isNextItem && !visitedItems.contains(currentItem));
752 { Qt::Key_Left,
"leftPressed" },
753 { Qt::Key_Right,
"rightPressed" },
754 { Qt::Key_Up,
"upPressed" },
755 { Qt::Key_Down,
"downPressed" },
756 { Qt::Key_Tab,
"tabPressed" },
757 { Qt::Key_Backtab,
"backtabPressed" },
758 { Qt::Key_Asterisk,
"asteriskPressed" },
759 { Qt::Key_NumberSign,
"numberSignPressed" },
760 { Qt::Key_Escape,
"escapePressed" },
761 { Qt::Key_Return,
"returnPressed" },
762 { Qt::Key_Enter,
"enterPressed" },
763 { Qt::Key_Delete,
"deletePressed" },
764 { Qt::Key_Space,
"spacePressed" },
765 { Qt::Key_Back,
"backPressed" },
766 { Qt::Key_Cancel,
"cancelPressed" },
767 { Qt::Key_Select,
"selectPressed" },
768 { Qt::Key_Yes,
"yesPressed" },
769 { Qt::Key_No,
"noPressed" },
770 { Qt::Key_Context1,
"context1Pressed" },
771 { Qt::Key_Context2,
"context2Pressed" },
772 { Qt::Key_Context3,
"context3Pressed" },
773 { Qt::Key_Context4,
"context4Pressed" },
774 { Qt::Key_Call,
"callPressed" },
775 { Qt::Key_Hangup,
"hangupPressed" },
776 { Qt::Key_Flip,
"flipPressed" },
777 { Qt::Key_Menu,
"menuPressed" },
778 { Qt::Key_VolumeUp,
"volumeUpPressed" },
779 { Qt::Key_VolumeDown,
"volumeDownPressed" },
783QByteArray QQuickKeysAttached::keyToSignal(
int key)
785 QByteArray keySignal;
786 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
787 keySignal =
"digit0Pressed";
788 keySignal[5] =
'0' + (key - Qt::Key_0);
791 while (sigMap[i].key && sigMap[i].key != key)
793 keySignal = sigMap[i].sig;
798bool QQuickKeysAttached::isConnected(
const char *signalName)
const
800 Q_D(
const QQuickKeysAttached);
801 int signal_index = d->signalIndex(signalName);
802 return d->isSignalConnected(signal_index);
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
861
862
863
864
865
866
867
868
871
872
873
874
875
878
879
880
881
882
883
884
885
886
887
888
889
890
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
923
924
925
926
927
930
931
932
933
934
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
965
966
967
968
969
970
971
972
975
976
977
978
979
982
983
984
985
986
989
990
991
992
993
996
997
998
999
1000
1003
1004
1005
1006
1007
1010
1011
1012
1013
1014
1017
1018
1019
1020
1021
1024
1025
1026
1027
1028
1031
1032
1033
1034
1035
1038
1039
1040
1041
1042
1045
1046
1047
1048
1049
1052
1053
1054
1055
1056
1059
1060
1061
1062
1063
1066
1067
1068
1069
1070
1073
1074
1075
1076
1077
1080
1081
1082
1083
1084
1087
1088
1089
1090
1091
1094
1095
1096
1097
1098
1101
1102
1103
1104
1105
1108
1109
1110
1111
1112
1115
1116
1117
1118
1119
1122
1123
1124
1125
1126
1129
1130
1131
1132
1133
1136
1137
1138
1139
1140
1143
1144
1145
1146
1147
1150
1151
1152
1153
1154
1157
1158
1159
1160
1161
1164
1165
1166
1167
1168
1171
1172
1173
1174
1175
1178
1179
1180
1181
1182
1185
1186
1187
1188
1189
1192
1193
1194
1195
1196
1199
1200
1201
1202
1203
1206
1207
1208
1209
1210
1213
1214
1215
1216
1217
1220
1221
1222
1223
1224
1227
1228
1229
1230
1231
1233QQuickKeysAttached::QQuickKeysAttached(QObject *parent)
1234: QObject(*(
new QQuickKeysAttachedPrivate), parent),
1235 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
1237 Q_D(QQuickKeysAttached);
1238 m_processPost =
false;
1239 d->item = qmlobject_cast<QQuickItem*>(parent);
1240 if (d->item != parent)
1241 qWarning() <<
"Could not attach Keys property to: " << parent <<
" is not an Item";
1244QQuickKeysAttached::~QQuickKeysAttached()
1248QQuickKeysAttached::Priority QQuickKeysAttached::priority()
const
1250 return m_processPost ? AfterItem : BeforeItem;
1253void QQuickKeysAttached::setPriority(Priority order)
1255 bool processPost = order == AfterItem;
1256 if (processPost != m_processPost) {
1257 m_processPost = processPost;
1258 emit priorityChanged();
1262void QQuickKeysAttached::componentComplete()
1265 Q_D(QQuickKeysAttached);
1267 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1268 QQuickItem *targetItem = d->targets.at(ii);
1269 if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1270 d->item->setFlag(QQuickItem::ItemAcceptsInputMethod);
1278void QQuickKeysAttached::keyPressed(QKeyEvent *event,
bool post)
1280 Q_D(QQuickKeysAttached);
1281 if (post != m_processPost || !d->enabled || d->inPress) {
1283 QQuickItemKeyFilter::keyPressed(event, post);
1288 if (d->item && d->item->window()) {
1290 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1291 QQuickItem *i = d->targets.at(ii);
1292 if (i && i->isVisible()) {
1294 QCoreApplication::sendEvent(i, event);
1295 if (event->isAccepted()) {
1304 QQuickKeyEvent &ke = d->theKeyEvent;
1306 QByteArray keySignal = keyToSignal(event->key());
1307 if (!keySignal.isEmpty()) {
1308 keySignal +=
"(QQuickKeyEvent*)";
1309 if (isConnected(keySignal)) {
1311 ke.setAccepted(
true);
1312 int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal);
1313 metaObject()->method(idx).invoke(
this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke));
1316 if (!ke.isAccepted())
1318 event->setAccepted(ke.isAccepted());
1320 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
1323void QQuickKeysAttached::keyReleased(QKeyEvent *event,
bool post)
1325 Q_D(QQuickKeysAttached);
1326 if (post != m_processPost || !d->enabled || d->inRelease) {
1328 QQuickItemKeyFilter::keyReleased(event, post);
1332 if (d->item && d->item->window()) {
1333 d->inRelease =
true;
1334 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1335 QQuickItem *i = d->targets.at(ii);
1336 if (i && i->isVisible()) {
1338 QCoreApplication::sendEvent(i, event);
1339 if (event->isAccepted()) {
1340 d->inRelease =
false;
1345 d->inRelease =
false;
1348 QQuickKeyEvent &ke = d->theKeyEvent;
1351 event->setAccepted(ke.isAccepted());
1353 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
1357void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event,
bool post)
1359 Q_D(QQuickKeysAttached);
1360 if (post == m_processPost && d->item && !d->inIM && d->item->window()) {
1362 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1363 QQuickItem *targetItem = d->targets.at(ii);
1364 if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1365 QCoreApplication::sendEvent(targetItem, event);
1366 if (event->isAccepted()) {
1367 d->imeItem = targetItem;
1375 QQuickItemKeyFilter::inputMethodEvent(event, post);
1378QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query)
const
1380 Q_D(
const QQuickKeysAttached);
1382 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1383 QQuickItem *i = d->targets.at(ii);
1384 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) {
1386 QVariant v = i->inputMethodQuery(query);
1387 if (v.userType() == QMetaType::QRectF)
1388 v = d->item->mapRectFromItem(i, v.toRectF());
1393 return QQuickItemKeyFilter::inputMethodQuery(query);
1397void QQuickKeysAttached::shortcutOverrideEvent(QKeyEvent *event)
1399 Q_D(QQuickKeysAttached);
1400 QQuickKeyEvent &keyEvent = d->theKeyEvent;
1401 keyEvent.reset(*event);
1402 emit shortcutOverride(&keyEvent);
1404 event->setAccepted(keyEvent.isAccepted());
1407QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
1409 return new QQuickKeysAttached(obj);
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
1457
1458
1459
1460
1461
1462
1463
1464
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1479
1480
1481
1482
1483
1484
1485
1488QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1490 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1491 itemPrivate = QQuickItemPrivate::get(item);
1492 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1493 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1496 itemPrivate->extra.value().layoutDirectionAttached =
this;
1498 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1501QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1503 return new QQuickLayoutMirroringAttached(object);
1506bool QQuickLayoutMirroringAttached::enabled()
const
1508 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1511void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1516 itemPrivate->isMirrorImplicit =
false;
1517 if (enabled != itemPrivate->effectiveLayoutMirror) {
1518 itemPrivate->setLayoutMirror(enabled);
1519 if (itemPrivate->inheritMirrorFromItem)
1520 itemPrivate->resolveLayoutMirror();
1524void QQuickLayoutMirroringAttached::resetEnabled()
1526 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1527 itemPrivate->isMirrorImplicit =
true;
1528 itemPrivate->resolveLayoutMirror();
1532bool QQuickLayoutMirroringAttached::childrenInherit()
const
1534 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1537void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1538 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1539 itemPrivate->inheritMirrorFromItem = childrenInherit;
1540 itemPrivate->resolveLayoutMirror();
1541 childrenInheritChanged();
1545void QQuickItemPrivate::resolveLayoutMirror()
1548 if (QQuickItem *parentItem = q->parentItem()) {
1549 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1550 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1552 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1556void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1558 inherit = inherit || inheritMirrorFromItem;
1559 if (!isMirrorImplicit && inheritMirrorFromItem)
1560 mirror = effectiveLayoutMirror;
1561 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1564 inheritMirrorFromParent = inherit;
1565 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1567 if (isMirrorImplicit)
1568 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1569 for (
int i = 0; i < childItems.size(); ++i) {
1570 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1571 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1572 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1577void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1579 if (mirror != effectiveLayoutMirror) {
1580 effectiveLayoutMirror = mirror;
1582 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1583 anchor_d->fillChanged();
1584 anchor_d->centerInChanged();
1585 anchor_d->updateHorizontalAnchors();
1588 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1589 emit extra->layoutDirectionAttached->enabledChanged();
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1641QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1642 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1644 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1645 itemPrivate = QQuickItemPrivate::get(item);
1646 itemPrivate->extra.value().enterKeyAttached =
this;
1648 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1651QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1653 return new QQuickEnterKeyAttached(object);
1656Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1661void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1663 if (keyType != type) {
1666 if (itemPrivate && itemPrivate->activeFocus)
1667 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1673void QQuickItemPrivate::setAccessible()
1675 isAccessible =
true;
1679
1680
1681
1682
1683void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1688 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1690 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1692 if (oldSubFocusItem) {
1693 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1694 while (sfi && sfi != scope) {
1695 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1696 sfi = sfi->parentItem();
1701 scopePrivate->subFocusItem = q;
1702 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1703 while (sfi && sfi != scope) {
1704 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1705 sfi = sfi->parentItem();
1708 scopePrivate->subFocusItem =
nullptr;
1713bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1716 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1717 Qt::FocusPolicy policy = Qt::ClickFocus;
1719 switch (eventType) {
1720 case QEvent::MouseButtonPress:
1721 case QEvent::MouseButtonDblClick:
1722 case QEvent::TouchBegin:
1723 if (setFocusOnRelease)
1726 case QEvent::MouseButtonRelease:
1727 case QEvent::TouchEnd:
1728 if (!setFocusOnRelease)
1732 policy = Qt::WheelFocus;
1738 if ((focusPolicy & policy) == policy) {
1739 setActiveFocus(q, Qt::MouseFocusReason);
1746Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1748 return static_cast<Qt::FocusReason>(focusReason);
1751bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1753 if (focusReason == reason)
1756 focusReason = reason;
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
1870
1871
1872
1873
1874
1875
1876
1877
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
2069
2070
2071
2072
2073
2074
2075
2076
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
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
2139
2140
2141
2142
2143
2144
2145
2146
2147
2150
2151
2152
2153
2154
2155
2156
2157
2158
2161
2162
2163
2166
2167
2168
2171
2172
2173
2176
2177
2178
2181
2182
2183
2184
2185
2186
2187
2190
2191
2192
2193
2194
2195
2198
2199
2200
2201
2202
2205
2206
2207
2208
2209
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2230
2231
2232
2235
2236
2237
2240
2241
2242
2245
2246
2247
2250
2251
2252
2255
2256
2257
2260
2261
2262
2265
2266
2267
2270
2271
2272
2275
2276
2277
2280
2281
2282
2285
2286
2287
2290
2291
2292
2295
2296
2297
2300
2301
2302
2305
2306
2307
2310
2311
2312
2315
2316
2317
2320
2321
2322
2325
2326
2327
2330
2331
2332
2335
2336
2337
2340
2341
2342
2345
2346
2347
2350
2351
2352
2355
2356
2357
2360
2361
2362
2363
2364
2365
2366
2367QQuickItem::QQuickItem(QQuickItem* parent)
2368: QObject(*(
new QQuickItemPrivate), parent)
2375
2376QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2377: QObject(dd, parent)
2384
2385
2386QQuickItem::~QQuickItem()
2389 d->inDestructor =
true;
2391#if QT_CONFIG(accessibility)
2392 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
2393 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
2396 if (d->windowRefCount > 1)
2397 d->windowRefCount = 1;
2399 setParentItem(
nullptr);
2403 for (QQuickItem *child : std::as_const(d->childItems))
2404 child->setParentItem(
nullptr);
2405 d->childItems.clear();
2407 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2408 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2410 anchor->clearItem(
this);
2413
2414
2415
2416 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2417 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2418 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2421 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2422 d->changeListeners.clear();
2425
2426
2427
2428
2429 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2430 QQuickTransform *t = d->transforms.at(ii);
2431 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2432 tp->items.removeOne(
this);
2435 if (d->extra.isAllocated()) {
2436 delete d->extra->contents; d->extra->contents =
nullptr;
2437#if QT_CONFIG(quick_shadereffect)
2438 delete d->extra->layer; d->extra->layer =
nullptr;
2442 delete d->_anchors; d->_anchors =
nullptr;
2443 delete d->_stateGroup; d->_stateGroup =
nullptr;
2445 d->isQuickItem =
false;
2449
2450
2451bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2453 if (!item->window())
2456 if (item == item->window()->contentItem())
2459 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2460 if (tabFocus == Qt::NoTabFocus)
2462 if (tabFocus == Qt::TabFocusAllControls)
2465 QVariant editable = item->property(
"editable");
2466 if (editable.isValid())
2467 return editable.toBool();
2469 QVariant readonly = item->property(
"readOnly");
2470 if (readonly.isValid())
2471 return !readonly.toBool() && item->property(
"text").isValid();
2473#if QT_CONFIG(accessibility)
2474 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2475 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2477 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2478 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2479 return iface->state().editable;
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2498 QQuickWindow *window = item->window();
2499 const bool wrap = !window || window->isTopLevel();
2501 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2506 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2508 if (!wrap && !next) {
2512 Q_ASSERT(window->parent());
2515 qt_window_private(window->parent())->setFocusToTarget(
2516 forward ? QWindowPrivate::FocusTarget::Next
2517 : QWindowPrivate::FocusTarget::Prev,
2519 window->parent()->requestActivate();
2523 next->forceActiveFocus(reason);
2528QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2531 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2534 const QList<QQuickItem *> &children = item->childItems();
2535 const int count = children.size();
2536 if (start < 0 || start >= count) {
2537 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2540 while (start < count) {
2541 QQuickItem *child = children.at(start);
2542 if (!child->d_func()->isTabFence)
2549QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2552 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2555 const QList<QQuickItem *> &children = item->childItems();
2556 const int count = children.size();
2559 if (start < 0 || start >= count) {
2560 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2563 while (start >= 0) {
2564 QQuickItem *child = children.at(start);
2565 if (!child->d_func()->isTabFence)
2572QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2575 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2577 if (!item->window())
2579 const QQuickItem *
const contentItem = item->window()->contentItem();
2583 QQuickItem *from =
nullptr;
2584 bool isTabFence = item->d_func()->isTabFence;
2587 from = item->parentItem();
2589 if (!item->childItems().isEmpty())
2590 from = item->d_func()->childItems.constFirst();
2591 else if (!isTabFence)
2592 from = item->parentItem();
2596 QQuickItem *startItem = item;
2597 QQuickItem *originalStartItem = startItem;
2602 while (startItem && !startItem->isVisible()) {
2603 startItem = startItem->parentItem();
2608 QQuickItem *firstFromItem = from;
2609 QQuickItem *current = item;
2610 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2611 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2612 QDuplicateTracker<QQuickItem *> cycleDetector;
2614 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2615 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2617 QQuickItem *last = current;
2619 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2620 QQuickItem *firstChild =
nullptr;
2621 QQuickItem *lastChild =
nullptr;
2623 firstChild = nextTabChildItem(current, 0);
2625 hasChildren =
false;
2627 lastChild = prevTabChildItem(current, -1);
2629 isTabFence = current->d_func()->isTabFence;
2630 if (isTabFence && !hasChildren)
2634 if (hasChildren && from == current->parentItem()) {
2636 current = firstChild;
2638 current = lastChild;
2639 if (!current->childItems().isEmpty())
2642 }
else if (hasChildren && forward && from != lastChild) {
2644 int nextChild = current->childItems().indexOf(from) + 1;
2645 current = nextTabChildItem(current, nextChild);
2646 }
else if (hasChildren && !forward && from != firstChild) {
2648 int prevChild = current->childItems().indexOf(from) - 1;
2649 current = prevTabChildItem(current, prevChild);
2650 if (!current->childItems().isEmpty())
2653 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2657 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2658 if (last != firstSibling
2659 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2663 }
else if (hasChildren) {
2665 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2666 <<
"Focus chain about to wrap but wrapping was set to false."
2673 current = firstChild;
2674 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2675 <<
"wrapping from last to first:" << current;
2677 current = lastChild;
2678 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2679 <<
"wrapping from first to last:" << current;
2680 if (!current->childItems().isEmpty())
2692 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2693 (!skip && cycleDetector.hasSeen(current))) {
2695 if (item == contentItem) {
2696 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2699 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2703 if (!firstFromItem) {
2704 if (startItem->d_func()->isTabFence) {
2705 if (current == startItem)
2706 firstFromItem = from;
2708 startItem = current;
2709 firstFromItem = from;
2712 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2713 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2719
2720
2721
2722
2723
2724
2725
2726
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742QQuickItem *QQuickItem::parentItem()
const
2744 Q_D(
const QQuickItem);
2745 return d->parentItem;
2748void QQuickItem::setParentItem(QQuickItem *parentItem)
2751 if (parentItem == d->parentItem)
2755 QQuickItem *itemAncestor = parentItem;
2756 while (itemAncestor !=
nullptr) {
2757 if (Q_UNLIKELY(itemAncestor ==
this)) {
2758 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2761 itemAncestor = itemAncestor->parentItem();
2763 auto engine = qmlEngine(
this);
2765 QV4::ExecutionEngine *v4 = engine->handle();
2766 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2767 QV4::QObjectWrapper::markWrapper(
this, ms);
2772 d->removeFromDirtyList();
2774 QQuickItem *oldParentItem = d->parentItem;
2775 QQuickItem *scopeFocusedItem =
nullptr;
2777 if (oldParentItem) {
2778 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2780 QQuickItem *scopeItem =
nullptr;
2782 if (hasFocus() || op->subFocusItem ==
this)
2783 scopeFocusedItem =
this;
2784 else if (!isFocusScope() && d->subFocusItem)
2785 scopeFocusedItem = d->subFocusItem;
2787 if (scopeFocusedItem) {
2788 scopeItem = oldParentItem;
2789 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2790 scopeItem = scopeItem->parentItem();
2792 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2793 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2794 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2796 if (scopeFocusedItem !=
this)
2797 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2799 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2803 const bool wasVisible = isVisible();
2804 op->removeChild(
this);
2805 if (wasVisible && !op->inDestructor)
2806 emit oldParentItem->visibleChildrenChanged();
2807 }
else if (d->window) {
2808 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2811 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2812 bool alreadyAddedChild =
false;
2813 if (d->window == parentWindow) {
2815 d->parentItem = parentItem;
2817 auto oldParentItem = d->parentItem;
2818 d->parentItem = parentItem;
2819 if (d->parentItem) {
2820 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2821 alreadyAddedChild =
true;
2829 if (!oldParentItem && d->window) {
2830 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2834 d->refWindow(parentWindow);
2837 d->dirty(QQuickItemPrivate::ParentChanged);
2839 if (d->parentItem && !alreadyAddedChild)
2840 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2841 else if (d->window && !alreadyAddedChild)
2842 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2844 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2845 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2847 if (d->parentItem) {
2848 if (!scopeFocusedItem) {
2850 scopeFocusedItem =
this;
2851 else if (!isFocusScope() && d->subFocusItem)
2852 scopeFocusedItem = d->subFocusItem;
2855 if (scopeFocusedItem) {
2857 QQuickItem *scopeItem = d->parentItem;
2858 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2859 scopeItem = scopeItem->parentItem();
2861 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2862 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2863 if (scopeFocusedItem !=
this)
2864 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2865 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2866 emit scopeFocusedItem->focusChanged(
false);
2869 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2870 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2871 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2874 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2881 d->resolveLayoutMirror();
2883 d->itemChange(ItemParentHasChanged, d->parentItem);
2885 if (!d->inDestructor)
2886 emit parentChanged(d->parentItem);
2887 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2888 emit d->parentItem->visibleChildrenChanged();
2890#if QT_CONFIG(accessibility)
2891 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2892 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2893 QAccessible::updateAccessibility(&qaEvent);
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916void QQuickItem::stackBefore(
const QQuickItem *sibling)
2919 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2920 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2921 <<
this <<
" before " << sibling <<
", which must be a sibling";
2925 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2927 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2928 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2930 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2932 if (myIndex == siblingIndex - 1)
2935 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2937 parentPrivate->markSortedChildrenDirty(
this);
2938 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2940 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2941 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962void QQuickItem::stackAfter(
const QQuickItem *sibling)
2965 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2966 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2967 <<
this <<
" after " << sibling <<
", which must be a sibling";
2971 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2973 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2974 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2976 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2978 if (myIndex == siblingIndex + 1)
2981 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2983 parentPrivate->markSortedChildrenDirty(
this);
2984 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2986 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2987 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2991
2992
2995
2996
2997
2998
2999
3000
3001QQuickWindow *QQuickItem::window()
const
3003 Q_D(
const QQuickItem);
3009 return lhs->z() < rhs->z();
3012QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3014 if (sortedChildItems)
3015 return *sortedChildItems;
3020 for (
int i = 0; i < childItems.size(); ++i) {
3021 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3027 sortedChildItems =
new QList<QQuickItem*>(childItems);
3028 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3029 return *sortedChildItems;
3032 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3037void QQuickItemPrivate::addChild(QQuickItem *child)
3041 Q_ASSERT(!childItems.contains(child));
3043 childItems.append(child);
3045 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3047#if QT_CONFIG(cursor)
3050 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3051 setHasCursorInChild(
true);
3054 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3055 setHasHoverInChild(
true);
3057 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3058 markSortedChildrenDirty(child);
3059 dirty(QQuickItemPrivate::ChildrenChanged);
3061 itemChange(QQuickItem::ItemChildAddedChange, child);
3063 emit q->childrenChanged();
3066void QQuickItemPrivate::removeChild(QQuickItem *child)
3071 if (!inDestructor) {
3073 Q_ASSERT(childItems.contains(child));
3074 childItems.removeOne(child);
3075 Q_ASSERT(!childItems.contains(child));
3078 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3080#if QT_CONFIG(cursor)
3082 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3083 setHasCursorInChild(
false);
3086 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3087 setHasHoverInChild(
false);
3089 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3090 if (!inDestructor) {
3091 markSortedChildrenDirty(child);
3092 dirty(QQuickItemPrivate::ChildrenChanged);
3095 itemChange(QQuickItem::ItemChildRemovedChange, child);
3098 emit q->childrenChanged();
3101void QQuickItemPrivate::refWindow(QQuickWindow *c)
3113 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3115 if (++windowRefCount > 1) {
3117 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3121 Q_ASSERT(window ==
nullptr);
3124 if (polishScheduled)
3125 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3128 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3130 for (
int ii = 0; ii < childItems.size(); ++ii) {
3131 QQuickItem *child = childItems.at(ii);
3132 QQuickItemPrivate::get(child)->refWindow(c);
3137 if (extra.isAllocated() && extra->screenAttached)
3138 extra->screenAttached->windowChanged(c);
3139 itemChange(QQuickItem::ItemSceneChange, c);
3142void QQuickItemPrivate::derefWindow()
3145 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3150 if (--windowRefCount > 0)
3153 q->releaseResources();
3154 removeFromDirtyList();
3155 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3156 if (polishScheduled)
3157 c->itemsToPolish.removeOne(q);
3158#if QT_CONFIG(cursor)
3159 if (c->cursorItem == q) {
3160 c->cursorItem =
nullptr;
3161 window->unsetCursor();
3164 if (itemNodeInstance)
3165 c->cleanup(itemNodeInstance);
3167 c->parentlessItems.remove(q);
3171 itemNodeInstance =
nullptr;
3173 if (extra.isAllocated()) {
3174 extra->opacityNode =
nullptr;
3175 extra->clipNode =
nullptr;
3176 extra->rootNode =
nullptr;
3179 paintNode =
nullptr;
3181 for (
int ii = 0; ii < childItems.size(); ++ii) {
3182 if (QQuickItem *child = childItems.at(ii))
3183 QQuickItemPrivate::get(child)->derefWindow();
3188 if (extra.isAllocated() && extra->screenAttached)
3189 extra->screenAttached->windowChanged(
nullptr);
3190 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3193qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3195 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3199
3200
3201QTransform QQuickItemPrivate::windowToItemTransform()
const
3204 return itemToWindowTransform().inverted();
3208
3209
3210QTransform QQuickItemPrivate::itemToWindowTransform()
const
3213 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3214 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3215 itemToParentTransform(&rv);
3220
3221
3222void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3225
3226
3227
3228
3229
3231 qreal x =
this->x.valueBypassingBindings();
3232 qreal y =
this->y.valueBypassingBindings();
3236 if (!transforms.isEmpty()) {
3238 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3239 transforms.at(ii)->applyTo(&m);
3240 *t = m.toTransform();
3243 if (scale() != 1. || rotation() != 0.) {
3244 QPointF tp = computeTransformOrigin();
3245 t->translate(tp.x(), tp.y());
3246 t->scale(scale(), scale());
3247 t->rotate(rotation());
3248 t->translate(-tp.x(), -tp.y());
3253
3254
3255
3256
3257
3258
3259
3260
3261bool QQuickItem::isComponentComplete()
const
3263 Q_D(
const QQuickItem);
3264 return d->componentComplete;
3267QQuickItemPrivate::QQuickItemPrivate()
3269 , _stateGroup(
nullptr)
3271 , widthValidFlag(
false)
3272 , heightValidFlag(
false)
3273 , componentComplete(
true)
3276 , hoverEnabled(
false)
3278 , antialiasing(
false)
3280 , activeFocus(
false)
3281 , notifiedFocus(
false)
3282 , notifiedActiveFocus(
false)
3283 , filtersChildMouseEvents(
false)
3284 , explicitVisible(
true)
3285 , effectiveVisible(
true)
3286 , explicitEnable(
true)
3287 , effectiveEnable(
true)
3288 , polishScheduled(
false)
3289 , inheritedLayoutMirror(
false)
3290 , effectiveLayoutMirror(
false)
3291 , isMirrorImplicit(
true)
3292 , inheritMirrorFromParent(
false)
3293 , inheritMirrorFromItem(
false)
3294 , isAccessible(
false)
3297 , subtreeCursorEnabled(
false)
3298 , subtreeHoverEnabled(
false)
3299 , activeFocusOnTab(
false)
3300 , implicitAntialiasing(
false)
3301 , antialiasingValid(
false)
3303 , replayingPressEvent(
false)
3304 , touchEnabled(
false)
3305 , hasCursorHandler(
false)
3306 , maybeHasSubsceneDeliveryAgent(
true)
3307 , subtreeTransformChangedEnabled(
true)
3308 , inDestructor(
false)
3309 , focusReason(Qt::OtherFocusReason)
3310 , focusPolicy(Qt::NoFocus)
3311 , dirtyAttributes(0)
3312 , nextDirtyItem(
nullptr)
3313 , prevDirtyItem(
nullptr)
3316 , parentItem(
nullptr)
3317 , sortedChildItems(&childItems)
3318 , subFocusItem(
nullptr)
3326 , itemNodeInstance(
nullptr)
3327 , paintNode(
nullptr)
3328 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3332QQuickItemPrivate::~QQuickItemPrivate()
3334 if (sortedChildItems != &childItems)
3335 delete sortedChildItems;
3338void QQuickItemPrivate::init(QQuickItem *parent)
3344 baselineOffset = 0.0;
3347 q->setParentItem(parent);
3348 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3349 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3353QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3358void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3360 szPolicy.setHorizontalPolicy(horizontalPolicy);
3361 szPolicy.setVerticalPolicy(verticalPolicy);
3364void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3369 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3371 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3372 item->setParentItem(that);
3373 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3374 if (pointerHandler->parent() != that) {
3375 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3376 pointerHandler->setParent(that);
3378 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3381 resources_append(prop, o);
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3420qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3422 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3423 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3424 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3425 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3427 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3430QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3432 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3433 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3434 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3435 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3437 qsizetype resourcesCount = resources_count(&resourcesProperty);
3438 if (i < resourcesCount)
3439 return resources_at(&resourcesProperty, i);
3440 const qsizetype j = i - resourcesCount;
3441 if (j < children_count(&childrenProperty))
3442 return children_at(&childrenProperty, j);
3446void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3448 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3449 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3450 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3451 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3453 resources_clear(&resourcesProperty);
3454 children_clear(&childrenProperty);
3457void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3459 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3460 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3462 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3463 if (children_count(&childrenProperty) > 0) {
3464 children_removeLast(&childrenProperty);
3468 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3469 if (resources_count(&resourcesProperty) > 0)
3470 resources_removeLast(&resourcesProperty);
3473QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3475 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3476 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3479void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3481 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3482 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3483 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3484 quickItemPrivate->extra.value().resourcesList.append(object);
3485 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3486 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3490qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3492 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3493 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3496void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3498 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3499 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3500 if (quickItemPrivate->extra.isAllocated()) {
3501 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3502 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3503 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3505 quickItemPrivate->extra->resourcesList.clear();
3509void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3511 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3512 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3513 if (quickItemPrivate->extra.isAllocated()) {
3514 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3515 if (resources->isEmpty())
3518 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3519 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3520 resources->removeLast();
3524QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3526 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3527 if (index >= p->childItems.size() || index < 0)
3530 return p->childItems.at(index);
3533void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3538 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3539 if (o->parentItem() == that)
3540 o->setParentItem(
nullptr);
3542 o->setParentItem(that);
3545qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3547 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3548 return p->childItems.size();
3551void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3553 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3554 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3555 while (!p->childItems.isEmpty())
3556 p->childItems.at(0)->setParentItem(
nullptr);
3559void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3561 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3562 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3563 if (!p->childItems.isEmpty())
3564 p->childItems.last()->setParentItem(
nullptr);
3567qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3569 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3570 qsizetype visibleCount = 0;
3571 qsizetype c = p->childItems.size();
3573 if (p->childItems.at(c)->isVisible()) visibleCount++;
3576 return visibleCount;
3579QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3581 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3582 const qsizetype childCount = p->childItems.size();
3583 if (index >= childCount || index < 0)
3586 qsizetype visibleCount = -1;
3587 for (qsizetype i = 0; i < childCount; i++) {
3588 if (p->childItems.at(i)->isVisible()) visibleCount++;
3589 if (visibleCount == index)
return p->childItems.at(i);
3594qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3596 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3597 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3599 return p->transforms.size();
3602void QQuickTransform::appendToItem(QQuickItem *item)
3604 Q_D(QQuickTransform);
3608 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3610 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3611 p->transforms.removeOne(
this);
3612 p->transforms.append(
this);
3614 p->transforms.append(
this);
3615 d->items.append(item);
3618 p->dirty(QQuickItemPrivate::Transform);
3621void QQuickTransform::prependToItem(QQuickItem *item)
3623 Q_D(QQuickTransform);
3627 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3629 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3630 p->transforms.removeOne(
this);
3631 p->transforms.prepend(
this);
3633 p->transforms.prepend(
this);
3634 d->items.append(item);
3637 p->dirty(QQuickItemPrivate::Transform);
3640void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3645 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3646 transform->appendToItem(that);
3649QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3651 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3652 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3654 if (idx < 0 || idx >= p->transforms.size())
3657 return p->transforms.at(idx);
3660void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3662 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3663 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3665 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3666 QQuickTransform *t = p->transforms.at(ii);
3667 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3668 tp->items.removeOne(that);
3671 p->transforms.clear();
3673 p->dirty(QQuickItemPrivate::Transform);
3676void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3678 if (extra.isAllocated() && extra->resourcesList.contains(object))
3679 extra->resourcesList.removeAll(object);
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
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776QQuickAnchors *QQuickItemPrivate::anchors()
const
3779 Q_Q(
const QQuickItem);
3780 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3781 if (!componentComplete)
3782 _anchors->classBegin();
3787void QQuickItemPrivate::siblingOrderChanged()
3790 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3793QQmlListProperty<QObject> QQuickItemPrivate::data()
3797 QQmlListProperty<QObject> result;
3798 result.object = q_func();
3799 result.append = QQuickItemPrivate::data_append;
3800 result.count = QQuickItemPrivate::data_count;
3801 result.at = QQuickItemPrivate::data_at;
3802 result.clear = QQuickItemPrivate::data_clear;
3803 result.removeLast = QQuickItemPrivate::data_removeLast;
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838QRectF QQuickItem::childrenRect()
3841 if (!d->extra.isAllocated() || !d->extra->contents) {
3842 d->extra.value().contents =
new QQuickContents(
this);
3843 if (d->componentComplete)
3844 d->extra->contents->complete();
3846 return d->extra->contents->rectF();
3850
3851
3852QList<QQuickItem *> QQuickItem::childItems()
const
3854 Q_D(
const QQuickItem);
3855 return d->childItems;
3859
3860
3861
3862
3863
3864
3865
3866
3867
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886bool QQuickItem::clip()
const
3888 return flags() & ItemClipsChildrenToShape;
3891void QQuickItem::setClip(
bool c)
3896 setFlag(ItemClipsChildrenToShape, c);
3898 setFlag(ItemIsViewport);
3899 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3900 setFlag(ItemIsViewport,
false);
3902 emit clipChanged(c);
3906
3907
3908
3909
3910
3911
3912
3913
3914void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3919 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3921 QQuickGeometryChange change;
3922 change.setXChange(newGeometry.x() != oldGeometry.x());
3923 change.setYChange(newGeometry.y() != oldGeometry.y());
3924 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3925 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3927 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3928 if (change.matches(listener.gTypes))
3929 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3934 if (change.xChange())
3936 if (change.yChange())
3938 if (change.widthChange())
3940 if (change.heightChange())
3942#if QT_CONFIG(accessibility)
3943 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3944 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3945 QAccessible::updateAccessibility(&ev);
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4004QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4006 Q_UNUSED(updatePaintNodeData);
4011QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4012: transformNode(
nullptr)
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4033void QQuickItem::releaseResources()
4037QSGTransformNode *QQuickItemPrivate::createTransformNode()
4039 return new QSGTransformNode;
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052void QQuickItem::updatePolish()
4056#define PRINT_LISTENERS() do
4058 qDebug().nospace() << q_func() << " (" << this
4059 << ") now has the following listeners:";
4060 for (const auto &listener : std::as_const(changeListeners)) {
4061 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4062 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4064}while
4067void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4070 changeListeners.append(ChangeListener(listener, types));
4071 listener->addSourceItem(q);
4073 if (lcChangeListeners().isDebugEnabled())
4077void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4081 const ChangeListener changeListener(listener, types);
4082 const int index = changeListeners.indexOf(changeListener);
4084 changeListeners[index].types = changeListener.types;
4086 changeListeners.append(changeListener);
4087 listener->addSourceItem(q);
4090 if (lcChangeListeners().isDebugEnabled())
4094void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4098 ChangeListener change(listener, types);
4099 changeListeners.removeOne(change);
4100 listener->removeSourceItem(q);
4102 if (lcChangeListeners().isDebugEnabled())
4106void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4107 QQuickGeometryChange types)
4111 ChangeListener change(listener, types);
4112 int index = changeListeners.indexOf(change);
4114 changeListeners[index].gTypes = change.gTypes;
4116 changeListeners.append(change);
4117 listener->addSourceItem(q);
4120 if (lcChangeListeners().isDebugEnabled())
4124void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4125 QQuickGeometryChange types)
4129 ChangeListener change(listener, types);
4130 if (types.noChange()) {
4131 changeListeners.removeOne(change);
4132 listener->removeSourceItem(q);
4134 int index = changeListeners.indexOf(change);
4136 changeListeners[index].gTypes = change.gTypes;
4139 if (lcChangeListeners().isDebugEnabled())
4144
4145
4146
4147
4148
4149
4150void QQuickItem::keyPressEvent(QKeyEvent *event)
4156
4157
4158
4159
4160
4161
4162void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4169
4170
4171
4172
4173
4174
4175void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191void QQuickItem::focusInEvent(QFocusEvent *event)
4194#if QT_CONFIG(accessibility)
4195 if (QAccessible::isActive()) {
4196 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4197 QAccessibleEvent ev(acc, QAccessible::Focus);
4198 QAccessible::updateAccessibility(&ev);
4202 d->setLastFocusChangeReason(event->reason());
4206
4207
4208
4209
4210
4211
4212void QQuickItem::focusOutEvent(QFocusEvent *event)
4215 d->setLastFocusChangeReason(event->reason());
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228void QQuickItem::mousePressEvent(QMouseEvent *event)
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4266
4267
4268
4269
4270
4271
4272void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4278
4279
4280
4281void QQuickItem::mouseUngrabEvent()
4287
4288
4289
4290void QQuickItem::touchUngrabEvent()
4295#if QT_CONFIG(wheelevent)
4297
4298
4299
4300
4301
4302
4303void QQuickItem::wheelEvent(QWheelEvent *event)
4310
4311
4312
4313
4314
4315
4316void QQuickItem::touchEvent(QTouchEvent *event)
4322
4323
4324
4325
4326
4327
4328
4329
4330void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4336
4337
4338
4339
4340
4341
4342
4343
4344void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4350
4351
4352
4353
4354
4355
4356
4357
4358void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4363#if QT_CONFIG(quick_draganddrop)
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427void QQuickItem::dropEvent(QDropEvent *event)
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4472
4473
4474
4475
4476
4477
4478
4479QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4481 Q_D(
const QQuickItem);
4486 v = (
bool)(flags() & ItemAcceptsInputMethod);
4489 case Qt::ImAnchorRectangle:
4490 case Qt::ImCursorRectangle:
4492 case Qt::ImCursorPosition:
4493 case Qt::ImSurroundingText:
4494 case Qt::ImCurrentSelection:
4495 case Qt::ImMaximumTextLength:
4496 case Qt::ImAnchorPosition:
4497 case Qt::ImPreferredLanguage:
4498 case Qt::ImReadOnly:
4499 if (d->extra.isAllocated() && d->extra->keyHandler)
4500 v = d->extra->keyHandler->inputMethodQuery(query);
4502 case Qt::ImEnterKeyType:
4503 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4504 v = d->extra->enterKeyAttached->type();
4506 case Qt::ImInputItemClipRectangle:
4507 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4508 QRectF rect = QRectF(0,0, width(), height());
4509 const QQuickItem *par =
this;
4510 while (QQuickItem *parpar = par->parentItem()) {
4511 rect = parpar->mapRectFromItem(par, rect);
4513 rect = rect.intersected(parpar->clipRect());
4516 rect = par->mapRectToScene(rect);
4518 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4520 v = mapRectFromScene(rect);
4531QQuickAnchorLine QQuickItemPrivate::left()
const
4533 Q_Q(
const QQuickItem);
4534 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4537QQuickAnchorLine QQuickItemPrivate::right()
const
4539 Q_Q(
const QQuickItem);
4540 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4543QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4545 Q_Q(
const QQuickItem);
4546 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4549QQuickAnchorLine QQuickItemPrivate::top()
const
4551 Q_Q(
const QQuickItem);
4552 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4555QQuickAnchorLine QQuickItemPrivate::bottom()
const
4557 Q_Q(
const QQuickItem);
4558 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4561QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4563 Q_Q(
const QQuickItem);
4564 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4567QQuickAnchorLine QQuickItemPrivate::baseline()
const
4569 Q_Q(
const QQuickItem);
4570 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595qreal QQuickItem::baselineOffset()
const
4597 Q_D(
const QQuickItem);
4598 return d->baselineOffset;
4601void QQuickItem::setBaselineOffset(qreal offset)
4604 if (offset == d->baselineOffset)
4607 d->baselineOffset = offset;
4609 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4610 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4612 anchor->updateVerticalAnchors();
4615 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4616 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4618 emit baselineOffsetChanged(offset);
4623
4624
4625
4626
4627
4628
4629
4630
4631void QQuickItem::update()
4634 if (!(flags() & ItemHasContents)) {
4636 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4640 d->dirty(QQuickItemPrivate::Content);
4644
4645
4646
4647
4648
4649
4650
4651void QQuickItem::polish()
4654 if (!d->polishScheduled) {
4655 d->polishScheduled =
true;
4657 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4658 bool maybeupdate = p->itemsToPolish.isEmpty();
4659 p->itemsToPolish.append(
this);
4660 if (maybeupdate) d->window->maybeUpdate();
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680void QQuickItem::ensurePolished()
4685#if QT_DEPRECATED_SINCE(6
, 5
)
4686static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4687 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4689 QV4::ExecutionEngine *v4 = args->v4engine();
4690 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4691 v4->throwTypeError();
4695 QV4::Scope scope(v4);
4696 QV4::ScopedValue item(scope, (*args)[0]);
4699 if (!item->isNull()) {
4700 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4702 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4705 if (!(*itemObj) && !item->isNull()) {
4706 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4707 <<
"\" which is neither null nor an Item";
4708 v4->throwTypeError();
4714 if (args->length() == 2) {
4715 QV4::ScopedValue sv(scope, (*args)[1]);
4717 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4718 <<
"\" which is neither a point nor a rect";
4719 v4->throwTypeError();
4722 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4723 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4724 if (v.canConvert<QPointF>()) {
4725 const QPointF p = v.toPointF();
4728 }
else if (v.canConvert<QRectF>()) {
4729 const QRectF r = v.toRectF();
4736 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4737 <<
"\" which is neither a point nor a rect";
4738 v4->throwTypeError();
4742 QV4::ScopedValue vx(scope, (*args)[1]);
4743 QV4::ScopedValue vy(scope, (*args)[2]);
4745 if (!vx->isNumber() || !vy->isNumber()) {
4746 v4->throwTypeError();
4750 *x = vx->asDouble();
4751 *y = vy->asDouble();
4753 if (args->length() > 3) {
4754 QV4::ScopedValue vw(scope, (*args)[3]);
4755 QV4::ScopedValue vh(scope, (*args)[4]);
4756 if (!vw->isNumber() || !vh->isNumber()) {
4757 v4->throwTypeError();
4760 *w = vw->asDouble();
4761 *h = vh->asDouble();
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4788#if QT_DEPRECATED_SINCE(6
, 5
)
4790
4791
4792void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4794 QV4::ExecutionEngine *v4 = args->v4engine();
4795 QV4::Scope scope(v4);
4799 QQuickItem *itemObj;
4800 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4803 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4804 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4806 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4807 args->setReturnValue(rv.asReturnedValue());
4812
4813
4814QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4816 Q_D(
const QQuickItem);
4822 QTransform t = d->itemToWindowTransform();
4823 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4846#if QT_DEPRECATED_SINCE(6
, 5
)
4848
4849
4850void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4852 QV4::ExecutionEngine *v4 = args->v4engine();
4853 QV4::Scope scope(v4);
4857 QQuickItem *itemObj;
4858 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4861 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4862 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4864 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4865 args->setReturnValue(rv.asReturnedValue());
4868static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4870 QV4::ExecutionEngine *v4 = args->v4engine();
4871 if (args->length() != 1 && args->length() != 2) {
4872 v4->throwTypeError();
4876 QV4::Scope scope(v4);
4878 if (args->length() == 1) {
4879 QV4::ScopedValue sv(scope, (*args)[0]);
4881 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4882 <<
"\" which is not a point";
4883 v4->throwTypeError();
4886 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4887 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4888 if (v.canConvert<QPointF>()) {
4889 const QPointF p = v.toPointF();
4893 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4894 <<
"\" which is not a point";
4895 v4->throwTypeError();
4899 QV4::ScopedValue vx(scope, (*args)[0]);
4900 QV4::ScopedValue vy(scope, (*args)[1]);
4902 if (!vx->isNumber() || !vy->isNumber()) {
4903 v4->throwTypeError();
4907 *x = vx->asDouble();
4908 *y = vy->asDouble();
4915
4916
4917
4918
4919
4920
4921
4922
4924
4925
4926void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4928 QV4::ExecutionEngine *v4 = args->v4engine();
4929 QV4::Scope scope(v4);
4932 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4935 QVariant result = mapFromGlobal(QPointF(x, y));
4937 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4938 args->setReturnValue(rv.asReturnedValue());
4943
4944
4945
4946
4947
4948
4949
4950
4952#if QT_DEPRECATED_SINCE(6
, 5
)
4954
4955
4956void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4958 QV4::ExecutionEngine *v4 = args->v4engine();
4959 QV4::Scope scope(v4);
4962 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4965 QVariant result = mapToGlobal(QPointF(x, y));
4967 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4968 args->setReturnValue(rv.asReturnedValue());
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998void QQuickItem::forceActiveFocus()
5000 forceActiveFocus(Qt::OtherFocusReason);
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5028void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5030 setFocus(
true, reason);
5031 QQuickItem *parent = parentItem();
5032 QQuickItem *scope =
nullptr;
5034 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5035 parent->setFocus(
true, reason);
5039 parent = parent->parentItem();
5044
5045
5046
5047
5048
5049
5050
5051
5052
5054
5055
5056
5057
5058
5060QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5062 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5066
5067
5068
5069
5070
5071
5072
5074
5075
5076
5077
5078
5079QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5081 const QList<QQuickItem *> children = childItems();
5082 for (
int i = children.size()-1; i >= 0; --i) {
5083 QQuickItem *child = children.at(i);
5085 QPointF point = mapToItem(child, QPointF(x, y));
5086 if (child->isVisible() && child->contains(point))
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133void QQuickItem::dumpItemTree()
const
5135 Q_D(
const QQuickItem);
5139void QQuickItemPrivate::dumpItemTree(
int indent)
const
5141 Q_Q(
const QQuickItem);
5143 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5144 qDebug().nospace().noquote() << indentStr <<
5145#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5146 const_cast<QQuickItem *>(q);
5150 if (extra.isAllocated()) {
5151 for (
const auto handler : extra->pointerHandlers)
5152 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5154 for (
const QQuickItem *ch : childItems) {
5155 auto itemPriv = QQuickItemPrivate::get(ch);
5156 itemPriv->dumpItemTree(indent + 1);
5160QQmlListProperty<QObject> QQuickItemPrivate::resources()
5164 QQmlListProperty<QObject> result;
5165 result.object = q_func();
5166 result.append = QQuickItemPrivate::resources_append;
5167 result.count = QQuickItemPrivate::resources_count;
5168 result.at = QQuickItemPrivate::resources_at;
5169 result.clear = QQuickItemPrivate::resources_clear;
5170 result.removeLast = QQuickItemPrivate::resources_removeLast;
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5188
5189
5190
5191QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5195 QQmlListProperty<QQuickItem> result;
5196 result.object = q_func();
5197 result.append = QQuickItemPrivate::children_append;
5198 result.count = QQuickItemPrivate::children_count;
5199 result.at = QQuickItemPrivate::children_at;
5200 result.clear = QQuickItemPrivate::children_clear;
5201 result.removeLast = QQuickItemPrivate::children_removeLast;
5206
5207
5208
5209
5210
5212
5213
5214
5215QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5217 return QQmlListProperty<QQuickItem>(q_func(),
5219 QQuickItemPrivate::visibleChildren_count,
5220 QQuickItemPrivate::visibleChildren_at);
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
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5261
5262
5263
5264QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5266 return _states()->statesProperty();
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5298
5299
5300
5301QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5303 return _states()->transitionsProperty();
5306QString QQuickItemPrivate::state()
const
5311 return _stateGroup->state();
5314void QQuickItemPrivate::setState(
const QString &state)
5316 _states()->setState(state);
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341QString QQuickItem::state()
const
5343 Q_D(
const QQuickItem);
5347void QQuickItem::setState(
const QString &state)
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5366
5367
5368
5370
5371
5372QQmlListProperty<QQuickTransform> QQuickItem::transform()
5374 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5375 QQuickItemPrivate::transform_count,
5376 QQuickItemPrivate::transform_at,
5377 QQuickItemPrivate::transform_clear);
5381
5382
5383
5384
5385void QQuickItem::classBegin()
5388 d->componentComplete =
false;
5390 d->_stateGroup->classBegin();
5392 d->_anchors->classBegin();
5393#if QT_CONFIG(quick_shadereffect)
5394 if (d->extra.isAllocated() && d->extra->layer)
5395 d->extra->layer->classBegin();
5400
5401
5402
5403
5404void QQuickItem::componentComplete()
5407 d->componentComplete =
true;
5409 d->_stateGroup->componentComplete();
5411 d->_anchors->componentComplete();
5412 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5415 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5416 safeArea->updateSafeArea();
5418 if (d->extra.isAllocated()) {
5419#if QT_CONFIG(quick_shadereffect)
5420 if (d->extra->layer)
5421 d->extra->layer->componentComplete();
5424 if (d->extra->keyHandler)
5425 d->extra->keyHandler->componentComplete();
5427 if (d->extra->contents)
5428 d->extra->contents->complete();
5431 if (d->window && d->dirtyAttributes) {
5432 d->addToDirtyList();
5433 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5436#if QT_CONFIG(accessibility)
5437 if (d->isAccessible && d->effectiveVisible) {
5438 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5439 QAccessible::updateAccessibility(&ev);
5444QQuickStateGroup *QQuickItemPrivate::_states()
5448 _stateGroup =
new QQuickStateGroup;
5449 if (!componentComplete)
5450 _stateGroup->classBegin();
5451 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5452 q, QQuickItem, SIGNAL(stateChanged(QString)));
5458QPointF QQuickItemPrivate::computeTransformOrigin()
const
5462 case QQuickItem::TopLeft:
5463 return QPointF(0, 0);
5464 case QQuickItem::Top:
5465 return QPointF(width / 2., 0);
5466 case QQuickItem::TopRight:
5467 return QPointF(width, 0);
5468 case QQuickItem::Left:
5469 return QPointF(0, height / 2.);
5470 case QQuickItem::Center:
5471 return QPointF(width / 2., height / 2.);
5472 case QQuickItem::Right:
5473 return QPointF(width, height / 2.);
5474 case QQuickItem::BottomLeft:
5475 return QPointF(0, height);
5476 case QQuickItem::Bottom:
5477 return QPointF(width / 2., height);
5478 case QQuickItem::BottomRight:
5479 return QPointF(width, height);
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5501#if QT_CONFIG(quick_shadereffect)
5502 if (q == transformedItem) {
5503 if (extra.isAllocated() && extra->layer)
5504 extra->layer->updateMatrix();
5508 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5510 bool childWantsIt =
false;
5511 if (subtreeTransformChangedEnabled) {
5514 const auto children = paintOrderChildItems();
5515 for (QQuickItem *child : children)
5516 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5519 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5520 const bool ret = childWantsIt || thisWantsIt;
5521 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5522 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5523 subtreeTransformChangedEnabled =
false;
5527 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5528 dirty(QQuickItemPrivate::Clip);
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5551 const QPointF &startPos,
5552 const QVector2D &activeTranslation,
5555 qreal startRotation,
5556 qreal activeRotation)
5559 QVector3D xformOrigin(q->transformOriginPoint());
5560 QMatrix4x4 startMatrix;
5561 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5562 startMatrix.translate(xformOrigin);
5563 startMatrix.scale(
float(startScale));
5564 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5565 startMatrix.translate(-xformOrigin);
5567 const QVector3D centroidParentVector(centroidParentPos);
5569 mat.translate(centroidParentVector);
5570 mat.rotate(
float(activeRotation), 0, 0, 1);
5571 mat.scale(
float(activeScale));
5572 mat.translate(-centroidParentVector);
5573 mat.translate(QVector3D(activeTranslation));
5575 mat = mat * startMatrix;
5577 QPointF xformOriginPoint = q->transformOriginPoint();
5578 QPointF pos = mat.map(xformOriginPoint);
5579 pos -= xformOriginPoint;
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5609 if (maybeHasSubsceneDeliveryAgent) {
5610 QQuickItemPrivate *p =
this;
5612 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5617 maybeHasSubsceneDeliveryAgent =
false;
5620 if (p->extra.isAllocated()) {
5621 if (
auto da = p->extra->subsceneDeliveryAgent)
5624 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5628 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5631 return QQuickWindowPrivate::get(window)->deliveryAgent;
5635QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5637 auto da = deliveryAgent();
5638 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5642
5643
5644
5645
5646
5647
5648
5649QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5655 maybeHasSubsceneDeliveryAgent =
true;
5656 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5657 return extra->subsceneDeliveryAgent;
5658 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5659 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5662 q->setFlag(QQuickItem::ItemIsFocusScope);
5663 return extra->subsceneDeliveryAgent;
5666bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5668 if (!extra.isAllocated() || !extra->keyHandler)
5674 if (e->type() == QEvent::KeyPress)
5675 extra->keyHandler->keyPressed(e, post);
5677 extra->keyHandler->keyReleased(e, post);
5679 return e->isAccepted();
5682void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5685 const auto eventType = event->type();
5686 const bool focusAccepted = setFocusIfNeeded(eventType);
5688 switch (eventType) {
5689 case QEvent::MouseButtonPress:
5690 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5692 case QEvent::MouseButtonRelease:
5693 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5695 case QEvent::MouseButtonDblClick:
5696 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5698#if QT_CONFIG(wheelevent)
5700 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5703 case QEvent::TouchBegin:
5704 case QEvent::TouchUpdate:
5705 case QEvent::TouchEnd:
5706 case QEvent::TouchCancel:
5707 q->touchEvent(
static_cast<QTouchEvent *>(event));
5717void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5721 Q_ASSERT(e->isAccepted());
5722 if (filterKeyEvent(e,
false))
5727 if (e->type() == QEvent::KeyPress)
5728 q->keyPressEvent(e);
5730 q->keyReleaseEvent(e);
5732 if (e->isAccepted())
5735 if (filterKeyEvent(e,
true) || !q->window())
5739 if (e->type() == QEvent::KeyPress &&
5740 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5742 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5743 if (e->key() == Qt::Key_Backtab
5744 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5745 res = QQuickItemPrivate::focusNextPrev(q,
false);
5746 else if (e->key() == Qt::Key_Tab)
5747 res = QQuickItemPrivate::focusNextPrev(q,
true);
5749 e->setAccepted(
true);
5755void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5759 Q_ASSERT(e->isAccepted());
5760 if (extra.isAllocated() && extra->keyHandler) {
5761 extra->keyHandler->inputMethodEvent(e,
false);
5763 if (e->isAccepted())
5769 q->inputMethodEvent(e);
5771 if (e->isAccepted())
5774 if (extra.isAllocated() && extra->keyHandler) {
5777 extra->keyHandler->inputMethodEvent(e,
true);
5782void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5784 if (extra.isAllocated() && extra->keyHandler)
5785 extra->keyHandler->shortcutOverrideEvent(event);
5790bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5792 if (!hasPointerHandlers())
5794 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5795 if (handler->wantsEventPoint(event, point))
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5817 bool delivered =
false;
5818 if (extra.isAllocated()) {
5819 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5820 bool avoidThisHandler =
false;
5821 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5822 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5823 avoidThisHandler =
true;
5824 }
else if (avoidGrabbers) {
5825 for (
auto &p : event->points()) {
5826 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5827 avoidThisHandler =
true;
5832 if (!avoidThisHandler &&
5833 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5834 handler->handlePointerEvent(event);
5842#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5843bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5845bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5848 if (extra.isAllocated() && extra->contextMenu)
5849 return extra->contextMenu->event(event);
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5869 if (change == ItemSceneChange)
5870 emit windowChanged(value.window);
5875
5876
5877
5878void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5880 if (hasActiveFocus())
5881 QGuiApplication::inputMethod()->update(queries);
5886
5887
5888
5889QRectF QQuickItem::boundingRect()
const
5891 Q_D(
const QQuickItem);
5892 return QRectF(0, 0, d->width, d->height);
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916QRectF QQuickItem::clipRect()
const
5918 Q_D(
const QQuickItem);
5919 QRectF ret(0, 0, d->width, d->height);
5920 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5921 if (QQuickItem *viewport = viewportItem()) {
5924 if (viewport ==
this)
5926 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5927 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5928 return mappedViewportRect.intersected(ret);
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945QQuickItem *QQuickItem::viewportItem()
const
5947 if (flags().testFlag(ItemObservesViewport)) {
5948 QQuickItem *par = parentItem();
5950 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
5952 par = par->parentItem();
5955 return (window() ? window()->contentItem() :
nullptr);
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5980
5981
5982
5983
5984
5985
5986
5987
5988QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
5990 Q_D(
const QQuickItem);
5994void QQuickItem::setTransformOrigin(TransformOrigin origin)
5997 if (origin == d->origin())
6000 d->extra.value().origin = origin;
6001 d->dirty(QQuickItemPrivate::TransformOrigin);
6003 emit transformOriginChanged(d->origin());
6007
6008
6009
6011
6012
6013QPointF QQuickItem::transformOriginPoint()
const
6015 Q_D(
const QQuickItem);
6016 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6017 return d->extra->userTransformOriginPoint;
6018 return d->computeTransformOrigin();
6022
6023
6024void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6027 if (d->extra.value().userTransformOriginPoint == point)
6030 d->extra->userTransformOriginPoint = point;
6031 d->dirty(QQuickItemPrivate::TransformOrigin);
6035
6036
6037
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
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188qreal QQuickItem::z()
const
6190 Q_D(
const QQuickItem);
6194void QQuickItem::setZ(qreal v)
6200 d->extra.value().z = v;
6202 d->dirty(QQuickItemPrivate::ZValue);
6203 if (d->parentItem) {
6204 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6205 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6210#if QT_CONFIG(quick_shadereffect)
6211 if (d->extra.isAllocated() && d->extra->layer)
6212 d->extra->layer->updateZ();
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
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268qreal QQuickItem::rotation()
const
6270 Q_D(
const QQuickItem);
6271 return d->rotation();
6274void QQuickItem::setRotation(qreal r)
6277 if (d->rotation() == r)
6280 d->extra.value().rotation = r;
6282 d->dirty(QQuickItemPrivate::BasicTransform);
6284 d->itemChange(ItemRotationHasChanged, r);
6286 emit rotationChanged();
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
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
6368qreal QQuickItem::scale()
const
6370 Q_D(
const QQuickItem);
6374void QQuickItem::setScale(qreal s)
6377 if (d->scale() == s)
6380 d->extra.value().scale = s;
6382 d->dirty(QQuickItemPrivate::BasicTransform);
6384 d->itemChange(ItemScaleHasChanged, s);
6386 emit scaleChanged();
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
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499qreal QQuickItem::opacity()
const
6501 Q_D(
const QQuickItem);
6502 return d->opacity();
6505void QQuickItem::setOpacity(qreal newOpacity)
6508 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6509 if (d->opacity() == o)
6512 d->extra.value().opacity = o;
6514 d->dirty(QQuickItemPrivate::OpacityValue);
6516 d->itemChange(ItemOpacityHasChanged, o);
6518 emit opacityChanged();
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585bool QQuickItem::isVisible()
const
6587 Q_D(
const QQuickItem);
6588 return d->effectiveVisible;
6591void QQuickItemPrivate::setVisible(
bool visible)
6593 if (visible == explicitVisible)
6596 explicitVisible = visible;
6598 dirty(QQuickItemPrivate::Visible);
6600 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6601 if (childVisibilityChanged && parentItem)
6602 emit parentItem->visibleChildrenChanged();
6605void QQuickItem::setVisible(
bool v)
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660bool QQuickItem::isEnabled()
const
6662 Q_D(
const QQuickItem);
6663 return d->effectiveEnable;
6666void QQuickItem::setEnabled(
bool e)
6669 if (e == d->explicitEnable)
6672 d->explicitEnable = e;
6674 QQuickItem *scope = parentItem();
6675 while (scope && !scope->isFocusScope())
6676 scope = scope->parentItem();
6678 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6681bool QQuickItemPrivate::calcEffectiveVisible()
const
6684 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6687bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6691 if (newEffectiveVisible && !explicitVisible) {
6696 if (newEffectiveVisible == effectiveVisible) {
6701 effectiveVisible = newEffectiveVisible;
6704 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6706 if (
auto agent = deliveryAgentPrivate())
6707 agent->removeGrabber(q,
true,
true,
true);
6710 bool childVisibilityChanged =
false;
6711 for (
int ii = 0; ii < childItems.size(); ++ii)
6712 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6714 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6715#if QT_CONFIG(accessibility)
6717 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6718 QAccessible::updateAccessibility(&ev);
6721 if (!inDestructor) {
6722 emit q->visibleChanged();
6723 if (childVisibilityChanged)
6724 emit q->visibleChildrenChanged();
6730bool QQuickItemPrivate::calcEffectiveEnable()
const
6735 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6738void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6742 if (newEffectiveEnable && !explicitEnable) {
6747 if (newEffectiveEnable == effectiveEnable) {
6752 effectiveEnable = newEffectiveEnable;
6754 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6756 da->removeGrabber(q,
true,
true,
true);
6757 if (scope && !effectiveEnable && activeFocus) {
6758 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6759 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6760 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6764 for (
int ii = 0; ii < childItems.size(); ++ii) {
6765 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6766 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6769 if (scope && effectiveEnable && focus && da) {
6770 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6771 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6772 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6775 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6776#if QT_CONFIG(accessibility)
6778 QAccessible::State changedState;
6779 changedState.disabled =
true;
6780 changedState.focusable =
true;
6781 QAccessibleStateChangeEvent ev(q, changedState);
6782 QAccessible::updateAccessibility(&ev);
6785 emit q->enabledChanged();
6788bool QQuickItemPrivate::isTransparentForPositioner()
const
6790 return extra.isAllocated() && extra.value().transparentForPositioner;
6793void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6795 extra.value().transparentForPositioner = transparent;
6799QString QQuickItemPrivate::dirtyToString()
const
6801#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6803 rv.append(QLatin1Char('|'));
6804 rv.append(QLatin1String(#value)); \
6805}
6832void QQuickItemPrivate::dirty(DirtyType type)
6835 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6836 dirtyAttributes |= type;
6837 if (window && componentComplete) {
6839 QQuickWindowPrivate::get(window)->dirtyItem(q);
6842 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6843 transformChanged(q);
6846void QQuickItemPrivate::addToDirtyList()
6851 if (!prevDirtyItem) {
6852 Q_ASSERT(!nextDirtyItem);
6854 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
6855 nextDirtyItem = p->dirtyItemList;
6856 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
6857 prevDirtyItem = &p->dirtyItemList;
6858 p->dirtyItemList = q;
6861 Q_ASSERT(prevDirtyItem);
6864void QQuickItemPrivate::removeFromDirtyList()
6866 if (prevDirtyItem) {
6867 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
6868 *prevDirtyItem = nextDirtyItem;
6869 prevDirtyItem =
nullptr;
6870 nextDirtyItem =
nullptr;
6872 Q_ASSERT(!prevDirtyItem);
6873 Q_ASSERT(!nextDirtyItem);
6876void QQuickItemPrivate::refFromEffectItem(
bool hide)
6878 ++extra.value().effectRefCount;
6879 if (extra->effectRefCount == 1) {
6880 dirty(EffectReference);
6882 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6885 if (++extra->hideRefCount == 1)
6886 dirty(HideReference);
6888 recursiveRefFromEffectItem(1);
6891void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
6896 extra.value().recursiveEffectRefCount += refs;
6897 for (
int ii = 0; ii < childItems.size(); ++ii) {
6898 QQuickItem *child = childItems.at(ii);
6899 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
6903 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
6907void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
6909 Q_ASSERT(extra->effectRefCount);
6910 --extra->effectRefCount;
6911 if (extra->effectRefCount == 0) {
6912 dirty(EffectReference);
6914 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6917 if (--extra->hideRefCount == 0)
6918 dirty(HideReference);
6920 recursiveRefFromEffectItem(-1);
6923void QQuickItemPrivate::setCulled(
bool cull)
6929 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
6930 dirty(HideReference);
6933void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
6937 case QQuickItem::ItemChildAddedChange: {
6938 q->itemChange(change, data);
6944 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
6945 if (!subtreeTransformChangedEnabled) {
6946 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
6947 subtreeTransformChangedEnabled =
true;
6949 enableSubtreeChangeNotificationsForParentHierachy();
6951 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
6954 case QQuickItem::ItemChildRemovedChange: {
6955 q->itemChange(change, data);
6956 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
6959 case QQuickItem::ItemSceneChange:
6960 q->itemChange(change, data);
6962 case QQuickItem::ItemVisibleHasChanged: {
6963 q->itemChange(change, data);
6964 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
6967 case QQuickItem::ItemEnabledHasChanged: {
6968 q->itemChange(change, data);
6969 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
6972 case QQuickItem::ItemParentHasChanged: {
6973 q->itemChange(change, data);
6974 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
6977 case QQuickItem::ItemOpacityHasChanged: {
6978 q->itemChange(change, data);
6979 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
6982 case QQuickItem::ItemActiveFocusHasChanged:
6983 q->itemChange(change, data);
6985 case QQuickItem::ItemRotationHasChanged: {
6986 q->itemChange(change, data);
6987 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
6990 case QQuickItem::ItemScaleHasChanged: {
6991 q->itemChange(change, data);
6992 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
6995 case QQuickItem::ItemTransformHasChanged: {
6996 q->itemChange(change, data);
6997 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7000 case QQuickItem::ItemAntialiasingHasChanged:
7002 case QQuickItem::ItemDevicePixelRatioHasChanged:
7003 q->itemChange(change, data);
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031bool QQuickItem::smooth()
const
7033 Q_D(
const QQuickItem);
7036void QQuickItem::setSmooth(
bool smooth)
7039 if (d->smooth == smooth)
7043 d->dirty(QQuickItemPrivate::Smooth);
7045 emit smoothChanged(smooth);
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7087bool QQuickItem::activeFocusOnTab()
const
7089 Q_D(
const QQuickItem);
7090 return d->activeFocusOnTab;
7092void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7095 if (d->activeFocusOnTab == activeFocusOnTab)
7099 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7100 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7105 d->activeFocusOnTab = activeFocusOnTab;
7107 emit activeFocusOnTabChanged(activeFocusOnTab);
7111
7112
7113
7114
7115
7116
7117
7118
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129bool QQuickItem::antialiasing()
const
7131 Q_D(
const QQuickItem);
7132 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7135void QQuickItem::setAntialiasing(
bool aa)
7139 if (!d->antialiasingValid) {
7140 d->antialiasingValid =
true;
7141 d->antialiasing = d->implicitAntialiasing;
7144 if (aa == d->antialiasing)
7147 d->antialiasing = aa;
7148 d->dirty(QQuickItemPrivate::Antialiasing);
7150 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7152 emit antialiasingChanged(antialiasing());
7155void QQuickItem::resetAntialiasing()
7158 if (!d->antialiasingValid)
7161 d->antialiasingValid =
false;
7163 if (d->implicitAntialiasing != d->antialiasing)
7164 emit antialiasingChanged(antialiasing());
7167void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7170 bool prev = q->antialiasing();
7171 implicitAntialiasing = antialiasing;
7172 if (componentComplete && (q->antialiasing() != prev))
7173 emit q->antialiasingChanged(q->antialiasing());
7177
7178
7179
7180
7181QQuickItem::Flags QQuickItem::flags()
const
7183 Q_D(
const QQuickItem);
7184 return (QQuickItem::Flags)d->flags;
7188
7189
7190
7191
7192
7193
7194
7195void QQuickItem::setFlag(Flag flag,
bool enabled)
7199 setFlags((Flags)(d->flags | (quint32)flag));
7201 setFlags((Flags)(d->flags & ~(quint32)flag));
7205 if (enabled && flag == ItemObservesViewport)
7206 d->enableSubtreeChangeNotificationsForParentHierachy();
7209void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7213 QQuickItem *par = q->parentItem();
7215 auto parPriv = QQuickItemPrivate::get(par);
7216 if (!parPriv->subtreeTransformChangedEnabled)
7217 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7218 parPriv->subtreeTransformChangedEnabled =
true;
7219 par = par->parentItem();
7224
7225
7226
7227
7228void QQuickItem::setFlags(Flags flags)
7232 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7233 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7234 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7235 flags &= ~ItemIsFocusScope;
7236 }
else if (d->flags & ItemIsFocusScope) {
7237 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7238 flags |= ItemIsFocusScope;
7242 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7243 d->dirty(QQuickItemPrivate::Clip);
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7264
7265
7266
7267
7269
7270
7271
7272
7273qreal QQuickItem::x()
const
7275 Q_D(
const QQuickItem);
7279qreal QQuickItem::y()
const
7281 Q_D(
const QQuickItem);
7286
7287
7288QPointF QQuickItem::position()
const
7290 Q_D(
const QQuickItem);
7291 return QPointF(d->x, d->y);
7294void QQuickItem::setX(qreal v)
7298
7299
7300
7301
7302
7303
7304
7305
7306 d->x.removeBindingUnlessInWrapper();
7310 const qreal oldx = d->x.valueBypassingBindings();
7314 d->x.setValueBypassingBindings(v);
7316 d->dirty(QQuickItemPrivate::Position);
7318 const qreal y = d->y.valueBypassingBindings();
7319 const qreal w = d->width.valueBypassingBindings();
7320 const qreal h = d->height.valueBypassingBindings();
7321 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7324void QQuickItem::setY(qreal v)
7327 d->y.removeBindingUnlessInWrapper();
7331 const qreal oldy = d->y.valueBypassingBindings();
7335 d->y.setValueBypassingBindings(v);
7337 d->dirty(QQuickItemPrivate::Position);
7341 const qreal x = d->x.valueBypassingBindings();
7342 const qreal w = d->width.valueBypassingBindings();
7343 const qreal h = d->height.valueBypassingBindings();
7344 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7348
7349
7350void QQuickItem::setPosition(
const QPointF &pos)
7354 const qreal oldx = d->x.valueBypassingBindings();
7355 const qreal oldy = d->y.valueBypassingBindings();
7357 if (QPointF(oldx, oldy) == pos)
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7373 d->x.setValueBypassingBindings(pos.x());
7374 d->y.setValueBypassingBindings(pos.y());
7376 d->dirty(QQuickItemPrivate::Position);
7378 const qreal w = d->width.valueBypassingBindings();
7379 const qreal h = d->height.valueBypassingBindings();
7380 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7384
7385
7386QBindable<qreal> QQuickItem::bindableX()
7388 return QBindable<qreal>(&d_func()->x);
7391QBindable<qreal> QQuickItem::bindableY()
7393 return QBindable<qreal>(&d_func()->y);
7397
7398
7399
7400
7401qreal QQuickItem::width()
const
7403 Q_D(
const QQuickItem);
7407void QQuickItem::setWidth(qreal w)
7410 d->width.removeBindingUnlessInWrapper();
7414 d->widthValidFlag =
true;
7415 const qreal oldWidth = d->width.valueBypassingBindings();
7419 d->width.setValueBypassingBindings(w);
7421 d->dirty(QQuickItemPrivate::Size);
7423 const qreal x = d->x.valueBypassingBindings();
7424 const qreal y = d->y.valueBypassingBindings();
7425 const qreal h = d->height.valueBypassingBindings();
7426 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7429void QQuickItem::resetWidth()
7432 d->width.takeBinding();
7433 d->widthValidFlag =
false;
7434 setImplicitWidth(implicitWidth());
7437void QQuickItemPrivate::implicitWidthChanged()
7440 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7441 emit q->implicitWidthChanged();
7444qreal QQuickItemPrivate::getImplicitWidth()
const
7446 return implicitWidth;
7449
7450
7451qreal QQuickItem::implicitWidth()
const
7453 Q_D(
const QQuickItem);
7454 return d->getImplicitWidth();
7457QBindable<qreal> QQuickItem::bindableWidth()
7459 return QBindable<qreal>(&d_func()->width);
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544void QQuickItem::setImplicitWidth(qreal w)
7547 bool changed = w != d->implicitWidth;
7548 d->implicitWidth = w;
7550 if (d->width.valueBypassingBindings() == w || widthValid()) {
7552 d->implicitWidthChanged();
7553 if (d->width.valueBypassingBindings() == w || widthValid())
7558 const qreal oldWidth = d->width.valueBypassingBindings();
7559 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7561 d->width.setValueBypassingBindings(w);
7563 d->dirty(QQuickItemPrivate::Size);
7565 const qreal x = d->x.valueBypassingBindings();
7566 const qreal y = d->y.valueBypassingBindings();
7567 const qreal width = w;
7568 const qreal height = d->height.valueBypassingBindings();
7569 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7572 d->implicitWidthChanged();
7576
7577
7578bool QQuickItem::widthValid()
const
7580 Q_D(
const QQuickItem);
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7598 return d->widthValid();
7602
7603
7604
7605
7606qreal QQuickItem::height()
const
7608 Q_D(
const QQuickItem);
7612void QQuickItem::setHeight(qreal h)
7618 d->height.removeBindingUnlessInWrapper();
7622 d->heightValidFlag =
true;
7623 const qreal oldHeight = d->height.valueBypassingBindings();
7627 d->height.setValueBypassingBindings(h);
7629 d->dirty(QQuickItemPrivate::Size);
7631 const qreal x = d->x.valueBypassingBindings();
7632 const qreal y = d->y.valueBypassingBindings();
7633 const qreal w = d->width.valueBypassingBindings();
7634 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7637void QQuickItem::resetHeight()
7643 d->height.takeBinding();
7644 d->heightValidFlag =
false;
7645 setImplicitHeight(implicitHeight());
7648void QQuickItemPrivate::implicitHeightChanged()
7651 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7652 emit q->implicitHeightChanged();
7655qreal QQuickItemPrivate::getImplicitHeight()
const
7657 return implicitHeight;
7660qreal QQuickItem::implicitHeight()
const
7662 Q_D(
const QQuickItem);
7663 return d->getImplicitHeight();
7666QBindable<qreal> QQuickItem::bindableHeight()
7668 return QBindable<qreal>(&d_func()->height);
7671void QQuickItem::setImplicitHeight(qreal h)
7674 bool changed = h != d->implicitHeight;
7675 d->implicitHeight = h;
7676 if (d->height.valueBypassingBindings() == h || heightValid()) {
7678 d->implicitHeightChanged();
7679 if (d->height.valueBypassingBindings() == h || heightValid())
7684 const qreal oldHeight = d->height.valueBypassingBindings();
7685 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7687 d->height.setValueBypassingBindings(h);
7689 d->dirty(QQuickItemPrivate::Size);
7691 const qreal x = d->x.valueBypassingBindings();
7692 const qreal y = d->y.valueBypassingBindings();
7693 const qreal width = d->width.valueBypassingBindings();
7694 const qreal height = d->height.valueBypassingBindings();
7695 geometryChange(QRectF(x, y, width, height),
7696 QRectF(x, y, width, oldHeight));
7699 d->implicitHeightChanged();
7703
7704
7705void QQuickItem::setImplicitSize(qreal w, qreal h)
7708 bool wChanged = w != d->implicitWidth;
7709 bool hChanged = h != d->implicitHeight;
7711 d->implicitWidth = w;
7712 d->implicitHeight = h;
7716 qreal width = d->width.valueBypassingBindings();
7717 qreal height = d->height.valueBypassingBindings();
7718 if (width == w || widthValid()) {
7720 d->implicitWidthChanged();
7721 wDone = width == w || widthValid();
7724 if (height == h || heightValid()) {
7726 d->implicitHeightChanged();
7727 hDone = height == h || heightValid();
7733 const qreal oldWidth = width;
7734 const qreal oldHeight = height;
7737 d->width.setValueBypassingBindings(w);
7741 d->height.setValueBypassingBindings(h);
7744 d->dirty(QQuickItemPrivate::Size);
7746 const qreal x = d->x.valueBypassingBindings();
7747 const qreal y = d->y.valueBypassingBindings();
7748 geometryChange(QRectF(x, y, width, height),
7749 QRectF(x, y, oldWidth, oldHeight));
7751 if (!wDone && wChanged)
7752 d->implicitWidthChanged();
7753 if (!hDone && hChanged)
7754 d->implicitHeightChanged();
7758
7759
7760bool QQuickItem::heightValid()
const
7762 Q_D(
const QQuickItem);
7763 return d->heightValid();
7767
7768
7769
7770
7771
7772
7774QSizeF QQuickItem::size()
const
7776 Q_D(
const QQuickItem);
7777 return QSizeF(d->width, d->height);
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791void QQuickItem::setSize(
const QSizeF &size)
7794 d->heightValidFlag =
true;
7795 d->widthValidFlag =
true;
7797 const qreal oldHeight = d->height.valueBypassingBindings();
7798 const qreal oldWidth = d->width.valueBypassingBindings();
7800 if (oldWidth == size.width() && oldHeight == size.height())
7803 d->height.setValueBypassingBindings(size.height());
7804 d->width.setValueBypassingBindings(size.width());
7806 d->dirty(QQuickItemPrivate::Size);
7808 const qreal x = d->x.valueBypassingBindings();
7809 const qreal y = d->y.valueBypassingBindings();
7810 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
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
7849
7850
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
7882bool QQuickItem::hasActiveFocus()
const
7884 Q_D(
const QQuickItem);
7885 return d->activeFocus;
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976bool QQuickItem::hasFocus()
const
7978 Q_D(
const QQuickItem);
7982void QQuickItem::setFocus(
bool focus)
7984 setFocus(focus, Qt::OtherFocusReason);
7987void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
7991 QQuickItem *scope = parentItem();
7992 while (scope && !scope->isFocusScope() && scope->parentItem())
7993 scope = scope->parentItem();
7995 if (d->focus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
7998 bool notifyListeners =
false;
7999 if (d->window || d->parentItem) {
8001 auto da = d->deliveryAgentPrivate();
8004 da->setFocusInScope(scope,
this, reason);
8006 da->clearFocusInScope(scope,
this, reason);
8010 QVarLengthArray<QQuickItem *, 20> changed;
8011 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8012 if (oldSubFocusItem) {
8013 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8014 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8015 changed << oldSubFocusItem;
8016 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8017 QQuickItemPrivate::get(scope)->focus =
false;
8020 d->updateSubFocusItem(scope, focus);
8024 notifyListeners =
true;
8025 emit focusChanged(focus);
8027 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8030 QVarLengthArray<QQuickItem *, 20> changed;
8031 QQuickItem *oldSubFocusItem = d->subFocusItem;
8032 if (!isFocusScope() && oldSubFocusItem) {
8033 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8034 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8035 changed << oldSubFocusItem;
8040 notifyListeners =
true;
8041 emit focusChanged(focus);
8043 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8045 if (notifyListeners)
8046 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8050
8051
8052bool QQuickItem::isFocusScope()
const
8054 return flags() & ItemIsFocusScope;
8058
8059
8060
8061
8062
8063QQuickItem *QQuickItem::scopedFocusItem()
const
8065 Q_D(
const QQuickItem);
8066 if (!isFocusScope())
8069 return d->subFocusItem;
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8087
8088
8089
8090
8091
8092
8093Qt::FocusPolicy QQuickItem::focusPolicy()
const
8095 Q_D(
const QQuickItem);
8096 uint policy = d->focusPolicy;
8097 if (activeFocusOnTab())
8098 policy |= Qt::TabFocus;
8099 return static_cast<Qt::FocusPolicy>(policy);
8103
8104
8105
8106
8107void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8110 if (d->focusPolicy == policy)
8113 d->focusPolicy = policy;
8114 setActiveFocusOnTab(policy & Qt::TabFocus);
8115 emit focusPolicyChanged(policy);
8119
8120
8121
8122
8123
8124
8125
8126bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8128 if (!child || child ==
this)
8130 const QQuickItem *ancestor = child;
8131 while ((ancestor = ancestor->parentItem())) {
8132 if (ancestor ==
this)
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8151 Q_D(
const QQuickItem);
8152 return d->acceptedMouseButtons();
8156
8157
8158
8159
8160
8161
8162
8163
8164void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8167 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8169 buttons &= ~Qt::LeftButton;
8170 if (buttons || d->extra.isAllocated()) {
8171 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8172 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187bool QQuickItem::filtersChildMouseEvents()
const
8189 Q_D(
const QQuickItem);
8190 return d->filtersChildMouseEvents;
8194
8195
8196
8197
8198
8199
8200
8201
8202void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8205 d->filtersChildMouseEvents = filter;
8209
8210
8211bool QQuickItem::isUnderMouse()
const
8213 Q_D(
const QQuickItem);
8220 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8223 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8224 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8228
8229
8230
8231
8232
8233
8234
8235bool QQuickItem::acceptHoverEvents()
const
8237 Q_D(
const QQuickItem);
8238 return d->hoverEnabled;
8242
8243
8244
8245
8246
8247void QQuickItem::setAcceptHoverEvents(
bool enabled)
8254 d->hoverEnabled = enabled;
8260 d->setHasHoverInChild(enabled);
8264 d->dirty(QQuickItemPrivate::Content);
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277bool QQuickItem::acceptTouchEvents()
const
8279 Q_D(
const QQuickItem);
8280 return d->touchEnabled;
8284
8285
8286
8287
8288
8289
8290
8291void QQuickItem::setAcceptTouchEvents(
bool enabled)
8294 d->touchEnabled = enabled;
8297void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8299#if QT_CONFIG(cursor)
8304 if (!hc && subtreeCursorEnabled) {
8307 for (QQuickItem *otherChild : std::as_const(childItems)) {
8308 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8309 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8314 subtreeCursorEnabled = hc;
8315 QQuickItem *parent = q->parentItem();
8317 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8318 parentPrivate->setHasCursorInChild(hc);
8325void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8331 if (!hasHover && subtreeHoverEnabled) {
8334 if (hasEnabledHoverHandlers())
8337 for (QQuickItem *otherChild : std::as_const(childItems)) {
8338 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8339 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8341 if (otherChildPrivate->hasEnabledHoverHandlers())
8346 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8347 subtreeHoverEnabled = hasHover;
8348 QQuickItem *parent = q->parentItem();
8350 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8351 parentPrivate->setHasHoverInChild(hasHover);
8355#if QT_CONFIG(cursor)
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8371QCursor QQuickItem::cursor()
const
8373 Q_D(
const QQuickItem);
8374 return d->extra.isAllocated()
8380
8381
8382
8383
8385void QQuickItem::setCursor(
const QCursor &cursor)
8389 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8390 qCDebug(lcHoverTrace) << oldShape <<
"->" << cursor.shape();
8392 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8393 d->extra.value().cursor = cursor;
8395 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8396 QWindow *window = renderWindow ? renderWindow : d->window;
8397 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8398 window->setCursor(cursor);
8402 QPointF updateCursorPos;
8403 if (!d->hasCursor) {
8404 d->hasCursor =
true;
8406 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8407 QWindow *window = renderWindow ? renderWindow : d->window;
8408 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8409 if (contains(mapFromScene(pos)))
8410 updateCursorPos = pos;
8413 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8414 if (!updateCursorPos.isNull())
8415 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8419
8420
8421
8422
8424void QQuickItem::unsetCursor()
8427 qCDebug(lcHoverTrace) <<
"clearing cursor";
8430 d->hasCursor =
false;
8431 d->setHasCursorInChild(d->hasCursorHandler);
8432 if (d->extra.isAllocated())
8433 d->extra->cursor = QCursor();
8436 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8437 if (windowPrivate->cursorItem ==
this) {
8438 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8439 windowPrivate->updateCursor(pos);
8445
8446
8447
8448
8449
8450
8451QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8453 Q_Q(
const QQuickItem);
8456 bool hoverCursorSet =
false;
8457 QCursor hoverCursor;
8458 bool activeCursorSet =
false;
8459 QCursor activeCursor;
8460 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8461 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8462 hoverCursor = hoverHandler->cursorShape();
8463 }
else if (handler->active()) {
8464 activeCursorSet = handler->isCursorShapeExplicitlySet();
8465 activeCursor = handler->cursorShape();
8467 if (activeCursorSet)
8468 return activeCursor;
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8496 if (!hasPointerHandlers())
8498 QQuickPointerHandler* activeHandler =
nullptr;
8499 QQuickPointerHandler* mouseHandler =
nullptr;
8500 QQuickPointerHandler* nonMouseHandler =
nullptr;
8501 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8502 if (!h->isCursorShapeExplicitlySet())
8504 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8509 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8510 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8511 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8513 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8514 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8515 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8517 mouseHandler = hoverHandler;
8520 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8521 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8522 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8524 nonMouseHandler = hoverHandler;
8527 if (!hoverHandler && h->active())
8530 if (activeHandler) {
8531 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8532 return activeHandler;
8538 if (nonMouseHandler) {
8540 const bool beforeTimeout =
8541 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8542 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8543 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8544 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8545 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8546 <<
"choosing cursor according to" << winner << winner->cursorShape();
8549 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8550 return nonMouseHandler;
8553 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8554 return mouseHandler;
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573void QQuickItem::grabMouse()
8578 auto da = d->deliveryAgentPrivate();
8580 auto eventInDelivery = da->eventInDelivery();
8581 if (!eventInDelivery) {
8582 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8585 auto epd = da->mousePointData();
8586 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600void QQuickItem::ungrabMouse()
8605 auto da = d->deliveryAgentPrivate();
8607 auto eventInDelivery = da->eventInDelivery();
8608 if (!eventInDelivery) {
8610 da->removeGrabber(
this);
8613 const auto &eventPoint = da->mousePointData()->eventPoint;
8614 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8615 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8619
8620
8621
8622
8623bool QQuickItem::keepMouseGrab()
const
8625 Q_D(
const QQuickItem);
8626 return d->keepMouse;
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645void QQuickItem::setKeepMouseGrab(
bool keep)
8648 d->keepMouse = keep;
8652
8653
8654
8655
8656
8657
8658
8659
8660void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8663 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8664 if (Q_UNLIKELY(!event)) {
8665 qWarning() <<
"cannot grab: no event is currently being delivered";
8668 for (
auto pt : event->points()) {
8669 if (ids.contains(pt.id()))
8670 event->setExclusiveGrabber(pt,
this);
8675
8676
8677
8678void QQuickItem::ungrabTouchPoints()
8683 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8684 da->removeGrabber(
this,
false,
true);
8688
8689
8690
8691
8692
8693bool QQuickItem::keepTouchGrab()
const
8695 Q_D(
const QQuickItem);
8696 return d->keepTouch;
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716void QQuickItem::setKeepTouchGrab(
bool keep)
8719 d->keepTouch = keep;
8723
8724
8725
8726
8727
8728
8729
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741bool QQuickItem::contains(
const QPointF &point)
const
8743 Q_D(
const QQuickItem);
8744 if (d->extra.isAllocated() && d->extra->mask) {
8745 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8746 return quickMask->contains(point - quickMask->position());
8749 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8750 maskContains.invoke(d->extra->mask,
8751 Qt::DirectConnection,
8752 Q_RETURN_ARG(
bool, res),
8753 Q_ARG(QPointF, point));
8757 qreal x = point.x();
8758 qreal y = point.y();
8759 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825QObject *QQuickItem::containmentMask()
const
8827 Q_D(
const QQuickItem);
8828 if (!d->extra.isAllocated())
8830 return d->extra->mask.data();
8833void QQuickItem::setContainmentMask(QObject *mask)
8836 const bool extraDataExists = d->extra.isAllocated();
8838 if (mask ==
static_cast<QObject *>(
this))
8841 if (!extraDataExists && !mask)
8844 if (extraDataExists && d->extra->mask == mask)
8847 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8850 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8851 maskPrivate->registerAsContainmentMask(
this,
false);
8854 if (!extraDataExists)
8857 int methodIndex = mask->metaObject()->indexOfMethod(QByteArrayLiteral(
"contains(QPointF)"));
8858 if (methodIndex < 0) {
8859 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
8862 d->extra->maskContainsIndex = methodIndex;
8864 d->extra->mask = mask;
8865 quickMask = qobject_cast<QQuickItem *>(mask);
8867 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8868 maskPrivate->registerAsContainmentMask(
this,
true);
8870 emit containmentMaskChanged();
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
8887 QPointF p = mapToScene(point);
8889 const auto *itemWindow = item->window();
8890 const auto *thisWindow = window();
8891 if (thisWindow && itemWindow && itemWindow != thisWindow)
8892 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
8894 p = item->mapFromScene(p);
8900
8901
8902
8903
8904
8905
8906
8907
8908QPointF QQuickItem::mapToScene(
const QPointF &point)
const
8910 Q_D(
const QQuickItem);
8911 return d->itemToWindowTransform().map(point);
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
8933 Q_D(
const QQuickItem);
8935 if (Q_UNLIKELY(d->window ==
nullptr))
8936 return mapToScene(point);
8938 QPoint renderOffset;
8939 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
8940 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
8941 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
8958 Q_D(
const QQuickItem);
8959 QTransform t = d->itemToWindowTransform();
8961 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
8962 return t.mapRect(rect);
8966
8967
8968
8969
8970
8971
8972
8973
8974QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
8976 Q_D(
const QQuickItem);
8977 return d->itemToWindowTransform().mapRect(rect);
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
8996 p = item->mapToScene(point);
8997 const auto *itemWindow = item->window();
8998 const auto *thisWindow = window();
8999 if (thisWindow && itemWindow && itemWindow != thisWindow)
9000 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9002 return mapFromScene(p);
9006
9007
9008
9009
9010
9011
9012
9013
9014QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9016 Q_D(
const QQuickItem);
9017 return d->windowToItemTransform().map(point);
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9045 Q_D(
const QQuickItem);
9048 if (Q_LIKELY(d->window)) {
9049 QPoint renderOffset;
9050 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9051 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9052 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9057 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9058 if (
auto sceneTransform = da->sceneTransform())
9059 scenePoint = sceneTransform->map(scenePoint);
9061 return mapFromScene(scenePoint);
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9078 Q_D(
const QQuickItem);
9079 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9080 t *= d->windowToItemTransform();
9081 return t.mapRect(rect);
9085
9086
9087
9088
9089
9090
9091
9092
9093QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9095 Q_D(
const QQuickItem);
9096 return d->windowToItemTransform().mapRect(rect);
9100
9101
9102
9105
9106
9107
9110
9111
9112
9115
9116
9117
9120
9121
9122
9125
9126
9127
9130
9131
9132
9135
9136
9137
9140
9141
9142
9145
9146
9147
9150
9151
9152bool QQuickItem::event(QEvent *ev)
9156 switch (ev->type()) {
9158 case QEvent::InputMethodQuery: {
9159 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9160 Qt::InputMethodQueries queries = query->queries();
9161 for (uint i = 0; i < 32; ++i) {
9162 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9164 QVariant v = inputMethodQuery(q);
9165 query->setValue(q, v);
9171 case QEvent::InputMethod:
9172 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9175 case QEvent::TouchBegin:
9176 case QEvent::TouchUpdate:
9177 case QEvent::TouchEnd:
9178 case QEvent::TouchCancel:
9179 case QEvent::MouseButtonPress:
9180 case QEvent::MouseButtonRelease:
9181 case QEvent::MouseButtonDblClick:
9182#if QT_CONFIG(wheelevent)
9185 d->deliverPointerEvent(ev);
9187 case QEvent::StyleAnimationUpdate:
9193 case QEvent::HoverEnter:
9194 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9196 case QEvent::HoverLeave:
9197 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9199 case QEvent::HoverMove:
9200 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9202 case QEvent::KeyPress:
9203 case QEvent::KeyRelease:
9204 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9206 case QEvent::ShortcutOverride:
9207 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9209 case QEvent::FocusIn:
9210 focusInEvent(
static_cast<QFocusEvent*>(ev));
9212 case QEvent::FocusOut:
9213 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9215 case QEvent::MouseMove:
9216 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9218#if QT_CONFIG(quick_draganddrop)
9219 case QEvent::DragEnter:
9220 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9222 case QEvent::DragLeave:
9223 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9225 case QEvent::DragMove:
9226 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9229 dropEvent(
static_cast<QDropEvent*>(ev));
9232#if QT_CONFIG(gestures)
9233 case QEvent::NativeGesture:
9237 case QEvent::LanguageChange:
9238 case QEvent::LocaleChange:
9239 for (QQuickItem *item : std::as_const(d->childItems))
9240 QCoreApplication::sendEvent(item, ev);
9242 case QEvent::WindowActivate:
9243 case QEvent::WindowDeactivate:
9244 if (d->providesPalette())
9245 d->setCurrentColorGroup();
9246 for (QQuickItem *item : std::as_const(d->childItems))
9247 QCoreApplication::sendEvent(item, ev);
9249 case QEvent::ApplicationPaletteChange:
9250 for (QQuickItem *item : std::as_const(d->childItems))
9251 QCoreApplication::sendEvent(item, ev);
9253 case QEvent::ContextMenu:
9255 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9258 return QObject::event(ev);
9264#ifndef QT_NO_DEBUG_STREAM
9266#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9271 QDebugStateSaver saver(debug);
9274 debug <<
"QQuickItem(nullptr)";
9278 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9280 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9284 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9285 if (QQmlContext *context = qmlContext(item)) {
9286 const auto objectId = context->nameForObject(item);
9287 if (!objectId.isEmpty())
9288 debug <<
", id=" << objectId;
9291 if (!item->objectName().isEmpty())
9292 debug <<
", name=" << item->objectName();
9293 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9295 QtDebugUtils::formatQRect(debug, rect);
9296 if (
const qreal z = item->z())
9297 debug <<
", z=" << z;
9298 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9299 debug <<
" \U0001f5bc";
9300 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9308
9309
9310
9311
9312
9313
9314
9316bool QQuickItem::isTextureProvider()
const
9318#if QT_CONFIG(quick_shadereffect)
9319 Q_D(
const QQuickItem);
9320 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9321 d->extra->layer->effectSource()->isTextureProvider() :
false;
9328
9329
9330
9331
9332
9333
9334
9336QSGTextureProvider *QQuickItem::textureProvider()
const
9338#if QT_CONFIG(quick_shadereffect)
9339 Q_D(
const QQuickItem);
9340 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9341 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9389#if QT_CONFIG(quick_shadereffect)
9391
9392
9393
9394QQuickItemLayer *QQuickItemPrivate::layer()
const
9396 if (!extra.isAllocated() || !extra->layer) {
9397 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9398 if (!componentComplete)
9399 extra->layer->classBegin();
9401 return extra->layer;
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9425 QList<QEventPoint> touchPoints;
9426 QEventPoint::States eventStates;
9428 bool anyPressOrReleaseInside =
false;
9429 bool anyGrabber =
false;
9430 for (
auto &p : event->points()) {
9435 auto pointGrabber = event->exclusiveGrabber(p);
9436 bool isGrabber = (pointGrabber == q);
9437 if (!isGrabber && pointGrabber && isFiltering) {
9438 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9439 if (handlerGrabber && handlerGrabber->parentItem() == q)
9446 const auto localPos = q->mapFromScene(p.scenePosition());
9447 bool isInside = q->contains(localPos);
9448 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9450 if (isFiltering && !pointGrabber) {
9451 const auto pg = event->passiveGrabbers(p);
9452 if (!pg.isEmpty()) {
9456 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9458 pointGrabber = handler->parentItem();
9463 bool grabberIsChild =
false;
9464 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9465 while (isFiltering && parent) {
9467 grabberIsChild =
true;
9470 parent = parent->parentItem();
9473 bool filterRelevant = isFiltering && grabberIsChild;
9474 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9476 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9477 anyPressOrReleaseInside =
true;
9478 QEventPoint pCopy(p);
9479 eventStates |= p.state();
9480 if (p.state() == QEventPoint::State::Released)
9481 QMutableEventPoint::detach(pCopy);
9482 QMutableEventPoint::setPosition(pCopy, localPos);
9483 touchPoints.append(std::move(pCopy));
9488 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9489 *localized = QMutableTouchEvent(QEvent::None);
9494 QEvent::Type eventType = event->type();
9495 switch (eventStates) {
9496 case QEventPoint::State::Pressed:
9497 eventType = QEvent::TouchBegin;
9499 case QEventPoint::State::Released:
9500 eventType = QEvent::TouchEnd;
9503 eventType = QEvent::TouchUpdate;
9507 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9509 ret.setTimestamp(event->timestamp());
9514bool QQuickItemPrivate::hasPointerHandlers()
const
9516 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9519bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9521 if (!hasPointerHandlers())
9523 for (QQuickPointerHandler *h : extra->pointerHandlers)
9524 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9529void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9535 extra.value().acceptedMouseButtons = Qt::AllButtons;
9536 auto &handlers = extra.value().pointerHandlers;
9537 if (!handlers.contains(h))
9538 handlers.prepend(h);
9539 auto &res = extra.value().resourcesList;
9540 if (!res.contains(h)) {
9542 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9543 _q_resourceObjectDeleted(o);
9548void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9552 auto &handlers = extra.value().pointerHandlers;
9553 handlers.removeOne(h);
9554 auto &res = extra.value().resourcesList;
9556 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9557 if (handlers.isEmpty())
9558 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9562
9563
9564
9565QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9567 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9568 extra.value().contextMenu = menu;
9572#if QT_CONFIG(quick_shadereffect)
9573QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9579 , m_componentComplete(
true)
9580 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9581 , m_format(QQuickShaderEffectSource::RGBA8)
9583 , m_effectComponent(
nullptr)
9585 , m_effectSource(
nullptr)
9586 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9591QQuickItemLayer::~QQuickItemLayer()
9593 delete m_effectSource;
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611void QQuickItemLayer::setEnabled(
bool e)
9616 if (m_componentComplete) {
9623 emit enabledChanged(e);
9626void QQuickItemLayer::classBegin()
9628 Q_ASSERT(!m_effectSource);
9629 Q_ASSERT(!m_effect);
9630 m_componentComplete =
false;
9633void QQuickItemLayer::componentComplete()
9635 Q_ASSERT(!m_componentComplete);
9636 m_componentComplete =
true;
9641void QQuickItemLayer::activate()
9643 Q_ASSERT(!m_effectSource);
9644 m_effectSource =
new QQuickShaderEffectSource();
9645 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9647 QQuickItem *parentItem = m_item->parentItem();
9649 m_effectSource->setParentItem(parentItem);
9650 m_effectSource->stackAfter(m_item);
9653 m_effectSource->setSourceItem(m_item);
9654 m_effectSource->setHideSource(
true);
9655 m_effectSource->setSmooth(m_smooth);
9656 m_effectSource->setLive(m_live);
9657 m_effectSource->setTextureSize(m_size);
9658 m_effectSource->setSourceRect(m_sourceRect);
9659 m_effectSource->setMipmap(m_mipmap);
9660 m_effectSource->setWrapMode(m_wrapMode);
9661 m_effectSource->setFormat(m_format);
9662 m_effectSource->setTextureMirroring(m_textureMirroring);
9663 m_effectSource->setSamples(m_samples);
9665 if (m_effectComponent)
9668 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9675 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9676 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9679void QQuickItemLayer::deactivate()
9681 Q_ASSERT(m_effectSource);
9683 if (m_effectComponent)
9686 delete m_effectSource;
9687 m_effectSource =
nullptr;
9689 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9690 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9693void QQuickItemLayer::activateEffect()
9695 Q_ASSERT(m_effectSource);
9696 Q_ASSERT(m_effectComponent);
9697 Q_ASSERT(!m_effect);
9699 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9700 m_effect = qobject_cast<QQuickItem *>(created);
9702 qWarning(
"Item: layer.effect is not a QML Item.");
9703 m_effectComponent->completeCreate();
9707 QQuickItem *parentItem = m_item->parentItem();
9709 m_effect->setParentItem(parentItem);
9710 m_effect->stackAfter(m_effectSource);
9712 m_effect->setVisible(m_item->isVisible());
9713 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9714 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9715 m_effectComponent->completeCreate();
9718void QQuickItemLayer::deactivateEffect()
9720 Q_ASSERT(m_effectSource);
9721 Q_ASSERT(m_effectComponent);
9729
9730
9731
9732
9733
9734
9735
9736
9737
9739void QQuickItemLayer::setEffect(QQmlComponent *component)
9741 if (component == m_effectComponent)
9744 bool updateNeeded =
false;
9745 if (m_effectSource && m_effectComponent) {
9747 updateNeeded =
true;
9750 m_effectComponent = component;
9752 if (m_effectSource && m_effectComponent) {
9754 updateNeeded =
true;
9762 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9765 emit effectChanged(component);
9770
9771
9772
9773
9774
9775
9776
9777
9778
9780void QQuickItemLayer::setMipmap(
bool mipmap)
9782 if (mipmap == m_mipmap)
9787 m_effectSource->setMipmap(m_mipmap);
9789 emit mipmapChanged(mipmap);
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9810void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9817 m_effectSource->setFormat(m_format);
9819 emit formatChanged(m_format);
9824
9825
9826
9827
9828
9829
9830
9831
9832
9834void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
9836 if (sourceRect == m_sourceRect)
9838 m_sourceRect = sourceRect;
9841 m_effectSource->setSourceRect(m_sourceRect);
9843 emit sourceRectChanged(sourceRect);
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9858void QQuickItemLayer::setSmooth(
bool s)
9865 m_effectSource->setSmooth(m_smooth);
9867 emit smoothChanged(s);
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9882void QQuickItemLayer::setLive(
bool live)
9889 m_effectSource->setLive(m_live);
9891 emit liveChanged(live);
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9907void QQuickItemLayer::setSize(
const QSize &size)
9914 m_effectSource->setTextureSize(size);
9916 emit sizeChanged(size);
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9937void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
9939 if (mode == m_wrapMode)
9944 m_effectSource->setWrapMode(m_wrapMode);
9946 emit wrapModeChanged(mode);
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9964void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
9966 if (mirroring == m_textureMirroring)
9968 m_textureMirroring = mirroring;
9971 m_effectSource->setTextureMirroring(m_textureMirroring);
9973 emit textureMirroringChanged(mirroring);
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10001void QQuickItemLayer::setSamples(
int count)
10003 if (m_samples == count)
10008 if (m_effectSource)
10009 m_effectSource->setSamples(m_samples);
10011 emit samplesChanged(count);
10015
10016
10017
10018
10019
10020
10021
10022
10023
10025void QQuickItemLayer::setName(
const QByteArray &name) {
10026 if (m_name == name)
10029 m_effect->setProperty(m_name, QVariant());
10030 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10033 emit nameChanged(name);
10036void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10042void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10047void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10050 Q_ASSERT(item == m_item);
10051 Q_ASSERT(parent != m_effectSource);
10052 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10054 m_effectSource->setParentItem(parent);
10056 m_effectSource->stackAfter(m_item);
10059 m_effect->setParentItem(parent);
10061 m_effect->stackAfter(m_effectSource);
10065void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10067 m_effectSource->stackAfter(m_item);
10069 m_effect->stackAfter(m_effectSource);
10072void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10074 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10077 l->setVisible(m_item->isVisible());
10080void QQuickItemLayer::updateZ()
10082 if (!m_componentComplete || !m_enabled)
10084 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10087 l->setZ(m_item->z());
10090void QQuickItemLayer::updateOpacity()
10092 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10095 l->setOpacity(m_item->opacity());
10098void QQuickItemLayer::updateGeometry()
10100 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10105 QRectF bounds = m_item->QQuickItem::boundingRect();
10106 l->setSize(bounds.size());
10107 l->setPosition(bounds.topLeft() + m_item->position());
10110void QQuickItemLayer::updateMatrix()
10114 if (!m_componentComplete || !m_enabled)
10116 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10119 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10120 l->setScale(m_item->scale());
10121 l->setRotation(m_item->rotation());
10122 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10123 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10124 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10125 ld->dirty(QQuickItemPrivate::Transform);
10129QQuickItemPrivate::ExtraData::ExtraData()
10130: z(0), scale(1), rotation(0), opacity(1),
10131 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10132 enterKeyAttached(
nullptr),
10133 keyHandler(
nullptr), contextMenu(
nullptr),
10134#if QT_CONFIG(quick_shadereffect)
10137 effectRefCount(0), hideRefCount(0),
10138 recursiveEffectRefCount(0),
10139 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10140 origin(QQuickItem::Center),
10141 transparentForPositioner(
false)
10146#if QT_CONFIG(accessibility)
10147QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10149 Q_Q(
const QQuickItem);
10150 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10151 auto role = QAccessible::NoRole;
10152 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10153 role = accessibleAttached->role();
10154 if (role == QAccessible::NoRole)
10155 role = accessibleRole();
10159QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10161 return QAccessible::NoRole;
10170 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10183 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10184 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10185 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10186 QV4::QObjectWrapper::markWrapper(child, markStack);
10188 QObjectWrapper::markObjects(that, markStack);
10191quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10193 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10198 QDebugStateSaver stateSaver(debug);
10199 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10204QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10205{
return mapFromItem(item, QPointF(x, y) ); }
10208QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10209{
return mapRectFromItem(item, rect); }
10212QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10213{
return mapFromItem(item, QRectF(x, y, width, height)); }
10216QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10217{
return mapToItem(item, QPointF(x, y)); }
10220QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10221{
return mapRectToItem(item, rect); }
10224QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10225{
return mapToItem(item, QRectF(x, y, width, height)); }
10228QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10229{
return mapToGlobal(QPointF(x, y)); }
10232QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10233{
return mapFromGlobal(QPointF(x, y)); }
10236QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10240#include <moc_qquickitem.cpp>
10242#include "moc_qquickitem_p.cpp"
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
#define PRINT_LISTENERS()
QDebug operator<<(QDebug debug, const QQuickItem *item)
static bool itemZOrder_sort(QQuickItem *lhs, QQuickItem *rhs)
#define DIRTY_TO_STRING(value)
void debugFocusTree(QQuickItem *item, QQuickItem *scope=nullptr, int depth=1)
DEFINE_OBJECT_VTABLE(QQuickItemWrapper)
static void setActiveFocus(QQuickItem *item, Qt::FocusReason reason)
static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack)