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#ifdef QT_BUILD_INTERNAL
3205 ++windowToItemTransform_counter;
3207 return itemToWindowTransform().inverted();
3211
3212
3213QTransform QQuickItemPrivate::itemToWindowTransform()
const
3215#ifdef QT_BUILD_INTERNAL
3216 ++itemToWindowTransform_counter;
3219 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3220 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3221 itemToParentTransform(&rv);
3226
3227
3228void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3230#ifdef QT_BUILD_INTERNAL
3231 ++itemToParentTransform_counter;
3234
3235
3236
3237
3238
3240 qreal x =
this->x.valueBypassingBindings();
3241 qreal y =
this->y.valueBypassingBindings();
3245 if (!transforms.isEmpty()) {
3247 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3248 transforms.at(ii)->applyTo(&m);
3249 *t = m.toTransform();
3252 if (scale() != 1. || rotation() != 0.) {
3253 QPointF tp = computeTransformOrigin();
3254 t->translate(tp.x(), tp.y());
3255 t->scale(scale(), scale());
3256 t->rotate(rotation());
3257 t->translate(-tp.x(), -tp.y());
3262
3263
3264
3265
3266
3267
3268
3269
3270bool QQuickItem::isComponentComplete()
const
3272 Q_D(
const QQuickItem);
3273 return d->componentComplete;
3276QQuickItemPrivate::QQuickItemPrivate()
3278 , _stateGroup(
nullptr)
3280 , widthValidFlag(
false)
3281 , heightValidFlag(
false)
3282 , componentComplete(
true)
3285 , hoverEnabled(
false)
3287 , antialiasing(
false)
3289 , activeFocus(
false)
3290 , notifiedFocus(
false)
3291 , notifiedActiveFocus(
false)
3292 , filtersChildMouseEvents(
false)
3293 , explicitVisible(
true)
3294 , effectiveVisible(
true)
3295 , explicitEnable(
true)
3296 , effectiveEnable(
true)
3297 , polishScheduled(
false)
3298 , inheritedLayoutMirror(
false)
3299 , effectiveLayoutMirror(
false)
3300 , isMirrorImplicit(
true)
3301 , inheritMirrorFromParent(
false)
3302 , inheritMirrorFromItem(
false)
3303 , isAccessible(
false)
3306 , subtreeCursorEnabled(
false)
3307 , subtreeHoverEnabled(
false)
3308 , activeFocusOnTab(
false)
3309 , implicitAntialiasing(
false)
3310 , antialiasingValid(
false)
3312 , replayingPressEvent(
false)
3313 , touchEnabled(
false)
3314 , hasCursorHandler(
false)
3315 , maybeHasSubsceneDeliveryAgent(
true)
3316 , subtreeTransformChangedEnabled(
true)
3317 , inDestructor(
false)
3318 , focusReason(Qt::OtherFocusReason)
3319 , focusPolicy(Qt::NoFocus)
3320 , dirtyAttributes(0)
3321 , nextDirtyItem(
nullptr)
3322 , prevDirtyItem(
nullptr)
3325 , parentItem(
nullptr)
3326 , sortedChildItems(&childItems)
3327 , subFocusItem(
nullptr)
3335 , itemNodeInstance(
nullptr)
3336 , paintNode(
nullptr)
3337 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3339#ifdef QT_BUILD_INTERNAL
3344QQuickItemPrivate::~QQuickItemPrivate()
3346 if (sortedChildItems != &childItems)
3347 delete sortedChildItems;
3350void QQuickItemPrivate::init(QQuickItem *parent)
3356 baselineOffset = 0.0;
3359 q->setParentItem(parent);
3360 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3361 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3365QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3370void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3372 szPolicy.setHorizontalPolicy(horizontalPolicy);
3373 szPolicy.setVerticalPolicy(verticalPolicy);
3376void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3381 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3383 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3384 item->setParentItem(that);
3385 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3386 if (pointerHandler->parent() != that) {
3387 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3388 pointerHandler->setParent(that);
3390 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3393 resources_append(prop, o);
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3432qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3434 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3435 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3436 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3437 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3439 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3442QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3444 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3445 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3446 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3447 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3449 qsizetype resourcesCount = resources_count(&resourcesProperty);
3450 if (i < resourcesCount)
3451 return resources_at(&resourcesProperty, i);
3452 const qsizetype j = i - resourcesCount;
3453 if (j < children_count(&childrenProperty))
3454 return children_at(&childrenProperty, j);
3458void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3460 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3461 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3462 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3463 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3465 resources_clear(&resourcesProperty);
3466 children_clear(&childrenProperty);
3469void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3471 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3472 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3474 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3475 if (children_count(&childrenProperty) > 0) {
3476 children_removeLast(&childrenProperty);
3480 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3481 if (resources_count(&resourcesProperty) > 0)
3482 resources_removeLast(&resourcesProperty);
3485QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3487 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3488 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3491void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3493 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3494 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3495 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3496 quickItemPrivate->extra.value().resourcesList.append(object);
3497 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3498 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3502qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3504 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3505 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3508void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3510 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3511 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3512 if (quickItemPrivate->extra.isAllocated()) {
3513 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3514 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3515 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3517 quickItemPrivate->extra->resourcesList.clear();
3521void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3523 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3524 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3525 if (quickItemPrivate->extra.isAllocated()) {
3526 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3527 if (resources->isEmpty())
3530 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3531 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3532 resources->removeLast();
3536QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3538 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3539 if (index >= p->childItems.size() || index < 0)
3542 return p->childItems.at(index);
3545void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3550 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3551 if (o->parentItem() == that)
3552 o->setParentItem(
nullptr);
3554 o->setParentItem(that);
3557qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3559 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3560 return p->childItems.size();
3563void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3565 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3566 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3567 while (!p->childItems.isEmpty())
3568 p->childItems.at(0)->setParentItem(
nullptr);
3571void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3573 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3574 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3575 if (!p->childItems.isEmpty())
3576 p->childItems.last()->setParentItem(
nullptr);
3579qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3581 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3582 qsizetype visibleCount = 0;
3583 qsizetype c = p->childItems.size();
3585 if (p->childItems.at(c)->isVisible()) visibleCount++;
3588 return visibleCount;
3591QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3593 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3594 const qsizetype childCount = p->childItems.size();
3595 if (index >= childCount || index < 0)
3598 qsizetype visibleCount = -1;
3599 for (qsizetype i = 0; i < childCount; i++) {
3600 if (p->childItems.at(i)->isVisible()) visibleCount++;
3601 if (visibleCount == index)
return p->childItems.at(i);
3606qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3608 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3609 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3611 return p->transforms.size();
3614void QQuickTransform::appendToItem(QQuickItem *item)
3616 Q_D(QQuickTransform);
3620 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3622 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3623 p->transforms.removeOne(
this);
3624 p->transforms.append(
this);
3626 p->transforms.append(
this);
3627 d->items.append(item);
3630 p->dirty(QQuickItemPrivate::Transform);
3633void QQuickTransform::prependToItem(QQuickItem *item)
3635 Q_D(QQuickTransform);
3639 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3641 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3642 p->transforms.removeOne(
this);
3643 p->transforms.prepend(
this);
3645 p->transforms.prepend(
this);
3646 d->items.append(item);
3649 p->dirty(QQuickItemPrivate::Transform);
3652void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3657 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3658 transform->appendToItem(that);
3661QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3663 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3664 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3666 if (idx < 0 || idx >= p->transforms.size())
3669 return p->transforms.at(idx);
3672void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3674 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3675 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3677 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3678 QQuickTransform *t = p->transforms.at(ii);
3679 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3680 tp->items.removeOne(that);
3683 p->transforms.clear();
3685 p->dirty(QQuickItemPrivate::Transform);
3688void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3690 if (extra.isAllocated() && extra->resourcesList.contains(object))
3691 extra->resourcesList.removeAll(object);
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
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788QQuickAnchors *QQuickItemPrivate::anchors()
const
3791 Q_Q(
const QQuickItem);
3792 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3793 if (!componentComplete)
3794 _anchors->classBegin();
3799void QQuickItemPrivate::siblingOrderChanged()
3802 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3805QQmlListProperty<QObject> QQuickItemPrivate::data()
3809 QQmlListProperty<QObject> result;
3810 result.object = q_func();
3811 result.append = QQuickItemPrivate::data_append;
3812 result.count = QQuickItemPrivate::data_count;
3813 result.at = QQuickItemPrivate::data_at;
3814 result.clear = QQuickItemPrivate::data_clear;
3815 result.removeLast = QQuickItemPrivate::data_removeLast;
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850QRectF QQuickItem::childrenRect()
3853 if (!d->extra.isAllocated() || !d->extra->contents) {
3854 d->extra.value().contents =
new QQuickContents(
this);
3855 if (d->componentComplete)
3856 d->extra->contents->complete();
3858 return d->extra->contents->rectF();
3862
3863
3864QList<QQuickItem *> QQuickItem::childItems()
const
3866 Q_D(
const QQuickItem);
3867 return d->childItems;
3871
3872
3873
3874
3875
3876
3877
3878
3879
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898bool QQuickItem::clip()
const
3900 return flags() & ItemClipsChildrenToShape;
3903void QQuickItem::setClip(
bool c)
3908 setFlag(ItemClipsChildrenToShape, c);
3910 setFlag(ItemIsViewport);
3911 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3912 setFlag(ItemIsViewport,
false);
3914 emit clipChanged(c);
3918
3919
3920
3921
3922
3923
3924
3925
3926void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3931 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3933 QQuickGeometryChange change;
3934 change.setXChange(newGeometry.x() != oldGeometry.x());
3935 change.setYChange(newGeometry.y() != oldGeometry.y());
3936 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3937 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3939 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3940 if (change.matches(listener.gTypes))
3941 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3946 if (change.xChange())
3948 if (change.yChange())
3950 if (change.widthChange())
3952 if (change.heightChange())
3954#if QT_CONFIG(accessibility)
3955 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3956 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3957 QAccessible::updateAccessibility(&ev);
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
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4016QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4018 Q_UNUSED(updatePaintNodeData);
4023QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4024: transformNode(
nullptr)
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4045void QQuickItem::releaseResources()
4049QSGTransformNode *QQuickItemPrivate::createTransformNode()
4051 return new QSGTransformNode;
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064void QQuickItem::updatePolish()
4068#define PRINT_LISTENERS() do
4070 qDebug().nospace() << q_func() << " (" << this
4071 << ") now has the following listeners:";
4072 for (const auto &listener : std::as_const(changeListeners)) {
4073 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4074 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4076}while
4079void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4082 changeListeners.append(ChangeListener(listener, types));
4083 listener->addSourceItem(q);
4085 if (lcChangeListeners().isDebugEnabled())
4089void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4093 const ChangeListener changeListener(listener, types);
4094 const int index = changeListeners.indexOf(changeListener);
4096 changeListeners[index].types = changeListener.types;
4098 changeListeners.append(changeListener);
4099 listener->addSourceItem(q);
4102 if (lcChangeListeners().isDebugEnabled())
4106void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4110 ChangeListener change(listener, types);
4111 changeListeners.removeOne(change);
4112 listener->removeSourceItem(q);
4114 if (lcChangeListeners().isDebugEnabled())
4118void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4119 QQuickGeometryChange types)
4123 ChangeListener change(listener, types);
4124 int index = changeListeners.indexOf(change);
4126 changeListeners[index].gTypes = change.gTypes;
4128 changeListeners.append(change);
4129 listener->addSourceItem(q);
4132 if (lcChangeListeners().isDebugEnabled())
4136void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4137 QQuickGeometryChange types)
4141 ChangeListener change(listener, types);
4142 if (types.noChange()) {
4143 changeListeners.removeOne(change);
4144 listener->removeSourceItem(q);
4146 int index = changeListeners.indexOf(change);
4148 changeListeners[index].gTypes = change.gTypes;
4151 if (lcChangeListeners().isDebugEnabled())
4156
4157
4158
4159
4160
4161
4162void QQuickItem::keyPressEvent(QKeyEvent *event)
4168
4169
4170
4171
4172
4173
4174void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4181
4182
4183
4184
4185
4186
4187void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203void QQuickItem::focusInEvent(QFocusEvent *event)
4206#if QT_CONFIG(accessibility)
4207 if (QAccessible::isActive()) {
4208 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4209 QAccessibleEvent ev(acc, QAccessible::Focus);
4210 QAccessible::updateAccessibility(&ev);
4214 d->setLastFocusChangeReason(event->reason());
4218
4219
4220
4221
4222
4223
4224void QQuickItem::focusOutEvent(QFocusEvent *event)
4227 d->setLastFocusChangeReason(event->reason());
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240void QQuickItem::mousePressEvent(QMouseEvent *event)
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4278
4279
4280
4281
4282
4283
4284void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4290
4291
4292
4293void QQuickItem::mouseUngrabEvent()
4299
4300
4301
4302void QQuickItem::touchUngrabEvent()
4307#if QT_CONFIG(wheelevent)
4309
4310
4311
4312
4313
4314
4315void QQuickItem::wheelEvent(QWheelEvent *event)
4322
4323
4324
4325
4326
4327
4328void QQuickItem::touchEvent(QTouchEvent *event)
4334
4335
4336
4337
4338
4339
4340
4341
4342void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4348
4349
4350
4351
4352
4353
4354
4355
4356void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4362
4363
4364
4365
4366
4367
4368
4369
4370void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4375#if QT_CONFIG(quick_draganddrop)
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439void QQuickItem::dropEvent(QDropEvent *event)
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4484
4485
4486
4487
4488
4489
4490
4491QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4493 Q_D(
const QQuickItem);
4498 v = (
bool)(flags() & ItemAcceptsInputMethod);
4501 case Qt::ImAnchorRectangle:
4502 case Qt::ImCursorRectangle:
4504 case Qt::ImCursorPosition:
4505 case Qt::ImSurroundingText:
4506 case Qt::ImCurrentSelection:
4507 case Qt::ImMaximumTextLength:
4508 case Qt::ImAnchorPosition:
4509 case Qt::ImPreferredLanguage:
4510 case Qt::ImReadOnly:
4511 if (d->extra.isAllocated() && d->extra->keyHandler)
4512 v = d->extra->keyHandler->inputMethodQuery(query);
4514 case Qt::ImEnterKeyType:
4515 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4516 v = d->extra->enterKeyAttached->type();
4518 case Qt::ImInputItemClipRectangle:
4519 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4520 QRectF rect = QRectF(0,0, width(), height());
4521 const QQuickItem *par =
this;
4522 while (QQuickItem *parpar = par->parentItem()) {
4523 rect = parpar->mapRectFromItem(par, rect);
4525 rect = rect.intersected(parpar->clipRect());
4528 rect = par->mapRectToScene(rect);
4530 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4532 v = mapRectFromScene(rect);
4543QQuickAnchorLine QQuickItemPrivate::left()
const
4545 Q_Q(
const QQuickItem);
4546 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4549QQuickAnchorLine QQuickItemPrivate::right()
const
4551 Q_Q(
const QQuickItem);
4552 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4555QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4557 Q_Q(
const QQuickItem);
4558 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4561QQuickAnchorLine QQuickItemPrivate::top()
const
4563 Q_Q(
const QQuickItem);
4564 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4567QQuickAnchorLine QQuickItemPrivate::bottom()
const
4569 Q_Q(
const QQuickItem);
4570 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4573QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4575 Q_Q(
const QQuickItem);
4576 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4579QQuickAnchorLine QQuickItemPrivate::baseline()
const
4581 Q_Q(
const QQuickItem);
4582 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607qreal QQuickItem::baselineOffset()
const
4609 Q_D(
const QQuickItem);
4610 return d->baselineOffset;
4613void QQuickItem::setBaselineOffset(qreal offset)
4616 if (offset == d->baselineOffset)
4619 d->baselineOffset = offset;
4621 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4622 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4624 anchor->updateVerticalAnchors();
4627 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4628 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4630 emit baselineOffsetChanged(offset);
4635
4636
4637
4638
4639
4640
4641
4642
4643void QQuickItem::update()
4646 if (!(flags() & ItemHasContents)) {
4648 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4652 d->dirty(QQuickItemPrivate::Content);
4656
4657
4658
4659
4660
4661
4662
4663void QQuickItem::polish()
4666 if (!d->polishScheduled) {
4667 d->polishScheduled =
true;
4669 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4670 bool maybeupdate = p->itemsToPolish.isEmpty();
4671 p->itemsToPolish.append(
this);
4672 if (maybeupdate) d->window->maybeUpdate();
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692void QQuickItem::ensurePolished()
4697#if QT_DEPRECATED_SINCE(6
, 5
)
4698static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4699 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4701 QV4::ExecutionEngine *v4 = args->v4engine();
4702 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4703 v4->throwTypeError();
4707 QV4::Scope scope(v4);
4708 QV4::ScopedValue item(scope, (*args)[0]);
4711 if (!item->isNull()) {
4712 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4714 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4717 if (!(*itemObj) && !item->isNull()) {
4718 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4719 <<
"\" which is neither null nor an Item";
4720 v4->throwTypeError();
4726 if (args->length() == 2) {
4727 QV4::ScopedValue sv(scope, (*args)[1]);
4729 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4730 <<
"\" which is neither a point nor a rect";
4731 v4->throwTypeError();
4734 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4735 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4736 if (v.canConvert<QPointF>()) {
4737 const QPointF p = v.toPointF();
4740 }
else if (v.canConvert<QRectF>()) {
4741 const QRectF r = v.toRectF();
4748 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4749 <<
"\" which is neither a point nor a rect";
4750 v4->throwTypeError();
4754 QV4::ScopedValue vx(scope, (*args)[1]);
4755 QV4::ScopedValue vy(scope, (*args)[2]);
4757 if (!vx->isNumber() || !vy->isNumber()) {
4758 v4->throwTypeError();
4762 *x = vx->asDouble();
4763 *y = vy->asDouble();
4765 if (args->length() > 3) {
4766 QV4::ScopedValue vw(scope, (*args)[3]);
4767 QV4::ScopedValue vh(scope, (*args)[4]);
4768 if (!vw->isNumber() || !vh->isNumber()) {
4769 v4->throwTypeError();
4772 *w = vw->asDouble();
4773 *h = vh->asDouble();
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4800#if QT_DEPRECATED_SINCE(6
, 5
)
4802
4803
4804void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4806 QV4::ExecutionEngine *v4 = args->v4engine();
4807 QV4::Scope scope(v4);
4811 QQuickItem *itemObj;
4812 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4815 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4816 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4818 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4819 args->setReturnValue(rv.asReturnedValue());
4824
4825
4826QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4828 Q_D(
const QQuickItem);
4834 QTransform t = d->itemToWindowTransform();
4835 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4858#if QT_DEPRECATED_SINCE(6
, 5
)
4860
4861
4862void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4864 QV4::ExecutionEngine *v4 = args->v4engine();
4865 QV4::Scope scope(v4);
4869 QQuickItem *itemObj;
4870 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4873 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4874 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4876 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4877 args->setReturnValue(rv.asReturnedValue());
4880static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4882 QV4::ExecutionEngine *v4 = args->v4engine();
4883 if (args->length() != 1 && args->length() != 2) {
4884 v4->throwTypeError();
4888 QV4::Scope scope(v4);
4890 if (args->length() == 1) {
4891 QV4::ScopedValue sv(scope, (*args)[0]);
4893 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4894 <<
"\" which is not a point";
4895 v4->throwTypeError();
4898 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4899 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4900 if (v.canConvert<QPointF>()) {
4901 const QPointF p = v.toPointF();
4905 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4906 <<
"\" which is not a point";
4907 v4->throwTypeError();
4911 QV4::ScopedValue vx(scope, (*args)[0]);
4912 QV4::ScopedValue vy(scope, (*args)[1]);
4914 if (!vx->isNumber() || !vy->isNumber()) {
4915 v4->throwTypeError();
4919 *x = vx->asDouble();
4920 *y = vy->asDouble();
4927
4928
4929
4930
4931
4932
4933
4934
4936
4937
4938void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4940 QV4::ExecutionEngine *v4 = args->v4engine();
4941 QV4::Scope scope(v4);
4944 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4947 QVariant result = mapFromGlobal(QPointF(x, y));
4949 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4950 args->setReturnValue(rv.asReturnedValue());
4955
4956
4957
4958
4959
4960
4961
4962
4964#if QT_DEPRECATED_SINCE(6
, 5
)
4966
4967
4968void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4970 QV4::ExecutionEngine *v4 = args->v4engine();
4971 QV4::Scope scope(v4);
4974 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4977 QVariant result = mapToGlobal(QPointF(x, y));
4979 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4980 args->setReturnValue(rv.asReturnedValue());
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010void QQuickItem::forceActiveFocus()
5012 forceActiveFocus(Qt::OtherFocusReason);
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5040void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5042 setFocus(
true, reason);
5043 QQuickItem *parent = parentItem();
5044 QQuickItem *scope =
nullptr;
5046 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5047 parent->setFocus(
true, reason);
5051 parent = parent->parentItem();
5056
5057
5058
5059
5060
5061
5062
5063
5064
5066
5067
5068
5069
5070
5072QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5074 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5078
5079
5080
5081
5082
5083
5084
5086
5087
5088
5089
5090
5091QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5093 const QList<QQuickItem *> children = childItems();
5094 for (
int i = children.size()-1; i >= 0; --i) {
5095 QQuickItem *child = children.at(i);
5097 QPointF point = mapToItem(child, QPointF(x, y));
5098 if (child->isVisible() && child->contains(point))
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145void QQuickItem::dumpItemTree()
const
5147 Q_D(
const QQuickItem);
5151void QQuickItemPrivate::dumpItemTree(
int indent)
const
5153 Q_Q(
const QQuickItem);
5155 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5156 qDebug().nospace().noquote() << indentStr <<
5157#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5158 const_cast<QQuickItem *>(q);
5162 if (extra.isAllocated()) {
5163 for (
const auto handler : extra->pointerHandlers)
5164 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5166 for (
const QQuickItem *ch : childItems) {
5167 auto itemPriv = QQuickItemPrivate::get(ch);
5168 itemPriv->dumpItemTree(indent + 1);
5172QQmlListProperty<QObject> QQuickItemPrivate::resources()
5176 QQmlListProperty<QObject> result;
5177 result.object = q_func();
5178 result.append = QQuickItemPrivate::resources_append;
5179 result.count = QQuickItemPrivate::resources_count;
5180 result.at = QQuickItemPrivate::resources_at;
5181 result.clear = QQuickItemPrivate::resources_clear;
5182 result.removeLast = QQuickItemPrivate::resources_removeLast;
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5200
5201
5202
5203QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5207 QQmlListProperty<QQuickItem> result;
5208 result.object = q_func();
5209 result.append = QQuickItemPrivate::children_append;
5210 result.count = QQuickItemPrivate::children_count;
5211 result.at = QQuickItemPrivate::children_at;
5212 result.clear = QQuickItemPrivate::children_clear;
5213 result.removeLast = QQuickItemPrivate::children_removeLast;
5218
5219
5220
5221
5222
5224
5225
5226
5227QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5229 return QQmlListProperty<QQuickItem>(q_func(),
5231 QQuickItemPrivate::visibleChildren_count,
5232 QQuickItemPrivate::visibleChildren_at);
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5273
5274
5275
5276QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5278 return _states()->statesProperty();
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5310
5311
5312
5313QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5315 return _states()->transitionsProperty();
5318QString QQuickItemPrivate::state()
const
5323 return _stateGroup->state();
5326void QQuickItemPrivate::setState(
const QString &state)
5328 _states()->setState(state);
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353QString QQuickItem::state()
const
5355 Q_D(
const QQuickItem);
5359void QQuickItem::setState(
const QString &state)
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5378
5379
5380
5382
5383
5384QQmlListProperty<QQuickTransform> QQuickItem::transform()
5386 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5387 QQuickItemPrivate::transform_count,
5388 QQuickItemPrivate::transform_at,
5389 QQuickItemPrivate::transform_clear);
5393
5394
5395
5396
5397void QQuickItem::classBegin()
5400 d->componentComplete =
false;
5402 d->_stateGroup->classBegin();
5404 d->_anchors->classBegin();
5405#if QT_CONFIG(quick_shadereffect)
5406 if (d->extra.isAllocated() && d->extra->layer)
5407 d->extra->layer->classBegin();
5412
5413
5414
5415
5416void QQuickItem::componentComplete()
5419 d->componentComplete =
true;
5421 d->_stateGroup->componentComplete();
5423 d->_anchors->componentComplete();
5424 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5427 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5428 safeArea->updateSafeArea();
5430 if (d->extra.isAllocated()) {
5431#if QT_CONFIG(quick_shadereffect)
5432 if (d->extra->layer)
5433 d->extra->layer->componentComplete();
5436 if (d->extra->keyHandler)
5437 d->extra->keyHandler->componentComplete();
5439 if (d->extra->contents)
5440 d->extra->contents->complete();
5443 if (d->window && d->dirtyAttributes) {
5444 d->addToDirtyList();
5445 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5448#if QT_CONFIG(accessibility)
5449 if (d->isAccessible && d->effectiveVisible) {
5450 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5451 QAccessible::updateAccessibility(&ev);
5456QQuickStateGroup *QQuickItemPrivate::_states()
5460 _stateGroup =
new QQuickStateGroup;
5461 if (!componentComplete)
5462 _stateGroup->classBegin();
5463 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5464 q, QQuickItem, SIGNAL(stateChanged(QString)));
5470QPointF QQuickItemPrivate::computeTransformOrigin()
const
5474 case QQuickItem::TopLeft:
5475 return QPointF(0, 0);
5476 case QQuickItem::Top:
5477 return QPointF(width / 2., 0);
5478 case QQuickItem::TopRight:
5479 return QPointF(width, 0);
5480 case QQuickItem::Left:
5481 return QPointF(0, height / 2.);
5482 case QQuickItem::Center:
5483 return QPointF(width / 2., height / 2.);
5484 case QQuickItem::Right:
5485 return QPointF(width, height / 2.);
5486 case QQuickItem::BottomLeft:
5487 return QPointF(0, height);
5488 case QQuickItem::Bottom:
5489 return QPointF(width / 2., height);
5490 case QQuickItem::BottomRight:
5491 return QPointF(width, height);
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5513#if QT_CONFIG(quick_shadereffect)
5514 if (q == transformedItem) {
5515 if (extra.isAllocated() && extra->layer)
5516 extra->layer->updateMatrix();
5520 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5522 bool childWantsIt =
false;
5523 if (subtreeTransformChangedEnabled) {
5526 const auto children = paintOrderChildItems();
5527 for (QQuickItem *child : children)
5528 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5531 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5532 const bool ret = childWantsIt || thisWantsIt;
5533 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5534 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5535 subtreeTransformChangedEnabled =
false;
5539 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5540 dirty(QQuickItemPrivate::Clip);
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5563 const QPointF &startPos,
5564 const QVector2D &activeTranslation,
5567 qreal startRotation,
5568 qreal activeRotation)
5571 QVector3D xformOrigin(q->transformOriginPoint());
5572 QMatrix4x4 startMatrix;
5573 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5574 startMatrix.translate(xformOrigin);
5575 startMatrix.scale(
float(startScale));
5576 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5577 startMatrix.translate(-xformOrigin);
5579 const QVector3D centroidParentVector(centroidParentPos);
5581 mat.translate(centroidParentVector);
5582 mat.rotate(
float(activeRotation), 0, 0, 1);
5583 mat.scale(
float(activeScale));
5584 mat.translate(-centroidParentVector);
5585 mat.translate(QVector3D(activeTranslation));
5587 mat = mat * startMatrix;
5589 QPointF xformOriginPoint = q->transformOriginPoint();
5590 QPointF pos = mat.map(xformOriginPoint);
5591 pos -= xformOriginPoint;
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5621 if (maybeHasSubsceneDeliveryAgent) {
5622 QQuickItemPrivate *p =
this;
5624 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5629 maybeHasSubsceneDeliveryAgent =
false;
5632 if (p->extra.isAllocated()) {
5633 if (
auto da = p->extra->subsceneDeliveryAgent)
5636 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5640 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5643 return QQuickWindowPrivate::get(window)->deliveryAgent;
5647QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5649 auto da = deliveryAgent();
5650 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5654
5655
5656
5657
5658
5659
5660
5661QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5667 maybeHasSubsceneDeliveryAgent =
true;
5668 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5669 return extra->subsceneDeliveryAgent;
5670 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5671 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5674 q->setFlag(QQuickItem::ItemIsFocusScope);
5675 return extra->subsceneDeliveryAgent;
5678bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5680 if (!extra.isAllocated() || !extra->keyHandler)
5686 if (e->type() == QEvent::KeyPress)
5687 extra->keyHandler->keyPressed(e, post);
5689 extra->keyHandler->keyReleased(e, post);
5691 return e->isAccepted();
5694void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5697 const auto eventType = event->type();
5698 const bool focusAccepted = setFocusIfNeeded(eventType);
5700 switch (eventType) {
5701 case QEvent::MouseButtonPress:
5702 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5704 case QEvent::MouseButtonRelease:
5705 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5707 case QEvent::MouseButtonDblClick:
5708 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5710#if QT_CONFIG(wheelevent)
5712 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5715 case QEvent::TouchBegin:
5716 case QEvent::TouchUpdate:
5717 case QEvent::TouchEnd:
5718 case QEvent::TouchCancel:
5719 q->touchEvent(
static_cast<QTouchEvent *>(event));
5729void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5733 Q_ASSERT(e->isAccepted());
5734 if (filterKeyEvent(e,
false))
5739 if (e->type() == QEvent::KeyPress)
5740 q->keyPressEvent(e);
5742 q->keyReleaseEvent(e);
5744 if (e->isAccepted())
5747 if (filterKeyEvent(e,
true) || !q->window())
5751 if (e->type() == QEvent::KeyPress &&
5752 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5754 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5755 if (e->key() == Qt::Key_Backtab
5756 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5757 res = QQuickItemPrivate::focusNextPrev(q,
false);
5758 else if (e->key() == Qt::Key_Tab)
5759 res = QQuickItemPrivate::focusNextPrev(q,
true);
5761 e->setAccepted(
true);
5767void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5771 Q_ASSERT(e->isAccepted());
5772 if (extra.isAllocated() && extra->keyHandler) {
5773 extra->keyHandler->inputMethodEvent(e,
false);
5775 if (e->isAccepted())
5781 q->inputMethodEvent(e);
5783 if (e->isAccepted())
5786 if (extra.isAllocated() && extra->keyHandler) {
5789 extra->keyHandler->inputMethodEvent(e,
true);
5794void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5796 if (extra.isAllocated() && extra->keyHandler)
5797 extra->keyHandler->shortcutOverrideEvent(event);
5802bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5804 if (!hasPointerHandlers())
5806 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5807 if (handler->wantsEventPoint(event, point))
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5829 bool delivered =
false;
5830 if (extra.isAllocated()) {
5831 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5832 bool avoidThisHandler =
false;
5833 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5834 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5835 avoidThisHandler =
true;
5836 }
else if (avoidGrabbers) {
5837 for (
auto &p : event->points()) {
5838 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5839 avoidThisHandler =
true;
5844 if (!avoidThisHandler &&
5845 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5846 handler->handlePointerEvent(event);
5854#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5855bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5857bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5860 if (extra.isAllocated() && extra->contextMenu)
5861 return extra->contextMenu->event(event);
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5881 if (change == ItemSceneChange)
5882 emit windowChanged(value.window);
5887
5888
5889
5890void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5892 if (hasActiveFocus())
5893 QGuiApplication::inputMethod()->update(queries);
5898
5899
5900
5901QRectF QQuickItem::boundingRect()
const
5903 Q_D(
const QQuickItem);
5904 return QRectF(0, 0, d->width, d->height);
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928QRectF QQuickItem::clipRect()
const
5930 Q_D(
const QQuickItem);
5931 QRectF ret(0, 0, d->width, d->height);
5932 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5933 if (QQuickItem *viewport = viewportItem()) {
5936 if (viewport ==
this)
5938 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5939 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5940 return mappedViewportRect.intersected(ret);
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957QQuickItem *QQuickItem::viewportItem()
const
5959 if (flags().testFlag(ItemObservesViewport)) {
5960 QQuickItem *par = parentItem();
5962 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
5964 par = par->parentItem();
5967 return (window() ? window()->contentItem() :
nullptr);
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5992
5993
5994
5995
5996
5997
5998
5999
6000QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6002 Q_D(
const QQuickItem);
6006void QQuickItem::setTransformOrigin(TransformOrigin origin)
6009 if (origin == d->origin())
6012 d->extra.value().origin = origin;
6013 d->dirty(QQuickItemPrivate::TransformOrigin);
6015 emit transformOriginChanged(d->origin());
6019
6020
6021
6023
6024
6025QPointF QQuickItem::transformOriginPoint()
const
6027 Q_D(
const QQuickItem);
6028 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6029 return d->extra->userTransformOriginPoint;
6030 return d->computeTransformOrigin();
6034
6035
6036void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6039 if (d->extra.value().userTransformOriginPoint == point)
6042 d->extra->userTransformOriginPoint = point;
6043 d->dirty(QQuickItemPrivate::TransformOrigin);
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200qreal QQuickItem::z()
const
6202 Q_D(
const QQuickItem);
6206void QQuickItem::setZ(qreal v)
6212 d->extra.value().z = v;
6214 d->dirty(QQuickItemPrivate::ZValue);
6215 if (d->parentItem) {
6216 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6217 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6222#if QT_CONFIG(quick_shadereffect)
6223 if (d->extra.isAllocated() && d->extra->layer)
6224 d->extra->layer->updateZ();
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280qreal QQuickItem::rotation()
const
6282 Q_D(
const QQuickItem);
6283 return d->rotation();
6286void QQuickItem::setRotation(qreal r)
6289 if (d->rotation() == r)
6292 d->extra.value().rotation = r;
6294 d->dirty(QQuickItemPrivate::BasicTransform);
6296 d->itemChange(ItemRotationHasChanged, r);
6298 emit rotationChanged();
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
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380qreal QQuickItem::scale()
const
6382 Q_D(
const QQuickItem);
6386void QQuickItem::setScale(qreal s)
6389 if (d->scale() == s)
6392 d->extra.value().scale = s;
6394 d->dirty(QQuickItemPrivate::BasicTransform);
6396 d->itemChange(ItemScaleHasChanged, s);
6398 emit scaleChanged();
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
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
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
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511qreal QQuickItem::opacity()
const
6513 Q_D(
const QQuickItem);
6514 return d->opacity();
6517void QQuickItem::setOpacity(qreal newOpacity)
6520 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6521 if (d->opacity() == o)
6524 d->extra.value().opacity = o;
6526 d->dirty(QQuickItemPrivate::OpacityValue);
6528 d->itemChange(ItemOpacityHasChanged, o);
6530 emit opacityChanged();
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597bool QQuickItem::isVisible()
const
6599 Q_D(
const QQuickItem);
6600 return d->effectiveVisible;
6603void QQuickItemPrivate::setVisible(
bool visible)
6605 if (visible == explicitVisible)
6608 explicitVisible = visible;
6610 dirty(QQuickItemPrivate::Visible);
6612 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6613 if (childVisibilityChanged && parentItem)
6614 emit parentItem->visibleChildrenChanged();
6617void QQuickItem::setVisible(
bool v)
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672bool QQuickItem::isEnabled()
const
6674 Q_D(
const QQuickItem);
6675 return d->effectiveEnable;
6678void QQuickItem::setEnabled(
bool e)
6681 if (e == d->explicitEnable)
6684 d->explicitEnable = e;
6686 QQuickItem *scope = parentItem();
6687 while (scope && !scope->isFocusScope())
6688 scope = scope->parentItem();
6690 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6693bool QQuickItemPrivate::calcEffectiveVisible()
const
6696 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6699bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6703 if (newEffectiveVisible && !explicitVisible) {
6708 if (newEffectiveVisible == effectiveVisible) {
6713 effectiveVisible = newEffectiveVisible;
6716 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6718 if (
auto agent = deliveryAgentPrivate())
6719 agent->removeGrabber(q,
true,
true,
true);
6722 bool childVisibilityChanged =
false;
6723 for (
int ii = 0; ii < childItems.size(); ++ii)
6724 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6726 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6727#if QT_CONFIG(accessibility)
6729 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6730 QAccessible::updateAccessibility(&ev);
6733 if (!inDestructor) {
6734 emit q->visibleChanged();
6735 if (childVisibilityChanged)
6736 emit q->visibleChildrenChanged();
6742bool QQuickItemPrivate::calcEffectiveEnable()
const
6747 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6750void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6754 if (newEffectiveEnable && !explicitEnable) {
6759 if (newEffectiveEnable == effectiveEnable) {
6764 effectiveEnable = newEffectiveEnable;
6766 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6768 da->removeGrabber(q,
true,
true,
true);
6769 if (scope && !effectiveEnable && activeFocus) {
6770 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6771 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6772 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6776 for (
int ii = 0; ii < childItems.size(); ++ii) {
6777 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6778 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6781 if (scope && effectiveEnable && focus && da) {
6782 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6783 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6784 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6787 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6788#if QT_CONFIG(accessibility)
6790 QAccessible::State changedState;
6791 changedState.disabled =
true;
6792 changedState.focusable =
true;
6793 QAccessibleStateChangeEvent ev(q, changedState);
6794 QAccessible::updateAccessibility(&ev);
6797 emit q->enabledChanged();
6800bool QQuickItemPrivate::isTransparentForPositioner()
const
6802 return extra.isAllocated() && extra.value().transparentForPositioner;
6805void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6807 extra.value().transparentForPositioner = transparent;
6811QString QQuickItemPrivate::dirtyToString()
const
6813#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6815 rv.append(QLatin1Char('|'));
6816 rv.append(QLatin1String(#value)); \
6817}
6844void QQuickItemPrivate::dirty(DirtyType type)
6847 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6848 dirtyAttributes |= type;
6849 if (window && componentComplete) {
6851 QQuickWindowPrivate::get(window)->dirtyItem(q);
6854 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6855 transformChanged(q);
6858void QQuickItemPrivate::addToDirtyList()
6863 if (!prevDirtyItem) {
6864 Q_ASSERT(!nextDirtyItem);
6866 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
6867 nextDirtyItem = p->dirtyItemList;
6868 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
6869 prevDirtyItem = &p->dirtyItemList;
6870 p->dirtyItemList = q;
6873 Q_ASSERT(prevDirtyItem);
6876void QQuickItemPrivate::removeFromDirtyList()
6878 if (prevDirtyItem) {
6879 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
6880 *prevDirtyItem = nextDirtyItem;
6881 prevDirtyItem =
nullptr;
6882 nextDirtyItem =
nullptr;
6884 Q_ASSERT(!prevDirtyItem);
6885 Q_ASSERT(!nextDirtyItem);
6888void QQuickItemPrivate::refFromEffectItem(
bool hide)
6890 ++extra.value().effectRefCount;
6891 if (extra->effectRefCount == 1) {
6892 dirty(EffectReference);
6894 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6897 if (++extra->hideRefCount == 1)
6898 dirty(HideReference);
6900 recursiveRefFromEffectItem(1);
6903void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
6908 extra.value().recursiveEffectRefCount += refs;
6909 for (
int ii = 0; ii < childItems.size(); ++ii) {
6910 QQuickItem *child = childItems.at(ii);
6911 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
6915 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
6919void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
6921 Q_ASSERT(extra->effectRefCount);
6922 --extra->effectRefCount;
6923 if (extra->effectRefCount == 0) {
6924 dirty(EffectReference);
6926 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6929 if (--extra->hideRefCount == 0)
6930 dirty(HideReference);
6932 recursiveRefFromEffectItem(-1);
6935void QQuickItemPrivate::setCulled(
bool cull)
6941 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
6942 dirty(HideReference);
6945void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
6949 case QQuickItem::ItemChildAddedChange: {
6950 q->itemChange(change, data);
6956 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
6957 if (!subtreeTransformChangedEnabled) {
6958 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
6959 subtreeTransformChangedEnabled =
true;
6961 enableSubtreeChangeNotificationsForParentHierachy();
6963 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
6966 case QQuickItem::ItemChildRemovedChange: {
6967 q->itemChange(change, data);
6968 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
6971 case QQuickItem::ItemSceneChange:
6972 q->itemChange(change, data);
6974 case QQuickItem::ItemVisibleHasChanged: {
6975 q->itemChange(change, data);
6976 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
6979 case QQuickItem::ItemEnabledHasChanged: {
6980 q->itemChange(change, data);
6981 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
6984 case QQuickItem::ItemParentHasChanged: {
6985 q->itemChange(change, data);
6986 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
6989 case QQuickItem::ItemOpacityHasChanged: {
6990 q->itemChange(change, data);
6991 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
6994 case QQuickItem::ItemActiveFocusHasChanged:
6995 q->itemChange(change, data);
6997 case QQuickItem::ItemRotationHasChanged: {
6998 q->itemChange(change, data);
6999 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7002 case QQuickItem::ItemScaleHasChanged: {
7003 q->itemChange(change, data);
7004 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7007 case QQuickItem::ItemTransformHasChanged: {
7008 q->itemChange(change, data);
7009 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7012 case QQuickItem::ItemAntialiasingHasChanged:
7014 case QQuickItem::ItemDevicePixelRatioHasChanged:
7015 q->itemChange(change, data);
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043bool QQuickItem::smooth()
const
7045 Q_D(
const QQuickItem);
7048void QQuickItem::setSmooth(
bool smooth)
7051 if (d->smooth == smooth)
7055 d->dirty(QQuickItemPrivate::Smooth);
7057 emit smoothChanged(smooth);
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7099bool QQuickItem::activeFocusOnTab()
const
7101 Q_D(
const QQuickItem);
7102 return d->activeFocusOnTab;
7104void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7107 if (d->activeFocusOnTab == activeFocusOnTab)
7111 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7112 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7117 d->activeFocusOnTab = activeFocusOnTab;
7119 emit activeFocusOnTabChanged(activeFocusOnTab);
7123
7124
7125
7126
7127
7128
7129
7130
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141bool QQuickItem::antialiasing()
const
7143 Q_D(
const QQuickItem);
7144 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7147void QQuickItem::setAntialiasing(
bool aa)
7151 if (!d->antialiasingValid) {
7152 d->antialiasingValid =
true;
7153 d->antialiasing = d->implicitAntialiasing;
7156 if (aa == d->antialiasing)
7159 d->antialiasing = aa;
7160 d->dirty(QQuickItemPrivate::Antialiasing);
7162 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7164 emit antialiasingChanged(antialiasing());
7167void QQuickItem::resetAntialiasing()
7170 if (!d->antialiasingValid)
7173 d->antialiasingValid =
false;
7175 if (d->implicitAntialiasing != d->antialiasing)
7176 emit antialiasingChanged(antialiasing());
7179void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7182 bool prev = q->antialiasing();
7183 implicitAntialiasing = antialiasing;
7184 if (componentComplete && (q->antialiasing() != prev))
7185 emit q->antialiasingChanged(q->antialiasing());
7189
7190
7191
7192
7193QQuickItem::Flags QQuickItem::flags()
const
7195 Q_D(
const QQuickItem);
7196 return (QQuickItem::Flags)d->flags;
7200
7201
7202
7203
7204
7205
7206
7207void QQuickItem::setFlag(Flag flag,
bool enabled)
7211 setFlags((Flags)(d->flags | (quint32)flag));
7213 setFlags((Flags)(d->flags & ~(quint32)flag));
7217 if (enabled && flag == ItemObservesViewport)
7218 d->enableSubtreeChangeNotificationsForParentHierachy();
7221void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7225 QQuickItem *par = q->parentItem();
7227 auto parPriv = QQuickItemPrivate::get(par);
7228 if (!parPriv->subtreeTransformChangedEnabled)
7229 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7230 parPriv->subtreeTransformChangedEnabled =
true;
7231 par = par->parentItem();
7236
7237
7238
7239
7240void QQuickItem::setFlags(Flags flags)
7244 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7245 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7246 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7247 flags &= ~ItemIsFocusScope;
7248 }
else if (d->flags & ItemIsFocusScope) {
7249 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7250 flags |= ItemIsFocusScope;
7254 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7255 d->dirty(QQuickItemPrivate::Clip);
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7276
7277
7278
7279
7281
7282
7283
7284
7285qreal QQuickItem::x()
const
7287 Q_D(
const QQuickItem);
7291qreal QQuickItem::y()
const
7293 Q_D(
const QQuickItem);
7298
7299
7300QPointF QQuickItem::position()
const
7302 Q_D(
const QQuickItem);
7303 return QPointF(d->x, d->y);
7306void QQuickItem::setX(qreal v)
7310
7311
7312
7313
7314
7315
7316
7317
7318 d->x.removeBindingUnlessInWrapper();
7322 const qreal oldx = d->x.valueBypassingBindings();
7326 d->x.setValueBypassingBindings(v);
7328 d->dirty(QQuickItemPrivate::Position);
7330 const qreal y = d->y.valueBypassingBindings();
7331 const qreal w = d->width.valueBypassingBindings();
7332 const qreal h = d->height.valueBypassingBindings();
7333 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7336void QQuickItem::setY(qreal v)
7339 d->y.removeBindingUnlessInWrapper();
7343 const qreal oldy = d->y.valueBypassingBindings();
7347 d->y.setValueBypassingBindings(v);
7349 d->dirty(QQuickItemPrivate::Position);
7353 const qreal x = d->x.valueBypassingBindings();
7354 const qreal w = d->width.valueBypassingBindings();
7355 const qreal h = d->height.valueBypassingBindings();
7356 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7360
7361
7362void QQuickItem::setPosition(
const QPointF &pos)
7366 const qreal oldx = d->x.valueBypassingBindings();
7367 const qreal oldy = d->y.valueBypassingBindings();
7369 if (QPointF(oldx, oldy) == pos)
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7385 d->x.setValueBypassingBindings(pos.x());
7386 d->y.setValueBypassingBindings(pos.y());
7388 d->dirty(QQuickItemPrivate::Position);
7390 const qreal w = d->width.valueBypassingBindings();
7391 const qreal h = d->height.valueBypassingBindings();
7392 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7396
7397
7398QBindable<qreal> QQuickItem::bindableX()
7400 return QBindable<qreal>(&d_func()->x);
7403QBindable<qreal> QQuickItem::bindableY()
7405 return QBindable<qreal>(&d_func()->y);
7409
7410
7411
7412
7413qreal QQuickItem::width()
const
7415 Q_D(
const QQuickItem);
7419void QQuickItem::setWidth(qreal w)
7422 d->width.removeBindingUnlessInWrapper();
7426 d->widthValidFlag =
true;
7427 const qreal oldWidth = d->width.valueBypassingBindings();
7431 d->width.setValueBypassingBindings(w);
7433 d->dirty(QQuickItemPrivate::Size);
7435 const qreal x = d->x.valueBypassingBindings();
7436 const qreal y = d->y.valueBypassingBindings();
7437 const qreal h = d->height.valueBypassingBindings();
7438 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7441void QQuickItem::resetWidth()
7444 d->width.takeBinding();
7445 d->widthValidFlag =
false;
7446 setImplicitWidth(implicitWidth());
7449void QQuickItemPrivate::implicitWidthChanged()
7452 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7453 emit q->implicitWidthChanged();
7456qreal QQuickItemPrivate::getImplicitWidth()
const
7458 return implicitWidth;
7461
7462
7463qreal QQuickItem::implicitWidth()
const
7465 Q_D(
const QQuickItem);
7466 return d->getImplicitWidth();
7469QBindable<qreal> QQuickItem::bindableWidth()
7471 return QBindable<qreal>(&d_func()->width);
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
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
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
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556void QQuickItem::setImplicitWidth(qreal w)
7559 bool changed = w != d->implicitWidth;
7560 d->implicitWidth = w;
7562 if (d->width.valueBypassingBindings() == w || widthValid()) {
7564 d->implicitWidthChanged();
7565 if (d->width.valueBypassingBindings() == w || widthValid())
7570 const qreal oldWidth = d->width.valueBypassingBindings();
7571 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7573 d->width.setValueBypassingBindings(w);
7575 d->dirty(QQuickItemPrivate::Size);
7577 const qreal x = d->x.valueBypassingBindings();
7578 const qreal y = d->y.valueBypassingBindings();
7579 const qreal width = w;
7580 const qreal height = d->height.valueBypassingBindings();
7581 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7584 d->implicitWidthChanged();
7588
7589
7590bool QQuickItem::widthValid()
const
7592 Q_D(
const QQuickItem);
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7610 return d->widthValid();
7614
7615
7616
7617
7618qreal QQuickItem::height()
const
7620 Q_D(
const QQuickItem);
7624void QQuickItem::setHeight(qreal h)
7630 d->height.removeBindingUnlessInWrapper();
7634 d->heightValidFlag =
true;
7635 const qreal oldHeight = d->height.valueBypassingBindings();
7639 d->height.setValueBypassingBindings(h);
7641 d->dirty(QQuickItemPrivate::Size);
7643 const qreal x = d->x.valueBypassingBindings();
7644 const qreal y = d->y.valueBypassingBindings();
7645 const qreal w = d->width.valueBypassingBindings();
7646 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7649void QQuickItem::resetHeight()
7655 d->height.takeBinding();
7656 d->heightValidFlag =
false;
7657 setImplicitHeight(implicitHeight());
7660void QQuickItemPrivate::implicitHeightChanged()
7663 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7664 emit q->implicitHeightChanged();
7667qreal QQuickItemPrivate::getImplicitHeight()
const
7669 return implicitHeight;
7672qreal QQuickItem::implicitHeight()
const
7674 Q_D(
const QQuickItem);
7675 return d->getImplicitHeight();
7678QBindable<qreal> QQuickItem::bindableHeight()
7680 return QBindable<qreal>(&d_func()->height);
7683void QQuickItem::setImplicitHeight(qreal h)
7686 bool changed = h != d->implicitHeight;
7687 d->implicitHeight = h;
7688 if (d->height.valueBypassingBindings() == h || heightValid()) {
7690 d->implicitHeightChanged();
7691 if (d->height.valueBypassingBindings() == h || heightValid())
7696 const qreal oldHeight = d->height.valueBypassingBindings();
7697 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7699 d->height.setValueBypassingBindings(h);
7701 d->dirty(QQuickItemPrivate::Size);
7703 const qreal x = d->x.valueBypassingBindings();
7704 const qreal y = d->y.valueBypassingBindings();
7705 const qreal width = d->width.valueBypassingBindings();
7706 const qreal height = d->height.valueBypassingBindings();
7707 geometryChange(QRectF(x, y, width, height),
7708 QRectF(x, y, width, oldHeight));
7711 d->implicitHeightChanged();
7715
7716
7717void QQuickItem::setImplicitSize(qreal w, qreal h)
7720 bool wChanged = w != d->implicitWidth;
7721 bool hChanged = h != d->implicitHeight;
7723 d->implicitWidth = w;
7724 d->implicitHeight = h;
7728 qreal width = d->width.valueBypassingBindings();
7729 qreal height = d->height.valueBypassingBindings();
7730 if (width == w || widthValid()) {
7732 d->implicitWidthChanged();
7733 wDone = width == w || widthValid();
7736 if (height == h || heightValid()) {
7738 d->implicitHeightChanged();
7739 hDone = height == h || heightValid();
7745 const qreal oldWidth = width;
7746 const qreal oldHeight = height;
7749 d->width.setValueBypassingBindings(w);
7753 d->height.setValueBypassingBindings(h);
7756 d->dirty(QQuickItemPrivate::Size);
7758 const qreal x = d->x.valueBypassingBindings();
7759 const qreal y = d->y.valueBypassingBindings();
7760 geometryChange(QRectF(x, y, width, height),
7761 QRectF(x, y, oldWidth, oldHeight));
7763 if (!wDone && wChanged)
7764 d->implicitWidthChanged();
7765 if (!hDone && hChanged)
7766 d->implicitHeightChanged();
7770
7771
7772bool QQuickItem::heightValid()
const
7774 Q_D(
const QQuickItem);
7775 return d->heightValid();
7779
7780
7781
7782
7783
7784
7786QSizeF QQuickItem::size()
const
7788 Q_D(
const QQuickItem);
7789 return QSizeF(d->width, d->height);
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803void QQuickItem::setSize(
const QSizeF &size)
7806 d->heightValidFlag =
true;
7807 d->widthValidFlag =
true;
7809 const qreal oldHeight = d->height.valueBypassingBindings();
7810 const qreal oldWidth = d->width.valueBypassingBindings();
7812 if (oldWidth == size.width() && oldHeight == size.height())
7815 d->height.setValueBypassingBindings(size.height());
7816 d->width.setValueBypassingBindings(size.width());
7818 d->dirty(QQuickItemPrivate::Size);
7820 const qreal x = d->x.valueBypassingBindings();
7821 const qreal y = d->y.valueBypassingBindings();
7822 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894bool QQuickItem::hasActiveFocus()
const
7896 Q_D(
const QQuickItem);
7897 return d->activeFocus;
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
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
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
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988bool QQuickItem::hasFocus()
const
7990 Q_D(
const QQuickItem);
7994void QQuickItem::setFocus(
bool focus)
7996 setFocus(focus, Qt::OtherFocusReason);
7999void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8003 QQuickItem *scope = parentItem();
8004 while (scope && !scope->isFocusScope() && scope->parentItem())
8005 scope = scope->parentItem();
8007 if (d->focus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8010 bool notifyListeners =
false;
8011 if (d->window || d->parentItem) {
8013 auto da = d->deliveryAgentPrivate();
8016 da->setFocusInScope(scope,
this, reason);
8018 da->clearFocusInScope(scope,
this, reason);
8022 QVarLengthArray<QQuickItem *, 20> changed;
8023 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8024 if (oldSubFocusItem) {
8025 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8026 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8027 changed << oldSubFocusItem;
8028 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8029 QQuickItemPrivate::get(scope)->focus =
false;
8032 d->updateSubFocusItem(scope, focus);
8036 notifyListeners =
true;
8037 emit focusChanged(focus);
8039 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8042 QVarLengthArray<QQuickItem *, 20> changed;
8043 QQuickItem *oldSubFocusItem = d->subFocusItem;
8044 if (!isFocusScope() && oldSubFocusItem) {
8045 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8046 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8047 changed << oldSubFocusItem;
8052 notifyListeners =
true;
8053 emit focusChanged(focus);
8055 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8057 if (notifyListeners)
8058 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8062
8063
8064bool QQuickItem::isFocusScope()
const
8066 return flags() & ItemIsFocusScope;
8070
8071
8072
8073
8074
8075QQuickItem *QQuickItem::scopedFocusItem()
const
8077 Q_D(
const QQuickItem);
8078 if (!isFocusScope())
8081 return d->subFocusItem;
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8099
8100
8101
8102
8103
8104
8105Qt::FocusPolicy QQuickItem::focusPolicy()
const
8107 Q_D(
const QQuickItem);
8108 uint policy = d->focusPolicy;
8109 if (activeFocusOnTab())
8110 policy |= Qt::TabFocus;
8111 return static_cast<Qt::FocusPolicy>(policy);
8115
8116
8117
8118
8119void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8122 if (d->focusPolicy == policy)
8125 d->focusPolicy = policy;
8126 setActiveFocusOnTab(policy & Qt::TabFocus);
8127 emit focusPolicyChanged(policy);
8131
8132
8133
8134
8135
8136
8137
8138bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8140 if (!child || child ==
this)
8142 const QQuickItem *ancestor = child;
8143 while ((ancestor = ancestor->parentItem())) {
8144 if (ancestor ==
this)
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8163 Q_D(
const QQuickItem);
8164 return d->acceptedMouseButtons();
8168
8169
8170
8171
8172
8173
8174
8175
8176void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8179 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8181 buttons &= ~Qt::LeftButton;
8182 if (buttons || d->extra.isAllocated()) {
8183 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8184 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199bool QQuickItem::filtersChildMouseEvents()
const
8201 Q_D(
const QQuickItem);
8202 return d->filtersChildMouseEvents;
8206
8207
8208
8209
8210
8211
8212
8213
8214void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8217 d->filtersChildMouseEvents = filter;
8221
8222
8223bool QQuickItem::isUnderMouse()
const
8225 Q_D(
const QQuickItem);
8232 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8235 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8236 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8240
8241
8242
8243
8244
8245
8246
8247bool QQuickItem::acceptHoverEvents()
const
8249 Q_D(
const QQuickItem);
8250 return d->hoverEnabled;
8254
8255
8256
8257
8258
8259void QQuickItem::setAcceptHoverEvents(
bool enabled)
8266 d->hoverEnabled = enabled;
8272 d->setHasHoverInChild(enabled);
8276 d->dirty(QQuickItemPrivate::Content);
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289bool QQuickItem::acceptTouchEvents()
const
8291 Q_D(
const QQuickItem);
8292 return d->touchEnabled;
8296
8297
8298
8299
8300
8301
8302
8303void QQuickItem::setAcceptTouchEvents(
bool enabled)
8306 d->touchEnabled = enabled;
8309void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8311#if QT_CONFIG(cursor)
8316 if (!hc && subtreeCursorEnabled) {
8319 for (QQuickItem *otherChild : std::as_const(childItems)) {
8320 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8321 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8326 subtreeCursorEnabled = hc;
8327 QQuickItem *parent = q->parentItem();
8329 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8330 parentPrivate->setHasCursorInChild(hc);
8337void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8343 if (!hasHover && subtreeHoverEnabled) {
8346 if (hasEnabledHoverHandlers())
8349 for (QQuickItem *otherChild : std::as_const(childItems)) {
8350 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8351 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8353 if (otherChildPrivate->hasEnabledHoverHandlers())
8358 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8359 subtreeHoverEnabled = hasHover;
8360 QQuickItem *parent = q->parentItem();
8362 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8363 parentPrivate->setHasHoverInChild(hasHover);
8367#if QT_CONFIG(cursor)
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8383QCursor QQuickItem::cursor()
const
8385 Q_D(
const QQuickItem);
8386 return d->extra.isAllocated()
8392
8393
8394
8395
8397void QQuickItem::setCursor(
const QCursor &cursor)
8401 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8402 qCDebug(lcHoverTrace) << oldShape <<
"->" << cursor.shape();
8404 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8405 d->extra.value().cursor = cursor;
8407 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8408 QWindow *window = renderWindow ? renderWindow : d->window;
8409 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8410 window->setCursor(cursor);
8414 QPointF updateCursorPos;
8415 if (!d->hasCursor) {
8416 d->hasCursor =
true;
8418 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8419 QWindow *window = renderWindow ? renderWindow : d->window;
8420 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8421 if (contains(mapFromScene(pos)))
8422 updateCursorPos = pos;
8425 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8426 if (!updateCursorPos.isNull())
8427 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8431
8432
8433
8434
8436void QQuickItem::unsetCursor()
8439 qCDebug(lcHoverTrace) <<
"clearing cursor";
8442 d->hasCursor =
false;
8443 d->setHasCursorInChild(d->hasCursorHandler);
8444 if (d->extra.isAllocated())
8445 d->extra->cursor = QCursor();
8448 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8449 if (windowPrivate->cursorItem ==
this) {
8450 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8451 windowPrivate->updateCursor(pos);
8457
8458
8459
8460
8461
8462
8463QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8465 Q_Q(
const QQuickItem);
8468 bool hoverCursorSet =
false;
8469 QCursor hoverCursor;
8470 bool activeCursorSet =
false;
8471 QCursor activeCursor;
8472 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8473 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8474 hoverCursor = hoverHandler->cursorShape();
8475 }
else if (handler->active()) {
8476 activeCursorSet = handler->isCursorShapeExplicitlySet();
8477 activeCursor = handler->cursorShape();
8479 if (activeCursorSet)
8480 return activeCursor;
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8508 if (!hasPointerHandlers())
8510 QQuickPointerHandler* activeHandler =
nullptr;
8511 QQuickPointerHandler* mouseHandler =
nullptr;
8512 QQuickPointerHandler* nonMouseHandler =
nullptr;
8513 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8514 if (!h->isCursorShapeExplicitlySet())
8516 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8521 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8522 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8523 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8525 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8526 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8527 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8529 mouseHandler = hoverHandler;
8532 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8533 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8534 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8536 nonMouseHandler = hoverHandler;
8539 if (!hoverHandler && h->active())
8542 if (activeHandler) {
8543 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8544 return activeHandler;
8550 if (nonMouseHandler) {
8552 const bool beforeTimeout =
8553 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8554 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8555 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8556 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8557 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8558 <<
"choosing cursor according to" << winner << winner->cursorShape();
8561 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8562 return nonMouseHandler;
8565 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8566 return mouseHandler;
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585void QQuickItem::grabMouse()
8590 auto da = d->deliveryAgentPrivate();
8592 auto eventInDelivery = da->eventInDelivery();
8593 if (!eventInDelivery) {
8594 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8597 auto epd = da->mousePointData();
8598 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612void QQuickItem::ungrabMouse()
8617 auto da = d->deliveryAgentPrivate();
8619 auto eventInDelivery = da->eventInDelivery();
8620 if (!eventInDelivery) {
8622 da->removeGrabber(
this);
8625 const auto &eventPoint = da->mousePointData()->eventPoint;
8626 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8627 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8631
8632
8633
8634
8635bool QQuickItem::keepMouseGrab()
const
8637 Q_D(
const QQuickItem);
8638 return d->keepMouse;
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657void QQuickItem::setKeepMouseGrab(
bool keep)
8660 d->keepMouse = keep;
8664
8665
8666
8667
8668
8669
8670
8671
8672void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8675 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8676 if (Q_UNLIKELY(!event)) {
8677 qWarning() <<
"cannot grab: no event is currently being delivered";
8680 for (
auto pt : event->points()) {
8681 if (ids.contains(pt.id()))
8682 event->setExclusiveGrabber(pt,
this);
8687
8688
8689
8690void QQuickItem::ungrabTouchPoints()
8695 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8696 da->removeGrabber(
this,
false,
true);
8700
8701
8702
8703
8704
8705bool QQuickItem::keepTouchGrab()
const
8707 Q_D(
const QQuickItem);
8708 return d->keepTouch;
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728void QQuickItem::setKeepTouchGrab(
bool keep)
8731 d->keepTouch = keep;
8735
8736
8737
8738
8739
8740
8741
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753bool QQuickItem::contains(
const QPointF &point)
const
8755 Q_D(
const QQuickItem);
8756 if (d->extra.isAllocated() && d->extra->mask) {
8757 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8758 return quickMask->contains(point - quickMask->position());
8761 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8762 maskContains.invoke(d->extra->mask,
8763 Qt::DirectConnection,
8764 Q_RETURN_ARG(
bool, res),
8765 Q_ARG(QPointF, point));
8769 qreal x = point.x();
8770 qreal y = point.y();
8771 return x >= 0 && y >= 0 && x < d->width && y < d->height;
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
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837QObject *QQuickItem::containmentMask()
const
8839 Q_D(
const QQuickItem);
8840 if (!d->extra.isAllocated())
8842 return d->extra->mask.data();
8845void QQuickItem::setContainmentMask(QObject *mask)
8848 const bool extraDataExists = d->extra.isAllocated();
8850 if (mask ==
static_cast<QObject *>(
this))
8853 if (!extraDataExists && !mask)
8856 if (extraDataExists && d->extra->mask == mask)
8859 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8862 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8863 maskPrivate->registerAsContainmentMask(
this,
false);
8866 if (!extraDataExists)
8869 int methodIndex = mask->metaObject()->indexOfMethod(QByteArrayLiteral(
"contains(QPointF)"));
8870 if (methodIndex < 0) {
8871 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
8874 d->extra->maskContainsIndex = methodIndex;
8876 d->extra->mask = mask;
8877 quickMask = qobject_cast<QQuickItem *>(mask);
8879 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8880 maskPrivate->registerAsContainmentMask(
this,
true);
8882 emit containmentMaskChanged();
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
8899 QPointF p = mapToScene(point);
8901 const auto *itemWindow = item->window();
8902 const auto *thisWindow = window();
8903 if (thisWindow && itemWindow && itemWindow != thisWindow)
8904 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
8906 p = item->mapFromScene(p);
8912
8913
8914
8915
8916
8917
8918
8919
8920QPointF QQuickItem::mapToScene(
const QPointF &point)
const
8922 Q_D(
const QQuickItem);
8923 return d->itemToWindowTransform().map(point);
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
8945 Q_D(
const QQuickItem);
8947 if (Q_UNLIKELY(d->window ==
nullptr))
8948 return mapToScene(point);
8950 QPoint renderOffset;
8951 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
8952 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
8953 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
8970 Q_D(
const QQuickItem);
8971 QTransform t = d->itemToWindowTransform();
8973 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
8974 return t.mapRect(rect);
8978
8979
8980
8981
8982
8983
8984
8985
8986QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
8988 Q_D(
const QQuickItem);
8989 return d->itemToWindowTransform().mapRect(rect);
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9008 p = item->mapToScene(point);
9009 const auto *itemWindow = item->window();
9010 const auto *thisWindow = window();
9011 if (thisWindow && itemWindow && itemWindow != thisWindow)
9012 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9014 return mapFromScene(p);
9018
9019
9020
9021
9022
9023
9024
9025
9026QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9028 Q_D(
const QQuickItem);
9029 return d->windowToItemTransform().map(point);
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9057 Q_D(
const QQuickItem);
9060 if (Q_LIKELY(d->window)) {
9061 QPoint renderOffset;
9062 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9063 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9064 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9069 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9070 if (
auto sceneTransform = da->sceneTransform())
9071 scenePoint = sceneTransform->map(scenePoint);
9073 return mapFromScene(scenePoint);
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9090 Q_D(
const QQuickItem);
9091 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9092 t *= d->windowToItemTransform();
9093 return t.mapRect(rect);
9097
9098
9099
9100
9101
9102
9103
9104
9105QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9107 Q_D(
const QQuickItem);
9108 return d->windowToItemTransform().mapRect(rect);
9112
9113
9114
9117
9118
9119
9122
9123
9124
9127
9128
9129
9132
9133
9134
9137
9138
9139
9142
9143
9144
9147
9148
9149
9152
9153
9154
9157
9158
9159
9162
9163
9164bool QQuickItem::event(QEvent *ev)
9168 switch (ev->type()) {
9170 case QEvent::InputMethodQuery: {
9171 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9172 Qt::InputMethodQueries queries = query->queries();
9173 for (uint i = 0; i < 32; ++i) {
9174 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9176 QVariant v = inputMethodQuery(q);
9177 query->setValue(q, v);
9183 case QEvent::InputMethod:
9184 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9187 case QEvent::TouchBegin:
9188 case QEvent::TouchUpdate:
9189 case QEvent::TouchEnd:
9190 case QEvent::TouchCancel:
9191 case QEvent::MouseButtonPress:
9192 case QEvent::MouseButtonRelease:
9193 case QEvent::MouseButtonDblClick:
9194#if QT_CONFIG(wheelevent)
9197 d->deliverPointerEvent(ev);
9199 case QEvent::StyleAnimationUpdate:
9205 case QEvent::HoverEnter:
9206 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9208 case QEvent::HoverLeave:
9209 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9211 case QEvent::HoverMove:
9212 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9214 case QEvent::KeyPress:
9215 case QEvent::KeyRelease:
9216 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9218 case QEvent::ShortcutOverride:
9219 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9221 case QEvent::FocusIn:
9222 focusInEvent(
static_cast<QFocusEvent*>(ev));
9224 case QEvent::FocusOut:
9225 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9227 case QEvent::MouseMove:
9228 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9230#if QT_CONFIG(quick_draganddrop)
9231 case QEvent::DragEnter:
9232 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9234 case QEvent::DragLeave:
9235 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9237 case QEvent::DragMove:
9238 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9241 dropEvent(
static_cast<QDropEvent*>(ev));
9244#if QT_CONFIG(gestures)
9245 case QEvent::NativeGesture:
9249 case QEvent::LanguageChange:
9250 case QEvent::LocaleChange:
9251 for (QQuickItem *item : std::as_const(d->childItems))
9252 QCoreApplication::sendEvent(item, ev);
9254 case QEvent::WindowActivate:
9255 case QEvent::WindowDeactivate:
9256 if (d->providesPalette())
9257 d->setCurrentColorGroup();
9258 for (QQuickItem *item : std::as_const(d->childItems))
9259 QCoreApplication::sendEvent(item, ev);
9261 case QEvent::ApplicationPaletteChange:
9262 for (QQuickItem *item : std::as_const(d->childItems))
9263 QCoreApplication::sendEvent(item, ev);
9265 case QEvent::ContextMenu:
9267 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9270 return QObject::event(ev);
9276#ifndef QT_NO_DEBUG_STREAM
9278#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9283 QDebugStateSaver saver(debug);
9286 debug <<
"QQuickItem(nullptr)";
9290 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9292 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9296 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9297 if (QQmlContext *context = qmlContext(item)) {
9298 const auto objectId = context->nameForObject(item);
9299 if (!objectId.isEmpty())
9300 debug <<
", id=" << objectId;
9303 if (!item->objectName().isEmpty())
9304 debug <<
", name=" << item->objectName();
9305 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9307 QtDebugUtils::formatQRect(debug, rect);
9308 if (
const qreal z = item->z())
9309 debug <<
", z=" << z;
9310 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9311 debug <<
" \U0001f5bc";
9312 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9320
9321
9322
9323
9324
9325
9326
9328bool QQuickItem::isTextureProvider()
const
9330#if QT_CONFIG(quick_shadereffect)
9331 Q_D(
const QQuickItem);
9332 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9333 d->extra->layer->effectSource()->isTextureProvider() :
false;
9340
9341
9342
9343
9344
9345
9346
9348QSGTextureProvider *QQuickItem::textureProvider()
const
9350#if QT_CONFIG(quick_shadereffect)
9351 Q_D(
const QQuickItem);
9352 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9353 d->extra->layer->effectSource()->textureProvider() :
nullptr;
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
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9401#if QT_CONFIG(quick_shadereffect)
9403
9404
9405
9406QQuickItemLayer *QQuickItemPrivate::layer()
const
9408 if (!extra.isAllocated() || !extra->layer) {
9409 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9410 if (!componentComplete)
9411 extra->layer->classBegin();
9413 return extra->layer;
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9437 QList<QEventPoint> touchPoints;
9438 QEventPoint::States eventStates;
9440 bool anyPressOrReleaseInside =
false;
9441 bool anyGrabber =
false;
9442 for (
auto &p : event->points()) {
9447 auto pointGrabber = event->exclusiveGrabber(p);
9448 bool isGrabber = (pointGrabber == q);
9449 if (!isGrabber && pointGrabber && isFiltering) {
9450 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9451 if (handlerGrabber && handlerGrabber->parentItem() == q)
9458 const auto localPos = q->mapFromScene(p.scenePosition());
9459 bool isInside = q->contains(localPos);
9460 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9462 if (isFiltering && !pointGrabber) {
9463 const auto pg = event->passiveGrabbers(p);
9464 if (!pg.isEmpty()) {
9468 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9470 pointGrabber = handler->parentItem();
9475 bool grabberIsChild =
false;
9476 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9477 while (isFiltering && parent) {
9479 grabberIsChild =
true;
9482 parent = parent->parentItem();
9485 bool filterRelevant = isFiltering && grabberIsChild;
9486 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9488 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9489 anyPressOrReleaseInside =
true;
9490 QEventPoint pCopy(p);
9491 eventStates |= p.state();
9492 if (p.state() == QEventPoint::State::Released)
9493 QMutableEventPoint::detach(pCopy);
9494 QMutableEventPoint::setPosition(pCopy, localPos);
9495 touchPoints.append(std::move(pCopy));
9500 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9501 *localized = QMutableTouchEvent(QEvent::None);
9506 QEvent::Type eventType = event->type();
9507 switch (eventStates) {
9508 case QEventPoint::State::Pressed:
9509 eventType = QEvent::TouchBegin;
9511 case QEventPoint::State::Released:
9512 eventType = QEvent::TouchEnd;
9515 eventType = QEvent::TouchUpdate;
9519 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9521 ret.setTimestamp(event->timestamp());
9526bool QQuickItemPrivate::hasPointerHandlers()
const
9528 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9531bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9533 if (!hasPointerHandlers())
9535 for (QQuickPointerHandler *h : extra->pointerHandlers)
9536 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9541void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9547 extra.value().acceptedMouseButtons = Qt::AllButtons;
9548 auto &handlers = extra.value().pointerHandlers;
9549 if (!handlers.contains(h))
9550 handlers.prepend(h);
9551 auto &res = extra.value().resourcesList;
9552 if (!res.contains(h)) {
9554 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9555 _q_resourceObjectDeleted(o);
9560void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9564 auto &handlers = extra.value().pointerHandlers;
9565 handlers.removeOne(h);
9566 auto &res = extra.value().resourcesList;
9568 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9569 if (handlers.isEmpty())
9570 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9574
9575
9576
9577QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9579 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9580 extra.value().contextMenu = menu;
9584#if QT_CONFIG(quick_shadereffect)
9585QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9591 , m_componentComplete(
true)
9592 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9593 , m_format(QQuickShaderEffectSource::RGBA8)
9595 , m_effectComponent(
nullptr)
9597 , m_effectSource(
nullptr)
9598 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9603QQuickItemLayer::~QQuickItemLayer()
9605 delete m_effectSource;
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623void QQuickItemLayer::setEnabled(
bool e)
9628 if (m_componentComplete) {
9635 emit enabledChanged(e);
9638void QQuickItemLayer::classBegin()
9640 Q_ASSERT(!m_effectSource);
9641 Q_ASSERT(!m_effect);
9642 m_componentComplete =
false;
9645void QQuickItemLayer::componentComplete()
9647 Q_ASSERT(!m_componentComplete);
9648 m_componentComplete =
true;
9653void QQuickItemLayer::activate()
9655 Q_ASSERT(!m_effectSource);
9656 m_effectSource =
new QQuickShaderEffectSource();
9657 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9659 QQuickItem *parentItem = m_item->parentItem();
9661 m_effectSource->setParentItem(parentItem);
9662 m_effectSource->stackAfter(m_item);
9665 m_effectSource->setSourceItem(m_item);
9666 m_effectSource->setHideSource(
true);
9667 m_effectSource->setSmooth(m_smooth);
9668 m_effectSource->setLive(m_live);
9669 m_effectSource->setTextureSize(m_size);
9670 m_effectSource->setSourceRect(m_sourceRect);
9671 m_effectSource->setMipmap(m_mipmap);
9672 m_effectSource->setWrapMode(m_wrapMode);
9673 m_effectSource->setFormat(m_format);
9674 m_effectSource->setTextureMirroring(m_textureMirroring);
9675 m_effectSource->setSamples(m_samples);
9677 if (m_effectComponent)
9680 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9687 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9688 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9691void QQuickItemLayer::deactivate()
9693 Q_ASSERT(m_effectSource);
9695 if (m_effectComponent)
9698 delete m_effectSource;
9699 m_effectSource =
nullptr;
9701 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9702 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9705void QQuickItemLayer::activateEffect()
9707 Q_ASSERT(m_effectSource);
9708 Q_ASSERT(m_effectComponent);
9709 Q_ASSERT(!m_effect);
9711 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9712 m_effect = qobject_cast<QQuickItem *>(created);
9714 qWarning(
"Item: layer.effect is not a QML Item.");
9715 m_effectComponent->completeCreate();
9719 QQuickItem *parentItem = m_item->parentItem();
9721 m_effect->setParentItem(parentItem);
9722 m_effect->stackAfter(m_effectSource);
9724 m_effect->setVisible(m_item->isVisible());
9725 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9726 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9727 m_effectComponent->completeCreate();
9730void QQuickItemLayer::deactivateEffect()
9732 Q_ASSERT(m_effectSource);
9733 Q_ASSERT(m_effectComponent);
9741
9742
9743
9744
9745
9746
9747
9748
9749
9751void QQuickItemLayer::setEffect(QQmlComponent *component)
9753 if (component == m_effectComponent)
9756 bool updateNeeded =
false;
9757 if (m_effectSource && m_effectComponent) {
9759 updateNeeded =
true;
9762 m_effectComponent = component;
9764 if (m_effectSource && m_effectComponent) {
9766 updateNeeded =
true;
9774 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9777 emit effectChanged(component);
9782
9783
9784
9785
9786
9787
9788
9789
9790
9792void QQuickItemLayer::setMipmap(
bool mipmap)
9794 if (mipmap == m_mipmap)
9799 m_effectSource->setMipmap(m_mipmap);
9801 emit mipmapChanged(mipmap);
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9822void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9829 m_effectSource->setFormat(m_format);
9831 emit formatChanged(m_format);
9836
9837
9838
9839
9840
9841
9842
9843
9844
9846void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
9848 if (sourceRect == m_sourceRect)
9850 m_sourceRect = sourceRect;
9853 m_effectSource->setSourceRect(m_sourceRect);
9855 emit sourceRectChanged(sourceRect);
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9870void QQuickItemLayer::setSmooth(
bool s)
9877 m_effectSource->setSmooth(m_smooth);
9879 emit smoothChanged(s);
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9894void QQuickItemLayer::setLive(
bool live)
9901 m_effectSource->setLive(m_live);
9903 emit liveChanged(live);
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9919void QQuickItemLayer::setSize(
const QSize &size)
9926 m_effectSource->setTextureSize(size);
9928 emit sizeChanged(size);
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9949void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
9951 if (mode == m_wrapMode)
9956 m_effectSource->setWrapMode(m_wrapMode);
9958 emit wrapModeChanged(mode);
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9976void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
9978 if (mirroring == m_textureMirroring)
9980 m_textureMirroring = mirroring;
9983 m_effectSource->setTextureMirroring(m_textureMirroring);
9985 emit textureMirroringChanged(mirroring);
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10013void QQuickItemLayer::setSamples(
int count)
10015 if (m_samples == count)
10020 if (m_effectSource)
10021 m_effectSource->setSamples(m_samples);
10023 emit samplesChanged(count);
10027
10028
10029
10030
10031
10032
10033
10034
10035
10037void QQuickItemLayer::setName(
const QByteArray &name) {
10038 if (m_name == name)
10041 m_effect->setProperty(m_name, QVariant());
10042 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10045 emit nameChanged(name);
10048void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10054void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10059void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10062 Q_ASSERT(item == m_item);
10063 Q_ASSERT(parent != m_effectSource);
10064 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10066 m_effectSource->setParentItem(parent);
10068 m_effectSource->stackAfter(m_item);
10071 m_effect->setParentItem(parent);
10073 m_effect->stackAfter(m_effectSource);
10077void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10079 m_effectSource->stackAfter(m_item);
10081 m_effect->stackAfter(m_effectSource);
10084void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10086 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10089 l->setVisible(m_item->isVisible());
10092void QQuickItemLayer::updateZ()
10094 if (!m_componentComplete || !m_enabled)
10096 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10099 l->setZ(m_item->z());
10102void QQuickItemLayer::updateOpacity()
10104 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10107 l->setOpacity(m_item->opacity());
10110void QQuickItemLayer::updateGeometry()
10112 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10117 QRectF bounds = m_item->QQuickItem::boundingRect();
10118 l->setSize(bounds.size());
10119 l->setPosition(bounds.topLeft() + m_item->position());
10122void QQuickItemLayer::updateMatrix()
10126 if (!m_componentComplete || !m_enabled)
10128 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10131 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10132 l->setScale(m_item->scale());
10133 l->setRotation(m_item->rotation());
10134 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10135 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10136 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10137 ld->dirty(QQuickItemPrivate::Transform);
10141QQuickItemPrivate::ExtraData::ExtraData()
10142: z(0), scale(1), rotation(0), opacity(1),
10143 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10144 enterKeyAttached(
nullptr),
10145 keyHandler(
nullptr), contextMenu(
nullptr),
10146#if QT_CONFIG(quick_shadereffect)
10149 effectRefCount(0), hideRefCount(0),
10150 recursiveEffectRefCount(0),
10151 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10152 origin(QQuickItem::Center),
10153 transparentForPositioner(
false)
10155#ifdef QT_BUILD_INTERNAL
10156 ++QQuickItemPrivate::itemExtra_counter;
10161#if QT_CONFIG(accessibility)
10162QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10164 Q_Q(
const QQuickItem);
10165 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10166 auto role = QAccessible::NoRole;
10167 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10168 role = accessibleAttached->role();
10169 if (role == QAccessible::NoRole)
10170 role = accessibleRole();
10174QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10176 return QAccessible::NoRole;
10185 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10198 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10199 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10200 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10201 QV4::QObjectWrapper::markWrapper(child, markStack);
10203 QObjectWrapper::markObjects(that, markStack);
10206quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10208 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10213 QDebugStateSaver stateSaver(debug);
10214 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10219QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10220{
return mapFromItem(item, QPointF(x, y) ); }
10223QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10224{
return mapRectFromItem(item, rect); }
10227QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10228{
return mapFromItem(item, QRectF(x, y, width, height)); }
10231QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10232{
return mapToItem(item, QPointF(x, y)); }
10235QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10236{
return mapRectToItem(item, rect); }
10239QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10240{
return mapToItem(item, QRectF(x, y, width, height)); }
10243QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10244{
return mapToGlobal(QPointF(x, y)); }
10247QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10248{
return mapFromGlobal(QPointF(x, y)); }
10251QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10255#include <moc_qquickitem.cpp>
10257#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)