8#include <QtQml/qjsengine.h>
15#include <QtQml/qqmlengine.h>
16#include <QtQml/qqmlcomponent.h>
17#include <QtQml/qqmlinfo.h>
18#include <QtGui/qpen.h>
19#include <QtGui/qguiapplication.h>
20#include <QtGui/qstylehints.h>
21#include <QtGui/private/qeventpoint_p.h>
22#include <QtGui/private/qguiapplication_p.h>
23#include <QtGui/private/qpointingdevice_p.h>
24#include <QtGui/qinputmethod.h>
25#include <QtCore/qcoreevent.h>
26#include <QtCore/private/qnumeric_p.h>
27#include <QtGui/qpa/qplatformtheme.h>
28#include <QtCore/qloggingcategory.h>
29#include <QtCore/private/qduplicatetracker_p.h>
31#include <private/qqmlglobal_p.h>
32#include <private/qqmlengine_p.h>
33#include <QtQuick/private/qquickstategroup_p.h>
34#include <private/qqmlopenmetaobject_p.h>
35#include <QtQuick/private/qquickstate_p.h>
36#include <private/qquickitem_p.h>
37#include <QtQuick/private/qquickaccessibleattached_p.h>
38#include <QtQuick/private/qquickhoverhandler_p.h>
39#include <QtQuick/private/qquickpointerhandler_p.h>
40#include <QtQuick/private/qquickpointerhandler_p_p.h>
42#include <private/qv4engine_p.h>
43#include <private/qv4object_p.h>
44#include <private/qv4qobjectwrapper_p.h>
45#include <private/qdebug_p.h>
46#include <private/qqmlvaluetypewrapper_p.h>
49# include <QtGui/qcursor.h>
52#include <QtCore/qpointer.h>
62Q_LOGGING_CATEGORY(lcVP,
"qt.quick.viewport")
63Q_STATIC_LOGGING_CATEGORY(lcChangeListeners,
"qt.quick.item.changelisteners")
66static const quint64 kCursorOverrideTimeout = 100;
68void debugFocusTree(QQuickItem *item, QQuickItem *scope =
nullptr,
int depth = 1)
70 if (lcFocus().isEnabled(QtDebugMsg)) {
72 << QByteArray(depth,
'\t').constData()
73 << (scope && QQuickItemPrivate::get(scope)->subFocusItem == item ?
'*' :
' ')
75 << item->hasActiveFocus()
76 << item->isFocusScope()
78 const auto childItems = item->childItems();
79 for (QQuickItem *child : childItems) {
82 item->isFocusScope() || !scope ? item : scope,
83 item->isFocusScope() || !scope ? depth + 1 : depth);
90 QQuickItemPrivate *d = QQuickItemPrivate::get(item);
91 if (d->subFocusItem && d->window && d->flags & QQuickItem::ItemIsFocusScope)
92 d->deliveryAgentPrivate()->clearFocusInScope(item, d->subFocusItem, reason);
93 item->forceActiveFocus(reason);
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120QQuickTransformPrivate::QQuickTransformPrivate()
124QQuickTransform::QQuickTransform(QObject *parent)
125: QObject(*(
new QQuickTransformPrivate), parent)
129QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent)
134QQuickTransform::~QQuickTransform()
136 Q_D(QQuickTransform);
137 for (
int ii = 0; ii < d->items.size(); ++ii) {
138 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
139 p->transforms.removeOne(
this);
140 p->dirty(QQuickItemPrivate::Transform);
144void QQuickTransform::update()
146 Q_D(QQuickTransform);
147 for (
int ii = 0; ii < d->items.size(); ++ii) {
148 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
149 p->dirty(QQuickItemPrivate::Transform);
153QQuickContents::QQuickContents(QQuickItem *item)
158QQuickContents::~QQuickContents()
161 QList<QQuickItem *> children = m_item->childItems();
162 for (
int i = 0; i < children.size(); ++i) {
163 QQuickItem *child = children.at(i);
164 QQuickItemPrivate::get(child)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
168bool QQuickContents::calcHeight(QQuickItem *changed)
170 qreal oldy = m_contents.y();
171 qreal oldheight = m_contents.height();
175 qreal bottom = oldy + oldheight;
176 qreal y = changed->y();
177 if (y + changed->height() > bottom)
178 bottom = y + changed->height();
181 m_contents.setY(top);
182 m_contents.setHeight(bottom - top);
184 qreal top = std::numeric_limits<qreal>::max();
185 qreal bottom = -std::numeric_limits<qreal>::max();
186 QList<QQuickItem *> children = m_item->childItems();
187 for (
int i = 0; i < children.size(); ++i) {
188 QQuickItem *child = children.at(i);
189 qreal y = child->y();
190 if (y + child->height() > bottom)
191 bottom = y + child->height();
195 if (!children.isEmpty())
196 m_contents.setY(top);
197 m_contents.setHeight(qMax(bottom - top, qreal(0.0)));
200 return (m_contents.height() != oldheight || m_contents.y() != oldy);
203bool QQuickContents::calcWidth(QQuickItem *changed)
205 qreal oldx = m_contents.x();
206 qreal oldwidth = m_contents.width();
210 qreal right = oldx + oldwidth;
211 qreal x = changed->x();
212 if (x + changed->width() > right)
213 right = x + changed->width();
216 m_contents.setX(left);
217 m_contents.setWidth(right - left);
219 qreal left = std::numeric_limits<qreal>::max();
220 qreal right = -std::numeric_limits<qreal>::max();
221 QList<QQuickItem *> children = m_item->childItems();
222 for (
int i = 0; i < children.size(); ++i) {
223 QQuickItem *child = children.at(i);
224 qreal x = child->x();
225 if (x + child->width() > right)
226 right = x + child->width();
230 if (!children.isEmpty())
231 m_contents.setX(left);
232 m_contents.setWidth(qMax(right - left, qreal(0.0)));
235 return (m_contents.width() != oldwidth || m_contents.x() != oldx);
238void QQuickContents::complete()
240 QQuickItemPrivate::get(m_item)->addItemChangeListener(
this, QQuickItemPrivate::Children);
242 QList<QQuickItem *> children = m_item->childItems();
243 for (
int i = 0; i < children.size(); ++i) {
244 QQuickItem *child = children.at(i);
245 QQuickItemPrivate::get(child)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
251void QQuickContents::updateRect()
253 QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF());
256void QQuickContents::itemGeometryChanged(QQuickItem *changed, QQuickGeometryChange change,
const QRectF &)
259 bool wChanged =
false;
260 bool hChanged =
false;
262 if (change.horizontalChange())
263 wChanged = calcWidth();
264 if (change.verticalChange())
265 hChanged = calcHeight();
266 if (wChanged || hChanged)
270void QQuickContents::itemDestroyed(QQuickItem *item)
273 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
277void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item)
280 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
284void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item)
287 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
291QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item)
292: m_processPost(
false), m_next(
nullptr)
294 QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):
nullptr;
296 m_next = p->extra.value().keyHandler;
297 p->extra->keyHandler =
this;
301QQuickItemKeyFilter::~QQuickItemKeyFilter()
305void QQuickItemKeyFilter::keyPressed(QKeyEvent *event,
bool post)
307 if (m_next) m_next->keyPressed(event, post);
310void QQuickItemKeyFilter::keyReleased(QKeyEvent *event,
bool post)
312 if (m_next) m_next->keyReleased(event, post);
316void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event,
bool post)
319 m_next->inputMethodEvent(event, post);
324QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query)
const
326 if (m_next)
return m_next->inputMethodQuery(query);
331void QQuickItemKeyFilter::shortcutOverrideEvent(QKeyEvent *event)
334 m_next->shortcutOverrideEvent(event);
339void QQuickItemKeyFilter::componentComplete()
341 if (m_next) m_next->componentComplete();
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
388
389
390
391
392
395
396
397
398
399
402
403
404
405
406
409
410
411
412
413
416
417
418
419
420
423
424
425
426
427
429QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent)
430: QObject(*(
new QQuickKeyNavigationAttachedPrivate), parent),
431 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
433 m_processPost =
true;
436QQuickKeyNavigationAttached *
437QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
439 return new QQuickKeyNavigationAttached(obj);
442QQuickItem *QQuickKeyNavigationAttached::left()
const
444 Q_D(
const QQuickKeyNavigationAttached);
448void QQuickKeyNavigationAttached::setLeft(QQuickItem *i)
450 Q_D(QQuickKeyNavigationAttached);
451 if (d->leftSet && d->left == i)
453 d->leftSet = d->left != i;
455 QQuickKeyNavigationAttached* other =
456 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
457 if (other && !other->d_func()->rightSet){
458 other->d_func()->right = qobject_cast<QQuickItem*>(parent());
459 emit other->rightChanged();
464QQuickItem *QQuickKeyNavigationAttached::right()
const
466 Q_D(
const QQuickKeyNavigationAttached);
470void QQuickKeyNavigationAttached::setRight(QQuickItem *i)
472 Q_D(QQuickKeyNavigationAttached);
473 if (d->rightSet && d->right == i)
475 d->rightSet = d->right != i;
477 QQuickKeyNavigationAttached* other =
478 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
479 if (other && !other->d_func()->leftSet){
480 other->d_func()->left = qobject_cast<QQuickItem*>(parent());
481 emit other->leftChanged();
486QQuickItem *QQuickKeyNavigationAttached::up()
const
488 Q_D(
const QQuickKeyNavigationAttached);
492void QQuickKeyNavigationAttached::setUp(QQuickItem *i)
494 Q_D(QQuickKeyNavigationAttached);
495 if (d->upSet && d->up == i)
497 d->upSet = d->up != i;
499 QQuickKeyNavigationAttached* other =
500 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
501 if (other && !other->d_func()->downSet){
502 other->d_func()->down = qobject_cast<QQuickItem*>(parent());
503 emit other->downChanged();
508QQuickItem *QQuickKeyNavigationAttached::down()
const
510 Q_D(
const QQuickKeyNavigationAttached);
514void QQuickKeyNavigationAttached::setDown(QQuickItem *i)
516 Q_D(QQuickKeyNavigationAttached);
517 if (d->downSet && d->down == i)
519 d->downSet = d->down != i;
521 QQuickKeyNavigationAttached* other =
522 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
523 if (other && !other->d_func()->upSet) {
524 other->d_func()->up = qobject_cast<QQuickItem*>(parent());
525 emit other->upChanged();
530QQuickItem *QQuickKeyNavigationAttached::tab()
const
532 Q_D(
const QQuickKeyNavigationAttached);
536void QQuickKeyNavigationAttached::setTab(QQuickItem *i)
538 Q_D(QQuickKeyNavigationAttached);
539 if (d->tabSet && d->tab == i)
541 d->tabSet = d->tab != i;
543 QQuickKeyNavigationAttached* other =
544 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
545 if (other && !other->d_func()->backtabSet) {
546 other->d_func()->backtab = qobject_cast<QQuickItem*>(parent());
547 emit other->backtabChanged();
552QQuickItem *QQuickKeyNavigationAttached::backtab()
const
554 Q_D(
const QQuickKeyNavigationAttached);
558void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i)
560 Q_D(QQuickKeyNavigationAttached);
561 if (d->backtabSet && d->backtab == i)
563 d->backtabSet = d->backtab != i;
565 QQuickKeyNavigationAttached* other =
566 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
567 if (other && !other->d_func()->tabSet) {
568 other->d_func()->tab = qobject_cast<QQuickItem*>(parent());
569 emit other->tabChanged();
571 emit backtabChanged();
575
576
577
578
579
580
581
582
583
584
585
586
587QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority()
const
589 return m_processPost ? AfterItem : BeforeItem;
592void QQuickKeyNavigationAttached::setPriority(Priority order)
594 bool processPost = order == AfterItem;
595 if (processPost != m_processPost) {
596 m_processPost = processPost;
597 emit priorityChanged();
601void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event,
bool post)
603 Q_D(QQuickKeyNavigationAttached);
606 if (post != m_processPost) {
607 QQuickItemKeyFilter::keyPressed(event, post);
612 switch (event->key()) {
614 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
615 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
616 QQuickItem* leftItem = mirror ? d->right : d->left;
618 setFocusNavigation(leftItem, mirror ?
"right" :
"left", mirror ? Qt::TabFocusReason : Qt::BacktabFocusReason);
623 case Qt::Key_Right: {
624 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
625 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
626 QQuickItem* rightItem = mirror ? d->left : d->right;
628 setFocusNavigation(rightItem, mirror ?
"left" :
"right", mirror ? Qt::BacktabFocusReason : Qt::TabFocusReason);
635 setFocusNavigation(d->up,
"up", Qt::BacktabFocusReason);
641 setFocusNavigation(d->down,
"down", Qt::TabFocusReason);
647 setFocusNavigation(d->tab,
"tab", Qt::TabFocusReason);
651 case Qt::Key_Backtab:
653 setFocusNavigation(d->backtab,
"backtab", Qt::BacktabFocusReason);
661 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
664void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event,
bool post)
666 Q_D(QQuickKeyNavigationAttached);
669 if (post != m_processPost) {
670 QQuickItemKeyFilter::keyReleased(event, post);
675 switch (event->key()) {
677 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
678 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
679 if (mirror ? d->right : d->left)
683 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
684 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
685 if (mirror ? d->left : d->right)
703 case Qt::Key_Backtab:
712 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
715void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem,
const char *dir,
716 Qt::FocusReason reason)
718 QQuickItem *initialItem = currentItem;
719 bool isNextItem =
false;
720 QVector<QQuickItem *> visitedItems;
723 if (currentItem->isVisible() && currentItem->isEnabled()) {
724 currentItem->forceActiveFocus(reason);
727 qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(currentItem,
false);
729 QQuickItem *tempItem = qvariant_cast<QQuickItem*>(attached->property(dir));
731 visitedItems.append(currentItem);
732 currentItem = tempItem;
738 while (currentItem != initialItem && isNextItem && !visitedItems.contains(currentItem));
747 { Qt::Key_Left,
"leftPressed" },
748 { Qt::Key_Right,
"rightPressed" },
749 { Qt::Key_Up,
"upPressed" },
750 { Qt::Key_Down,
"downPressed" },
751 { Qt::Key_Tab,
"tabPressed" },
752 { Qt::Key_Backtab,
"backtabPressed" },
753 { Qt::Key_Asterisk,
"asteriskPressed" },
754 { Qt::Key_NumberSign,
"numberSignPressed" },
755 { Qt::Key_Escape,
"escapePressed" },
756 { Qt::Key_Return,
"returnPressed" },
757 { Qt::Key_Enter,
"enterPressed" },
758 { Qt::Key_Delete,
"deletePressed" },
759 { Qt::Key_Space,
"spacePressed" },
760 { Qt::Key_Back,
"backPressed" },
761 { Qt::Key_Cancel,
"cancelPressed" },
762 { Qt::Key_Select,
"selectPressed" },
763 { Qt::Key_Yes,
"yesPressed" },
764 { Qt::Key_No,
"noPressed" },
765 { Qt::Key_Context1,
"context1Pressed" },
766 { Qt::Key_Context2,
"context2Pressed" },
767 { Qt::Key_Context3,
"context3Pressed" },
768 { Qt::Key_Context4,
"context4Pressed" },
769 { Qt::Key_Call,
"callPressed" },
770 { Qt::Key_Hangup,
"hangupPressed" },
771 { Qt::Key_Flip,
"flipPressed" },
772 { Qt::Key_Menu,
"menuPressed" },
773 { Qt::Key_VolumeUp,
"volumeUpPressed" },
774 { Qt::Key_VolumeDown,
"volumeDownPressed" },
778QByteArray QQuickKeysAttached::keyToSignal(
int key)
780 QByteArray keySignal;
781 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
782 keySignal =
"digit0Pressed";
783 keySignal[5] =
'0' + (key - Qt::Key_0);
786 while (sigMap[i].key && sigMap[i].key != key)
788 keySignal = sigMap[i].sig;
793bool QQuickKeysAttached::isConnected(
const char *signalName)
const
795 Q_D(
const QQuickKeysAttached);
796 int signal_index = d->signalIndex(signalName);
797 return d->isSignalConnected(signal_index);
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
866
867
868
869
870
873
874
875
876
877
878
879
880
881
882
883
884
885
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
918
919
920
921
922
925
926
927
928
929
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
970
971
972
973
974
977
978
979
980
981
984
985
986
987
988
991
992
993
994
995
998
999
1000
1001
1002
1005
1006
1007
1008
1009
1012
1013
1014
1015
1016
1019
1020
1021
1022
1023
1026
1027
1028
1029
1030
1033
1034
1035
1036
1037
1040
1041
1042
1043
1044
1047
1048
1049
1050
1051
1054
1055
1056
1057
1058
1061
1062
1063
1064
1065
1068
1069
1070
1071
1072
1075
1076
1077
1078
1079
1082
1083
1084
1085
1086
1089
1090
1091
1092
1093
1096
1097
1098
1099
1100
1103
1104
1105
1106
1107
1110
1111
1112
1113
1114
1117
1118
1119
1120
1121
1124
1125
1126
1127
1128
1131
1132
1133
1134
1135
1138
1139
1140
1141
1142
1145
1146
1147
1148
1149
1152
1153
1154
1155
1156
1159
1160
1161
1162
1163
1166
1167
1168
1169
1170
1173
1174
1175
1176
1177
1180
1181
1182
1183
1184
1187
1188
1189
1190
1191
1194
1195
1196
1197
1198
1201
1202
1203
1204
1205
1208
1209
1210
1211
1212
1215
1216
1217
1218
1219
1222
1223
1224
1225
1226
1228QQuickKeysAttached::QQuickKeysAttached(QObject *parent)
1229: QObject(*(
new QQuickKeysAttachedPrivate), parent),
1230 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
1232 Q_D(QQuickKeysAttached);
1233 m_processPost =
false;
1234 d->item = qmlobject_cast<QQuickItem*>(parent);
1235 if (d->item != parent)
1236 qWarning() <<
"Could not attach Keys property to: " << parent <<
" is not an Item";
1239QQuickKeysAttached::~QQuickKeysAttached()
1243QQuickKeysAttached::Priority QQuickKeysAttached::priority()
const
1245 return m_processPost ? AfterItem : BeforeItem;
1248void QQuickKeysAttached::setPriority(Priority order)
1250 bool processPost = order == AfterItem;
1251 if (processPost != m_processPost) {
1252 m_processPost = processPost;
1253 emit priorityChanged();
1257void QQuickKeysAttached::componentComplete()
1260 Q_D(QQuickKeysAttached);
1262 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1263 QQuickItem *targetItem = d->targets.at(ii);
1264 if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1265 d->item->setFlag(QQuickItem::ItemAcceptsInputMethod);
1273void QQuickKeysAttached::keyPressed(QKeyEvent *event,
bool post)
1275 Q_D(QQuickKeysAttached);
1276 if (post != m_processPost || !d->enabled || d->inPress) {
1278 QQuickItemKeyFilter::keyPressed(event, post);
1283 if (d->item && d->item->window()) {
1285 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1286 QQuickItem *i = d->targets.at(ii);
1287 if (i && i->isVisible()) {
1289 QCoreApplication::sendEvent(i, event);
1290 if (event->isAccepted()) {
1299 QQuickKeyEvent &ke = d->theKeyEvent;
1301 QByteArray keySignal = keyToSignal(event->key());
1302 if (!keySignal.isEmpty()) {
1303 keySignal +=
"(QQuickKeyEvent*)";
1304 if (isConnected(keySignal)) {
1306 ke.setAccepted(
true);
1307 int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal);
1308 metaObject()->method(idx).invoke(
this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke));
1311 if (!ke.isAccepted())
1313 event->setAccepted(ke.isAccepted());
1315 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
1318void QQuickKeysAttached::keyReleased(QKeyEvent *event,
bool post)
1320 Q_D(QQuickKeysAttached);
1321 if (post != m_processPost || !d->enabled || d->inRelease) {
1323 QQuickItemKeyFilter::keyReleased(event, post);
1327 if (d->item && d->item->window()) {
1328 d->inRelease =
true;
1329 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1330 QQuickItem *i = d->targets.at(ii);
1331 if (i && i->isVisible()) {
1333 QCoreApplication::sendEvent(i, event);
1334 if (event->isAccepted()) {
1335 d->inRelease =
false;
1340 d->inRelease =
false;
1343 QQuickKeyEvent &ke = d->theKeyEvent;
1346 event->setAccepted(ke.isAccepted());
1348 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
1352void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event,
bool post)
1354 Q_D(QQuickKeysAttached);
1355 if (post == m_processPost && d->item && !d->inIM && d->item->window()) {
1357 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1358 QQuickItem *targetItem = d->targets.at(ii);
1359 if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1360 QCoreApplication::sendEvent(targetItem, event);
1361 if (event->isAccepted()) {
1362 d->imeItem = targetItem;
1370 QQuickItemKeyFilter::inputMethodEvent(event, post);
1373QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query)
const
1375 Q_D(
const QQuickKeysAttached);
1377 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1378 QQuickItem *i = d->targets.at(ii);
1379 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) {
1381 QVariant v = i->inputMethodQuery(query);
1382 if (v.userType() == QMetaType::QRectF)
1383 v = d->item->mapRectFromItem(i, v.toRectF());
1388 return QQuickItemKeyFilter::inputMethodQuery(query);
1392void QQuickKeysAttached::shortcutOverrideEvent(QKeyEvent *event)
1394 Q_D(QQuickKeysAttached);
1395 QQuickKeyEvent &keyEvent = d->theKeyEvent;
1396 keyEvent.reset(*event);
1397 emit shortcutOverride(&keyEvent);
1399 event->setAccepted(keyEvent.isAccepted());
1402QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
1404 return new QQuickKeysAttached(obj);
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1474
1475
1476
1477
1478
1479
1480
1483QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1485 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1486 itemPrivate = QQuickItemPrivate::get(item);
1487 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1488 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1491 itemPrivate->extra.value().layoutDirectionAttached =
this;
1493 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1496QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1498 return new QQuickLayoutMirroringAttached(object);
1501bool QQuickLayoutMirroringAttached::enabled()
const
1503 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1506void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1511 itemPrivate->isMirrorImplicit =
false;
1512 if (enabled != itemPrivate->effectiveLayoutMirror) {
1513 itemPrivate->setLayoutMirror(enabled);
1514 if (itemPrivate->inheritMirrorFromItem)
1515 itemPrivate->resolveLayoutMirror();
1519void QQuickLayoutMirroringAttached::resetEnabled()
1521 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1522 itemPrivate->isMirrorImplicit =
true;
1523 itemPrivate->resolveLayoutMirror();
1527bool QQuickLayoutMirroringAttached::childrenInherit()
const
1529 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1532void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1533 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1534 itemPrivate->inheritMirrorFromItem = childrenInherit;
1535 itemPrivate->resolveLayoutMirror();
1536 childrenInheritChanged();
1540void QQuickItemPrivate::resolveLayoutMirror()
1543 if (QQuickItem *parentItem = q->parentItem()) {
1544 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1545 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1547 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1551void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1553 inherit = inherit || inheritMirrorFromItem;
1554 if (!isMirrorImplicit && inheritMirrorFromItem)
1555 mirror = effectiveLayoutMirror;
1556 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1559 inheritMirrorFromParent = inherit;
1560 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1562 if (isMirrorImplicit)
1563 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1564 for (
int i = 0; i < childItems.size(); ++i) {
1565 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1566 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1567 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1572void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1574 if (mirror != effectiveLayoutMirror) {
1575 effectiveLayoutMirror = mirror;
1577 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1578 anchor_d->fillChanged();
1579 anchor_d->centerInChanged();
1580 anchor_d->updateHorizontalAnchors();
1583 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1584 emit extra->layoutDirectionAttached->enabledChanged();
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1636QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1637 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1639 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1640 itemPrivate = QQuickItemPrivate::get(item);
1641 itemPrivate->extra.value().enterKeyAttached =
this;
1643 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1646QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1648 return new QQuickEnterKeyAttached(object);
1651Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1656void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1658 if (keyType != type) {
1661 if (itemPrivate && itemPrivate->activeFocus)
1662 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1668void QQuickItemPrivate::setAccessible()
1670 isAccessible =
true;
1674
1675
1676
1677
1678void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1683 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1685 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1687 if (oldSubFocusItem) {
1688 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1689 while (sfi && sfi != scope) {
1690 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1691 sfi = sfi->parentItem();
1696 scopePrivate->subFocusItem = q;
1697 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1698 while (sfi && sfi != scope) {
1699 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1700 sfi = sfi->parentItem();
1703 scopePrivate->subFocusItem =
nullptr;
1708bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1711 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1712 Qt::FocusPolicy policy = Qt::ClickFocus;
1714 switch (eventType) {
1715 case QEvent::MouseButtonPress:
1716 case QEvent::MouseButtonDblClick:
1717 case QEvent::TouchBegin:
1718 if (setFocusOnRelease)
1721 case QEvent::MouseButtonRelease:
1722 case QEvent::TouchEnd:
1723 if (!setFocusOnRelease)
1727 policy = Qt::WheelFocus;
1733 if ((focusPolicy & policy) == policy) {
1734 setActiveFocus(q, Qt::MouseFocusReason);
1741Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1743 return static_cast<Qt::FocusReason>(focusReason);
1746bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1748 if (focusReason == reason)
1751 focusReason = reason;
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2145
2146
2147
2148
2149
2150
2151
2152
2153
2156
2157
2158
2161
2162
2163
2166
2167
2168
2171
2172
2173
2176
2177
2178
2179
2180
2181
2182
2185
2186
2187
2188
2189
2190
2193
2194
2195
2196
2197
2200
2201
2202
2203
2204
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
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
2358
2359
2360
2361
2362QQuickItem::QQuickItem(QQuickItem* parent)
2363: QObject(*(
new QQuickItemPrivate), parent)
2370
2371QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2372: QObject(dd, parent)
2379
2380
2381QQuickItem::~QQuickItem()
2384 d->inDestructor =
true;
2386 if (d->windowRefCount > 1)
2387 d->windowRefCount = 1;
2389 setParentItem(
nullptr);
2393 for (QQuickItem *child : std::as_const(d->childItems))
2394 child->setParentItem(
nullptr);
2395 d->childItems.clear();
2397 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2398 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2400 anchor->clearItem(
this);
2403
2404
2405
2406 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2407 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2408 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2411 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2412 d->changeListeners.clear();
2415
2416
2417
2418
2419 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2420 QQuickTransform *t = d->transforms.at(ii);
2421 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2422 tp->items.removeOne(
this);
2425 if (d->extra.isAllocated()) {
2426 delete d->extra->contents; d->extra->contents =
nullptr;
2427#if QT_CONFIG(quick_shadereffect)
2428 delete d->extra->layer; d->extra->layer =
nullptr;
2432 delete d->_anchors; d->_anchors =
nullptr;
2433 delete d->_stateGroup; d->_stateGroup =
nullptr;
2435 d->isQuickItem =
false;
2439
2440
2441bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2443 if (!item->window())
2446 if (item == item->window()->contentItem())
2449 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2450 if (tabFocus == Qt::NoTabFocus)
2452 if (tabFocus == Qt::TabFocusAllControls)
2455 QVariant editable = item->property(
"editable");
2456 if (editable.isValid())
2457 return editable.toBool();
2459 QVariant readonly = item->property(
"readOnly");
2460 if (readonly.isValid())
2461 return !readonly.toBool() && item->property(
"text").isValid();
2463#if QT_CONFIG(accessibility)
2464 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2465 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2467 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2468 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2469 return iface->state().editable;
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2488 QQuickWindow *window = item->window();
2489 const bool wrap = !window || window->isTopLevel();
2491 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2496 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2498 if (!wrap && !next) {
2502 Q_ASSERT(window->parent());
2505 qt_window_private(window->parent())->setFocusToTarget(
2506 forward ? QWindowPrivate::FocusTarget::Next
2507 : QWindowPrivate::FocusTarget::Prev,
2509 window->parent()->requestActivate();
2513 next->forceActiveFocus(reason);
2518QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2521 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2524 const QList<QQuickItem *> &children = item->childItems();
2525 const int count = children.size();
2526 if (start < 0 || start >= count) {
2527 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2530 while (start < count) {
2531 QQuickItem *child = children.at(start);
2532 if (!child->d_func()->isTabFence)
2539QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2542 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2545 const QList<QQuickItem *> &children = item->childItems();
2546 const int count = children.size();
2549 if (start < 0 || start >= count) {
2550 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2553 while (start >= 0) {
2554 QQuickItem *child = children.at(start);
2555 if (!child->d_func()->isTabFence)
2562QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2565 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2567 if (!item->window())
2569 const QQuickItem *
const contentItem = item->window()->contentItem();
2573 QQuickItem *from =
nullptr;
2574 bool isTabFence = item->d_func()->isTabFence;
2577 from = item->parentItem();
2579 if (!item->childItems().isEmpty())
2580 from = item->d_func()->childItems.constFirst();
2581 else if (!isTabFence)
2582 from = item->parentItem();
2586 QQuickItem *startItem = item;
2587 QQuickItem *originalStartItem = startItem;
2592 while (startItem && !startItem->isVisible()) {
2593 startItem = startItem->parentItem();
2598 QQuickItem *firstFromItem = from;
2599 QQuickItem *current = item;
2600 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2601 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2602 QDuplicateTracker<QQuickItem *> cycleDetector;
2604 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2605 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2607 QQuickItem *last = current;
2609 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2610 QQuickItem *firstChild =
nullptr;
2611 QQuickItem *lastChild =
nullptr;
2613 firstChild = nextTabChildItem(current, 0);
2615 hasChildren =
false;
2617 lastChild = prevTabChildItem(current, -1);
2619 isTabFence = current->d_func()->isTabFence;
2620 if (isTabFence && !hasChildren)
2624 if (hasChildren && from == current->parentItem()) {
2626 current = firstChild;
2628 current = lastChild;
2629 if (!current->childItems().isEmpty())
2632 }
else if (hasChildren && forward && from != lastChild) {
2634 int nextChild = current->childItems().indexOf(from) + 1;
2635 current = nextTabChildItem(current, nextChild);
2636 }
else if (hasChildren && !forward && from != firstChild) {
2638 int prevChild = current->childItems().indexOf(from) - 1;
2639 current = prevTabChildItem(current, prevChild);
2640 if (!current->childItems().isEmpty())
2643 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2647 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2648 if (last != firstSibling
2649 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2653 }
else if (hasChildren) {
2655 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2656 <<
"Focus chain about to wrap but wrapping was set to false."
2663 current = firstChild;
2665 current = lastChild;
2666 if (!current->childItems().isEmpty())
2678 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2679 (!skip && cycleDetector.hasSeen(current))) {
2681 if (item == contentItem) {
2682 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2685 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2689 if (!firstFromItem) {
2690 if (startItem->d_func()->isTabFence) {
2691 if (current == startItem)
2692 firstFromItem = from;
2694 startItem = current;
2695 firstFromItem = from;
2698 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2699 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2705
2706
2707
2708
2709
2710
2711
2712
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728QQuickItem *QQuickItem::parentItem()
const
2730 Q_D(
const QQuickItem);
2731 return d->parentItem;
2734void QQuickItem::setParentItem(QQuickItem *parentItem)
2737 if (parentItem == d->parentItem)
2741 QQuickItem *itemAncestor = parentItem;
2742 while (itemAncestor !=
nullptr) {
2743 if (Q_UNLIKELY(itemAncestor ==
this)) {
2744 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2747 itemAncestor = itemAncestor->parentItem();
2749 auto engine = qmlEngine(
this);
2751 QV4::ExecutionEngine *v4 = engine->handle();
2752 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2753 QV4::QObjectWrapper::markWrapper(
this, ms);
2758 d->removeFromDirtyList();
2760 QQuickItem *oldParentItem = d->parentItem;
2761 QQuickItem *scopeFocusedItem =
nullptr;
2763 if (oldParentItem) {
2764 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2766 QQuickItem *scopeItem =
nullptr;
2768 if (hasFocus() || op->subFocusItem ==
this)
2769 scopeFocusedItem =
this;
2770 else if (!isFocusScope() && d->subFocusItem)
2771 scopeFocusedItem = d->subFocusItem;
2773 if (scopeFocusedItem) {
2774 scopeItem = oldParentItem;
2775 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2776 scopeItem = scopeItem->parentItem();
2778 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2779 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2780 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2782 if (scopeFocusedItem !=
this)
2783 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2785 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2789 const bool wasVisible = isVisible();
2790 op->removeChild(
this);
2791 if (wasVisible && !op->inDestructor)
2792 emit oldParentItem->visibleChildrenChanged();
2793 }
else if (d->window) {
2794 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2797 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2798 bool alreadyAddedChild =
false;
2799 if (d->window == parentWindow) {
2801 d->parentItem = parentItem;
2803 auto oldParentItem = d->parentItem;
2804 d->parentItem = parentItem;
2805 if (d->parentItem) {
2806 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2807 alreadyAddedChild =
true;
2815 if (!oldParentItem && d->window) {
2816 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2820 d->refWindow(parentWindow);
2823 d->dirty(QQuickItemPrivate::ParentChanged);
2825 if (d->parentItem && !alreadyAddedChild)
2826 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2827 else if (d->window && !alreadyAddedChild)
2828 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2830 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2831 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2833 if (d->parentItem) {
2834 if (!scopeFocusedItem) {
2836 scopeFocusedItem =
this;
2837 else if (!isFocusScope() && d->subFocusItem)
2838 scopeFocusedItem = d->subFocusItem;
2841 if (scopeFocusedItem) {
2843 QQuickItem *scopeItem = d->parentItem;
2844 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2845 scopeItem = scopeItem->parentItem();
2847 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2848 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2849 if (scopeFocusedItem !=
this)
2850 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2851 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2852 emit scopeFocusedItem->focusChanged(
false);
2855 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2856 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2857 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2860 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2867 d->resolveLayoutMirror();
2869 d->itemChange(ItemParentHasChanged, d->parentItem);
2871 if (!d->inDestructor)
2872 emit parentChanged(d->parentItem);
2873 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2874 emit d->parentItem->visibleChildrenChanged();
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894void QQuickItem::stackBefore(
const QQuickItem *sibling)
2897 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2898 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2899 <<
this <<
" before " << sibling <<
", which must be a sibling";
2903 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2905 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2906 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2908 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2910 if (myIndex == siblingIndex - 1)
2913 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2915 parentPrivate->markSortedChildrenDirty(
this);
2916 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2918 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2919 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939void QQuickItem::stackAfter(
const QQuickItem *sibling)
2942 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2943 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2944 <<
this <<
" after " << sibling <<
", which must be a sibling";
2948 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2950 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2951 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2953 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2955 if (myIndex == siblingIndex + 1)
2958 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2960 parentPrivate->markSortedChildrenDirty(
this);
2961 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2963 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2964 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2968
2969
2972
2973
2974
2975
2976
2977
2978QQuickWindow *QQuickItem::window()
const
2980 Q_D(
const QQuickItem);
2986 return lhs->z() < rhs->z();
2989QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
2991 if (sortedChildItems)
2992 return *sortedChildItems;
2997 for (
int i = 0; i < childItems.size(); ++i) {
2998 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3004 sortedChildItems =
new QList<QQuickItem*>(childItems);
3005 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3006 return *sortedChildItems;
3009 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3014void QQuickItemPrivate::addChild(QQuickItem *child)
3018 Q_ASSERT(!childItems.contains(child));
3020 childItems.append(child);
3022 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3024#if QT_CONFIG(cursor)
3027 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3028 setHasCursorInChild(
true);
3031 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3032 setHasHoverInChild(
true);
3034 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3035 markSortedChildrenDirty(child);
3036 dirty(QQuickItemPrivate::ChildrenChanged);
3038 itemChange(QQuickItem::ItemChildAddedChange, child);
3040 emit q->childrenChanged();
3043void QQuickItemPrivate::removeChild(QQuickItem *child)
3048 if (!inDestructor) {
3050 Q_ASSERT(childItems.contains(child));
3051 childItems.removeOne(child);
3052 Q_ASSERT(!childItems.contains(child));
3055 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3057#if QT_CONFIG(cursor)
3059 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3060 setHasCursorInChild(
false);
3063 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3064 setHasHoverInChild(
false);
3066 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3067 if (!inDestructor) {
3068 markSortedChildrenDirty(child);
3069 dirty(QQuickItemPrivate::ChildrenChanged);
3072 itemChange(QQuickItem::ItemChildRemovedChange, child);
3075 emit q->childrenChanged();
3078void QQuickItemPrivate::refWindow(QQuickWindow *c)
3090 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3092 if (++windowRefCount > 1) {
3094 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3098 Q_ASSERT(window ==
nullptr);
3101 if (polishScheduled)
3102 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3105 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3107 for (
int ii = 0; ii < childItems.size(); ++ii) {
3108 QQuickItem *child = childItems.at(ii);
3109 QQuickItemPrivate::get(child)->refWindow(c);
3114 if (extra.isAllocated() && extra->screenAttached)
3115 extra->screenAttached->windowChanged(c);
3116 itemChange(QQuickItem::ItemSceneChange, c);
3119void QQuickItemPrivate::derefWindow()
3122 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3127 if (--windowRefCount > 0)
3130 q->releaseResources();
3131 removeFromDirtyList();
3132 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3133 if (polishScheduled)
3134 c->itemsToPolish.removeOne(q);
3135#if QT_CONFIG(cursor)
3136 if (c->cursorItem == q) {
3137 c->cursorItem =
nullptr;
3138 window->unsetCursor();
3141 if (itemNodeInstance)
3142 c->cleanup(itemNodeInstance);
3144 c->parentlessItems.remove(q);
3148 itemNodeInstance =
nullptr;
3150 if (extra.isAllocated()) {
3151 extra->opacityNode =
nullptr;
3152 extra->clipNode =
nullptr;
3153 extra->rootNode =
nullptr;
3156 paintNode =
nullptr;
3158 for (
int ii = 0; ii < childItems.size(); ++ii) {
3159 if (QQuickItem *child = childItems.at(ii))
3160 QQuickItemPrivate::get(child)->derefWindow();
3165 if (extra.isAllocated() && extra->screenAttached)
3166 extra->screenAttached->windowChanged(
nullptr);
3167 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3172
3173
3174QTransform QQuickItemPrivate::windowToItemTransform()
const
3177 return itemToWindowTransform().inverted();
3181
3182
3183QTransform QQuickItemPrivate::itemToWindowTransform()
const
3186 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3187 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3188 itemToParentTransform(&rv);
3193
3194
3195void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3198
3199
3200
3201
3202
3204 qreal x =
this->x.valueBypassingBindings();
3205 qreal y =
this->y.valueBypassingBindings();
3209 if (!transforms.isEmpty()) {
3211 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3212 transforms.at(ii)->applyTo(&m);
3213 *t = m.toTransform();
3216 if (scale() != 1. || rotation() != 0.) {
3217 QPointF tp = computeTransformOrigin();
3218 t->translate(tp.x(), tp.y());
3219 t->scale(scale(), scale());
3220 t->rotate(rotation());
3221 t->translate(-tp.x(), -tp.y());
3226
3227
3228
3229
3230
3231
3232
3233
3234bool QQuickItem::isComponentComplete()
const
3236 Q_D(
const QQuickItem);
3237 return d->componentComplete;
3240QQuickItemPrivate::QQuickItemPrivate()
3242 , _stateGroup(
nullptr)
3244 , widthValidFlag(
false)
3245 , heightValidFlag(
false)
3246 , componentComplete(
true)
3249 , hoverEnabled(
false)
3251 , antialiasing(
false)
3253 , activeFocus(
false)
3254 , notifiedFocus(
false)
3255 , notifiedActiveFocus(
false)
3256 , filtersChildMouseEvents(
false)
3257 , explicitVisible(
true)
3258 , effectiveVisible(
true)
3259 , explicitEnable(
true)
3260 , effectiveEnable(
true)
3261 , polishScheduled(
false)
3262 , inheritedLayoutMirror(
false)
3263 , effectiveLayoutMirror(
false)
3264 , isMirrorImplicit(
true)
3265 , inheritMirrorFromParent(
false)
3266 , inheritMirrorFromItem(
false)
3267 , isAccessible(
false)
3270 , subtreeCursorEnabled(
false)
3271 , subtreeHoverEnabled(
false)
3272 , activeFocusOnTab(
false)
3273 , implicitAntialiasing(
false)
3274 , antialiasingValid(
false)
3276 , replayingPressEvent(
false)
3277 , touchEnabled(
false)
3278 , hasCursorHandler(
false)
3279 , maybeHasSubsceneDeliveryAgent(
true)
3280 , subtreeTransformChangedEnabled(
true)
3281 , inDestructor(
false)
3282 , focusReason(Qt::OtherFocusReason)
3283 , focusPolicy(Qt::NoFocus)
3284 , dirtyAttributes(0)
3285 , nextDirtyItem(
nullptr)
3286 , prevDirtyItem(
nullptr)
3289 , parentItem(
nullptr)
3290 , sortedChildItems(&childItems)
3291 , subFocusItem(
nullptr)
3299 , itemNodeInstance(
nullptr)
3300 , paintNode(
nullptr)
3301 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3305QQuickItemPrivate::~QQuickItemPrivate()
3307 if (sortedChildItems != &childItems)
3308 delete sortedChildItems;
3311void QQuickItemPrivate::init(QQuickItem *parent)
3317 baselineOffset = 0.0;
3320 q->setParentItem(parent);
3321 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3322 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3326QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3331void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3333 szPolicy.setHorizontalPolicy(horizontalPolicy);
3334 szPolicy.setVerticalPolicy(verticalPolicy);
3337void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3342 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3344 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3345 item->setParentItem(that);
3346 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3347 if (pointerHandler->parent() != that) {
3348 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3349 pointerHandler->setParent(that);
3351 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3354 resources_append(prop, o);
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3393qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3395 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3396 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3397 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3398 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3400 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3403QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3405 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3406 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3407 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3408 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3410 qsizetype resourcesCount = resources_count(&resourcesProperty);
3411 if (i < resourcesCount)
3412 return resources_at(&resourcesProperty, i);
3413 const qsizetype j = i - resourcesCount;
3414 if (j < children_count(&childrenProperty))
3415 return children_at(&childrenProperty, j);
3419void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3421 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3422 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3423 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3424 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3426 resources_clear(&resourcesProperty);
3427 children_clear(&childrenProperty);
3430void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3432 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3433 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3435 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3436 if (children_count(&childrenProperty) > 0) {
3437 children_removeLast(&childrenProperty);
3441 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3442 if (resources_count(&resourcesProperty) > 0)
3443 resources_removeLast(&resourcesProperty);
3446QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3448 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3449 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3452void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3454 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3455 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3456 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3457 quickItemPrivate->extra.value().resourcesList.append(object);
3458 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3459 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3463qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3465 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3466 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3469void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3471 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3472 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3473 if (quickItemPrivate->extra.isAllocated()) {
3474 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3475 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3476 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3478 quickItemPrivate->extra->resourcesList.clear();
3482void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3484 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3485 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3486 if (quickItemPrivate->extra.isAllocated()) {
3487 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3488 if (resources->isEmpty())
3491 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3492 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3493 resources->removeLast();
3497QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3499 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3500 if (index >= p->childItems.size() || index < 0)
3503 return p->childItems.at(index);
3506void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3511 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3512 if (o->parentItem() == that)
3513 o->setParentItem(
nullptr);
3515 o->setParentItem(that);
3518qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3520 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3521 return p->childItems.size();
3524void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3526 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3527 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3528 while (!p->childItems.isEmpty())
3529 p->childItems.at(0)->setParentItem(
nullptr);
3532void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3534 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3535 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3536 if (!p->childItems.isEmpty())
3537 p->childItems.last()->setParentItem(
nullptr);
3540qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3542 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3543 qsizetype visibleCount = 0;
3544 qsizetype c = p->childItems.size();
3546 if (p->childItems.at(c)->isVisible()) visibleCount++;
3549 return visibleCount;
3552QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3554 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3555 const qsizetype childCount = p->childItems.size();
3556 if (index >= childCount || index < 0)
3559 qsizetype visibleCount = -1;
3560 for (qsizetype i = 0; i < childCount; i++) {
3561 if (p->childItems.at(i)->isVisible()) visibleCount++;
3562 if (visibleCount == index)
return p->childItems.at(i);
3567qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3569 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3570 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3572 return p->transforms.size();
3575void QQuickTransform::appendToItem(QQuickItem *item)
3577 Q_D(QQuickTransform);
3581 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3583 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3584 p->transforms.removeOne(
this);
3585 p->transforms.append(
this);
3587 p->transforms.append(
this);
3588 d->items.append(item);
3591 p->dirty(QQuickItemPrivate::Transform);
3594void QQuickTransform::prependToItem(QQuickItem *item)
3596 Q_D(QQuickTransform);
3600 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3602 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3603 p->transforms.removeOne(
this);
3604 p->transforms.prepend(
this);
3606 p->transforms.prepend(
this);
3607 d->items.append(item);
3610 p->dirty(QQuickItemPrivate::Transform);
3613void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3618 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3619 transform->appendToItem(that);
3622QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3624 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3625 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3627 if (idx < 0 || idx >= p->transforms.size())
3630 return p->transforms.at(idx);
3633void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3635 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3636 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3638 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3639 QQuickTransform *t = p->transforms.at(ii);
3640 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3641 tp->items.removeOne(that);
3644 p->transforms.clear();
3646 p->dirty(QQuickItemPrivate::Transform);
3649void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3651 if (extra.isAllocated() && extra->resourcesList.contains(object))
3652 extra->resourcesList.removeAll(object);
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749QQuickAnchors *QQuickItemPrivate::anchors()
const
3752 Q_Q(
const QQuickItem);
3753 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3754 if (!componentComplete)
3755 _anchors->classBegin();
3760void QQuickItemPrivate::siblingOrderChanged()
3763 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3766QQmlListProperty<QObject> QQuickItemPrivate::data()
3770 QQmlListProperty<QObject> result;
3771 result.object = q_func();
3772 result.append = QQuickItemPrivate::data_append;
3773 result.count = QQuickItemPrivate::data_count;
3774 result.at = QQuickItemPrivate::data_at;
3775 result.clear = QQuickItemPrivate::data_clear;
3776 result.removeLast = QQuickItemPrivate::data_removeLast;
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811QRectF QQuickItem::childrenRect()
3814 if (!d->extra.isAllocated() || !d->extra->contents) {
3815 d->extra.value().contents =
new QQuickContents(
this);
3816 if (d->componentComplete)
3817 d->extra->contents->complete();
3819 return d->extra->contents->rectF();
3823
3824
3825QList<QQuickItem *> QQuickItem::childItems()
const
3827 Q_D(
const QQuickItem);
3828 return d->childItems;
3832
3833
3834
3835
3836
3837
3838
3839
3840
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859bool QQuickItem::clip()
const
3861 return flags() & ItemClipsChildrenToShape;
3864void QQuickItem::setClip(
bool c)
3869 setFlag(ItemClipsChildrenToShape, c);
3871 setFlag(ItemIsViewport);
3872 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3873 setFlag(ItemIsViewport,
false);
3875 emit clipChanged(c);
3879
3880
3881
3882
3883
3884
3885
3886
3887void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3892 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3894 QQuickGeometryChange change;
3895 change.setXChange(newGeometry.x() != oldGeometry.x());
3896 change.setYChange(newGeometry.y() != oldGeometry.y());
3897 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3898 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3900 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3901 if (change.matches(listener.gTypes))
3902 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3907 if (change.xChange())
3909 if (change.yChange())
3911 if (change.widthChange())
3913 if (change.heightChange())
3915#if QT_CONFIG(accessibility)
3916 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3917 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3918 QAccessible::updateAccessibility(&ev);
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3977QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
3979 Q_UNUSED(updatePaintNodeData);
3984QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
3985: transformNode(
nullptr)
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4006void QQuickItem::releaseResources()
4010QSGTransformNode *QQuickItemPrivate::createTransformNode()
4012 return new QSGTransformNode;
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025void QQuickItem::updatePolish()
4029#define PRINT_LISTENERS() do
4031 qDebug().nospace() << q_func() << " (" << this
4032 << ") now has the following listeners:";
4033 for (const auto &listener : std::as_const(changeListeners)) {
4034 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4035 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4037}while
4040void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4043 changeListeners.append(ChangeListener(listener, types));
4044 listener->addSourceItem(q);
4046 if (lcChangeListeners().isDebugEnabled())
4050void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4054 const ChangeListener changeListener(listener, types);
4055 const int index = changeListeners.indexOf(changeListener);
4057 changeListeners[index].types = changeListener.types;
4059 changeListeners.append(changeListener);
4060 listener->addSourceItem(q);
4063 if (lcChangeListeners().isDebugEnabled())
4067void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4071 ChangeListener change(listener, types);
4072 changeListeners.removeOne(change);
4073 listener->removeSourceItem(q);
4075 if (lcChangeListeners().isDebugEnabled())
4079void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4080 QQuickGeometryChange types)
4084 ChangeListener change(listener, types);
4085 int index = changeListeners.indexOf(change);
4087 changeListeners[index].gTypes = change.gTypes;
4089 changeListeners.append(change);
4090 listener->addSourceItem(q);
4093 if (lcChangeListeners().isDebugEnabled())
4097void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4098 QQuickGeometryChange types)
4102 ChangeListener change(listener, types);
4103 if (types.noChange()) {
4104 changeListeners.removeOne(change);
4105 listener->removeSourceItem(q);
4107 int index = changeListeners.indexOf(change);
4109 changeListeners[index].gTypes = change.gTypes;
4112 if (lcChangeListeners().isDebugEnabled())
4117
4118
4119
4120
4121
4122
4123void QQuickItem::keyPressEvent(QKeyEvent *event)
4129
4130
4131
4132
4133
4134
4135void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4142
4143
4144
4145
4146
4147
4148void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164void QQuickItem::focusInEvent(QFocusEvent *event)
4167#if QT_CONFIG(accessibility)
4168 if (QAccessible::isActive()) {
4169 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4170 QAccessibleEvent ev(acc, QAccessible::Focus);
4171 QAccessible::updateAccessibility(&ev);
4175 d->setLastFocusChangeReason(event->reason());
4179
4180
4181
4182
4183
4184
4185void QQuickItem::focusOutEvent(QFocusEvent *event)
4188 d->setLastFocusChangeReason(event->reason());
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201void QQuickItem::mousePressEvent(QMouseEvent *event)
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4239
4240
4241
4242
4243
4244
4245void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4251
4252
4253
4254void QQuickItem::mouseUngrabEvent()
4260
4261
4262
4263void QQuickItem::touchUngrabEvent()
4268#if QT_CONFIG(wheelevent)
4270
4271
4272
4273
4274
4275
4276void QQuickItem::wheelEvent(QWheelEvent *event)
4283
4284
4285
4286
4287
4288
4289void QQuickItem::touchEvent(QTouchEvent *event)
4295
4296
4297
4298
4299
4300
4301
4302
4303void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4309
4310
4311
4312
4313
4314
4315
4316
4317void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4323
4324
4325
4326
4327
4328
4329
4330
4331void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4336#if QT_CONFIG(quick_draganddrop)
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400void QQuickItem::dropEvent(QDropEvent *event)
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4445
4446
4447
4448
4449
4450
4451
4452QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4454 Q_D(
const QQuickItem);
4459 v = (
bool)(flags() & ItemAcceptsInputMethod);
4462 case Qt::ImAnchorRectangle:
4463 case Qt::ImCursorRectangle:
4465 case Qt::ImCursorPosition:
4466 case Qt::ImSurroundingText:
4467 case Qt::ImCurrentSelection:
4468 case Qt::ImMaximumTextLength:
4469 case Qt::ImAnchorPosition:
4470 case Qt::ImPreferredLanguage:
4471 case Qt::ImReadOnly:
4472 if (d->extra.isAllocated() && d->extra->keyHandler)
4473 v = d->extra->keyHandler->inputMethodQuery(query);
4475 case Qt::ImEnterKeyType:
4476 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4477 v = d->extra->enterKeyAttached->type();
4479 case Qt::ImInputItemClipRectangle:
4480 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4481 QRectF rect = QRectF(0,0, width(), height());
4482 const QQuickItem *par =
this;
4483 while (QQuickItem *parpar = par->parentItem()) {
4484 rect = parpar->mapRectFromItem(par, rect);
4486 rect = rect.intersected(parpar->clipRect());
4489 rect = par->mapRectToScene(rect);
4491 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4493 v = mapRectFromScene(rect);
4504QQuickAnchorLine QQuickItemPrivate::left()
const
4506 Q_Q(
const QQuickItem);
4507 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4510QQuickAnchorLine QQuickItemPrivate::right()
const
4512 Q_Q(
const QQuickItem);
4513 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4516QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4518 Q_Q(
const QQuickItem);
4519 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4522QQuickAnchorLine QQuickItemPrivate::top()
const
4524 Q_Q(
const QQuickItem);
4525 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4528QQuickAnchorLine QQuickItemPrivate::bottom()
const
4530 Q_Q(
const QQuickItem);
4531 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4534QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4536 Q_Q(
const QQuickItem);
4537 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4540QQuickAnchorLine QQuickItemPrivate::baseline()
const
4542 Q_Q(
const QQuickItem);
4543 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568qreal QQuickItem::baselineOffset()
const
4570 Q_D(
const QQuickItem);
4571 return d->baselineOffset;
4574void QQuickItem::setBaselineOffset(qreal offset)
4577 if (offset == d->baselineOffset)
4580 d->baselineOffset = offset;
4582 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4583 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4585 anchor->updateVerticalAnchors();
4588 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4589 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4591 emit baselineOffsetChanged(offset);
4596
4597
4598
4599
4600
4601
4602
4603
4604void QQuickItem::update()
4607 if (!(flags() & ItemHasContents)) {
4609 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4613 d->dirty(QQuickItemPrivate::Content);
4617
4618
4619
4620
4621
4622
4623
4624void QQuickItem::polish()
4627 if (!d->polishScheduled) {
4628 d->polishScheduled =
true;
4630 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4631 bool maybeupdate = p->itemsToPolish.isEmpty();
4632 p->itemsToPolish.append(
this);
4633 if (maybeupdate) d->window->maybeUpdate();
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653void QQuickItem::ensurePolished()
4658#if QT_DEPRECATED_SINCE(6
, 5
)
4659static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4660 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4662 QV4::ExecutionEngine *v4 = args->v4engine();
4663 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4664 v4->throwTypeError();
4668 QV4::Scope scope(v4);
4669 QV4::ScopedValue item(scope, (*args)[0]);
4672 if (!item->isNull()) {
4673 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4675 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4678 if (!(*itemObj) && !item->isNull()) {
4679 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4680 <<
"\" which is neither null nor an Item";
4681 v4->throwTypeError();
4687 if (args->length() == 2) {
4688 QV4::ScopedValue sv(scope, (*args)[1]);
4690 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4691 <<
"\" which is neither a point nor a rect";
4692 v4->throwTypeError();
4695 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4696 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4697 if (v.canConvert<QPointF>()) {
4698 const QPointF p = v.toPointF();
4701 }
else if (v.canConvert<QRectF>()) {
4702 const QRectF r = v.toRectF();
4709 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4710 <<
"\" which is neither a point nor a rect";
4711 v4->throwTypeError();
4715 QV4::ScopedValue vx(scope, (*args)[1]);
4716 QV4::ScopedValue vy(scope, (*args)[2]);
4718 if (!vx->isNumber() || !vy->isNumber()) {
4719 v4->throwTypeError();
4723 *x = vx->asDouble();
4724 *y = vy->asDouble();
4726 if (args->length() > 3) {
4727 QV4::ScopedValue vw(scope, (*args)[3]);
4728 QV4::ScopedValue vh(scope, (*args)[4]);
4729 if (!vw->isNumber() || !vh->isNumber()) {
4730 v4->throwTypeError();
4733 *w = vw->asDouble();
4734 *h = vh->asDouble();
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4761#if QT_DEPRECATED_SINCE(6
, 5
)
4763
4764
4765void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4767 QV4::ExecutionEngine *v4 = args->v4engine();
4768 QV4::Scope scope(v4);
4772 QQuickItem *itemObj;
4773 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4776 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4777 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4779 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4780 args->setReturnValue(rv.asReturnedValue());
4785
4786
4787QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4789 Q_D(
const QQuickItem);
4795 QTransform t = d->itemToWindowTransform();
4796 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4819#if QT_DEPRECATED_SINCE(6
, 5
)
4821
4822
4823void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4825 QV4::ExecutionEngine *v4 = args->v4engine();
4826 QV4::Scope scope(v4);
4830 QQuickItem *itemObj;
4831 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4834 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4835 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4837 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4838 args->setReturnValue(rv.asReturnedValue());
4841static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4843 QV4::ExecutionEngine *v4 = args->v4engine();
4844 if (args->length() != 1 && args->length() != 2) {
4845 v4->throwTypeError();
4849 QV4::Scope scope(v4);
4851 if (args->length() == 1) {
4852 QV4::ScopedValue sv(scope, (*args)[0]);
4854 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4855 <<
"\" which is not a point";
4856 v4->throwTypeError();
4859 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4860 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4861 if (v.canConvert<QPointF>()) {
4862 const QPointF p = v.toPointF();
4866 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4867 <<
"\" which is not a point";
4868 v4->throwTypeError();
4872 QV4::ScopedValue vx(scope, (*args)[0]);
4873 QV4::ScopedValue vy(scope, (*args)[1]);
4875 if (!vx->isNumber() || !vy->isNumber()) {
4876 v4->throwTypeError();
4880 *x = vx->asDouble();
4881 *y = vy->asDouble();
4888
4889
4890
4891
4892
4893
4894
4895
4897
4898
4899void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4901 QV4::ExecutionEngine *v4 = args->v4engine();
4902 QV4::Scope scope(v4);
4905 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4908 QVariant result = mapFromGlobal(QPointF(x, y));
4910 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4911 args->setReturnValue(rv.asReturnedValue());
4916
4917
4918
4919
4920
4921
4922
4923
4925#if QT_DEPRECATED_SINCE(6
, 5
)
4927
4928
4929void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4931 QV4::ExecutionEngine *v4 = args->v4engine();
4932 QV4::Scope scope(v4);
4935 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4938 QVariant result = mapToGlobal(QPointF(x, y));
4940 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4941 args->setReturnValue(rv.asReturnedValue());
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971void QQuickItem::forceActiveFocus()
4973 forceActiveFocus(Qt::OtherFocusReason);
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5001void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5003 setFocus(
true, reason);
5004 QQuickItem *parent = parentItem();
5005 QQuickItem *scope =
nullptr;
5007 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5008 parent->setFocus(
true, reason);
5012 parent = parent->parentItem();
5017
5018
5019
5020
5021
5022
5023
5024
5025
5027
5028
5029
5030
5031
5033QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5035 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5039
5040
5041
5042
5043
5044
5045
5047
5048
5049
5050
5051
5052QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5054 const QList<QQuickItem *> children = childItems();
5055 for (
int i = children.size()-1; i >= 0; --i) {
5056 QQuickItem *child = children.at(i);
5058 QPointF point = mapToItem(child, QPointF(x, y));
5059 if (child->isVisible() && child->contains(point))
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106void QQuickItem::dumpItemTree()
const
5108 Q_D(
const QQuickItem);
5112void QQuickItemPrivate::dumpItemTree(
int indent)
const
5114 Q_Q(
const QQuickItem);
5116 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5117 qDebug().nospace().noquote() << indentStr <<
5118#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5119 const_cast<QQuickItem *>(q);
5123 if (extra.isAllocated()) {
5124 for (
const auto handler : extra->pointerHandlers)
5125 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5127 for (
const QQuickItem *ch : childItems) {
5128 auto itemPriv = QQuickItemPrivate::get(ch);
5129 itemPriv->dumpItemTree(indent + 1);
5133QQmlListProperty<QObject> QQuickItemPrivate::resources()
5137 QQmlListProperty<QObject> result;
5138 result.object = q_func();
5139 result.append = QQuickItemPrivate::resources_append;
5140 result.count = QQuickItemPrivate::resources_count;
5141 result.at = QQuickItemPrivate::resources_at;
5142 result.clear = QQuickItemPrivate::resources_clear;
5143 result.removeLast = QQuickItemPrivate::resources_removeLast;
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5161
5162
5163
5164QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5168 QQmlListProperty<QQuickItem> result;
5169 result.object = q_func();
5170 result.append = QQuickItemPrivate::children_append;
5171 result.count = QQuickItemPrivate::children_count;
5172 result.at = QQuickItemPrivate::children_at;
5173 result.clear = QQuickItemPrivate::children_clear;
5174 result.removeLast = QQuickItemPrivate::children_removeLast;
5179
5180
5181
5182
5183
5185
5186
5187
5188QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5190 return QQmlListProperty<QQuickItem>(q_func(),
5192 QQuickItemPrivate::visibleChildren_count,
5193 QQuickItemPrivate::visibleChildren_at);
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5234
5235
5236
5237QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5239 return _states()->statesProperty();
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
5271
5272
5273
5274QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5276 return _states()->transitionsProperty();
5279QString QQuickItemPrivate::state()
const
5284 return _stateGroup->state();
5287void QQuickItemPrivate::setState(
const QString &state)
5289 _states()->setState(state);
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314QString QQuickItem::state()
const
5316 Q_D(
const QQuickItem);
5320void QQuickItem::setState(
const QString &state)
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5349
5350
5351
5353
5354
5355QQmlListProperty<QQuickTransform> QQuickItem::transform()
5357 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5358 QQuickItemPrivate::transform_count,
5359 QQuickItemPrivate::transform_at,
5360 QQuickItemPrivate::transform_clear);
5364
5365
5366
5367
5368void QQuickItem::classBegin()
5371 d->componentComplete =
false;
5373 d->_stateGroup->classBegin();
5375 d->_anchors->classBegin();
5376#if QT_CONFIG(quick_shadereffect)
5377 if (d->extra.isAllocated() && d->extra->layer)
5378 d->extra->layer->classBegin();
5383
5384
5385
5386
5387void QQuickItem::componentComplete()
5390 d->componentComplete =
true;
5392 d->_stateGroup->componentComplete();
5394 d->_anchors->componentComplete();
5395 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5398 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5399 safeArea->updateSafeArea();
5401 if (d->extra.isAllocated()) {
5402#if QT_CONFIG(quick_shadereffect)
5403 if (d->extra->layer)
5404 d->extra->layer->componentComplete();
5407 if (d->extra->keyHandler)
5408 d->extra->keyHandler->componentComplete();
5410 if (d->extra->contents)
5411 d->extra->contents->complete();
5414 if (d->window && d->dirtyAttributes) {
5415 d->addToDirtyList();
5416 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5419#if QT_CONFIG(accessibility)
5420 if (d->isAccessible && d->effectiveVisible) {
5421 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5422 QAccessible::updateAccessibility(&ev);
5427QQuickStateGroup *QQuickItemPrivate::_states()
5431 _stateGroup =
new QQuickStateGroup;
5432 if (!componentComplete)
5433 _stateGroup->classBegin();
5434 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5435 q, QQuickItem, SIGNAL(stateChanged(QString)));
5441QPointF QQuickItemPrivate::computeTransformOrigin()
const
5445 case QQuickItem::TopLeft:
5446 return QPointF(0, 0);
5447 case QQuickItem::Top:
5448 return QPointF(width / 2., 0);
5449 case QQuickItem::TopRight:
5450 return QPointF(width, 0);
5451 case QQuickItem::Left:
5452 return QPointF(0, height / 2.);
5453 case QQuickItem::Center:
5454 return QPointF(width / 2., height / 2.);
5455 case QQuickItem::Right:
5456 return QPointF(width, height / 2.);
5457 case QQuickItem::BottomLeft:
5458 return QPointF(0, height);
5459 case QQuickItem::Bottom:
5460 return QPointF(width / 2., height);
5461 case QQuickItem::BottomRight:
5462 return QPointF(width, height);
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5484#if QT_CONFIG(quick_shadereffect)
5485 if (q == transformedItem) {
5486 if (extra.isAllocated() && extra->layer)
5487 extra->layer->updateMatrix();
5491 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5493 bool childWantsIt =
false;
5494 if (subtreeTransformChangedEnabled) {
5497 const auto children = paintOrderChildItems();
5498 for (QQuickItem *child : children)
5499 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5502 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5503 const bool ret = childWantsIt || thisWantsIt;
5504 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5505 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5506 subtreeTransformChangedEnabled =
false;
5510 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5511 dirty(QQuickItemPrivate::Clip);
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5534 const QPointF &startPos,
5535 const QVector2D &activeTranslation,
5538 qreal startRotation,
5539 qreal activeRotation)
5542 QVector3D xformOrigin(q->transformOriginPoint());
5543 QMatrix4x4 startMatrix;
5544 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5545 startMatrix.translate(xformOrigin);
5546 startMatrix.scale(
float(startScale));
5547 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5548 startMatrix.translate(-xformOrigin);
5550 const QVector3D centroidParentVector(centroidParentPos);
5552 mat.translate(centroidParentVector);
5553 mat.rotate(
float(activeRotation), 0, 0, 1);
5554 mat.scale(
float(activeScale));
5555 mat.translate(-centroidParentVector);
5556 mat.translate(QVector3D(activeTranslation));
5558 mat = mat * startMatrix;
5560 QPointF xformOriginPoint = q->transformOriginPoint();
5561 QPointF pos = mat.map(xformOriginPoint);
5562 pos -= xformOriginPoint;
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5592 if (maybeHasSubsceneDeliveryAgent) {
5593 QQuickItemPrivate *p =
this;
5595 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5600 maybeHasSubsceneDeliveryAgent =
false;
5603 if (p->extra.isAllocated()) {
5604 if (
auto da = p->extra->subsceneDeliveryAgent)
5607 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5611 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5614 return QQuickWindowPrivate::get(window)->deliveryAgent;
5618QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5620 auto da = deliveryAgent();
5621 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5625
5626
5627
5628
5629
5630
5631
5632QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5638 maybeHasSubsceneDeliveryAgent =
true;
5639 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5640 return extra->subsceneDeliveryAgent;
5641 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5642 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5645 q->setFlag(QQuickItem::ItemIsFocusScope);
5646 return extra->subsceneDeliveryAgent;
5649bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5651 if (!extra.isAllocated() || !extra->keyHandler)
5657 if (e->type() == QEvent::KeyPress)
5658 extra->keyHandler->keyPressed(e, post);
5660 extra->keyHandler->keyReleased(e, post);
5662 return e->isAccepted();
5665void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5668 const auto eventType = event->type();
5669 const bool focusAccepted = setFocusIfNeeded(eventType);
5671 switch (eventType) {
5672 case QEvent::MouseButtonPress:
5673 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5675 case QEvent::MouseButtonRelease:
5676 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5678 case QEvent::MouseButtonDblClick:
5679 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5681#if QT_CONFIG(wheelevent)
5683 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5686 case QEvent::TouchBegin:
5687 case QEvent::TouchUpdate:
5688 case QEvent::TouchEnd:
5689 case QEvent::TouchCancel:
5690 q->touchEvent(
static_cast<QTouchEvent *>(event));
5700void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5704 Q_ASSERT(e->isAccepted());
5705 if (filterKeyEvent(e,
false))
5710 if (e->type() == QEvent::KeyPress)
5711 q->keyPressEvent(e);
5713 q->keyReleaseEvent(e);
5715 if (e->isAccepted())
5718 if (filterKeyEvent(e,
true) || !q->window())
5722 if (e->type() == QEvent::KeyPress &&
5723 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5725 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5726 if (e->key() == Qt::Key_Backtab
5727 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5728 res = QQuickItemPrivate::focusNextPrev(q,
false);
5729 else if (e->key() == Qt::Key_Tab)
5730 res = QQuickItemPrivate::focusNextPrev(q,
true);
5732 e->setAccepted(
true);
5738void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5742 Q_ASSERT(e->isAccepted());
5743 if (extra.isAllocated() && extra->keyHandler) {
5744 extra->keyHandler->inputMethodEvent(e,
false);
5746 if (e->isAccepted())
5752 q->inputMethodEvent(e);
5754 if (e->isAccepted())
5757 if (extra.isAllocated() && extra->keyHandler) {
5760 extra->keyHandler->inputMethodEvent(e,
true);
5765void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5767 if (extra.isAllocated() && extra->keyHandler)
5768 extra->keyHandler->shortcutOverrideEvent(event);
5773bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5775 if (!hasPointerHandlers())
5777 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5778 if (handler->wantsEventPoint(event, point))
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5796 bool delivered =
false;
5797 if (extra.isAllocated()) {
5798 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5799 bool avoidThisHandler =
false;
5800 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5801 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5802 avoidThisHandler =
true;
5803 }
else if (avoidGrabbers) {
5804 for (
auto &p : event->points()) {
5805 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5806 avoidThisHandler =
true;
5811 if (!avoidThisHandler &&
5812 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5813 handler->handlePointerEvent(event);
5821#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5822bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5824bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5827 if (extra.isAllocated() && extra->contextMenu)
5828 return extra->contextMenu->event(event);
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5848 if (change == ItemSceneChange)
5849 emit windowChanged(value.window);
5854
5855
5856
5857void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5859 if (hasActiveFocus())
5860 QGuiApplication::inputMethod()->update(queries);
5865
5866
5867
5868QRectF QQuickItem::boundingRect()
const
5870 Q_D(
const QQuickItem);
5871 return QRectF(0, 0, d->width, d->height);
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895QRectF QQuickItem::clipRect()
const
5897 Q_D(
const QQuickItem);
5898 QRectF ret(0, 0, d->width, d->height);
5899 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5900 if (QQuickItem *viewport = viewportItem()) {
5903 if (viewport ==
this)
5905 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5906 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5907 return mappedViewportRect.intersected(ret);
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924QQuickItem *QQuickItem::viewportItem()
const
5926 if (flags().testFlag(ItemObservesViewport)) {
5927 QQuickItem *par = parentItem();
5929 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
5931 par = par->parentItem();
5934 return (window() ? window()->contentItem() :
nullptr);
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5959
5960
5961
5962
5963
5964
5965
5966
5967QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
5969 Q_D(
const QQuickItem);
5973void QQuickItem::setTransformOrigin(TransformOrigin origin)
5976 if (origin == d->origin())
5979 d->extra.value().origin = origin;
5980 d->dirty(QQuickItemPrivate::TransformOrigin);
5982 emit transformOriginChanged(d->origin());
5986
5987
5988
5990
5991
5992QPointF QQuickItem::transformOriginPoint()
const
5994 Q_D(
const QQuickItem);
5995 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
5996 return d->extra->userTransformOriginPoint;
5997 return d->computeTransformOrigin();
6001
6002
6003void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6006 if (d->extra.value().userTransformOriginPoint == point)
6009 d->extra->userTransformOriginPoint = point;
6010 d->dirty(QQuickItemPrivate::TransformOrigin);
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167qreal QQuickItem::z()
const
6169 Q_D(
const QQuickItem);
6173void QQuickItem::setZ(qreal v)
6179 d->extra.value().z = v;
6181 d->dirty(QQuickItemPrivate::ZValue);
6182 if (d->parentItem) {
6183 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6184 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6189#if QT_CONFIG(quick_shadereffect)
6190 if (d->extra.isAllocated() && d->extra->layer)
6191 d->extra->layer->updateZ();
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247qreal QQuickItem::rotation()
const
6249 Q_D(
const QQuickItem);
6250 return d->rotation();
6253void QQuickItem::setRotation(qreal r)
6256 if (d->rotation() == r)
6259 d->extra.value().rotation = r;
6261 d->dirty(QQuickItemPrivate::BasicTransform);
6263 d->itemChange(ItemRotationHasChanged, r);
6265 emit rotationChanged();
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
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
6341
6342
6343
6344
6345
6346
6347qreal QQuickItem::scale()
const
6349 Q_D(
const QQuickItem);
6353void QQuickItem::setScale(qreal s)
6356 if (d->scale() == s)
6359 d->extra.value().scale = s;
6361 d->dirty(QQuickItemPrivate::BasicTransform);
6363 d->itemChange(ItemScaleHasChanged, s);
6365 emit scaleChanged();
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
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
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478qreal QQuickItem::opacity()
const
6480 Q_D(
const QQuickItem);
6481 return d->opacity();
6484void QQuickItem::setOpacity(qreal newOpacity)
6487 qreal o = qBound<qreal>(0, newOpacity, 1);
6488 if (d->opacity() == o)
6491 d->extra.value().opacity = o;
6493 d->dirty(QQuickItemPrivate::OpacityValue);
6495 d->itemChange(ItemOpacityHasChanged, o);
6497 emit opacityChanged();
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6528
6529
6530
6531
6532
6533
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
6560
6561
6562
6563
6564bool QQuickItem::isVisible()
const
6566 Q_D(
const QQuickItem);
6567 return d->effectiveVisible;
6570void QQuickItemPrivate::setVisible(
bool visible)
6572 if (visible == explicitVisible)
6575 explicitVisible = visible;
6577 dirty(QQuickItemPrivate::Visible);
6579 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6580 if (childVisibilityChanged && parentItem)
6581 emit parentItem->visibleChildrenChanged();
6584void QQuickItem::setVisible(
bool v)
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631bool QQuickItem::isEnabled()
const
6633 Q_D(
const QQuickItem);
6634 return d->effectiveEnable;
6637void QQuickItem::setEnabled(
bool e)
6640 if (e == d->explicitEnable)
6643 d->explicitEnable = e;
6645 QQuickItem *scope = parentItem();
6646 while (scope && !scope->isFocusScope())
6647 scope = scope->parentItem();
6649 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6652bool QQuickItemPrivate::calcEffectiveVisible()
const
6655 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6658bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6662 if (newEffectiveVisible && !explicitVisible) {
6667 if (newEffectiveVisible == effectiveVisible) {
6672 effectiveVisible = newEffectiveVisible;
6675 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6677 if (
auto agent = deliveryAgentPrivate())
6678 agent->removeGrabber(q,
true,
true,
true);
6681 bool childVisibilityChanged =
false;
6682 for (
int ii = 0; ii < childItems.size(); ++ii)
6683 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6685 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6686#if QT_CONFIG(accessibility)
6688 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6689 QAccessible::updateAccessibility(&ev);
6692 if (!inDestructor) {
6693 emit q->visibleChanged();
6694 if (childVisibilityChanged)
6695 emit q->visibleChildrenChanged();
6701bool QQuickItemPrivate::calcEffectiveEnable()
const
6706 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6709void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6713 if (newEffectiveEnable && !explicitEnable) {
6718 if (newEffectiveEnable == effectiveEnable) {
6723 effectiveEnable = newEffectiveEnable;
6725 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6727 da->removeGrabber(q,
true,
true,
true);
6728 if (scope && !effectiveEnable && activeFocus) {
6729 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6730 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6731 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6735 for (
int ii = 0; ii < childItems.size(); ++ii) {
6736 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6737 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6740 if (scope && effectiveEnable && focus && da) {
6741 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6742 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6743 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6746 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6747#if QT_CONFIG(accessibility)
6749 QAccessible::State changedState;
6750 changedState.disabled =
true;
6751 changedState.focusable =
true;
6752 QAccessibleStateChangeEvent ev(q, changedState);
6753 QAccessible::updateAccessibility(&ev);
6756 emit q->enabledChanged();
6759bool QQuickItemPrivate::isTransparentForPositioner()
const
6761 return extra.isAllocated() && extra.value().transparentForPositioner;
6764void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6766 extra.value().transparentForPositioner = transparent;
6770QString QQuickItemPrivate::dirtyToString()
const
6772#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6774 rv.append(QLatin1Char('|'));
6775 rv.append(QLatin1String(#value)); \
6776}
6803void QQuickItemPrivate::dirty(DirtyType type)
6806 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6807 dirtyAttributes |= type;
6808 if (window && componentComplete) {
6810 QQuickWindowPrivate::get(window)->dirtyItem(q);
6813 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6814 transformChanged(q);
6817void QQuickItemPrivate::addToDirtyList()
6822 if (!prevDirtyItem) {
6823 Q_ASSERT(!nextDirtyItem);
6825 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
6826 nextDirtyItem = p->dirtyItemList;
6827 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
6828 prevDirtyItem = &p->dirtyItemList;
6829 p->dirtyItemList = q;
6832 Q_ASSERT(prevDirtyItem);
6835void QQuickItemPrivate::removeFromDirtyList()
6837 if (prevDirtyItem) {
6838 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
6839 *prevDirtyItem = nextDirtyItem;
6840 prevDirtyItem =
nullptr;
6841 nextDirtyItem =
nullptr;
6843 Q_ASSERT(!prevDirtyItem);
6844 Q_ASSERT(!nextDirtyItem);
6847void QQuickItemPrivate::refFromEffectItem(
bool hide)
6849 ++extra.value().effectRefCount;
6850 if (extra->effectRefCount == 1) {
6851 dirty(EffectReference);
6853 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6856 if (++extra->hideRefCount == 1)
6857 dirty(HideReference);
6859 recursiveRefFromEffectItem(1);
6862void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
6867 extra.value().recursiveEffectRefCount += refs;
6868 for (
int ii = 0; ii < childItems.size(); ++ii) {
6869 QQuickItem *child = childItems.at(ii);
6870 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
6874 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
6878void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
6880 Q_ASSERT(extra->effectRefCount);
6881 --extra->effectRefCount;
6882 if (extra->effectRefCount == 0) {
6883 dirty(EffectReference);
6885 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6888 if (--extra->hideRefCount == 0)
6889 dirty(HideReference);
6891 recursiveRefFromEffectItem(-1);
6894void QQuickItemPrivate::setCulled(
bool cull)
6900 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
6901 dirty(HideReference);
6904void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
6908 case QQuickItem::ItemChildAddedChange: {
6909 q->itemChange(change, data);
6915 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
6916 if (!subtreeTransformChangedEnabled) {
6917 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
6918 subtreeTransformChangedEnabled =
true;
6920 enableSubtreeChangeNotificationsForParentHierachy();
6922 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
6925 case QQuickItem::ItemChildRemovedChange: {
6926 q->itemChange(change, data);
6927 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
6930 case QQuickItem::ItemSceneChange:
6931 q->itemChange(change, data);
6933 case QQuickItem::ItemVisibleHasChanged: {
6934 q->itemChange(change, data);
6935 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
6938 case QQuickItem::ItemEnabledHasChanged: {
6939 q->itemChange(change, data);
6940 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
6943 case QQuickItem::ItemParentHasChanged: {
6944 q->itemChange(change, data);
6945 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
6948 case QQuickItem::ItemOpacityHasChanged: {
6949 q->itemChange(change, data);
6950 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
6953 case QQuickItem::ItemActiveFocusHasChanged:
6954 q->itemChange(change, data);
6956 case QQuickItem::ItemRotationHasChanged: {
6957 q->itemChange(change, data);
6958 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
6961 case QQuickItem::ItemScaleHasChanged: {
6962 q->itemChange(change, data);
6963 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
6966 case QQuickItem::ItemTransformHasChanged: {
6967 q->itemChange(change, data);
6968 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
6971 case QQuickItem::ItemAntialiasingHasChanged:
6973 case QQuickItem::ItemDevicePixelRatioHasChanged:
6974 q->itemChange(change, data);
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002bool QQuickItem::smooth()
const
7004 Q_D(
const QQuickItem);
7007void QQuickItem::setSmooth(
bool smooth)
7010 if (d->smooth == smooth)
7014 d->dirty(QQuickItemPrivate::Smooth);
7016 emit smoothChanged(smooth);
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7058bool QQuickItem::activeFocusOnTab()
const
7060 Q_D(
const QQuickItem);
7061 return d->activeFocusOnTab;
7063void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7066 if (d->activeFocusOnTab == activeFocusOnTab)
7070 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7071 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7076 d->activeFocusOnTab = activeFocusOnTab;
7078 emit activeFocusOnTabChanged(activeFocusOnTab);
7082
7083
7084
7085
7086
7087
7088
7089
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100bool QQuickItem::antialiasing()
const
7102 Q_D(
const QQuickItem);
7103 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7106void QQuickItem::setAntialiasing(
bool aa)
7110 if (!d->antialiasingValid) {
7111 d->antialiasingValid =
true;
7112 d->antialiasing = d->implicitAntialiasing;
7115 if (aa == d->antialiasing)
7118 d->antialiasing = aa;
7119 d->dirty(QQuickItemPrivate::Antialiasing);
7121 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7123 emit antialiasingChanged(antialiasing());
7126void QQuickItem::resetAntialiasing()
7129 if (!d->antialiasingValid)
7132 d->antialiasingValid =
false;
7134 if (d->implicitAntialiasing != d->antialiasing)
7135 emit antialiasingChanged(antialiasing());
7138void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7141 bool prev = q->antialiasing();
7142 implicitAntialiasing = antialiasing;
7143 if (componentComplete && (q->antialiasing() != prev))
7144 emit q->antialiasingChanged(q->antialiasing());
7148
7149
7150
7151
7152QQuickItem::Flags QQuickItem::flags()
const
7154 Q_D(
const QQuickItem);
7155 return (QQuickItem::Flags)d->flags;
7159
7160
7161
7162
7163
7164
7165
7166void QQuickItem::setFlag(Flag flag,
bool enabled)
7170 setFlags((Flags)(d->flags | (quint32)flag));
7172 setFlags((Flags)(d->flags & ~(quint32)flag));
7176 if (enabled && flag == ItemObservesViewport)
7177 d->enableSubtreeChangeNotificationsForParentHierachy();
7180void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7184 QQuickItem *par = q->parentItem();
7186 auto parPriv = QQuickItemPrivate::get(par);
7187 if (!parPriv->subtreeTransformChangedEnabled)
7188 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7189 parPriv->subtreeTransformChangedEnabled =
true;
7190 par = par->parentItem();
7195
7196
7197
7198
7199void QQuickItem::setFlags(Flags flags)
7203 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7204 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7205 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7206 flags &= ~ItemIsFocusScope;
7207 }
else if (d->flags & ItemIsFocusScope) {
7208 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7209 flags |= ItemIsFocusScope;
7213 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7214 d->dirty(QQuickItemPrivate::Clip);
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7235
7236
7237
7238
7240
7241
7242
7243
7244qreal QQuickItem::x()
const
7246 Q_D(
const QQuickItem);
7250qreal QQuickItem::y()
const
7252 Q_D(
const QQuickItem);
7257
7258
7259QPointF QQuickItem::position()
const
7261 Q_D(
const QQuickItem);
7262 return QPointF(d->x, d->y);
7265void QQuickItem::setX(qreal v)
7269
7270
7271
7272
7273
7274
7275
7276
7277 d->x.removeBindingUnlessInWrapper();
7281 const qreal oldx = d->x.valueBypassingBindings();
7285 d->x.setValueBypassingBindings(v);
7287 d->dirty(QQuickItemPrivate::Position);
7289 const qreal y = d->y.valueBypassingBindings();
7290 const qreal w = d->width.valueBypassingBindings();
7291 const qreal h = d->height.valueBypassingBindings();
7292 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7295void QQuickItem::setY(qreal v)
7298 d->y.removeBindingUnlessInWrapper();
7302 const qreal oldy = d->y.valueBypassingBindings();
7306 d->y.setValueBypassingBindings(v);
7308 d->dirty(QQuickItemPrivate::Position);
7312 const qreal x = d->x.valueBypassingBindings();
7313 const qreal w = d->width.valueBypassingBindings();
7314 const qreal h = d->height.valueBypassingBindings();
7315 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7319
7320
7321void QQuickItem::setPosition(
const QPointF &pos)
7325 const qreal oldx = d->x.valueBypassingBindings();
7326 const qreal oldy = d->y.valueBypassingBindings();
7328 if (QPointF(oldx, oldy) == pos)
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7344 d->x.setValueBypassingBindings(pos.x());
7345 d->y.setValueBypassingBindings(pos.y());
7347 d->dirty(QQuickItemPrivate::Position);
7349 const qreal w = d->width.valueBypassingBindings();
7350 const qreal h = d->height.valueBypassingBindings();
7351 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7355
7356
7357QBindable<qreal> QQuickItem::bindableX()
7359 return QBindable<qreal>(&d_func()->x);
7362QBindable<qreal> QQuickItem::bindableY()
7364 return QBindable<qreal>(&d_func()->y);
7368
7369
7370
7371
7372qreal QQuickItem::width()
const
7374 Q_D(
const QQuickItem);
7378void QQuickItem::setWidth(qreal w)
7381 d->width.removeBindingUnlessInWrapper();
7385 d->widthValidFlag =
true;
7386 const qreal oldWidth = d->width.valueBypassingBindings();
7390 d->width.setValueBypassingBindings(w);
7392 d->dirty(QQuickItemPrivate::Size);
7394 const qreal x = d->x.valueBypassingBindings();
7395 const qreal y = d->y.valueBypassingBindings();
7396 const qreal h = d->height.valueBypassingBindings();
7397 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7400void QQuickItem::resetWidth()
7403 d->width.takeBinding();
7404 d->widthValidFlag =
false;
7405 setImplicitWidth(implicitWidth());
7408void QQuickItemPrivate::implicitWidthChanged()
7411 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7412 emit q->implicitWidthChanged();
7415qreal QQuickItemPrivate::getImplicitWidth()
const
7417 return implicitWidth;
7420
7421
7422qreal QQuickItem::implicitWidth()
const
7424 Q_D(
const QQuickItem);
7425 return d->getImplicitWidth();
7428QBindable<qreal> QQuickItem::bindableWidth()
7430 return QBindable<qreal>(&d_func()->width);
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
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
7515void QQuickItem::setImplicitWidth(qreal w)
7518 bool changed = w != d->implicitWidth;
7519 d->implicitWidth = w;
7521 if (d->width.valueBypassingBindings() == w || widthValid()) {
7523 d->implicitWidthChanged();
7524 if (d->width.valueBypassingBindings() == w || widthValid())
7529 const qreal oldWidth = d->width.valueBypassingBindings();
7530 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7532 d->width.setValueBypassingBindings(w);
7534 d->dirty(QQuickItemPrivate::Size);
7536 const qreal x = d->x.valueBypassingBindings();
7537 const qreal y = d->y.valueBypassingBindings();
7538 const qreal width = w;
7539 const qreal height = d->height.valueBypassingBindings();
7540 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7543 d->implicitWidthChanged();
7547
7548
7549bool QQuickItem::widthValid()
const
7551 Q_D(
const QQuickItem);
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7569 return d->widthValid();
7573
7574
7575
7576
7577qreal QQuickItem::height()
const
7579 Q_D(
const QQuickItem);
7583void QQuickItem::setHeight(qreal h)
7589 d->height.removeBindingUnlessInWrapper();
7593 d->heightValidFlag =
true;
7594 const qreal oldHeight = d->height.valueBypassingBindings();
7598 d->height.setValueBypassingBindings(h);
7600 d->dirty(QQuickItemPrivate::Size);
7602 const qreal x = d->x.valueBypassingBindings();
7603 const qreal y = d->y.valueBypassingBindings();
7604 const qreal w = d->width.valueBypassingBindings();
7605 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7608void QQuickItem::resetHeight()
7614 d->height.takeBinding();
7615 d->heightValidFlag =
false;
7616 setImplicitHeight(implicitHeight());
7619void QQuickItemPrivate::implicitHeightChanged()
7622 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7623 emit q->implicitHeightChanged();
7626qreal QQuickItemPrivate::getImplicitHeight()
const
7628 return implicitHeight;
7631qreal QQuickItem::implicitHeight()
const
7633 Q_D(
const QQuickItem);
7634 return d->getImplicitHeight();
7637QBindable<qreal> QQuickItem::bindableHeight()
7639 return QBindable<qreal>(&d_func()->height);
7642void QQuickItem::setImplicitHeight(qreal h)
7645 bool changed = h != d->implicitHeight;
7646 d->implicitHeight = h;
7647 if (d->height.valueBypassingBindings() == h || heightValid()) {
7649 d->implicitHeightChanged();
7650 if (d->height.valueBypassingBindings() == h || heightValid())
7655 const qreal oldHeight = d->height.valueBypassingBindings();
7656 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7658 d->height.setValueBypassingBindings(h);
7660 d->dirty(QQuickItemPrivate::Size);
7662 const qreal x = d->x.valueBypassingBindings();
7663 const qreal y = d->y.valueBypassingBindings();
7664 const qreal width = d->width.valueBypassingBindings();
7665 const qreal height = d->height.valueBypassingBindings();
7666 geometryChange(QRectF(x, y, width, height),
7667 QRectF(x, y, width, oldHeight));
7670 d->implicitHeightChanged();
7674
7675
7676void QQuickItem::setImplicitSize(qreal w, qreal h)
7679 bool wChanged = w != d->implicitWidth;
7680 bool hChanged = h != d->implicitHeight;
7682 d->implicitWidth = w;
7683 d->implicitHeight = h;
7687 qreal width = d->width.valueBypassingBindings();
7688 qreal height = d->height.valueBypassingBindings();
7689 if (width == w || widthValid()) {
7691 d->implicitWidthChanged();
7692 wDone = width == w || widthValid();
7695 if (height == h || heightValid()) {
7697 d->implicitHeightChanged();
7698 hDone = height == h || heightValid();
7704 const qreal oldWidth = width;
7705 const qreal oldHeight = height;
7708 d->width.setValueBypassingBindings(w);
7712 d->height.setValueBypassingBindings(h);
7715 d->dirty(QQuickItemPrivate::Size);
7717 const qreal x = d->x.valueBypassingBindings();
7718 const qreal y = d->y.valueBypassingBindings();
7719 geometryChange(QRectF(x, y, width, height),
7720 QRectF(x, y, oldWidth, oldHeight));
7722 if (!wDone && wChanged)
7723 d->implicitWidthChanged();
7724 if (!hDone && hChanged)
7725 d->implicitHeightChanged();
7729
7730
7731bool QQuickItem::heightValid()
const
7733 Q_D(
const QQuickItem);
7734 return d->heightValid();
7738
7739
7740
7741
7742
7743
7745QSizeF QQuickItem::size()
const
7747 Q_D(
const QQuickItem);
7748 return QSizeF(d->width, d->height);
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762void QQuickItem::setSize(
const QSizeF &size)
7765 d->heightValidFlag =
true;
7766 d->widthValidFlag =
true;
7768 const qreal oldHeight = d->height.valueBypassingBindings();
7769 const qreal oldWidth = d->width.valueBypassingBindings();
7771 if (oldWidth == size.width() && oldHeight == size.height())
7774 d->height.setValueBypassingBindings(size.height());
7775 d->width.setValueBypassingBindings(size.width());
7777 d->dirty(QQuickItemPrivate::Size);
7779 const qreal x = d->x.valueBypassingBindings();
7780 const qreal y = d->y.valueBypassingBindings();
7781 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853bool QQuickItem::hasActiveFocus()
const
7855 Q_D(
const QQuickItem);
7856 return d->activeFocus;
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
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
7944
7945
7946
7947bool QQuickItem::hasFocus()
const
7949 Q_D(
const QQuickItem);
7953void QQuickItem::setFocus(
bool focus)
7955 setFocus(focus, Qt::OtherFocusReason);
7958void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
7962 QQuickItem *scope = parentItem();
7963 while (scope && !scope->isFocusScope() && scope->parentItem())
7964 scope = scope->parentItem();
7966 if (d->focus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
7969 bool notifyListeners =
false;
7970 if (d->window || d->parentItem) {
7972 auto da = d->deliveryAgentPrivate();
7975 da->setFocusInScope(scope,
this, reason);
7977 da->clearFocusInScope(scope,
this, reason);
7981 QVarLengthArray<QQuickItem *, 20> changed;
7982 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
7983 if (oldSubFocusItem) {
7984 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
7985 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
7986 changed << oldSubFocusItem;
7987 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
7988 QQuickItemPrivate::get(scope)->focus =
false;
7991 d->updateSubFocusItem(scope, focus);
7995 notifyListeners =
true;
7996 emit focusChanged(focus);
7998 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8001 QVarLengthArray<QQuickItem *, 20> changed;
8002 QQuickItem *oldSubFocusItem = d->subFocusItem;
8003 if (!isFocusScope() && oldSubFocusItem) {
8004 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8005 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8006 changed << oldSubFocusItem;
8011 notifyListeners =
true;
8012 emit focusChanged(focus);
8014 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8016 if (notifyListeners)
8017 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8021
8022
8023bool QQuickItem::isFocusScope()
const
8025 return flags() & ItemIsFocusScope;
8029
8030
8031
8032
8033
8034QQuickItem *QQuickItem::scopedFocusItem()
const
8036 Q_D(
const QQuickItem);
8037 if (!isFocusScope())
8040 return d->subFocusItem;
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8058
8059
8060
8061
8062
8063
8064Qt::FocusPolicy QQuickItem::focusPolicy()
const
8066 Q_D(
const QQuickItem);
8067 uint policy = d->focusPolicy;
8068 if (activeFocusOnTab())
8069 policy |= Qt::TabFocus;
8070 return static_cast<Qt::FocusPolicy>(policy);
8074
8075
8076
8077
8078void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8081 if (d->focusPolicy == policy)
8084 d->focusPolicy = policy;
8085 setActiveFocusOnTab(policy & Qt::TabFocus);
8086 emit focusPolicyChanged(policy);
8090
8091
8092
8093
8094
8095
8096
8097bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8099 if (!child || child ==
this)
8101 const QQuickItem *ancestor = child;
8102 while ((ancestor = ancestor->parentItem())) {
8103 if (ancestor ==
this)
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8122 Q_D(
const QQuickItem);
8123 return d->acceptedMouseButtons();
8127
8128
8129
8130
8131
8132
8133
8134
8135void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8138 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8140 buttons &= ~Qt::LeftButton;
8141 if (buttons || d->extra.isAllocated()) {
8142 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8143 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158bool QQuickItem::filtersChildMouseEvents()
const
8160 Q_D(
const QQuickItem);
8161 return d->filtersChildMouseEvents;
8165
8166
8167
8168
8169
8170
8171
8172
8173void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8176 d->filtersChildMouseEvents = filter;
8180
8181
8182bool QQuickItem::isUnderMouse()
const
8184 Q_D(
const QQuickItem);
8191 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8194 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8195 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8199
8200
8201
8202
8203
8204
8205
8206bool QQuickItem::acceptHoverEvents()
const
8208 Q_D(
const QQuickItem);
8209 return d->hoverEnabled;
8213
8214
8215
8216
8217
8218void QQuickItem::setAcceptHoverEvents(
bool enabled)
8221 d->hoverEnabled = enabled;
8222 d->setHasHoverInChild(enabled);
8226 d->dirty(QQuickItemPrivate::Content);
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239bool QQuickItem::acceptTouchEvents()
const
8241 Q_D(
const QQuickItem);
8242 return d->touchEnabled;
8246
8247
8248
8249
8250
8251
8252
8253void QQuickItem::setAcceptTouchEvents(
bool enabled)
8256 d->touchEnabled = enabled;
8259void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8261#if QT_CONFIG(cursor)
8266 if (!hc && subtreeCursorEnabled) {
8269 for (QQuickItem *otherChild : std::as_const(childItems)) {
8270 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8271 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8276 subtreeCursorEnabled = hc;
8277 QQuickItem *parent = q->parentItem();
8279 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8280 parentPrivate->setHasCursorInChild(hc);
8287void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8293 if (!hasHover && subtreeHoverEnabled) {
8296 if (hasEnabledHoverHandlers())
8299 for (QQuickItem *otherChild : std::as_const(childItems)) {
8300 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8301 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8303 if (otherChildPrivate->hasEnabledHoverHandlers())
8308 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8309 subtreeHoverEnabled = hasHover;
8310 QQuickItem *parent = q->parentItem();
8312 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8313 parentPrivate->setHasHoverInChild(hasHover);
8317#if QT_CONFIG(cursor)
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8333QCursor QQuickItem::cursor()
const
8335 Q_D(
const QQuickItem);
8336 return d->extra.isAllocated()
8342
8343
8344
8345
8347void QQuickItem::setCursor(
const QCursor &cursor)
8351 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8352 qCDebug(lcHoverTrace) << oldShape <<
"->" << cursor.shape();
8354 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8355 d->extra.value().cursor = cursor;
8357 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8358 QWindow *window = renderWindow ? renderWindow : d->window;
8359 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8360 window->setCursor(cursor);
8364 QPointF updateCursorPos;
8365 if (!d->hasCursor) {
8366 d->hasCursor =
true;
8368 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8369 QWindow *window = renderWindow ? renderWindow : d->window;
8370 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8371 if (contains(mapFromScene(pos)))
8372 updateCursorPos = pos;
8375 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8376 if (!updateCursorPos.isNull())
8377 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8381
8382
8383
8384
8386void QQuickItem::unsetCursor()
8389 qCDebug(lcHoverTrace) <<
"clearing cursor";
8392 d->hasCursor =
false;
8393 d->setHasCursorInChild(d->hasCursorHandler);
8394 if (d->extra.isAllocated())
8395 d->extra->cursor = QCursor();
8398 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8399 if (windowPrivate->cursorItem ==
this) {
8400 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8401 windowPrivate->updateCursor(pos);
8407
8408
8409
8410
8411
8412
8413QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8415 Q_Q(
const QQuickItem);
8418 bool hoverCursorSet =
false;
8419 QCursor hoverCursor;
8420 bool activeCursorSet =
false;
8421 QCursor activeCursor;
8422 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8423 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8424 hoverCursor = hoverHandler->cursorShape();
8425 }
else if (handler->active()) {
8426 activeCursorSet = handler->isCursorShapeExplicitlySet();
8427 activeCursor = handler->cursorShape();
8429 if (activeCursorSet)
8430 return activeCursor;
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8458 if (!hasPointerHandlers())
8460 QQuickPointerHandler* activeHandler =
nullptr;
8461 QQuickPointerHandler* mouseHandler =
nullptr;
8462 QQuickPointerHandler* nonMouseHandler =
nullptr;
8463 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8464 if (!h->isCursorShapeExplicitlySet())
8466 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8471 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8472 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8473 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8475 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8476 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8477 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8479 mouseHandler = hoverHandler;
8482 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8483 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8484 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8486 nonMouseHandler = hoverHandler;
8489 if (!hoverHandler && h->active())
8492 if (activeHandler) {
8493 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8494 return activeHandler;
8500 if (nonMouseHandler) {
8502 const bool beforeTimeout =
8503 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8504 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8505 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8506 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8507 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8508 <<
"choosing cursor according to" << winner << winner->cursorShape();
8511 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8512 return nonMouseHandler;
8515 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8516 return mouseHandler;
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535void QQuickItem::grabMouse()
8540 auto da = d->deliveryAgentPrivate();
8542 auto eventInDelivery = da->eventInDelivery();
8543 if (!eventInDelivery) {
8544 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8547 auto epd = da->mousePointData();
8548 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562void QQuickItem::ungrabMouse()
8567 auto da = d->deliveryAgentPrivate();
8569 auto eventInDelivery = da->eventInDelivery();
8570 if (!eventInDelivery) {
8572 da->removeGrabber(
this);
8575 const auto &eventPoint = da->mousePointData()->eventPoint;
8576 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8577 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8581
8582
8583
8584
8585bool QQuickItem::keepMouseGrab()
const
8587 Q_D(
const QQuickItem);
8588 return d->keepMouse;
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607void QQuickItem::setKeepMouseGrab(
bool keep)
8610 d->keepMouse = keep;
8614
8615
8616
8617
8618
8619
8620
8621
8622void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8625 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8626 if (Q_UNLIKELY(!event)) {
8627 qWarning() <<
"cannot grab: no event is currently being delivered";
8630 for (
auto pt : event->points()) {
8631 if (ids.contains(pt.id()))
8632 event->setExclusiveGrabber(pt,
this);
8637
8638
8639
8640void QQuickItem::ungrabTouchPoints()
8645 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8646 da->removeGrabber(
this,
false,
true);
8650
8651
8652
8653
8654
8655bool QQuickItem::keepTouchGrab()
const
8657 Q_D(
const QQuickItem);
8658 return d->keepTouch;
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678void QQuickItem::setKeepTouchGrab(
bool keep)
8681 d->keepTouch = keep;
8685
8686
8687
8688
8689
8690
8691
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703bool QQuickItem::contains(
const QPointF &point)
const
8705 Q_D(
const QQuickItem);
8706 if (d->extra.isAllocated() && d->extra->mask) {
8707 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8708 return quickMask->contains(point - quickMask->position());
8711 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8712 maskContains.invoke(d->extra->mask,
8713 Qt::DirectConnection,
8714 Q_RETURN_ARG(
bool, res),
8715 Q_ARG(QPointF, point));
8719 qreal x = point.x();
8720 qreal y = point.y();
8721 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787QObject *QQuickItem::containmentMask()
const
8789 Q_D(
const QQuickItem);
8790 if (!d->extra.isAllocated())
8792 return d->extra->mask.data();
8795void QQuickItem::setContainmentMask(QObject *mask)
8798 const bool extraDataExists = d->extra.isAllocated();
8800 if (mask ==
static_cast<QObject *>(
this))
8803 if (!extraDataExists && !mask)
8806 if (extraDataExists && d->extra->mask == mask)
8809 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8812 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8813 maskPrivate->registerAsContainmentMask(
this,
false);
8816 if (!extraDataExists)
8819 int methodIndex = mask->metaObject()->indexOfMethod(QByteArrayLiteral(
"contains(QPointF)"));
8820 if (methodIndex < 0) {
8821 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
8824 d->extra->maskContainsIndex = methodIndex;
8826 d->extra->mask = mask;
8827 quickMask = qobject_cast<QQuickItem *>(mask);
8829 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8830 maskPrivate->registerAsContainmentMask(
this,
true);
8832 emit containmentMaskChanged();
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
8849 QPointF p = mapToScene(point);
8851 const auto *itemWindow = item->window();
8852 const auto *thisWindow = window();
8853 if (thisWindow && itemWindow && itemWindow != thisWindow)
8854 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
8856 p = item->mapFromScene(p);
8862
8863
8864
8865
8866
8867
8868
8869
8870QPointF QQuickItem::mapToScene(
const QPointF &point)
const
8872 Q_D(
const QQuickItem);
8873 return d->itemToWindowTransform().map(point);
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
8895 Q_D(
const QQuickItem);
8897 if (Q_UNLIKELY(d->window ==
nullptr))
8898 return mapToScene(point);
8900 QPoint renderOffset;
8901 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
8902 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
8903 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
8920 Q_D(
const QQuickItem);
8921 QTransform t = d->itemToWindowTransform();
8923 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
8924 return t.mapRect(rect);
8928
8929
8930
8931
8932
8933
8934
8935
8936QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
8938 Q_D(
const QQuickItem);
8939 return d->itemToWindowTransform().mapRect(rect);
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
8958 p = item->mapToScene(point);
8959 const auto *itemWindow = item->window();
8960 const auto *thisWindow = window();
8961 if (thisWindow && itemWindow && itemWindow != thisWindow)
8962 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
8964 return mapFromScene(p);
8968
8969
8970
8971
8972
8973
8974
8975
8976QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
8978 Q_D(
const QQuickItem);
8979 return d->windowToItemTransform().map(point);
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9007 Q_D(
const QQuickItem);
9010 if (Q_LIKELY(d->window)) {
9011 QPoint renderOffset;
9012 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9013 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9014 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9019 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9020 if (
auto sceneTransform = da->sceneTransform())
9021 scenePoint = sceneTransform->map(scenePoint);
9023 return mapFromScene(scenePoint);
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9040 Q_D(
const QQuickItem);
9041 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9042 t *= d->windowToItemTransform();
9043 return t.mapRect(rect);
9047
9048
9049
9050
9051
9052
9053
9054
9055QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9057 Q_D(
const QQuickItem);
9058 return d->windowToItemTransform().mapRect(rect);
9062
9063
9064
9067
9068
9069
9072
9073
9074
9077
9078
9079
9082
9083
9084
9087
9088
9089
9092
9093
9094
9097
9098
9099
9102
9103
9104
9107
9108
9109
9112
9113
9114bool QQuickItem::event(QEvent *ev)
9118 switch (ev->type()) {
9120 case QEvent::InputMethodQuery: {
9121 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9122 Qt::InputMethodQueries queries = query->queries();
9123 for (uint i = 0; i < 32; ++i) {
9124 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9126 QVariant v = inputMethodQuery(q);
9127 query->setValue(q, v);
9133 case QEvent::InputMethod:
9134 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9137 case QEvent::TouchBegin:
9138 case QEvent::TouchUpdate:
9139 case QEvent::TouchEnd:
9140 case QEvent::TouchCancel:
9141 case QEvent::MouseButtonPress:
9142 case QEvent::MouseButtonRelease:
9143 case QEvent::MouseButtonDblClick:
9144#if QT_CONFIG(wheelevent)
9147 d->deliverPointerEvent(ev);
9149 case QEvent::StyleAnimationUpdate:
9155 case QEvent::HoverEnter:
9156 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9158 case QEvent::HoverLeave:
9159 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9161 case QEvent::HoverMove:
9162 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9164 case QEvent::KeyPress:
9165 case QEvent::KeyRelease:
9166 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9168 case QEvent::ShortcutOverride:
9169 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9171 case QEvent::FocusIn:
9172 focusInEvent(
static_cast<QFocusEvent*>(ev));
9174 case QEvent::FocusOut:
9175 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9177 case QEvent::MouseMove:
9178 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9180#if QT_CONFIG(quick_draganddrop)
9181 case QEvent::DragEnter:
9182 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9184 case QEvent::DragLeave:
9185 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9187 case QEvent::DragMove:
9188 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9191 dropEvent(
static_cast<QDropEvent*>(ev));
9194#if QT_CONFIG(gestures)
9195 case QEvent::NativeGesture:
9199 case QEvent::LanguageChange:
9200 case QEvent::LocaleChange:
9201 for (QQuickItem *item : std::as_const(d->childItems))
9202 QCoreApplication::sendEvent(item, ev);
9204 case QEvent::WindowActivate:
9205 case QEvent::WindowDeactivate:
9206 if (d->providesPalette())
9207 d->setCurrentColorGroup();
9208 for (QQuickItem *item : std::as_const(d->childItems))
9209 QCoreApplication::sendEvent(item, ev);
9211 case QEvent::ApplicationPaletteChange:
9212 for (QQuickItem *item : std::as_const(d->childItems))
9213 QCoreApplication::sendEvent(item, ev);
9215 case QEvent::ContextMenu:
9217 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9220 return QObject::event(ev);
9226#ifndef QT_NO_DEBUG_STREAM
9228#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9233 QDebugStateSaver saver(debug);
9236 debug <<
"QQuickItem(nullptr)";
9240 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9242 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9246 if (item->isComponentComplete()) {
9247 if (QQmlContext *context = qmlContext(item)) {
9248 const auto objectId = context->nameForObject(item);
9249 if (!objectId.isEmpty())
9250 debug <<
", id=" << objectId;
9253 if (!item->objectName().isEmpty())
9254 debug <<
", name=" << item->objectName();
9255 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9257 QtDebugUtils::formatQRect(debug, rect);
9258 if (
const qreal z = item->z())
9259 debug <<
", z=" << z;
9260 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9261 debug <<
" \U0001f5bc";
9262 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9270
9271
9272
9273
9274
9275
9276
9278bool QQuickItem::isTextureProvider()
const
9280#if QT_CONFIG(quick_shadereffect)
9281 Q_D(
const QQuickItem);
9282 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9283 d->extra->layer->effectSource()->isTextureProvider() :
false;
9290
9291
9292
9293
9294
9295
9296
9298QSGTextureProvider *QQuickItem::textureProvider()
const
9300#if QT_CONFIG(quick_shadereffect)
9301 Q_D(
const QQuickItem);
9302 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9303 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9351#if QT_CONFIG(quick_shadereffect)
9353
9354
9355
9356QQuickItemLayer *QQuickItemPrivate::layer()
const
9358 if (!extra.isAllocated() || !extra->layer) {
9359 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9360 if (!componentComplete)
9361 extra->layer->classBegin();
9363 return extra->layer;
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9387 QList<QEventPoint> touchPoints;
9388 QEventPoint::States eventStates;
9390 bool anyPressOrReleaseInside =
false;
9391 bool anyGrabber =
false;
9392 for (
auto &p : event->points()) {
9397 auto pointGrabber = event->exclusiveGrabber(p);
9398 bool isGrabber = (pointGrabber == q);
9399 if (!isGrabber && pointGrabber && isFiltering) {
9400 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9401 if (handlerGrabber && handlerGrabber->parentItem() == q)
9408 const auto localPos = q->mapFromScene(p.scenePosition());
9409 bool isInside = q->contains(localPos);
9410 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9412 if (isFiltering && !pointGrabber) {
9413 const auto pg = event->passiveGrabbers(p);
9414 if (!pg.isEmpty()) {
9418 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9420 pointGrabber = handler->parentItem();
9425 bool grabberIsChild =
false;
9426 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9427 while (isFiltering && parent) {
9429 grabberIsChild =
true;
9432 parent = parent->parentItem();
9435 bool filterRelevant = isFiltering && grabberIsChild;
9436 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9438 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9439 anyPressOrReleaseInside =
true;
9440 QEventPoint pCopy(p);
9441 eventStates |= p.state();
9442 if (p.state() == QEventPoint::State::Released)
9443 QMutableEventPoint::detach(pCopy);
9444 QMutableEventPoint::setPosition(pCopy, localPos);
9445 touchPoints.append(std::move(pCopy));
9450 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9451 *localized = QMutableTouchEvent(QEvent::None);
9456 QEvent::Type eventType = event->type();
9457 switch (eventStates) {
9458 case QEventPoint::State::Pressed:
9459 eventType = QEvent::TouchBegin;
9461 case QEventPoint::State::Released:
9462 eventType = QEvent::TouchEnd;
9465 eventType = QEvent::TouchUpdate;
9469 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9471 ret.setTimestamp(event->timestamp());
9476bool QQuickItemPrivate::hasPointerHandlers()
const
9478 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9481bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9483 if (!hasPointerHandlers())
9485 for (QQuickPointerHandler *h : extra->pointerHandlers)
9486 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9491void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9497 extra.value().acceptedMouseButtons = Qt::AllButtons;
9498 auto &handlers = extra.value().pointerHandlers;
9499 if (!handlers.contains(h))
9500 handlers.prepend(h);
9501 auto &res = extra.value().resourcesList;
9502 if (!res.contains(h)) {
9504 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9505 _q_resourceObjectDeleted(o);
9510void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9514 auto &handlers = extra.value().pointerHandlers;
9515 handlers.removeOne(h);
9516 auto &res = extra.value().resourcesList;
9518 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9519 if (handlers.isEmpty())
9520 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9524
9525
9526
9527QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9529 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9530 extra.value().contextMenu = menu;
9534#if QT_CONFIG(quick_shadereffect)
9535QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9541 , m_componentComplete(
true)
9542 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9543 , m_format(QQuickShaderEffectSource::RGBA8)
9545 , m_effectComponent(
nullptr)
9547 , m_effectSource(
nullptr)
9548 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9553QQuickItemLayer::~QQuickItemLayer()
9555 delete m_effectSource;
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573void QQuickItemLayer::setEnabled(
bool e)
9578 if (m_componentComplete) {
9585 emit enabledChanged(e);
9588void QQuickItemLayer::classBegin()
9590 Q_ASSERT(!m_effectSource);
9591 Q_ASSERT(!m_effect);
9592 m_componentComplete =
false;
9595void QQuickItemLayer::componentComplete()
9597 Q_ASSERT(!m_componentComplete);
9598 m_componentComplete =
true;
9603void QQuickItemLayer::activate()
9605 Q_ASSERT(!m_effectSource);
9606 m_effectSource =
new QQuickShaderEffectSource();
9607 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9609 QQuickItem *parentItem = m_item->parentItem();
9611 m_effectSource->setParentItem(parentItem);
9612 m_effectSource->stackAfter(m_item);
9615 m_effectSource->setSourceItem(m_item);
9616 m_effectSource->setHideSource(
true);
9617 m_effectSource->setSmooth(m_smooth);
9618 m_effectSource->setLive(m_live);
9619 m_effectSource->setTextureSize(m_size);
9620 m_effectSource->setSourceRect(m_sourceRect);
9621 m_effectSource->setMipmap(m_mipmap);
9622 m_effectSource->setWrapMode(m_wrapMode);
9623 m_effectSource->setFormat(m_format);
9624 m_effectSource->setTextureMirroring(m_textureMirroring);
9625 m_effectSource->setSamples(m_samples);
9627 if (m_effectComponent)
9630 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9637 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9638 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9641void QQuickItemLayer::deactivate()
9643 Q_ASSERT(m_effectSource);
9645 if (m_effectComponent)
9648 delete m_effectSource;
9649 m_effectSource =
nullptr;
9651 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9652 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9655void QQuickItemLayer::activateEffect()
9657 Q_ASSERT(m_effectSource);
9658 Q_ASSERT(m_effectComponent);
9659 Q_ASSERT(!m_effect);
9661 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9662 m_effect = qobject_cast<QQuickItem *>(created);
9664 qWarning(
"Item: layer.effect is not a QML Item.");
9665 m_effectComponent->completeCreate();
9669 QQuickItem *parentItem = m_item->parentItem();
9671 m_effect->setParentItem(parentItem);
9672 m_effect->stackAfter(m_effectSource);
9674 m_effect->setVisible(m_item->isVisible());
9675 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9676 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9677 m_effectComponent->completeCreate();
9680void QQuickItemLayer::deactivateEffect()
9682 Q_ASSERT(m_effectSource);
9683 Q_ASSERT(m_effectComponent);
9691
9692
9693
9694
9695
9696
9697
9698
9699
9701void QQuickItemLayer::setEffect(QQmlComponent *component)
9703 if (component == m_effectComponent)
9706 bool updateNeeded =
false;
9707 if (m_effectSource && m_effectComponent) {
9709 updateNeeded =
true;
9712 m_effectComponent = component;
9714 if (m_effectSource && m_effectComponent) {
9716 updateNeeded =
true;
9724 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9727 emit effectChanged(component);
9732
9733
9734
9735
9736
9737
9738
9739
9740
9742void QQuickItemLayer::setMipmap(
bool mipmap)
9744 if (mipmap == m_mipmap)
9749 m_effectSource->setMipmap(m_mipmap);
9751 emit mipmapChanged(mipmap);
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9772void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9779 m_effectSource->setFormat(m_format);
9781 emit formatChanged(m_format);
9786
9787
9788
9789
9790
9791
9792
9793
9794
9796void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
9798 if (sourceRect == m_sourceRect)
9800 m_sourceRect = sourceRect;
9803 m_effectSource->setSourceRect(m_sourceRect);
9805 emit sourceRectChanged(sourceRect);
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9820void QQuickItemLayer::setSmooth(
bool s)
9827 m_effectSource->setSmooth(m_smooth);
9829 emit smoothChanged(s);
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9844void QQuickItemLayer::setLive(
bool live)
9851 m_effectSource->setLive(m_live);
9853 emit liveChanged(live);
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9869void QQuickItemLayer::setSize(
const QSize &size)
9876 m_effectSource->setTextureSize(size);
9878 emit sizeChanged(size);
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9899void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
9901 if (mode == m_wrapMode)
9906 m_effectSource->setWrapMode(m_wrapMode);
9908 emit wrapModeChanged(mode);
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9926void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
9928 if (mirroring == m_textureMirroring)
9930 m_textureMirroring = mirroring;
9933 m_effectSource->setTextureMirroring(m_textureMirroring);
9935 emit textureMirroringChanged(mirroring);
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9963void QQuickItemLayer::setSamples(
int count)
9965 if (m_samples == count)
9971 m_effectSource->setSamples(m_samples);
9973 emit samplesChanged(count);
9977
9978
9979
9980
9981
9982
9983
9984
9985
9987void QQuickItemLayer::setName(
const QByteArray &name) {
9991 m_effect->setProperty(m_name, QVariant());
9992 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
9995 emit nameChanged(name);
9998void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10004void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10009void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10012 Q_ASSERT(item == m_item);
10013 Q_ASSERT(parent != m_effectSource);
10014 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10016 m_effectSource->setParentItem(parent);
10018 m_effectSource->stackAfter(m_item);
10021 m_effect->setParentItem(parent);
10023 m_effect->stackAfter(m_effectSource);
10027void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10029 m_effectSource->stackAfter(m_item);
10031 m_effect->stackAfter(m_effectSource);
10034void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10036 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10039 l->setVisible(m_item->isVisible());
10042void QQuickItemLayer::updateZ()
10044 if (!m_componentComplete || !m_enabled)
10046 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10049 l->setZ(m_item->z());
10052void QQuickItemLayer::updateOpacity()
10054 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10057 l->setOpacity(m_item->opacity());
10060void QQuickItemLayer::updateGeometry()
10062 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10067 QRectF bounds = m_item->QQuickItem::boundingRect();
10068 l->setSize(bounds.size());
10069 l->setPosition(bounds.topLeft() + m_item->position());
10072void QQuickItemLayer::updateMatrix()
10076 if (!m_componentComplete || !m_enabled)
10078 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10081 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10082 l->setScale(m_item->scale());
10083 l->setRotation(m_item->rotation());
10084 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10085 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10086 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10087 ld->dirty(QQuickItemPrivate::Transform);
10091QQuickItemPrivate::ExtraData::ExtraData()
10092: z(0), scale(1), rotation(0), opacity(1),
10093 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10094 enterKeyAttached(
nullptr),
10095 keyHandler(
nullptr), contextMenu(
nullptr),
10096#if QT_CONFIG(quick_shadereffect)
10099 effectRefCount(0), hideRefCount(0),
10100 recursiveEffectRefCount(0),
10101 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10102 origin(QQuickItem::Center),
10103 transparentForPositioner(
false)
10108#if QT_CONFIG(accessibility)
10109QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10111 Q_Q(
const QQuickItem);
10112 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10113 auto role = QAccessible::NoRole;
10114 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10115 role = accessibleAttached->role();
10116 if (role == QAccessible::NoRole)
10117 role = accessibleRole();
10121QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10123 return QAccessible::NoRole;
10132 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10145 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10146 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10147 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10148 QV4::QObjectWrapper::markWrapper(child, markStack);
10150 QObjectWrapper::markObjects(that, markStack);
10153quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10155 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10160 QDebugStateSaver stateSaver(debug);
10161 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10166QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10167{
return mapFromItem(item, QPointF(x, y) ); }
10170QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10171{
return mapRectFromItem(item, rect); }
10174QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10175{
return mapFromItem(item, QRectF(x, y, width, height)); }
10178QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10179{
return mapToItem(item, QPointF(x, y)); }
10182QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10183{
return mapRectToItem(item, rect); }
10186QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10187{
return mapToItem(item, QRectF(x, y, width, height)); }
10190QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10191{
return mapToGlobal(QPointF(x, y)); }
10194QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10195{
return mapFromGlobal(QPointF(x, y)); }
10198QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10202#include <moc_qquickitem.cpp>
10204#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)