9#include <QtQml/qjsengine.h>
16#include <QtQml/qqmlengine.h>
17#include <QtQml/qqmlcomponent.h>
18#include <QtQml/qqmlinfo.h>
19#include <QtGui/qpen.h>
20#include <QtGui/qguiapplication.h>
21#include <QtGui/qstylehints.h>
22#include <QtGui/private/qeventpoint_p.h>
23#include <QtGui/private/qguiapplication_p.h>
24#include <QtGui/private/qpointingdevice_p.h>
25#include <QtGui/qinputmethod.h>
26#include <QtCore/qcoreevent.h>
27#include <QtCore/private/qnumeric_p.h>
28#include <QtGui/qpa/qplatformtheme.h>
29#include <QtCore/qloggingcategory.h>
30#include <QtCore/private/qduplicatetracker_p.h>
32#include <private/qqmlglobal_p.h>
33#include <private/qqmlengine_p.h>
34#include <QtQuick/private/qquickstategroup_p.h>
35#include <private/qqmlopenmetaobject_p.h>
36#include <QtQuick/private/qquickstate_p.h>
37#include <private/qquickitem_p.h>
38#include <QtQuick/private/qquickaccessibleattached_p.h>
39#include <QtQuick/private/qquickattachedpropertypropagator_p.h>
40#include <QtQuick/private/qquickhoverhandler_p.h>
41#include <QtQuick/private/qquickpointerhandler_p.h>
42#include <QtQuick/private/qquickpointerhandler_p_p.h>
44#include <private/qv4engine_p.h>
45#include <private/qv4object_p.h>
46#include <private/qv4qobjectwrapper_p.h>
47#include <private/qdebug_p.h>
48#include <private/qqmlvaluetypewrapper_p.h>
51# include <QtGui/qcursor.h>
54#if QT_CONFIG(accessibility)
55# include <private/qaccessiblecache_p.h>
58#include <QtCore/qpointer.h>
68Q_LOGGING_CATEGORY(lcVP,
"qt.quick.viewport")
69Q_STATIC_LOGGING_CATEGORY(lcEffClip,
"qt.quick.effectiveclip")
70Q_STATIC_LOGGING_CATEGORY(lcChangeListeners,
"qt.quick.item.changelisteners")
73static const quint64 kCursorOverrideTimeout = 100;
75void debugFocusTree(QQuickItem *item, QQuickItem *scope =
nullptr,
int depth = 1)
77 if (lcFocus().isEnabled(QtDebugMsg)) {
79 << QByteArray(depth,
'\t').constData()
80 << (scope && QQuickItemPrivate::get(scope)->subFocusItem == item ?
'*' :
' ')
82 << item->hasActiveFocus()
83 << item->isFocusScope()
85 const auto childItems = item->childItems();
86 for (QQuickItem *child : childItems) {
89 item->isFocusScope() || !scope ? item : scope,
90 item->isFocusScope() || !scope ? depth + 1 : depth);
97 QQuickItemPrivate *d = QQuickItemPrivate::get(item);
98 if (d->subFocusItem && d->window && d->flags & QQuickItem::ItemIsFocusScope)
99 d->deliveryAgentPrivate()->clearFocusInScope(item, d->subFocusItem, reason);
100 item->forceActiveFocus(reason);
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127QQuickTransformPrivate::QQuickTransformPrivate()
131QQuickTransform::QQuickTransform(QObject *parent)
132: QObject(*(
new QQuickTransformPrivate), parent)
136QQuickTransform::QQuickTransform(QQuickTransformPrivate &dd, QObject *parent)
141QQuickTransform::~QQuickTransform()
143 Q_D(QQuickTransform);
144 for (
int ii = 0; ii < d->items.size(); ++ii) {
145 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
146 p->transforms.removeOne(
this);
147 p->dirty(QQuickItemPrivate::Transform);
151void QQuickTransform::update()
153 Q_D(QQuickTransform);
154 for (
int ii = 0; ii < d->items.size(); ++ii) {
155 QQuickItemPrivate *p = QQuickItemPrivate::get(d->items.at(ii));
156 p->dirty(QQuickItemPrivate::Transform);
160QQuickContents::QQuickContents(QQuickItem *item)
165QQuickContents::~QQuickContents()
168 QList<QQuickItem *> children = m_item->childItems();
169 for (
int i = 0; i < children.size(); ++i) {
170 QQuickItem *child = children.at(i);
171 QQuickItemPrivate::get(child)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
175bool QQuickContents::calcHeight(QQuickItem *changed)
177 qreal oldy = m_contents.y();
178 qreal oldheight = m_contents.height();
182 qreal bottom = oldy + oldheight;
183 qreal y = changed->y();
184 if (y + changed->height() > bottom)
185 bottom = y + changed->height();
188 m_contents.setY(top);
189 m_contents.setHeight(bottom - top);
191 qreal top = std::numeric_limits<qreal>::max();
192 qreal bottom = -std::numeric_limits<qreal>::max();
193 QList<QQuickItem *> children = m_item->childItems();
194 for (
int i = 0; i < children.size(); ++i) {
195 QQuickItem *child = children.at(i);
196 qreal y = child->y();
197 if (y + child->height() > bottom)
198 bottom = y + child->height();
202 if (!children.isEmpty())
203 m_contents.setY(top);
204 m_contents.setHeight(qMax(bottom - top, qreal(0.0)));
207 return (m_contents.height() != oldheight || m_contents.y() != oldy);
210bool QQuickContents::calcWidth(QQuickItem *changed)
212 qreal oldx = m_contents.x();
213 qreal oldwidth = m_contents.width();
217 qreal right = oldx + oldwidth;
218 qreal x = changed->x();
219 if (x + changed->width() > right)
220 right = x + changed->width();
223 m_contents.setX(left);
224 m_contents.setWidth(right - left);
226 qreal left = std::numeric_limits<qreal>::max();
227 qreal right = -std::numeric_limits<qreal>::max();
228 QList<QQuickItem *> children = m_item->childItems();
229 for (
int i = 0; i < children.size(); ++i) {
230 QQuickItem *child = children.at(i);
231 qreal x = child->x();
232 if (x + child->width() > right)
233 right = x + child->width();
237 if (!children.isEmpty())
238 m_contents.setX(left);
239 m_contents.setWidth(qMax(right - left, qreal(0.0)));
242 return (m_contents.width() != oldwidth || m_contents.x() != oldx);
245void QQuickContents::complete()
247 QQuickItemPrivate::get(m_item)->addItemChangeListener(
this, QQuickItemPrivate::Children);
249 QList<QQuickItem *> children = m_item->childItems();
250 for (
int i = 0; i < children.size(); ++i) {
251 QQuickItem *child = children.at(i);
252 QQuickItemPrivate::get(child)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
258void QQuickContents::updateRect()
260 QQuickItemPrivate::get(m_item)->emitChildrenRectChanged(rectF());
263void QQuickContents::itemGeometryChanged(QQuickItem *changed, QQuickGeometryChange change,
const QRectF &)
266 bool wChanged =
false;
267 bool hChanged =
false;
269 if (change.horizontalChange())
270 wChanged = calcWidth();
271 if (change.verticalChange())
272 hChanged = calcHeight();
273 if (wChanged || hChanged)
277void QQuickContents::itemDestroyed(QQuickItem *item)
280 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
284void QQuickContents::itemChildRemoved(QQuickItem *, QQuickItem *item)
287 QQuickItemPrivate::get(item)->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
291void QQuickContents::itemChildAdded(QQuickItem *, QQuickItem *item)
294 QQuickItemPrivate::get(item)->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Destroyed);
298QQuickItemKeyFilter::QQuickItemKeyFilter(QQuickItem *item)
299: m_processPost(
false), m_next(
nullptr)
301 QQuickItemPrivate *p = item?QQuickItemPrivate::get(item):
nullptr;
303 m_next = p->extra.value().keyHandler;
304 p->extra->keyHandler =
this;
308QQuickItemKeyFilter::~QQuickItemKeyFilter()
312void QQuickItemKeyFilter::keyPressed(QKeyEvent *event,
bool post)
314 if (m_next) m_next->keyPressed(event, post);
317void QQuickItemKeyFilter::keyReleased(QKeyEvent *event,
bool post)
319 if (m_next) m_next->keyReleased(event, post);
323void QQuickItemKeyFilter::inputMethodEvent(QInputMethodEvent *event,
bool post)
326 m_next->inputMethodEvent(event, post);
331QVariant QQuickItemKeyFilter::inputMethodQuery(Qt::InputMethodQuery query)
const
333 if (m_next)
return m_next->inputMethodQuery(query);
338void QQuickItemKeyFilter::shortcutOverrideEvent(QKeyEvent *event)
341 m_next->shortcutOverrideEvent(event);
346void QQuickItemKeyFilter::componentComplete()
348 if (m_next) m_next->componentComplete();
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
395
396
397
398
399
402
403
404
405
406
409
410
411
412
413
416
417
418
419
420
423
424
425
426
427
430
431
432
433
434
436QQuickKeyNavigationAttached::QQuickKeyNavigationAttached(QObject *parent)
437: QObject(*(
new QQuickKeyNavigationAttachedPrivate), parent),
438 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
440 m_processPost =
true;
443QQuickKeyNavigationAttached *
444QQuickKeyNavigationAttached::qmlAttachedProperties(QObject *obj)
446 return new QQuickKeyNavigationAttached(obj);
449QQuickItem *QQuickKeyNavigationAttached::left()
const
451 Q_D(
const QQuickKeyNavigationAttached);
455void QQuickKeyNavigationAttached::setLeft(QQuickItem *i)
457 Q_D(QQuickKeyNavigationAttached);
458 if (d->leftSet && d->left == i)
460 d->leftSet = d->left != i;
462 QQuickKeyNavigationAttached* other =
463 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
464 if (other && !other->d_func()->rightSet){
465 other->d_func()->right = qobject_cast<QQuickItem*>(parent());
466 emit other->rightChanged();
471QQuickItem *QQuickKeyNavigationAttached::right()
const
473 Q_D(
const QQuickKeyNavigationAttached);
477void QQuickKeyNavigationAttached::setRight(QQuickItem *i)
479 Q_D(QQuickKeyNavigationAttached);
480 if (d->rightSet && d->right == i)
482 d->rightSet = d->right != i;
484 QQuickKeyNavigationAttached* other =
485 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
486 if (other && !other->d_func()->leftSet){
487 other->d_func()->left = qobject_cast<QQuickItem*>(parent());
488 emit other->leftChanged();
493QQuickItem *QQuickKeyNavigationAttached::up()
const
495 Q_D(
const QQuickKeyNavigationAttached);
499void QQuickKeyNavigationAttached::setUp(QQuickItem *i)
501 Q_D(QQuickKeyNavigationAttached);
502 if (d->upSet && d->up == i)
504 d->upSet = d->up != i;
506 QQuickKeyNavigationAttached* other =
507 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
508 if (other && !other->d_func()->downSet){
509 other->d_func()->down = qobject_cast<QQuickItem*>(parent());
510 emit other->downChanged();
515QQuickItem *QQuickKeyNavigationAttached::down()
const
517 Q_D(
const QQuickKeyNavigationAttached);
521void QQuickKeyNavigationAttached::setDown(QQuickItem *i)
523 Q_D(QQuickKeyNavigationAttached);
524 if (d->downSet && d->down == i)
526 d->downSet = d->down != i;
528 QQuickKeyNavigationAttached* other =
529 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
530 if (other && !other->d_func()->upSet) {
531 other->d_func()->up = qobject_cast<QQuickItem*>(parent());
532 emit other->upChanged();
537QQuickItem *QQuickKeyNavigationAttached::tab()
const
539 Q_D(
const QQuickKeyNavigationAttached);
543void QQuickKeyNavigationAttached::setTab(QQuickItem *i)
545 Q_D(QQuickKeyNavigationAttached);
546 if (d->tabSet && d->tab == i)
548 d->tabSet = d->tab != i;
550 QQuickKeyNavigationAttached* other =
551 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
552 if (other && !other->d_func()->backtabSet) {
553 other->d_func()->backtab = qobject_cast<QQuickItem*>(parent());
554 emit other->backtabChanged();
559QQuickItem *QQuickKeyNavigationAttached::backtab()
const
561 Q_D(
const QQuickKeyNavigationAttached);
565void QQuickKeyNavigationAttached::setBacktab(QQuickItem *i)
567 Q_D(QQuickKeyNavigationAttached);
568 if (d->backtabSet && d->backtab == i)
570 d->backtabSet = d->backtab != i;
572 QQuickKeyNavigationAttached* other =
573 qobject_cast<QQuickKeyNavigationAttached*>(qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(i));
574 if (other && !other->d_func()->tabSet) {
575 other->d_func()->tab = qobject_cast<QQuickItem*>(parent());
576 emit other->tabChanged();
578 emit backtabChanged();
582
583
584
585
586
587
588
589
590
591
592
593
594QQuickKeyNavigationAttached::Priority QQuickKeyNavigationAttached::priority()
const
596 return m_processPost ? AfterItem : BeforeItem;
599void QQuickKeyNavigationAttached::setPriority(Priority order)
601 bool processPost = order == AfterItem;
602 if (processPost != m_processPost) {
603 m_processPost = processPost;
604 emit priorityChanged();
608void QQuickKeyNavigationAttached::keyPressed(QKeyEvent *event,
bool post)
610 Q_D(QQuickKeyNavigationAttached);
613 if (post != m_processPost) {
614 QQuickItemKeyFilter::keyPressed(event, post);
619 switch (event->key()) {
621 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
622 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
623 QQuickItem* leftItem = mirror ? d->right : d->left;
625 setFocusNavigation(leftItem, mirror ?
"right" :
"left", mirror ? Qt::TabFocusReason : Qt::BacktabFocusReason);
630 case Qt::Key_Right: {
631 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
632 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
633 QQuickItem* rightItem = mirror ? d->left : d->right;
635 setFocusNavigation(rightItem, mirror ?
"left" :
"right", mirror ? Qt::BacktabFocusReason : Qt::TabFocusReason);
642 setFocusNavigation(d->up,
"up", Qt::BacktabFocusReason);
648 setFocusNavigation(d->down,
"down", Qt::TabFocusReason);
654 setFocusNavigation(d->tab,
"tab", Qt::TabFocusReason);
658 case Qt::Key_Backtab:
660 setFocusNavigation(d->backtab,
"backtab", Qt::BacktabFocusReason);
668 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
671void QQuickKeyNavigationAttached::keyReleased(QKeyEvent *event,
bool post)
673 Q_D(QQuickKeyNavigationAttached);
676 if (post != m_processPost) {
677 QQuickItemKeyFilter::keyReleased(event, post);
682 switch (event->key()) {
684 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
685 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
686 if (mirror ? d->right : d->left)
690 if (QQuickItem *parentItem = qobject_cast<QQuickItem*>(parent()))
691 mirror = QQuickItemPrivate::get(parentItem)->effectiveLayoutMirror;
692 if (mirror ? d->left : d->right)
710 case Qt::Key_Backtab:
719 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
722void QQuickKeyNavigationAttached::setFocusNavigation(QQuickItem *currentItem,
const char *dir,
723 Qt::FocusReason reason)
725 QQuickItem *initialItem = currentItem;
726 bool isNextItem =
false;
727 QList<QQuickItem *> visitedItems;
730 if (currentItem->isVisible() && currentItem->isEnabled()) {
731 currentItem->forceActiveFocus(reason);
734 qmlAttachedPropertiesObject<QQuickKeyNavigationAttached>(currentItem,
false);
736 QQuickItem *tempItem = qvariant_cast<QQuickItem*>(attached->property(dir));
738 visitedItems.append(currentItem);
739 currentItem = tempItem;
745 while (currentItem != initialItem && isNextItem && !visitedItems.contains(currentItem));
754 { Qt::Key_Left,
"leftPressed" },
755 { Qt::Key_Right,
"rightPressed" },
756 { Qt::Key_Up,
"upPressed" },
757 { Qt::Key_Down,
"downPressed" },
758 { Qt::Key_Tab,
"tabPressed" },
759 { Qt::Key_Backtab,
"backtabPressed" },
760 { Qt::Key_Asterisk,
"asteriskPressed" },
761 { Qt::Key_NumberSign,
"numberSignPressed" },
762 { Qt::Key_Escape,
"escapePressed" },
763 { Qt::Key_Return,
"returnPressed" },
764 { Qt::Key_Enter,
"enterPressed" },
765 { Qt::Key_Delete,
"deletePressed" },
766 { Qt::Key_Space,
"spacePressed" },
767 { Qt::Key_Back,
"backPressed" },
768 { Qt::Key_Cancel,
"cancelPressed" },
769 { Qt::Key_Select,
"selectPressed" },
770 { Qt::Key_Yes,
"yesPressed" },
771 { Qt::Key_No,
"noPressed" },
772 { Qt::Key_Context1,
"context1Pressed" },
773 { Qt::Key_Context2,
"context2Pressed" },
774 { Qt::Key_Context3,
"context3Pressed" },
775 { Qt::Key_Context4,
"context4Pressed" },
776 { Qt::Key_Call,
"callPressed" },
777 { Qt::Key_Hangup,
"hangupPressed" },
778 { Qt::Key_Flip,
"flipPressed" },
779 { Qt::Key_Menu,
"menuPressed" },
780 { Qt::Key_VolumeUp,
"volumeUpPressed" },
781 { Qt::Key_VolumeDown,
"volumeDownPressed" },
785QByteArray QQuickKeysAttached::keyToSignal(
int key)
787 QByteArray keySignal;
788 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
789 keySignal =
"digit0Pressed";
790 keySignal[5] =
'0' + (key - Qt::Key_0);
793 while (sigMap[i].key && sigMap[i].key != key)
795 keySignal = sigMap[i].sig;
800bool QQuickKeysAttached::isConnected(
const char *signalName)
const
802 Q_D(
const QQuickKeysAttached);
803 int signal_index = d->signalIndex(signalName);
804 return d->isSignalConnected(signal_index);
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
873
874
875
876
877
880
881
882
883
884
885
886
887
888
889
890
891
892
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
925
926
927
928
929
932
933
934
935
936
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
977
978
979
980
981
984
985
986
987
988
991
992
993
994
995
998
999
1000
1001
1002
1005
1006
1007
1008
1009
1012
1013
1014
1015
1016
1019
1020
1021
1022
1023
1026
1027
1028
1029
1030
1033
1034
1035
1036
1037
1040
1041
1042
1043
1044
1047
1048
1049
1050
1051
1054
1055
1056
1057
1058
1061
1062
1063
1064
1065
1068
1069
1070
1071
1072
1075
1076
1077
1078
1079
1082
1083
1084
1085
1086
1089
1090
1091
1092
1093
1096
1097
1098
1099
1100
1103
1104
1105
1106
1107
1110
1111
1112
1113
1114
1117
1118
1119
1120
1121
1124
1125
1126
1127
1128
1131
1132
1133
1134
1135
1138
1139
1140
1141
1142
1145
1146
1147
1148
1149
1152
1153
1154
1155
1156
1159
1160
1161
1162
1163
1166
1167
1168
1169
1170
1173
1174
1175
1176
1177
1180
1181
1182
1183
1184
1187
1188
1189
1190
1191
1194
1195
1196
1197
1198
1201
1202
1203
1204
1205
1208
1209
1210
1211
1212
1215
1216
1217
1218
1219
1222
1223
1224
1225
1226
1229
1230
1231
1232
1233
1235QQuickKeysAttached::QQuickKeysAttached(QObject *parent)
1236: QObject(*(
new QQuickKeysAttachedPrivate), parent),
1237 QQuickItemKeyFilter(qmlobject_cast<QQuickItem*>(parent))
1239 Q_D(QQuickKeysAttached);
1240 m_processPost =
false;
1241 d->item = qmlobject_cast<QQuickItem*>(parent);
1242 if (d->item != parent)
1243 qWarning() <<
"Could not attach Keys property to: " << parent <<
" is not an Item";
1246QQuickKeysAttached::~QQuickKeysAttached()
1250QQuickKeysAttached::Priority QQuickKeysAttached::priority()
const
1252 return m_processPost ? AfterItem : BeforeItem;
1255void QQuickKeysAttached::setPriority(Priority order)
1257 bool processPost = order == AfterItem;
1258 if (processPost != m_processPost) {
1259 m_processPost = processPost;
1260 emit priorityChanged();
1264void QQuickKeysAttached::componentComplete()
1267 Q_D(QQuickKeysAttached);
1269 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1270 QQuickItem *targetItem = d->targets.at(ii);
1271 if (targetItem && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1272 d->item->setFlag(QQuickItem::ItemAcceptsInputMethod);
1280void QQuickKeysAttached::keyPressed(QKeyEvent *event,
bool post)
1282 Q_D(QQuickKeysAttached);
1283 if (post != m_processPost || !d->enabled || d->inPress) {
1285 QQuickItemKeyFilter::keyPressed(event, post);
1290 if (d->item && d->item->window()) {
1292 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1293 QQuickItem *i = d->targets.at(ii);
1294 if (i && i->isVisible()) {
1296 QCoreApplication::sendEvent(i, event);
1297 if (event->isAccepted()) {
1306 QQuickKeyEvent &ke = d->theKeyEvent;
1308 QByteArray keySignal = keyToSignal(event->key());
1309 if (!keySignal.isEmpty()) {
1310 keySignal +=
"(QQuickKeyEvent*)";
1311 if (isConnected(keySignal)) {
1313 ke.setAccepted(
true);
1314 int idx = QQuickKeysAttached::staticMetaObject.indexOfSignal(keySignal);
1315 metaObject()->method(idx).invoke(
this, Qt::DirectConnection, Q_ARG(QQuickKeyEvent*, &ke));
1318 if (!ke.isAccepted())
1320 event->setAccepted(ke.isAccepted());
1322 if (!event->isAccepted()) QQuickItemKeyFilter::keyPressed(event, post);
1325void QQuickKeysAttached::keyReleased(QKeyEvent *event,
bool post)
1327 Q_D(QQuickKeysAttached);
1328 if (post != m_processPost || !d->enabled || d->inRelease) {
1330 QQuickItemKeyFilter::keyReleased(event, post);
1334 if (d->item && d->item->window()) {
1335 d->inRelease =
true;
1336 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1337 QQuickItem *i = d->targets.at(ii);
1338 if (i && i->isVisible()) {
1340 QCoreApplication::sendEvent(i, event);
1341 if (event->isAccepted()) {
1342 d->inRelease =
false;
1347 d->inRelease =
false;
1350 QQuickKeyEvent &ke = d->theKeyEvent;
1353 event->setAccepted(ke.isAccepted());
1355 if (!event->isAccepted()) QQuickItemKeyFilter::keyReleased(event, post);
1359void QQuickKeysAttached::inputMethodEvent(QInputMethodEvent *event,
bool post)
1361 Q_D(QQuickKeysAttached);
1362 if (post == m_processPost && d->item && !d->inIM && d->item->window()) {
1364 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1365 QQuickItem *targetItem = d->targets.at(ii);
1366 if (targetItem && targetItem->isVisible() && (targetItem->flags() & QQuickItem::ItemAcceptsInputMethod)) {
1367 QCoreApplication::sendEvent(targetItem, event);
1368 if (event->isAccepted()) {
1369 d->imeItem = targetItem;
1377 QQuickItemKeyFilter::inputMethodEvent(event, post);
1380QVariant QQuickKeysAttached::inputMethodQuery(Qt::InputMethodQuery query)
const
1382 Q_D(
const QQuickKeysAttached);
1384 for (
int ii = 0; ii < d->targets.size(); ++ii) {
1385 QQuickItem *i = d->targets.at(ii);
1386 if (i && i->isVisible() && (i->flags() & QQuickItem::ItemAcceptsInputMethod) && i == d->imeItem) {
1388 QVariant v = i->inputMethodQuery(query);
1389 if (v.userType() == QMetaType::QRectF)
1390 v = d->item->mapRectFromItem(i, v.toRectF());
1395 return QQuickItemKeyFilter::inputMethodQuery(query);
1399void QQuickKeysAttached::shortcutOverrideEvent(QKeyEvent *event)
1401 Q_D(QQuickKeysAttached);
1402 QQuickKeyEvent &keyEvent = d->theKeyEvent;
1403 keyEvent.reset(*event);
1404 emit shortcutOverride(&keyEvent);
1406 event->setAccepted(keyEvent.isAccepted());
1409QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj)
1411 return new QQuickKeysAttached(obj);
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1482
1483
1484
1485
1486
1487
1488
1491QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1493 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1494 itemPrivate = QQuickItemPrivate::get(item);
1495 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1496 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1499 itemPrivate->extra.value().layoutDirectionAttached =
this;
1501 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1504QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1506 return new QQuickLayoutMirroringAttached(object);
1509bool QQuickLayoutMirroringAttached::enabled()
const
1511 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1514void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1519 itemPrivate->isMirrorImplicit =
false;
1520 if (enabled != itemPrivate->effectiveLayoutMirror) {
1521 itemPrivate->setLayoutMirror(enabled);
1522 if (itemPrivate->inheritMirrorFromItem)
1523 itemPrivate->resolveLayoutMirror();
1527void QQuickLayoutMirroringAttached::resetEnabled()
1529 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1530 itemPrivate->isMirrorImplicit =
true;
1531 itemPrivate->resolveLayoutMirror();
1535bool QQuickLayoutMirroringAttached::childrenInherit()
const
1537 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1540void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1541 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1542 itemPrivate->inheritMirrorFromItem = childrenInherit;
1543 itemPrivate->resolveLayoutMirror();
1544 childrenInheritChanged();
1548void QQuickItemPrivate::resolveLayoutMirror()
1551 if (QQuickItem *parentItem = q->parentItem()) {
1552 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1553 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1555 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1559void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1561 inherit = inherit || inheritMirrorFromItem;
1562 if (!isMirrorImplicit && inheritMirrorFromItem)
1563 mirror = effectiveLayoutMirror;
1564 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1567 inheritMirrorFromParent = inherit;
1568 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1570 if (isMirrorImplicit)
1571 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1572 for (
int i = 0; i < childItems.size(); ++i) {
1573 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1574 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1575 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1580void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1582 if (mirror != effectiveLayoutMirror) {
1583 effectiveLayoutMirror = mirror;
1585 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1586 anchor_d->fillChanged();
1587 anchor_d->centerInChanged();
1588 anchor_d->updateHorizontalAnchors();
1591 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1592 emit extra->layoutDirectionAttached->enabledChanged();
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1644QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1645 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1647 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1648 itemPrivate = QQuickItemPrivate::get(item);
1649 itemPrivate->extra.value().enterKeyAttached =
this;
1651 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1654QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1656 return new QQuickEnterKeyAttached(object);
1659Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1664void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1666 if (keyType != type) {
1669 if (itemPrivate && itemPrivate->activeFocus)
1670 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1676void QQuickItemPrivate::setAccessible()
1678 isAccessible =
true;
1682
1683
1684
1685
1686void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1691 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1693 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1695 if (oldSubFocusItem) {
1696 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1697 while (sfi && sfi != scope) {
1698 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1699 sfi = sfi->parentItem();
1704 scopePrivate->subFocusItem = q;
1705 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1706 while (sfi && sfi != scope) {
1707 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1708 sfi = sfi->parentItem();
1711 scopePrivate->subFocusItem =
nullptr;
1716bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1719 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1720 Qt::FocusPolicy policy = Qt::ClickFocus;
1722 switch (eventType) {
1723 case QEvent::MouseButtonPress:
1724 case QEvent::MouseButtonDblClick:
1725 case QEvent::TouchBegin:
1726 if (setFocusOnRelease)
1729 case QEvent::MouseButtonRelease:
1730 case QEvent::TouchEnd:
1731 if (!setFocusOnRelease)
1735 policy = Qt::WheelFocus;
1741 if ((focusPolicy & policy) == policy) {
1742 setActiveFocus(q, Qt::MouseFocusReason);
1749Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1751 return static_cast<Qt::FocusReason>(focusReason);
1754bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1756 if (focusReason == reason)
1759 focusReason = reason;
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2155
2156
2157
2158
2159
2160
2161
2162
2163
2166
2167
2168
2171
2172
2173
2176
2177
2178
2181
2182
2183
2186
2187
2188
2189
2190
2191
2192
2195
2196
2197
2198
2199
2200
2203
2204
2205
2206
2207
2210
2211
2212
2213
2214
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2235
2236
2237
2240
2241
2242
2245
2246
2247
2250
2251
2252
2255
2256
2257
2260
2261
2262
2265
2266
2267
2270
2271
2272
2275
2276
2277
2280
2281
2282
2285
2286
2287
2290
2291
2292
2295
2296
2297
2300
2301
2302
2305
2306
2307
2310
2311
2312
2315
2316
2317
2320
2321
2322
2325
2326
2327
2330
2331
2332
2335
2336
2337
2340
2341
2342
2345
2346
2347
2350
2351
2352
2355
2356
2357
2360
2361
2362
2365
2366
2367
2370
2371
2372
2373
2374
2375
2376
2377QQuickItem::QQuickItem(QQuickItem* parent)
2378: QObject(*(
new QQuickItemPrivate), parent)
2385
2386QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2387: QObject(dd, parent)
2394
2395
2396QQuickItem::~QQuickItem()
2399 d->inDestructor =
true;
2401#if QT_CONFIG(accessibility)
2402 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
2403 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
2405 d->isAccessible =
false;
2408 if (d->windowRefCount > 1)
2409 d->windowRefCount = 1;
2411 setParentItem(
nullptr);
2415 for (QQuickItem *child : std::as_const(d->childItems))
2416 child->setParentItem(
nullptr);
2417 d->childItems.clear();
2419 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2420 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2422 anchor->clearItem(
this);
2425
2426
2427
2428 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2429 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2430 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2433 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2434 d->changeListeners.clear();
2437
2438
2439
2440
2441 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2442 QQuickTransform *t = d->transforms.at(ii);
2443 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2444 tp->items.removeOne(
this);
2447 if (d->extra.isAllocated()) {
2448 delete d->extra->contents; d->extra->contents =
nullptr;
2449#if QT_CONFIG(quick_shadereffect)
2450 delete d->extra->layer; d->extra->layer =
nullptr;
2454 delete d->_anchors; d->_anchors =
nullptr;
2455 delete d->_stateGroup; d->_stateGroup =
nullptr;
2457 d->isQuickItem =
false;
2461
2462
2463bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2465 if (!item->window())
2468 if (item == item->window()->contentItem())
2471 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2472 if (tabFocus == Qt::NoTabFocus)
2474 if (tabFocus == Qt::TabFocusAllControls)
2477 QVariant editable = item->property(
"editable");
2478 if (editable.isValid())
2479 return editable.toBool();
2481 QVariant readonly = item->property(
"readOnly");
2482 if (readonly.isValid())
2483 return !readonly.toBool() && item->property(
"text").isValid();
2485#if QT_CONFIG(accessibility)
2486 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2487 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2489 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2490 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2491 return iface->state().editable;
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2510 QQuickWindow *window = item->window();
2511 const bool wrap = !window || window->isTopLevel();
2513 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2518 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2520 if (!wrap && !next) {
2524 Q_ASSERT(window->parent());
2527 qt_window_private(window->parent())->setFocusToTarget(
2528 forward ? QWindowPrivate::FocusTarget::Next
2529 : QWindowPrivate::FocusTarget::Prev,
2531 window->parent()->requestActivate();
2535 next->forceActiveFocus(reason);
2540QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2543 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2546 const QList<QQuickItem *> &children = item->childItems();
2547 const int count = children.size();
2548 if (start < 0 || start >= count) {
2549 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2552 while (start < count) {
2553 QQuickItem *child = children.at(start);
2554 if (!child->d_func()->isTabFence)
2561QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2564 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2567 const QList<QQuickItem *> &children = item->childItems();
2568 const int count = children.size();
2571 if (start < 0 || start >= count) {
2572 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2575 while (start >= 0) {
2576 QQuickItem *child = children.at(start);
2577 if (!child->d_func()->isTabFence)
2584QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2587 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2589 if (!item->window())
2591 const QQuickItem *
const contentItem = item->window()->contentItem();
2595 QQuickItem *from =
nullptr;
2596 bool isTabFence = item->d_func()->isTabFence;
2599 from = item->parentItem();
2601 if (!item->childItems().isEmpty())
2602 from = item->d_func()->childItems.constFirst();
2603 else if (!isTabFence)
2604 from = item->parentItem();
2608 QQuickItem *startItem = item;
2609 QQuickItem *originalStartItem = startItem;
2614 while (startItem && !startItem->isVisible()) {
2615 startItem = startItem->parentItem();
2620 QQuickItem *firstFromItem = from;
2621 QQuickItem *current = item;
2622 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2623 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2624 QDuplicateTracker<QQuickItem *> cycleDetector;
2626 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2627 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2629 QQuickItem *last = current;
2631 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2632 QQuickItem *firstChild =
nullptr;
2633 QQuickItem *lastChild =
nullptr;
2635 firstChild = nextTabChildItem(current, 0);
2637 hasChildren =
false;
2639 lastChild = prevTabChildItem(current, -1);
2641 isTabFence = current->d_func()->isTabFence;
2642 if (isTabFence && !hasChildren)
2646 if (hasChildren && from == current->parentItem()) {
2648 current = firstChild;
2650 current = lastChild;
2651 if (!current->childItems().isEmpty())
2654 }
else if (hasChildren && forward && from != lastChild) {
2656 int nextChild = current->childItems().indexOf(from) + 1;
2657 current = nextTabChildItem(current, nextChild);
2658 }
else if (hasChildren && !forward && from != firstChild) {
2660 int prevChild = current->childItems().indexOf(from) - 1;
2661 current = prevTabChildItem(current, prevChild);
2662 if (!current->childItems().isEmpty())
2665 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2669 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2670 if (last != firstSibling
2671 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2675 }
else if (hasChildren) {
2676 if (!wrap && !isTabFence) {
2677 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2678 <<
"Focus chain about to wrap but we're outside a tab fence and wrapping was set to false."
2685 current = firstChild;
2686 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2687 <<
"wrapping from last to first:" << current;
2689 current = lastChild;
2690 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2691 <<
"wrapping from first to last:" << current;
2692 if (!current->childItems().isEmpty())
2704 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2705 (!skip && cycleDetector.hasSeen(current))) {
2707 if (item == contentItem) {
2708 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2711 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2715 if (!firstFromItem) {
2716 if (startItem->d_func()->isTabFence) {
2717 if (current == startItem)
2718 firstFromItem = from;
2720 startItem = current;
2721 firstFromItem = from;
2724 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2725 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2731
2732
2733
2734
2735
2736
2737
2738
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754QQuickItem *QQuickItem::parentItem()
const
2756 Q_D(
const QQuickItem);
2757 return d->parentItem;
2760void QQuickItem::setParentItem(QQuickItem *parentItem)
2763 if (parentItem == d->parentItem)
2767 QQuickItem *itemAncestor = parentItem;
2768 while (itemAncestor !=
nullptr) {
2769 if (Q_UNLIKELY(itemAncestor ==
this)) {
2770 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2773 itemAncestor = itemAncestor->parentItem();
2775 auto engine = qmlEngine(
this);
2777 QV4::ExecutionEngine *v4 = engine->handle();
2778 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2779 QV4::QObjectWrapper::markWrapper(
this, ms);
2784 d->removeFromDirtyList();
2786 QQuickItem *oldParentItem = d->parentItem;
2787 QQuickItem *scopeFocusedItem =
nullptr;
2789 if (oldParentItem) {
2790 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2792 QQuickItem *scopeItem =
nullptr;
2794 if (hasFocus() || op->subFocusItem ==
this)
2795 scopeFocusedItem =
this;
2796 else if (!isFocusScope() && d->subFocusItem)
2797 scopeFocusedItem = d->subFocusItem;
2799 if (scopeFocusedItem) {
2800 scopeItem = oldParentItem;
2801 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2802 scopeItem = scopeItem->parentItem();
2804 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2805 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2806 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2808 if (scopeFocusedItem !=
this)
2809 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2811 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2815 const bool wasVisible = isVisible();
2816 op->removeChild(
this);
2817 if (wasVisible && !op->inDestructor)
2818 emit oldParentItem->visibleChildrenChanged();
2819 }
else if (d->window) {
2820 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2823 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2824 bool alreadyAddedChild =
false;
2825 if (d->window == parentWindow) {
2827 d->parentItem = parentItem;
2829 auto oldParentItem = d->parentItem;
2830 d->parentItem = parentItem;
2831 if (d->parentItem) {
2832 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2833 alreadyAddedChild =
true;
2841 if (!oldParentItem && d->window) {
2842 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2846 d->refWindow(parentWindow);
2849 d->dirty(QQuickItemPrivate::ParentChanged);
2851 if (d->parentItem && !alreadyAddedChild)
2852 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2853 else if (d->window && !alreadyAddedChild)
2854 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2856 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2857 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2859 if (d->parentItem) {
2860 if (!scopeFocusedItem) {
2862 scopeFocusedItem =
this;
2863 else if (!isFocusScope() && d->subFocusItem)
2864 scopeFocusedItem = d->subFocusItem;
2867 if (scopeFocusedItem) {
2869 QQuickItem *scopeItem = d->parentItem;
2870 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2871 scopeItem = scopeItem->parentItem();
2873 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2874 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2875 if (scopeFocusedItem !=
this)
2876 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2877 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2878 emit scopeFocusedItem->focusChanged(
false);
2881 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2882 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2883 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2886 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2893 d->resolveLayoutMirror();
2895 d->itemChange(ItemParentHasChanged, d->parentItem);
2897 if (!d->inDestructor)
2898 emit parentChanged(d->parentItem);
2899 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2900 emit d->parentItem->visibleChildrenChanged();
2902#if QT_CONFIG(accessibility)
2903 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2904 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2905 QAccessible::updateAccessibility(&qaEvent);
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928void QQuickItem::stackBefore(
const QQuickItem *sibling)
2931 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2932 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2933 <<
this <<
" before " << sibling <<
", which must be a sibling";
2937 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2939 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2940 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2942 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2944 if (myIndex == siblingIndex - 1)
2947 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2949 parentPrivate->markSortedChildrenDirty(
this);
2950 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2952 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2953 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974void QQuickItem::stackAfter(
const QQuickItem *sibling)
2977 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2978 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2979 <<
this <<
" after " << sibling <<
", which must be a sibling";
2983 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2985 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2986 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2988 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2990 if (myIndex == siblingIndex + 1)
2993 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2995 parentPrivate->markSortedChildrenDirty(
this);
2996 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2998 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2999 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
3003
3004
3007
3008
3009
3010
3011
3012
3013QQuickWindow *QQuickItem::window()
const
3015 Q_D(
const QQuickItem);
3021 return lhs->z() < rhs->z();
3024QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3026 if (sortedChildItems)
3027 return *sortedChildItems;
3032 for (
int i = 0; i < childItems.size(); ++i) {
3033 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3039 sortedChildItems =
new QList<QQuickItem*>(childItems);
3040 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3041 return *sortedChildItems;
3044 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3049void QQuickItemPrivate::addChild(QQuickItem *child)
3053 Q_ASSERT(!childItems.contains(child));
3055 childItems.append(child);
3057 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3059#if QT_CONFIG(cursor)
3062 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3063 setHasCursorInChild(
true);
3066 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3067 setHasHoverInChild(
true);
3069 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3070 markSortedChildrenDirty(child);
3071 dirty(QQuickItemPrivate::ChildrenChanged);
3073 itemChange(QQuickItem::ItemChildAddedChange, child);
3075 emit q->childrenChanged();
3078void QQuickItemPrivate::removeChild(QQuickItem *child)
3083 if (!inDestructor) {
3085 Q_ASSERT(childItems.contains(child));
3086 childItems.removeOne(child);
3087 Q_ASSERT(!childItems.contains(child));
3090 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3092#if QT_CONFIG(cursor)
3094 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3095 setHasCursorInChild(
false);
3098 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3099 setHasHoverInChild(
false);
3101 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3102 if (!inDestructor) {
3103 markSortedChildrenDirty(child);
3104 dirty(QQuickItemPrivate::ChildrenChanged);
3107 itemChange(QQuickItem::ItemChildRemovedChange, child);
3110 emit q->childrenChanged();
3113void QQuickItemPrivate::refWindow(QQuickWindow *c)
3125 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3127 if (++windowRefCount > 1) {
3129 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3133 Q_ASSERT(window ==
nullptr);
3136 if (polishScheduled)
3137 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3140 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3142 for (
int ii = 0; ii < childItems.size(); ++ii) {
3143 QQuickItem *child = childItems.at(ii);
3144 QQuickItemPrivate::get(child)->refWindow(c);
3149 if (extra.isAllocated() && extra->screenAttached)
3150 extra->screenAttached->windowChanged(c);
3151 itemChange(QQuickItem::ItemSceneChange, c);
3154void QQuickItemPrivate::derefWindow()
3157 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3162 if (--windowRefCount > 0)
3165 q->releaseResources();
3166 removeFromDirtyList();
3167 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3168 if (polishScheduled)
3169 c->itemsToPolish.removeOne(q);
3170#if QT_CONFIG(cursor)
3171 if (c->cursorItem == q) {
3172 c->cursorItem =
nullptr;
3173 window->unsetCursor();
3176 if (itemNodeInstance)
3177 c->cleanup(itemNodeInstance);
3179 c->parentlessItems.remove(q);
3181 if (
auto *da = deliveryAgentPrivate()) {
3182 if (da->activeFocusItem == q) {
3183 qCDebug(lcFocus) <<
"Removing active focus item from window's delivery agent";
3184 da->activeFocusItem =
nullptr;
3189 itemNodeInstance =
nullptr;
3191 if (extra.isAllocated()) {
3192 extra->opacityNode =
nullptr;
3193 extra->clipNode =
nullptr;
3194 extra->rootNode =
nullptr;
3197 paintNode =
nullptr;
3199 for (
int ii = 0; ii < childItems.size(); ++ii) {
3200 if (QQuickItem *child = childItems.at(ii))
3201 QQuickItemPrivate::get(child)->derefWindow();
3206 if (extra.isAllocated() && extra->screenAttached)
3207 extra->screenAttached->windowChanged(
nullptr);
3208 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3211qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3213 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3217
3218
3219QTransform QQuickItemPrivate::windowToItemTransform()
const
3222#ifdef QT_BUILD_INTERNAL
3223 ++windowToItemTransform_counter;
3225 return itemToWindowTransform().inverted();
3229
3230
3231QTransform QQuickItemPrivate::itemToWindowTransform()
const
3233#ifdef QT_BUILD_INTERNAL
3234 ++itemToWindowTransform_counter;
3237 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3238 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3239 itemToParentTransform(&rv);
3244
3245
3246void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3248#ifdef QT_BUILD_INTERNAL
3249 ++itemToParentTransform_counter;
3252
3253
3254
3255
3256
3258 qreal x =
this->x.valueBypassingBindings();
3259 qreal y =
this->y.valueBypassingBindings();
3263 if (!transforms.isEmpty()) {
3265 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3266 transforms.at(ii)->applyTo(&m);
3267 *t = m.toTransform();
3270 if (scale() != 1. || rotation() != 0.) {
3271 QPointF tp = computeTransformOrigin();
3272 t->translate(tp.x(), tp.y());
3273 t->scale(scale(), scale());
3274 t->rotate(rotation());
3275 t->translate(-tp.x(), -tp.y());
3280
3281
3282
3283
3284
3285
3286
3287
3288bool QQuickItem::isComponentComplete()
const
3290 Q_D(
const QQuickItem);
3291 return d->componentComplete;
3294QQuickItemPrivate::QQuickItemPrivate()
3296 , _stateGroup(
nullptr)
3298 , widthValidFlag(
false)
3299 , heightValidFlag(
false)
3300 , componentComplete(
true)
3303 , hoverEnabled(
false)
3305 , antialiasing(
false)
3307 , activeFocus(
false)
3308 , notifiedFocus(
false)
3309 , notifiedActiveFocus(
false)
3310 , filtersChildMouseEvents(
false)
3311 , explicitVisible(
true)
3312 , effectiveVisible(
true)
3313 , explicitEnable(
true)
3314 , effectiveEnable(
true)
3315 , polishScheduled(
false)
3316 , inheritedLayoutMirror(
false)
3317 , effectiveLayoutMirror(
false)
3318 , isMirrorImplicit(
true)
3319 , inheritMirrorFromParent(
false)
3320 , inheritMirrorFromItem(
false)
3321 , isAccessible(
false)
3324 , subtreeCursorEnabled(
false)
3325 , subtreeHoverEnabled(
false)
3326 , activeFocusOnTab(
false)
3327 , implicitAntialiasing(
false)
3328 , antialiasingValid(
false)
3330 , replayingPressEvent(
false)
3331 , touchEnabled(
false)
3332 , hasCursorHandler(
false)
3333 , maybeHasSubsceneDeliveryAgent(
true)
3334 , subtreeTransformChangedEnabled(
true)
3335 , inDestructor(
false)
3336 , focusReason(Qt::OtherFocusReason)
3337 , focusPolicy(Qt::NoFocus)
3338 , eventHandlingChildrenWithinBounds(
false)
3339 , eventHandlingChildrenWithinBoundsSet(
false)
3340 , customOverlay(
false)
3341 , dirtyAttributes(0)
3342 , nextDirtyItem(
nullptr)
3343 , prevDirtyItem(
nullptr)
3346 , parentItem(
nullptr)
3347 , sortedChildItems(&childItems)
3348 , subFocusItem(
nullptr)
3356 , itemNodeInstance(
nullptr)
3357 , paintNode(
nullptr)
3358 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3360#ifdef QT_BUILD_INTERNAL
3365QQuickItemPrivate::~QQuickItemPrivate()
3367 if (sortedChildItems != &childItems)
3368 delete sortedChildItems;
3371void QQuickItemPrivate::init(QQuickItem *parent)
3377 baselineOffset = 0.0;
3380 q->setParentItem(parent);
3381 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3382 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3386QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3391void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3393 szPolicy.setHorizontalPolicy(horizontalPolicy);
3394 szPolicy.setVerticalPolicy(verticalPolicy);
3397void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3402 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3404 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3405 item->setParentItem(that);
3406 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3407 if (pointerHandler->parent() != that) {
3408 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3409 pointerHandler->setParent(that);
3411 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3414 resources_append(prop, o);
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3453qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3455 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3456 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3457 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3458 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3460 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3463QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3465 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3466 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3467 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3468 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3470 qsizetype resourcesCount = resources_count(&resourcesProperty);
3471 if (i < resourcesCount)
3472 return resources_at(&resourcesProperty, i);
3473 const qsizetype j = i - resourcesCount;
3474 if (j < children_count(&childrenProperty))
3475 return children_at(&childrenProperty, j);
3479void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3481 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3482 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3483 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3484 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3486 resources_clear(&resourcesProperty);
3487 children_clear(&childrenProperty);
3490void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3492 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3493 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3495 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3496 if (children_count(&childrenProperty) > 0) {
3497 children_removeLast(&childrenProperty);
3501 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3502 if (resources_count(&resourcesProperty) > 0)
3503 resources_removeLast(&resourcesProperty);
3506QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3508 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3509 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3512void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3514 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3515 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3516 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3517 quickItemPrivate->extra.value().resourcesList.append(object);
3518 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3519 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3523qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3525 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3526 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3529void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3531 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3532 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3533 if (quickItemPrivate->extra.isAllocated()) {
3534 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3535 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3536 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3538 quickItemPrivate->extra->resourcesList.clear();
3542void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3544 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3545 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3546 if (quickItemPrivate->extra.isAllocated()) {
3547 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3548 if (resources->isEmpty())
3551 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3552 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3553 resources->removeLast();
3557QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3559 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3560 if (index >= p->childItems.size() || index < 0)
3563 return p->childItems.at(index);
3566void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3571 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3572 if (o->parentItem() == that)
3573 o->setParentItem(
nullptr);
3575 o->setParentItem(that);
3578qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3580 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3581 return p->childItems.size();
3584void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3586 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3587 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3588 while (!p->childItems.isEmpty())
3589 p->childItems.at(0)->setParentItem(
nullptr);
3592void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3594 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3595 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3596 if (!p->childItems.isEmpty())
3597 p->childItems.last()->setParentItem(
nullptr);
3600qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3602 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3603 qsizetype visibleCount = 0;
3604 qsizetype c = p->childItems.size();
3606 if (p->childItems.at(c)->isVisible()) visibleCount++;
3609 return visibleCount;
3612QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3614 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3615 const qsizetype childCount = p->childItems.size();
3616 if (index >= childCount || index < 0)
3619 qsizetype visibleCount = -1;
3620 for (qsizetype i = 0; i < childCount; i++) {
3621 if (p->childItems.at(i)->isVisible()) visibleCount++;
3622 if (visibleCount == index)
return p->childItems.at(i);
3627qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3629 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3630 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3632 return p->transforms.size();
3635void QQuickTransform::appendToItem(QQuickItem *item)
3637 Q_D(QQuickTransform);
3641 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3643 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3644 p->transforms.removeOne(
this);
3645 p->transforms.append(
this);
3647 p->transforms.append(
this);
3648 d->items.append(item);
3651 p->dirty(QQuickItemPrivate::Transform);
3654void QQuickTransform::prependToItem(QQuickItem *item)
3656 Q_D(QQuickTransform);
3660 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3662 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3663 p->transforms.removeOne(
this);
3664 p->transforms.prepend(
this);
3666 p->transforms.prepend(
this);
3667 d->items.append(item);
3670 p->dirty(QQuickItemPrivate::Transform);
3673void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3678 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3679 transform->appendToItem(that);
3682QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3684 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3685 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3687 if (idx < 0 || idx >= p->transforms.size())
3690 return p->transforms.at(idx);
3693void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3695 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3696 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3698 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3699 QQuickTransform *t = p->transforms.at(ii);
3700 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3701 tp->items.removeOne(that);
3704 p->transforms.clear();
3706 p->dirty(QQuickItemPrivate::Transform);
3709void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3711 if (extra.isAllocated() && extra->resourcesList.contains(object))
3712 extra->resourcesList.removeAll(object);
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811QQuickAnchors *QQuickItemPrivate::anchors()
const
3814 Q_Q(
const QQuickItem);
3815 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3816 if (!componentComplete)
3817 _anchors->classBegin();
3822void QQuickItemPrivate::siblingOrderChanged()
3825 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3828QQmlListProperty<QObject> QQuickItemPrivate::data()
3832 QQmlListProperty<QObject> result;
3833 result.object = q_func();
3834 result.append = QQuickItemPrivate::data_append;
3835 result.count = QQuickItemPrivate::data_count;
3836 result.at = QQuickItemPrivate::data_at;
3837 result.clear = QQuickItemPrivate::data_clear;
3838 result.removeLast = QQuickItemPrivate::data_removeLast;
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873QRectF QQuickItem::childrenRect()
3876 if (!d->extra.isAllocated() || !d->extra->contents) {
3877 d->extra.value().contents =
new QQuickContents(
this);
3878 if (d->componentComplete)
3879 d->extra->contents->complete();
3881 return d->extra->contents->rectF();
3885
3886
3887QList<QQuickItem *> QQuickItem::childItems()
const
3889 Q_D(
const QQuickItem);
3890 return d->childItems;
3894
3895
3896
3897
3898
3899
3900
3901
3902
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921bool QQuickItem::clip()
const
3923 return flags() & ItemClipsChildrenToShape;
3926void QQuickItem::setClip(
bool c)
3931 setFlag(ItemClipsChildrenToShape, c);
3933 setFlag(ItemIsViewport);
3934 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3935 setFlag(ItemIsViewport,
false);
3937 emit clipChanged(c);
3941
3942
3943
3944
3945
3946
3947
3948
3949void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3954 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3956 QQuickGeometryChange change;
3957 change.setXChange(newGeometry.x() != oldGeometry.x());
3958 change.setYChange(newGeometry.y() != oldGeometry.y());
3959 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3960 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3962 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3963 if (change.matches(listener.gTypes))
3964 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3969 if (change.xChange())
3971 if (change.yChange())
3973 if (change.widthChange())
3975 if (change.heightChange())
3977#if QT_CONFIG(accessibility)
3978 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3979 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3980 QAccessible::updateAccessibility(&ev);
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4039QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4041 Q_UNUSED(updatePaintNodeData);
4046QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4047: transformNode(
nullptr)
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4068void QQuickItem::releaseResources()
4072QSGTransformNode *QQuickItemPrivate::createTransformNode()
4074 return new QSGTransformNode;
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087void QQuickItem::updatePolish()
4091#define PRINT_LISTENERS() do
4093 qDebug().nospace() << q_func() << " (" << this
4094 << ") now has the following listeners:";
4095 for (const auto &listener : std::as_const(changeListeners)) {
4096 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4097 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4099}while
4102void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4105 changeListeners.append(ChangeListener(listener, types));
4106 listener->addSourceItem(q);
4108 if (lcChangeListeners().isDebugEnabled())
4112void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4116 const ChangeListener changeListener(listener, types);
4117 const int index = changeListeners.indexOf(changeListener);
4119 changeListeners[index].types = changeListener.types;
4121 changeListeners.append(changeListener);
4122 listener->addSourceItem(q);
4125 if (lcChangeListeners().isDebugEnabled())
4129void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4133 ChangeListener change(listener, types);
4134 changeListeners.removeOne(change);
4135 listener->removeSourceItem(q);
4137 if (lcChangeListeners().isDebugEnabled())
4141void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4142 QQuickGeometryChange types)
4146 ChangeListener change(listener, types);
4147 int index = changeListeners.indexOf(change);
4149 changeListeners[index].gTypes = change.gTypes;
4151 changeListeners.append(change);
4152 listener->addSourceItem(q);
4155 if (lcChangeListeners().isDebugEnabled())
4159void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4160 QQuickGeometryChange types)
4164 ChangeListener change(listener, types);
4165 if (types.noChange()) {
4166 changeListeners.removeOne(change);
4167 listener->removeSourceItem(q);
4169 int index = changeListeners.indexOf(change);
4171 changeListeners[index].gTypes = change.gTypes;
4174 if (lcChangeListeners().isDebugEnabled())
4179
4180
4181
4182
4183
4184
4185void QQuickItem::keyPressEvent(QKeyEvent *event)
4191
4192
4193
4194
4195
4196
4197void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4204
4205
4206
4207
4208
4209
4210void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226void QQuickItem::focusInEvent(QFocusEvent *event)
4229#if QT_CONFIG(accessibility)
4230 if (d->isAccessible && QAccessible::isActive()) {
4231 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4232 QAccessibleEvent ev(acc, QAccessible::Focus);
4233 QAccessible::updateAccessibility(&ev);
4237 d->setLastFocusChangeReason(event->reason());
4241
4242
4243
4244
4245
4246
4247void QQuickItem::focusOutEvent(QFocusEvent *event)
4250 d->setLastFocusChangeReason(event->reason());
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263void QQuickItem::mousePressEvent(QMouseEvent *event)
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4301
4302
4303
4304
4305
4306
4307void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4313
4314
4315
4316void QQuickItem::mouseUngrabEvent()
4322
4323
4324
4325void QQuickItem::touchUngrabEvent()
4330#if QT_CONFIG(wheelevent)
4332
4333
4334
4335
4336
4337
4338void QQuickItem::wheelEvent(QWheelEvent *event)
4345
4346
4347
4348
4349
4350
4351void QQuickItem::touchEvent(QTouchEvent *event)
4357
4358
4359
4360
4361
4362
4363
4364
4365void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4371
4372
4373
4374
4375
4376
4377
4378
4379void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4385
4386
4387
4388
4389
4390
4391
4392
4393void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4398#if QT_CONFIG(quick_draganddrop)
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462void QQuickItem::dropEvent(QDropEvent *event)
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4507
4508
4509
4510
4511
4512
4513
4514QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4516 Q_D(
const QQuickItem);
4521 v = (
bool)(flags() & ItemAcceptsInputMethod);
4524 case Qt::ImAnchorRectangle:
4525 case Qt::ImCursorRectangle:
4527 case Qt::ImCursorPosition:
4528 case Qt::ImSurroundingText:
4529 case Qt::ImCurrentSelection:
4530 case Qt::ImMaximumTextLength:
4531 case Qt::ImAnchorPosition:
4532 case Qt::ImPreferredLanguage:
4533 case Qt::ImReadOnly:
4534 if (d->extra.isAllocated() && d->extra->keyHandler)
4535 v = d->extra->keyHandler->inputMethodQuery(query);
4537 case Qt::ImEnterKeyType:
4538 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4539 v = d->extra->enterKeyAttached->type();
4541 case Qt::ImInputItemClipRectangle:
4542 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4543 QRectF rect = QRectF(0,0, width(), height());
4544 const QQuickItem *par =
this;
4545 while (QQuickItem *parpar = par->parentItem()) {
4546 rect = parpar->mapRectFromItem(par, rect);
4548 rect = rect.intersected(parpar->clipRect());
4551 rect = par->mapRectToScene(rect);
4553 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4555 v = mapRectFromScene(rect);
4566QQuickAnchorLine QQuickItemPrivate::left()
const
4568 Q_Q(
const QQuickItem);
4569 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4572QQuickAnchorLine QQuickItemPrivate::right()
const
4574 Q_Q(
const QQuickItem);
4575 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4578QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4580 Q_Q(
const QQuickItem);
4581 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4584QQuickAnchorLine QQuickItemPrivate::top()
const
4586 Q_Q(
const QQuickItem);
4587 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4590QQuickAnchorLine QQuickItemPrivate::bottom()
const
4592 Q_Q(
const QQuickItem);
4593 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4596QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4598 Q_Q(
const QQuickItem);
4599 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4602QQuickAnchorLine QQuickItemPrivate::baseline()
const
4604 Q_Q(
const QQuickItem);
4605 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630qreal QQuickItem::baselineOffset()
const
4632 Q_D(
const QQuickItem);
4633 return d->baselineOffset;
4636void QQuickItem::setBaselineOffset(qreal offset)
4639 if (offset == d->baselineOffset)
4642 d->baselineOffset = offset;
4644 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4645 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4647 anchor->updateVerticalAnchors();
4650 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4651 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4653 emit baselineOffsetChanged(offset);
4658
4659
4660
4661
4662
4663
4664
4665
4666void QQuickItem::update()
4669 if (!(flags() & ItemHasContents)) {
4671 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4675 d->dirty(QQuickItemPrivate::Content);
4679
4680
4681
4682
4683
4684
4685
4686void QQuickItem::polish()
4689 if (!d->polishScheduled) {
4690 d->polishScheduled =
true;
4692 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4693 bool maybeupdate = p->itemsToPolish.isEmpty();
4694 p->itemsToPolish.append(
this);
4695 if (maybeupdate) d->window->maybeUpdate();
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715void QQuickItem::ensurePolished()
4720#if QT_DEPRECATED_SINCE(6
, 5
)
4721static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4722 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4724 QV4::ExecutionEngine *v4 = args->v4engine();
4725 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4726 v4->throwTypeError();
4730 QV4::Scope scope(v4);
4731 QV4::ScopedValue item(scope, (*args)[0]);
4734 if (!item->isNull()) {
4735 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4737 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4740 if (!(*itemObj) && !item->isNull()) {
4741 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4742 <<
"\" which is neither null nor an Item";
4743 v4->throwTypeError();
4749 if (args->length() == 2) {
4750 QV4::ScopedValue sv(scope, (*args)[1]);
4752 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4753 <<
"\" which is neither a point nor a rect";
4754 v4->throwTypeError();
4757 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4758 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4759 if (v.canConvert<QPointF>()) {
4760 const QPointF p = v.toPointF();
4763 }
else if (v.canConvert<QRectF>()) {
4764 const QRectF r = v.toRectF();
4771 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4772 <<
"\" which is neither a point nor a rect";
4773 v4->throwTypeError();
4777 QV4::ScopedValue vx(scope, (*args)[1]);
4778 QV4::ScopedValue vy(scope, (*args)[2]);
4780 if (!vx->isNumber() || !vy->isNumber()) {
4781 v4->throwTypeError();
4785 *x = vx->asDouble();
4786 *y = vy->asDouble();
4788 if (args->length() > 3) {
4789 QV4::ScopedValue vw(scope, (*args)[3]);
4790 QV4::ScopedValue vh(scope, (*args)[4]);
4791 if (!vw->isNumber() || !vh->isNumber()) {
4792 v4->throwTypeError();
4795 *w = vw->asDouble();
4796 *h = vh->asDouble();
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4823#if QT_DEPRECATED_SINCE(6
, 5
)
4825
4826
4827void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4829 QV4::ExecutionEngine *v4 = args->v4engine();
4830 QV4::Scope scope(v4);
4834 QQuickItem *itemObj;
4835 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4838 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4839 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4841 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4842 args->setReturnValue(rv.asReturnedValue());
4847
4848
4849QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4851 Q_D(
const QQuickItem);
4857 QTransform t = d->itemToWindowTransform();
4858 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4881#if QT_DEPRECATED_SINCE(6
, 5
)
4883
4884
4885void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4887 QV4::ExecutionEngine *v4 = args->v4engine();
4888 QV4::Scope scope(v4);
4892 QQuickItem *itemObj;
4893 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4896 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4897 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4899 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4900 args->setReturnValue(rv.asReturnedValue());
4903static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4905 QV4::ExecutionEngine *v4 = args->v4engine();
4906 if (args->length() != 1 && args->length() != 2) {
4907 v4->throwTypeError();
4911 QV4::Scope scope(v4);
4913 if (args->length() == 1) {
4914 QV4::ScopedValue sv(scope, (*args)[0]);
4916 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4917 <<
"\" which is not a point";
4918 v4->throwTypeError();
4921 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4922 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4923 if (v.canConvert<QPointF>()) {
4924 const QPointF p = v.toPointF();
4928 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4929 <<
"\" which is not a point";
4930 v4->throwTypeError();
4934 QV4::ScopedValue vx(scope, (*args)[0]);
4935 QV4::ScopedValue vy(scope, (*args)[1]);
4937 if (!vx->isNumber() || !vy->isNumber()) {
4938 v4->throwTypeError();
4942 *x = vx->asDouble();
4943 *y = vy->asDouble();
4950
4951
4952
4953
4954
4955
4956
4957
4959
4960
4961void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4963 QV4::ExecutionEngine *v4 = args->v4engine();
4964 QV4::Scope scope(v4);
4967 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4970 QVariant result = mapFromGlobal(QPointF(x, y));
4972 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4973 args->setReturnValue(rv.asReturnedValue());
4978
4979
4980
4981
4982
4983
4984
4985
4987#if QT_DEPRECATED_SINCE(6
, 5
)
4989
4990
4991void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4993 QV4::ExecutionEngine *v4 = args->v4engine();
4994 QV4::Scope scope(v4);
4997 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
5000 QVariant result = mapToGlobal(QPointF(x, y));
5002 QV4::ScopedObject rv(scope, v4->fromVariant(result));
5003 args->setReturnValue(rv.asReturnedValue());
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033void QQuickItem::forceActiveFocus()
5035 forceActiveFocus(Qt::OtherFocusReason);
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5063void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5065 setFocus(
true, reason);
5066 QQuickItem *parent = parentItem();
5067 QQuickItem *scope =
nullptr;
5069 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5070 parent->setFocus(
true, reason);
5074 parent = parent->parentItem();
5079
5080
5081
5082
5083
5084
5085
5086
5087
5089
5090
5091
5092
5093
5095QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5097 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5101
5102
5103
5104
5105
5106
5107
5109
5110
5111
5112
5113
5114QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5116 const QList<QQuickItem *> children = childItems();
5117 for (
int i = children.size()-1; i >= 0; --i) {
5118 QQuickItem *child = children.at(i);
5120 QPointF point = mapToItem(child, QPointF(x, y));
5121 if (child->isVisible() && child->contains(point))
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168void QQuickItem::dumpItemTree()
const
5170 Q_D(
const QQuickItem);
5174void QQuickItemPrivate::dumpItemTree(
int indent)
const
5176 Q_Q(
const QQuickItem);
5178 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5179 qDebug().nospace().noquote() << indentStr <<
5180#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5181 const_cast<QQuickItem *>(q);
5185 if (extra.isAllocated()) {
5186 for (
const auto handler : extra->pointerHandlers)
5187 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5189 for (
const QQuickItem *ch : childItems) {
5190 auto itemPriv = QQuickItemPrivate::get(ch);
5191 itemPriv->dumpItemTree(indent + 1);
5195QQmlListProperty<QObject> QQuickItemPrivate::resources()
5199 QQmlListProperty<QObject> result;
5200 result.object = q_func();
5201 result.append = QQuickItemPrivate::resources_append;
5202 result.count = QQuickItemPrivate::resources_count;
5203 result.at = QQuickItemPrivate::resources_at;
5204 result.clear = QQuickItemPrivate::resources_clear;
5205 result.removeLast = QQuickItemPrivate::resources_removeLast;
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5223
5224
5225
5226QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5230 QQmlListProperty<QQuickItem> result;
5231 result.object = q_func();
5232 result.append = QQuickItemPrivate::children_append;
5233 result.count = QQuickItemPrivate::children_count;
5234 result.at = QQuickItemPrivate::children_at;
5235 result.clear = QQuickItemPrivate::children_clear;
5236 result.removeLast = QQuickItemPrivate::children_removeLast;
5241
5242
5243
5244
5245
5247
5248
5249
5250QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5252 return QQmlListProperty<QQuickItem>(q_func(),
5254 QQuickItemPrivate::visibleChildren_count,
5255 QQuickItemPrivate::visibleChildren_at);
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5296
5297
5298
5299QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5301 return _states()->statesProperty();
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5333
5334
5335
5336QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5338 return _states()->transitionsProperty();
5341QString QQuickItemPrivate::state()
const
5346 return _stateGroup->state();
5349void QQuickItemPrivate::setState(
const QString &state)
5351 _states()->setState(state);
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376QString QQuickItem::state()
const
5378 Q_D(
const QQuickItem);
5382void QQuickItem::setState(
const QString &state)
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5401
5402
5403
5405
5406
5407QQmlListProperty<QQuickTransform> QQuickItem::transform()
5409 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5410 QQuickItemPrivate::transform_count,
5411 QQuickItemPrivate::transform_at,
5412 QQuickItemPrivate::transform_clear);
5416
5417
5418
5419
5420void QQuickItem::classBegin()
5423 d->componentComplete =
false;
5425 d->_stateGroup->classBegin();
5427 d->_anchors->classBegin();
5428#if QT_CONFIG(quick_shadereffect)
5429 if (d->extra.isAllocated() && d->extra->layer)
5430 d->extra->layer->classBegin();
5435
5436
5437
5438
5439void QQuickItem::componentComplete()
5442 d->componentComplete =
true;
5444 d->_stateGroup->componentComplete();
5446 d->_anchors->componentComplete();
5447 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5450 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5451 safeArea->updateSafeArea();
5453 if (d->extra.isAllocated()) {
5454#if QT_CONFIG(quick_shadereffect)
5455 if (d->extra->layer)
5456 d->extra->layer->componentComplete();
5459 if (d->extra->keyHandler)
5460 d->extra->keyHandler->componentComplete();
5462 if (d->extra->contents)
5463 d->extra->contents->complete();
5466 if (d->window && d->dirtyAttributes) {
5467 d->addToDirtyList();
5468 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5471#if QT_CONFIG(accessibility)
5472 if (d->isAccessible && d->effectiveVisible) {
5473 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5474 QAccessible::updateAccessibility(&ev);
5479QQuickStateGroup *QQuickItemPrivate::_states()
5483 _stateGroup =
new QQuickStateGroup;
5484 if (!componentComplete)
5485 _stateGroup->classBegin();
5486 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5487 q, QQuickItem, SIGNAL(stateChanged(QString)));
5493bool QQuickItemPrivate::customOverlayRequested =
false;
5495void QQuickItemPrivate::requestCustomOverlay()
5497 customOverlayRequested =
true;
5498 customOverlay =
true;
5501QPointF QQuickItemPrivate::computeTransformOrigin()
const
5505 case QQuickItem::TopLeft:
5506 return QPointF(0, 0);
5507 case QQuickItem::Top:
5508 return QPointF(width / 2., 0);
5509 case QQuickItem::TopRight:
5510 return QPointF(width, 0);
5511 case QQuickItem::Left:
5512 return QPointF(0, height / 2.);
5513 case QQuickItem::Center:
5514 return QPointF(width / 2., height / 2.);
5515 case QQuickItem::Right:
5516 return QPointF(width, height / 2.);
5517 case QQuickItem::BottomLeft:
5518 return QPointF(0, height);
5519 case QQuickItem::Bottom:
5520 return QPointF(width / 2., height);
5521 case QQuickItem::BottomRight:
5522 return QPointF(width, height);
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5544#if QT_CONFIG(quick_shadereffect)
5545 if (q == transformedItem) {
5546 if (extra.isAllocated() && extra->layer)
5547 extra->layer->updateMatrix();
5551 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5553 bool childWantsIt =
false;
5554 if (subtreeTransformChangedEnabled) {
5557 const auto children = paintOrderChildItems();
5558 for (QQuickItem *child : children)
5559 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5562 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5563 const bool ret = childWantsIt || thisWantsIt;
5564 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5565 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5566 subtreeTransformChangedEnabled =
false;
5570 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5571 dirty(QQuickItemPrivate::Clip);
5576 QQuickItemPrivate *itemPriv =
this;
5577 while (itemPriv->parentItem) {
5578 auto *parentPriv = QQuickItemPrivate::get(itemPriv->parentItem);
5579 if (parentPriv->eventHandlingChildrenWithinBounds) {
5580 Q_ASSERT(parentPriv->eventHandlingChildrenWithinBoundsSet);
5581 if (itemPriv->parentFullyContains())
5584 parentPriv->eventHandlingChildrenWithinBounds =
false;
5586 itemPriv = parentPriv;
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5609 const QPointF &startPos,
5610 const QVector2D &activeTranslation,
5613 qreal startRotation,
5614 qreal activeRotation)
5617 QVector3D xformOrigin(q->transformOriginPoint());
5618 QMatrix4x4 startMatrix;
5619 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5620 startMatrix.translate(xformOrigin);
5621 startMatrix.scale(
float(startScale));
5622 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5623 startMatrix.translate(-xformOrigin);
5625 const QVector3D centroidParentVector(centroidParentPos);
5627 mat.translate(centroidParentVector);
5628 mat.rotate(
float(activeRotation), 0, 0, 1);
5629 mat.scale(
float(activeScale));
5630 mat.translate(-centroidParentVector);
5631 mat.translate(QVector3D(activeTranslation));
5633 mat = mat * startMatrix;
5635 QPointF xformOriginPoint = q->transformOriginPoint();
5636 QPointF pos = mat.map(xformOriginPoint);
5637 pos -= xformOriginPoint;
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5667 if (maybeHasSubsceneDeliveryAgent) {
5668 QQuickItemPrivate *p =
this;
5670 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5675 maybeHasSubsceneDeliveryAgent =
false;
5678 if (p->extra.isAllocated()) {
5679 if (
auto da = p->extra->subsceneDeliveryAgent)
5682 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5686 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5689 return QQuickWindowPrivate::get(window)->deliveryAgent;
5693QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5695 auto da = deliveryAgent();
5696 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5700
5701
5702
5703
5704
5705
5706
5707QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5713 maybeHasSubsceneDeliveryAgent =
true;
5714 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5715 return extra->subsceneDeliveryAgent;
5716 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5717 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5720 q->setFlag(QQuickItem::ItemIsFocusScope);
5721 return extra->subsceneDeliveryAgent;
5724bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5726 if (!extra.isAllocated() || !extra->keyHandler)
5732 if (e->type() == QEvent::KeyPress)
5733 extra->keyHandler->keyPressed(e, post);
5735 extra->keyHandler->keyReleased(e, post);
5737 return e->isAccepted();
5740void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5743 const auto eventType = event->type();
5744 const bool focusAccepted = setFocusIfNeeded(eventType);
5746 switch (eventType) {
5747 case QEvent::MouseButtonPress:
5748 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5750 case QEvent::MouseButtonRelease:
5751 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5753 case QEvent::MouseButtonDblClick:
5754 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5756#if QT_CONFIG(wheelevent)
5758 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5761 case QEvent::TouchBegin:
5762 case QEvent::TouchUpdate:
5763 case QEvent::TouchEnd:
5764 case QEvent::TouchCancel:
5765 q->touchEvent(
static_cast<QTouchEvent *>(event));
5775void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5779 Q_ASSERT(e->isAccepted());
5780 if (filterKeyEvent(e,
false))
5785 if (e->type() == QEvent::KeyPress)
5786 q->keyPressEvent(e);
5788 q->keyReleaseEvent(e);
5790 if (e->isAccepted())
5793 if (filterKeyEvent(e,
true) || !q->window())
5797 if (e->type() == QEvent::KeyPress &&
5798 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5800 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5801 if (e->key() == Qt::Key_Backtab
5802 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5803 res = QQuickItemPrivate::focusNextPrev(q,
false);
5804 else if (e->key() == Qt::Key_Tab)
5805 res = QQuickItemPrivate::focusNextPrev(q,
true);
5807 e->setAccepted(
true);
5813void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5817 Q_ASSERT(e->isAccepted());
5818 if (extra.isAllocated() && extra->keyHandler) {
5819 extra->keyHandler->inputMethodEvent(e,
false);
5821 if (e->isAccepted())
5827 q->inputMethodEvent(e);
5829 if (e->isAccepted())
5832 if (extra.isAllocated() && extra->keyHandler) {
5835 extra->keyHandler->inputMethodEvent(e,
true);
5840void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5842 if (extra.isAllocated() && extra->keyHandler)
5843 extra->keyHandler->shortcutOverrideEvent(event);
5848bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5850 if (!hasPointerHandlers())
5852 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5853 if (handler->wantsEventPoint(event, point))
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5875 bool delivered =
false;
5876 if (extra.isAllocated()) {
5877 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5878 bool avoidThisHandler =
false;
5879 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5880 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5881 avoidThisHandler =
true;
5882 }
else if (avoidGrabbers) {
5883 for (
auto &p : event->points()) {
5884 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5885 avoidThisHandler =
true;
5890 if (!avoidThisHandler &&
5891 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5892 handler->handlePointerEvent(event);
5900#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5901bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5903bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5906 if (extra.isAllocated() && extra->contextMenu)
5907 return extra->contextMenu->event(event);
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5927 if (change == ItemSceneChange)
5928 emit windowChanged(value.window);
5933
5934
5935
5936void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5938 if (hasActiveFocus())
5939 QGuiApplication::inputMethod()->update(queries);
5944
5945
5946
5947QRectF QQuickItem::boundingRect()
const
5949 Q_D(
const QQuickItem);
5950 return QRectF(0, 0, d->width, d->height);
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974QRectF QQuickItem::clipRect()
const
5976 Q_D(
const QQuickItem);
5977 QRectF ret(0, 0, d->width.valueBypassingBindings(), d->height.valueBypassingBindings());
5978 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5979 if (QQuickItem *viewport = viewportItem()) {
5982 if (viewport ==
this)
5984 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5985 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5986 return mappedViewportRect.intersected(ret);
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003QQuickItem *QQuickItem::viewportItem()
const
6005 if (flags().testFlag(ItemObservesViewport)) {
6006 QQuickItem *par = parentItem();
6008 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
6010 par = par->parentItem();
6013 return (window() ? window()->contentItem() :
nullptr);
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6052 Q_D(
const QQuickItem);
6056void QQuickItem::setTransformOrigin(TransformOrigin origin)
6059 if (origin == d->origin())
6062 d->extra.value().origin = origin;
6063 d->dirty(QQuickItemPrivate::TransformOrigin);
6065 emit transformOriginChanged(d->origin());
6069
6070
6071
6073
6074
6075QPointF QQuickItem::transformOriginPoint()
const
6077 Q_D(
const QQuickItem);
6078 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6079 return d->extra->userTransformOriginPoint;
6080 return d->computeTransformOrigin();
6084
6085
6086void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6089 if (d->extra.value().userTransformOriginPoint == point)
6092 d->extra->userTransformOriginPoint = point;
6093 d->dirty(QQuickItemPrivate::TransformOrigin);
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
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
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
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258qreal QQuickItem::z()
const
6260 Q_D(
const QQuickItem);
6264void QQuickItem::setZ(qreal v)
6270 d->extra.value().z = v;
6272 d->dirty(QQuickItemPrivate::ZValue);
6273 if (d->parentItem) {
6274 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6275 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6280#if QT_CONFIG(quick_shadereffect)
6281 if (d->extra.isAllocated() && d->extra->layer)
6282 d->extra->layer->updateZ();
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
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
6340qreal QQuickItem::rotation()
const
6342 Q_D(
const QQuickItem);
6343 return d->rotation();
6346void QQuickItem::setRotation(qreal r)
6349 if (d->rotation() == r)
6352 d->extra.value().rotation = r;
6354 d->dirty(QQuickItemPrivate::BasicTransform);
6356 d->itemChange(ItemRotationHasChanged, r);
6358 emit rotationChanged();
6362
6363
6364
6365
6366
6367
6368
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
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442qreal QQuickItem::scale()
const
6444 Q_D(
const QQuickItem);
6448void QQuickItem::setScale(qreal s)
6451 if (d->scale() == s)
6454 d->extra.value().scale = s;
6456 d->dirty(QQuickItemPrivate::BasicTransform);
6458 d->itemChange(ItemScaleHasChanged, s);
6460 emit scaleChanged();
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577qreal QQuickItem::opacity()
const
6579 Q_D(
const QQuickItem);
6580 return d->opacity();
6583void QQuickItem::setOpacity(qreal newOpacity)
6586 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6587 if (d->opacity() == o)
6590 d->extra.value().opacity = o;
6592 d->dirty(QQuickItemPrivate::OpacityValue);
6594 d->itemChange(ItemOpacityHasChanged, o);
6596 emit opacityChanged();
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663bool QQuickItem::isVisible()
const
6665 Q_D(
const QQuickItem);
6666 return d->effectiveVisible;
6669void QQuickItemPrivate::setVisible(
bool visible)
6671 if (visible == explicitVisible)
6674 explicitVisible = visible;
6676 dirty(QQuickItemPrivate::Visible);
6678 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6679 if (childVisibilityChanged && parentItem)
6680 emit parentItem->visibleChildrenChanged();
6683void QQuickItem::setVisible(
bool v)
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738bool QQuickItem::isEnabled()
const
6740 Q_D(
const QQuickItem);
6741 return d->effectiveEnable;
6744void QQuickItem::setEnabled(
bool e)
6747 if (e == d->explicitEnable)
6750 d->explicitEnable = e;
6752 QQuickItem *scope = parentItem();
6753 while (scope && !scope->isFocusScope())
6754 scope = scope->parentItem();
6756 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6759bool QQuickItemPrivate::calcEffectiveVisible()
const
6762 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6765bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6769 if (newEffectiveVisible && !explicitVisible) {
6774 if (newEffectiveVisible == effectiveVisible) {
6779 effectiveVisible = newEffectiveVisible;
6782 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6784 if (
auto agent = deliveryAgentPrivate())
6785 agent->removeGrabber(q,
true,
true,
true);
6788 bool childVisibilityChanged =
false;
6789 for (
int ii = 0; ii < childItems.size(); ++ii)
6790 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6792 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6793#if QT_CONFIG(accessibility)
6795 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6796 QAccessible::updateAccessibility(&ev);
6799 if (!inDestructor) {
6800 emit q->visibleChanged();
6801 if (childVisibilityChanged)
6802 emit q->visibleChildrenChanged();
6808bool QQuickItemPrivate::calcEffectiveEnable()
const
6813 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6816void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6820 if (newEffectiveEnable && !explicitEnable) {
6825 if (newEffectiveEnable == effectiveEnable) {
6830 effectiveEnable = newEffectiveEnable;
6832 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6834 da->removeGrabber(q,
true,
true,
true);
6835 if (scope && !effectiveEnable && activeFocus) {
6836 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6837 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6838 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6842 for (
int ii = 0; ii < childItems.size(); ++ii) {
6843 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6844 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6847 if (scope && effectiveEnable && focus && da) {
6848 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6849 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6850 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6853 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6854#if QT_CONFIG(accessibility)
6856 QAccessible::State changedState;
6857 changedState.disabled =
true;
6858 changedState.focusable =
true;
6859 QAccessibleStateChangeEvent ev(q, changedState);
6860 QAccessible::updateAccessibility(&ev);
6863 emit q->enabledChanged();
6867
6868
6869
6870qreal QQuickItemPrivate::biggestPointerHandlerMargin()
const
6872 if (hasPointerHandlers()) {
6873 if (extra->biggestPointerHandlerMarginCache < 0) {
6874 const auto maxMarginIt = std::max_element(extra->pointerHandlers.constBegin(),
6875 extra->pointerHandlers.constEnd(),
6876 [](
const QQuickPointerHandler *a,
const QQuickPointerHandler *b) {
6877 return a->margin() < b->margin(); });
6878 Q_ASSERT(maxMarginIt != extra->pointerHandlers.constEnd());
6879 extra->biggestPointerHandlerMarginCache = (*maxMarginIt)->margin();
6881 return extra->biggestPointerHandlerMarginCache;
6887
6888
6889
6890
6891
6892
6893QRectF QQuickItemPrivate::eventHandlingBounds(qreal margin)
const
6895 const qreal biggestMargin = margin > 0 ? margin : biggestPointerHandlerMargin();
6896 return QRectF(-biggestMargin, -biggestMargin, width + biggestMargin * 2, height + biggestMargin * 2);
6900
6901
6902
6903bool QQuickItemPrivate::parentFullyContains()
const
6905 Q_Q(
const QQuickItem);
6909 itemToParentTransform(&t);
6910 const auto bounds = eventHandlingBounds();
6911 const auto boundsInParent = t.mapRect(bounds);
6912 const bool ret = parentItem->clipRect().contains(boundsInParent);
6913 qCDebug(lcEffClip) <<
"in parent bounds?" << ret << q << boundsInParent << parentItem << parentItem->clipRect();
6918
6919
6920
6921bool QQuickItemPrivate::effectivelyClipsEventHandlingChildren()
const
6923 Q_Q(
const QQuickItem);
6925 if (flags & QQuickItem::ItemClipsChildrenToShape) {
6926 qCDebug(lcEffClip) << q <<
"result: true because clip is true";
6929 if (!eventHandlingChildrenWithinBoundsSet) {
6931 eventHandlingChildrenWithinBounds =
true;
6932 for (
const auto *child : childItems) {
6933 const auto *childPriv = QQuickItemPrivate::get(child);
6937 if (childPriv->childItems.isEmpty() &&
6938 !(childPriv->hoverEnabled || childPriv->subtreeHoverEnabled || childPriv->touchEnabled ||
6939 childPriv->hasCursor || childPriv->hasCursorHandler || child->acceptedMouseButtons() ||
6940 childPriv->hasPointerHandlers())) {
6941 qCDebug(lcEffClip) << child <<
"doesn't handle pointer events";
6944 if (!childPriv->parentFullyContains()) {
6945 eventHandlingChildrenWithinBounds =
false;
6946 qCDebug(lcEffClip) <<
"child goes outside: giving up" << child;
6949 if (!childPriv->eventHandlingChildrenWithinBoundsSet) {
6950 eventHandlingChildrenWithinBounds = childPriv->effectivelyClipsEventHandlingChildren();
6951 if (!eventHandlingChildrenWithinBounds)
6952 qCDebug(lcEffClip) <<
"child has children that go outside: giving up" << child;
6955#ifdef QT_BUILD_INTERNAL
6956 if (!eventHandlingChildrenWithinBoundsSet && eventHandlingChildrenWithinBounds)
6957 ++eventHandlingChildrenWithinBounds_counter;
6960 eventHandlingChildrenWithinBoundsSet =
true;
6961 qCDebug(lcEffClip) << q << q->clipRect() <<
"result:" <<
static_cast<
bool>(eventHandlingChildrenWithinBounds);
6963 return eventHandlingChildrenWithinBounds;
6966bool QQuickItemPrivate::isTransparentForPositioner()
const
6968 return extra.isAllocated() && extra.value().transparentForPositioner;
6971void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6973 extra.value().transparentForPositioner = transparent;
6977QString QQuickItemPrivate::dirtyToString()
const
6979#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6981 rv.append(QLatin1Char('|'));
6982 rv.append(QLatin1String(#value)); \
6983}
7010void QQuickItemPrivate::dirty(DirtyType type)
7013 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
7014 dirtyAttributes |= type;
7015 if (window && componentComplete) {
7017 QQuickWindowPrivate::get(window)->dirtyItem(q,
true);
7020 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
7021 transformChanged(q);
7024void QQuickItemPrivate::addToDirtyList()
7029 if (!prevDirtyItem) {
7030 Q_ASSERT(!nextDirtyItem);
7032 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
7033 nextDirtyItem = p->dirtyItemList;
7034 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
7035 prevDirtyItem = &p->dirtyItemList;
7036 p->dirtyItemList = q;
7037 p->dirtyItem(q,
true);
7039 Q_ASSERT(prevDirtyItem);
7042void QQuickItemPrivate::removeFromDirtyList()
7044 if (prevDirtyItem) {
7045 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
7046 *prevDirtyItem = nextDirtyItem;
7047 prevDirtyItem =
nullptr;
7048 nextDirtyItem =
nullptr;
7050 Q_ASSERT(!prevDirtyItem);
7051 Q_ASSERT(!nextDirtyItem);
7054void QQuickItemPrivate::refFromEffectItem(
bool hide)
7056 ++extra.value().effectRefCount;
7057 if (extra->effectRefCount == 1) {
7058 dirty(EffectReference);
7060 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7063 if (++extra->hideRefCount == 1)
7064 dirty(HideReference);
7066 recursiveRefFromEffectItem(1);
7069void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
7074 extra.value().recursiveEffectRefCount += refs;
7075 for (
int ii = 0; ii < childItems.size(); ++ii) {
7076 QQuickItem *child = childItems.at(ii);
7077 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
7081 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
7085void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
7087 Q_ASSERT(extra->effectRefCount);
7088 --extra->effectRefCount;
7089 if (extra->effectRefCount == 0) {
7090 dirty(EffectReference);
7092 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7095 if (--extra->hideRefCount == 0)
7096 dirty(HideReference);
7098 recursiveRefFromEffectItem(-1);
7101void QQuickItemPrivate::setCulled(
bool cull)
7107 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
7108 dirty(HideReference);
7111void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
7115 case QQuickItem::ItemChildAddedChange: {
7116 q->itemChange(change, data);
7122 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
7123 if (!subtreeTransformChangedEnabled) {
7124 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
7125 subtreeTransformChangedEnabled =
true;
7127 enableSubtreeChangeNotificationsForParentHierachy();
7129 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
7132 case QQuickItem::ItemChildRemovedChange: {
7133 q->itemChange(change, data);
7134 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
7137 case QQuickItem::ItemSceneChange:
7138 q->itemChange(change, data);
7140 case QQuickItem::ItemVisibleHasChanged: {
7141 q->itemChange(change, data);
7142 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
7145 case QQuickItem::ItemEnabledHasChanged: {
7146 q->itemChange(change, data);
7147 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
7150 case QQuickItem::ItemParentHasChanged: {
7151 q->itemChange(change, data);
7152 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
7155 case QQuickItem::ItemOpacityHasChanged: {
7156 q->itemChange(change, data);
7157 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
7160 case QQuickItem::ItemActiveFocusHasChanged:
7161 q->itemChange(change, data);
7163 case QQuickItem::ItemRotationHasChanged: {
7164 q->itemChange(change, data);
7165 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7168 case QQuickItem::ItemScaleHasChanged: {
7169 q->itemChange(change, data);
7170 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7173 case QQuickItem::ItemTransformHasChanged: {
7174 q->itemChange(change, data);
7175 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7178 case QQuickItem::ItemAntialiasingHasChanged:
7180 case QQuickItem::ItemDevicePixelRatioHasChanged:
7181 q->itemChange(change, data);
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209bool QQuickItem::smooth()
const
7211 Q_D(
const QQuickItem);
7214void QQuickItem::setSmooth(
bool smooth)
7217 if (d->smooth == smooth)
7221 d->dirty(QQuickItemPrivate::Smooth);
7223 emit smoothChanged(smooth);
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7265bool QQuickItem::activeFocusOnTab()
const
7267 Q_D(
const QQuickItem);
7268 return d->activeFocusOnTab;
7270void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7273 if (d->activeFocusOnTab == activeFocusOnTab)
7277 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7278 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7283 d->activeFocusOnTab = activeFocusOnTab;
7285 emit activeFocusOnTabChanged(activeFocusOnTab);
7289
7290
7291
7292
7293
7294
7295
7296
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307bool QQuickItem::antialiasing()
const
7309 Q_D(
const QQuickItem);
7310 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7313void QQuickItem::setAntialiasing(
bool aa)
7317 if (!d->antialiasingValid) {
7318 d->antialiasingValid =
true;
7319 d->antialiasing = d->implicitAntialiasing;
7322 if (aa == d->antialiasing)
7325 d->antialiasing = aa;
7326 d->dirty(QQuickItemPrivate::Antialiasing);
7328 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7330 emit antialiasingChanged(antialiasing());
7333void QQuickItem::resetAntialiasing()
7336 if (!d->antialiasingValid)
7339 d->antialiasingValid =
false;
7341 if (d->implicitAntialiasing != d->antialiasing)
7342 emit antialiasingChanged(antialiasing());
7345void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7348 bool prev = q->antialiasing();
7349 implicitAntialiasing = antialiasing;
7350 if (componentComplete && (q->antialiasing() != prev))
7351 emit q->antialiasingChanged(q->antialiasing());
7355
7356
7357
7358
7359QQuickItem::Flags QQuickItem::flags()
const
7361 Q_D(
const QQuickItem);
7362 return (QQuickItem::Flags)d->flags;
7366
7367
7368
7369
7370
7371
7372
7373void QQuickItem::setFlag(Flag flag,
bool enabled)
7377 setFlags((Flags)(d->flags | (quint32)flag));
7379 setFlags((Flags)(d->flags & ~(quint32)flag));
7383 if (enabled && flag == ItemObservesViewport)
7384 d->enableSubtreeChangeNotificationsForParentHierachy();
7387void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7391 QQuickItem *par = q->parentItem();
7393 auto parPriv = QQuickItemPrivate::get(par);
7394 if (!parPriv->subtreeTransformChangedEnabled)
7395 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7396 parPriv->subtreeTransformChangedEnabled =
true;
7397 par = par->parentItem();
7402
7403
7404
7405
7406void QQuickItem::setFlags(Flags flags)
7410 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7411 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7412 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7413 flags &= ~ItemIsFocusScope;
7414 }
else if (d->flags & ItemIsFocusScope) {
7415 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7416 flags |= ItemIsFocusScope;
7420 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7421 d->dirty(QQuickItemPrivate::Clip);
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7442
7443
7444
7445
7447
7448
7449
7450
7451qreal QQuickItem::x()
const
7453 Q_D(
const QQuickItem);
7457qreal QQuickItem::y()
const
7459 Q_D(
const QQuickItem);
7464
7465
7466QPointF QQuickItem::position()
const
7468 Q_D(
const QQuickItem);
7469 return QPointF(d->x, d->y);
7472void QQuickItem::setX(qreal v)
7476
7477
7478
7479
7480
7481
7482
7483
7484 d->x.removeBindingUnlessInWrapper();
7488 const qreal oldx = d->x.valueBypassingBindings();
7492 d->x.setValueBypassingBindings(v);
7494 d->dirty(QQuickItemPrivate::Position);
7496 const qreal y = d->y.valueBypassingBindings();
7497 const qreal w = d->width.valueBypassingBindings();
7498 const qreal h = d->height.valueBypassingBindings();
7499 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7502void QQuickItem::setY(qreal v)
7505 d->y.removeBindingUnlessInWrapper();
7509 const qreal oldy = d->y.valueBypassingBindings();
7513 d->y.setValueBypassingBindings(v);
7515 d->dirty(QQuickItemPrivate::Position);
7519 const qreal x = d->x.valueBypassingBindings();
7520 const qreal w = d->width.valueBypassingBindings();
7521 const qreal h = d->height.valueBypassingBindings();
7522 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7526
7527
7528void QQuickItem::setPosition(
const QPointF &pos)
7532 const qreal oldx = d->x.valueBypassingBindings();
7533 const qreal oldy = d->y.valueBypassingBindings();
7535 if (QPointF(oldx, oldy) == pos)
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7551 d->x.setValueBypassingBindings(pos.x());
7552 d->y.setValueBypassingBindings(pos.y());
7554 d->dirty(QQuickItemPrivate::Position);
7556 const qreal w = d->width.valueBypassingBindings();
7557 const qreal h = d->height.valueBypassingBindings();
7558 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7562
7563
7564QBindable<qreal> QQuickItem::bindableX()
7566 return QBindable<qreal>(&d_func()->x);
7569QBindable<qreal> QQuickItem::bindableY()
7571 return QBindable<qreal>(&d_func()->y);
7575
7576
7577
7578
7579qreal QQuickItem::width()
const
7581 Q_D(
const QQuickItem);
7585void QQuickItem::setWidth(qreal w)
7588 d->width.removeBindingUnlessInWrapper();
7592 d->widthValidFlag =
true;
7593 const qreal oldWidth = d->width.valueBypassingBindings();
7597 d->width.setValueBypassingBindings(w);
7599 d->dirty(QQuickItemPrivate::Size);
7601 const qreal x = d->x.valueBypassingBindings();
7602 const qreal y = d->y.valueBypassingBindings();
7603 const qreal h = d->height.valueBypassingBindings();
7604 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7607void QQuickItem::resetWidth()
7610 d->width.takeBinding();
7611 d->widthValidFlag =
false;
7612 setImplicitWidth(implicitWidth());
7615void QQuickItemPrivate::implicitWidthChanged()
7618 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7619 emit q->implicitWidthChanged();
7622qreal QQuickItemPrivate::getImplicitWidth()
const
7624 return implicitWidth;
7627
7628
7629qreal QQuickItem::implicitWidth()
const
7631 Q_D(
const QQuickItem);
7632 return d->getImplicitWidth();
7635QBindable<qreal> QQuickItem::bindableWidth()
7637 return QBindable<qreal>(&d_func()->width);
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722void QQuickItem::setImplicitWidth(qreal w)
7725 bool changed = w != d->implicitWidth;
7726 d->implicitWidth = w;
7728 if (d->width.valueBypassingBindings() == w || widthValid()) {
7730 d->implicitWidthChanged();
7731 if (d->width.valueBypassingBindings() == w || widthValid())
7736 const qreal oldWidth = d->width.valueBypassingBindings();
7737 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7739 d->width.setValueBypassingBindings(w);
7741 d->dirty(QQuickItemPrivate::Size);
7743 const qreal x = d->x.valueBypassingBindings();
7744 const qreal y = d->y.valueBypassingBindings();
7745 const qreal width = w;
7746 const qreal height = d->height.valueBypassingBindings();
7747 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7750 d->implicitWidthChanged();
7754
7755
7756bool QQuickItem::widthValid()
const
7758 Q_D(
const QQuickItem);
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7776 return d->widthValid();
7780
7781
7782
7783
7784qreal QQuickItem::height()
const
7786 Q_D(
const QQuickItem);
7790void QQuickItem::setHeight(qreal h)
7796 d->height.removeBindingUnlessInWrapper();
7800 d->heightValidFlag =
true;
7801 const qreal oldHeight = d->height.valueBypassingBindings();
7805 d->height.setValueBypassingBindings(h);
7807 d->dirty(QQuickItemPrivate::Size);
7809 const qreal x = d->x.valueBypassingBindings();
7810 const qreal y = d->y.valueBypassingBindings();
7811 const qreal w = d->width.valueBypassingBindings();
7812 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7815void QQuickItem::resetHeight()
7821 d->height.takeBinding();
7822 d->heightValidFlag =
false;
7823 setImplicitHeight(implicitHeight());
7826void QQuickItemPrivate::implicitHeightChanged()
7829 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7830 emit q->implicitHeightChanged();
7833qreal QQuickItemPrivate::getImplicitHeight()
const
7835 return implicitHeight;
7838qreal QQuickItem::implicitHeight()
const
7840 Q_D(
const QQuickItem);
7841 return d->getImplicitHeight();
7844QBindable<qreal> QQuickItem::bindableHeight()
7846 return QBindable<qreal>(&d_func()->height);
7849void QQuickItem::setImplicitHeight(qreal h)
7852 bool changed = h != d->implicitHeight;
7853 d->implicitHeight = h;
7854 if (d->height.valueBypassingBindings() == h || heightValid()) {
7856 d->implicitHeightChanged();
7857 if (d->height.valueBypassingBindings() == h || heightValid())
7862 const qreal oldHeight = d->height.valueBypassingBindings();
7863 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7865 d->height.setValueBypassingBindings(h);
7867 d->dirty(QQuickItemPrivate::Size);
7869 const qreal x = d->x.valueBypassingBindings();
7870 const qreal y = d->y.valueBypassingBindings();
7871 const qreal width = d->width.valueBypassingBindings();
7872 const qreal height = d->height.valueBypassingBindings();
7873 geometryChange(QRectF(x, y, width, height),
7874 QRectF(x, y, width, oldHeight));
7877 d->implicitHeightChanged();
7881
7882
7883void QQuickItem::setImplicitSize(qreal w, qreal h)
7886 bool wChanged = w != d->implicitWidth;
7887 bool hChanged = h != d->implicitHeight;
7889 d->implicitWidth = w;
7890 d->implicitHeight = h;
7894 qreal width = d->width.valueBypassingBindings();
7895 qreal height = d->height.valueBypassingBindings();
7896 if (width == w || widthValid()) {
7898 d->implicitWidthChanged();
7899 wDone = width == w || widthValid();
7902 if (height == h || heightValid()) {
7904 d->implicitHeightChanged();
7905 hDone = height == h || heightValid();
7911 const qreal oldWidth = width;
7912 const qreal oldHeight = height;
7915 d->width.setValueBypassingBindings(w);
7919 d->height.setValueBypassingBindings(h);
7922 d->dirty(QQuickItemPrivate::Size);
7924 const qreal x = d->x.valueBypassingBindings();
7925 const qreal y = d->y.valueBypassingBindings();
7926 geometryChange(QRectF(x, y, width, height),
7927 QRectF(x, y, oldWidth, oldHeight));
7929 if (!wDone && wChanged)
7930 d->implicitWidthChanged();
7931 if (!hDone && hChanged)
7932 d->implicitHeightChanged();
7936
7937
7938bool QQuickItem::heightValid()
const
7940 Q_D(
const QQuickItem);
7941 return d->heightValid();
7945
7946
7947
7948
7949
7950
7952QSizeF QQuickItem::size()
const
7954 Q_D(
const QQuickItem);
7955 return QSizeF(d->width, d->height);
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969void QQuickItem::setSize(
const QSizeF &size)
7972 d->heightValidFlag =
true;
7973 d->widthValidFlag =
true;
7975 const qreal oldHeight = d->height.valueBypassingBindings();
7976 const qreal oldWidth = d->width.valueBypassingBindings();
7978 if (oldWidth == size.width() && oldHeight == size.height())
7981 d->height.setValueBypassingBindings(size.height());
7982 d->width.setValueBypassingBindings(size.width());
7984 d->dirty(QQuickItemPrivate::Size);
7986 const qreal x = d->x.valueBypassingBindings();
7987 const qreal y = d->y.valueBypassingBindings();
7988 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060bool QQuickItem::hasActiveFocus()
const
8062 Q_D(
const QQuickItem);
8063 return d->activeFocus;
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154bool QQuickItem::hasFocus()
const
8156 Q_D(
const QQuickItem);
8160void QQuickItem::setFocus(
bool focus)
8162 setFocus(focus, Qt::OtherFocusReason);
8165void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8169 QQuickItem *scope = parentItem();
8170 while (scope && !scope->isFocusScope() && scope->parentItem())
8171 scope = scope->parentItem();
8173 if (d->focus == focus && d->activeFocus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8176 bool notifyListeners =
false;
8177 if (d->window || d->parentItem) {
8179 auto da = d->deliveryAgentPrivate();
8182 da->setFocusInScope(scope,
this, reason);
8184 da->clearFocusInScope(scope,
this, reason);
8188 QVarLengthArray<QQuickItem *, 20> changed;
8189 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8190 if (oldSubFocusItem) {
8191 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8192 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8193 changed << oldSubFocusItem;
8194 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8195 QQuickItemPrivate::get(scope)->focus =
false;
8198 d->updateSubFocusItem(scope, focus);
8202 notifyListeners =
true;
8203 emit focusChanged(focus);
8205 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8208 QVarLengthArray<QQuickItem *, 20> changed;
8209 QQuickItem *oldSubFocusItem = d->subFocusItem;
8210 if (!isFocusScope() && oldSubFocusItem) {
8211 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8212 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8213 changed << oldSubFocusItem;
8218 notifyListeners =
true;
8219 emit focusChanged(focus);
8221 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8223 if (notifyListeners)
8224 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8228
8229
8230bool QQuickItem::isFocusScope()
const
8232 return flags() & ItemIsFocusScope;
8236
8237
8238
8239
8240
8241QQuickItem *QQuickItem::scopedFocusItem()
const
8243 Q_D(
const QQuickItem);
8244 if (!isFocusScope())
8247 return d->subFocusItem;
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8265
8266
8267
8268
8269
8270
8271Qt::FocusPolicy QQuickItem::focusPolicy()
const
8273 Q_D(
const QQuickItem);
8274 uint policy = d->focusPolicy;
8275 if (activeFocusOnTab())
8276 policy |= Qt::TabFocus;
8277 return static_cast<Qt::FocusPolicy>(policy);
8281
8282
8283
8284
8285void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8288 if (d->focusPolicy == policy)
8291 d->focusPolicy = policy;
8292 setActiveFocusOnTab(policy & Qt::TabFocus);
8293 emit focusPolicyChanged(policy);
8297
8298
8299
8300
8301
8302
8303
8304bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8306 if (!child || child ==
this)
8308 const QQuickItem *ancestor = child;
8309 while ((ancestor = ancestor->parentItem())) {
8310 if (ancestor ==
this)
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8329 Q_D(
const QQuickItem);
8330 return d->acceptedMouseButtons();
8334
8335
8336
8337
8338
8339
8340
8341
8342void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8345 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8347 buttons &= ~Qt::LeftButton;
8348 if (buttons || d->extra.isAllocated()) {
8349 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8350 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365bool QQuickItem::filtersChildMouseEvents()
const
8367 Q_D(
const QQuickItem);
8368 return d->filtersChildMouseEvents;
8372
8373
8374
8375
8376
8377
8378
8379
8380void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8383 d->filtersChildMouseEvents = filter;
8387
8388
8389bool QQuickItem::isUnderMouse()
const
8391 Q_D(
const QQuickItem);
8398 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8401 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8402 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8406
8407
8408
8409
8410
8411
8412
8413bool QQuickItem::acceptHoverEvents()
const
8415 Q_D(
const QQuickItem);
8416 return d->hoverEnabled;
8420
8421
8422
8423
8424
8425void QQuickItem::setAcceptHoverEvents(
bool enabled)
8432 d->hoverEnabled = enabled;
8438 d->setHasHoverInChild(enabled);
8442 d->dirty(QQuickItemPrivate::Content);
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455bool QQuickItem::acceptTouchEvents()
const
8457 Q_D(
const QQuickItem);
8458 return d->touchEnabled;
8462
8463
8464
8465
8466
8467
8468
8469void QQuickItem::setAcceptTouchEvents(
bool enabled)
8472 d->touchEnabled = enabled;
8475void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8477#if QT_CONFIG(cursor)
8482 if (!hc && subtreeCursorEnabled) {
8483 if (hasCursor || hasCursorHandler)
8485 for (QQuickItem *otherChild : std::as_const(childItems)) {
8486 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8487 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8492 subtreeCursorEnabled = hc;
8493 QQuickItem *parent = q->parentItem();
8495 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8496 parentPrivate->setHasCursorInChild(hc);
8503void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8509 if (!hasHover && subtreeHoverEnabled) {
8512 if (hasEnabledHoverHandlers())
8515 for (QQuickItem *otherChild : std::as_const(childItems)) {
8516 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8517 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8519 if (otherChildPrivate->hasEnabledHoverHandlers())
8524 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8525 subtreeHoverEnabled = hasHover;
8526 QQuickItem *parent = q->parentItem();
8528 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8529 parentPrivate->setHasHoverInChild(hasHover);
8533#if QT_CONFIG(cursor)
8535QWindow *QQuickItemPrivate::renderWindow(QPoint *offset)
const
8537 QWindow *result = QQuickRenderControl::renderWindowFor(window, offset);
8538 return result ? result : window;
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8555QCursor QQuickItem::cursor()
const
8557 Q_D(
const QQuickItem);
8558 return d->extra.isAllocated()
8564
8565
8566
8567
8569void QQuickItem::setCursor(
const QCursor &cursor)
8573 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8574 qCDebug(lcHoverCursor) << oldShape <<
"->" << cursor.shape();
8576 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8577 d->extra.value().cursor = cursor;
8579 QWindow *renderWindow = d->renderWindow();
8580 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8581 renderWindow->setCursor(cursor);
8585 QPointF updateCursorPos;
8586 if (!d->hasCursor) {
8587 d->hasCursor =
true;
8589 QWindow *renderWindow = d->renderWindow();
8590 QPointF pos = renderWindow->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8591 if (contains(mapFromScene(pos)))
8592 updateCursorPos = pos;
8595 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8596 if (!updateCursorPos.isNull())
8597 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8601
8602
8603
8604
8606void QQuickItem::unsetCursor()
8609 qCDebug(lcHoverTrace) <<
"clearing cursor";
8612 d->hasCursor =
false;
8613 d->setHasCursorInChild(d->hasCursorHandler);
8614 if (d->extra.isAllocated())
8615 d->extra->cursor = QCursor();
8618 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8619 if (windowPrivate->cursorItem ==
this) {
8620 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8621 windowPrivate->updateCursor(pos);
8627
8628
8629
8630
8631
8632
8633QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8635 Q_Q(
const QQuickItem);
8638 bool hoverCursorSet =
false;
8639 QCursor hoverCursor;
8640 bool activeCursorSet =
false;
8641 QCursor activeCursor;
8642 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8643 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8644 hoverCursor = hoverHandler->cursorShape();
8645 }
else if (handler->active()) {
8646 activeCursorSet = handler->isCursorShapeExplicitlySet();
8647 activeCursor = handler->cursorShape();
8649 if (activeCursorSet)
8650 return activeCursor;
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8678 if (!hasPointerHandlers())
8680 QQuickPointerHandler* activeHandler =
nullptr;
8681 QQuickPointerHandler* mouseHandler =
nullptr;
8682 QQuickPointerHandler* nonMouseHandler =
nullptr;
8683 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8684 if (!h->isCursorShapeExplicitlySet())
8686 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8691 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8692 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8693 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8695 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8696 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8697 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8699 mouseHandler = hoverHandler;
8702 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8703 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8704 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8706 nonMouseHandler = hoverHandler;
8709 if (!hoverHandler && h->active())
8712 if (activeHandler) {
8713 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8714 return activeHandler;
8720 if (nonMouseHandler) {
8722 const bool beforeTimeout =
8723 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8724 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8725 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8726 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8727 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8728 <<
"choosing cursor according to" << winner << winner->cursorShape();
8731 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8732 return nonMouseHandler;
8735 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8736 return mouseHandler;
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755void QQuickItem::grabMouse()
8760 auto da = d->deliveryAgentPrivate();
8762 auto eventInDelivery = da->eventInDelivery();
8763 if (!eventInDelivery) {
8764 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8767 auto epd = da->mousePointData();
8768 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782void QQuickItem::ungrabMouse()
8787 auto da = d->deliveryAgentPrivate();
8789 auto eventInDelivery = da->eventInDelivery();
8790 if (!eventInDelivery) {
8792 da->removeGrabber(
this);
8795 const auto &eventPoint = da->mousePointData()->eventPoint;
8796 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8797 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8801
8802
8803
8804
8805bool QQuickItem::keepMouseGrab()
const
8807 Q_D(
const QQuickItem);
8808 return d->keepMouse;
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827void QQuickItem::setKeepMouseGrab(
bool keep)
8830 d->keepMouse = keep;
8834
8835
8836
8837
8838
8839
8840
8841
8842void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8845 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8846 if (Q_UNLIKELY(!event)) {
8847 qWarning() <<
"cannot grab: no event is currently being delivered";
8850 for (
auto pt : event->points()) {
8851 if (ids.contains(pt.id()))
8852 event->setExclusiveGrabber(pt,
this);
8857
8858
8859
8860void QQuickItem::ungrabTouchPoints()
8865 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8866 da->removeGrabber(
this,
false,
true);
8870
8871
8872
8873
8874
8875bool QQuickItem::keepTouchGrab()
const
8877 Q_D(
const QQuickItem);
8878 return d->keepTouch;
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898void QQuickItem::setKeepTouchGrab(
bool keep)
8901 d->keepTouch = keep;
8905
8906
8907
8908
8909
8910
8911
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923bool QQuickItem::contains(
const QPointF &point)
const
8925 Q_D(
const QQuickItem);
8926 if (d->extra.isAllocated() && d->extra->mask) {
8927 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8928 return quickMask->contains(point - quickMask->position());
8931 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8932 maskContains.invoke(d->extra->mask,
8933 Qt::DirectConnection,
8934 Q_RETURN_ARG(
bool, res),
8935 Q_ARG(QPointF, point));
8939 qreal x = point.x();
8940 qreal y = point.y();
8941 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009QObject *QQuickItem::containmentMask()
const
9011 Q_D(
const QQuickItem);
9012 if (!d->extra.isAllocated())
9014 return d->extra->mask.data();
9017void QQuickItem::setContainmentMask(QObject *mask)
9020 const bool extraDataExists = d->extra.isAllocated();
9022 if (mask ==
static_cast<QObject *>(
this))
9025 if (!extraDataExists && !mask)
9028 if (extraDataExists && d->extra->mask == mask)
9031 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
9034 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9035 maskPrivate->registerAsContainmentMask(
this,
false);
9038 if (!extraDataExists)
9041 int methodIndex = mask->metaObject()->indexOfMethod(
"contains(QPointF)");
9042 if (methodIndex < 0) {
9043 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
9046 d->extra->maskContainsIndex = methodIndex;
9048 d->extra->mask = mask;
9049 quickMask = qobject_cast<QQuickItem *>(mask);
9051 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9052 maskPrivate->registerAsContainmentMask(
this,
true);
9054 emit containmentMaskChanged();
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
9071 QPointF p = mapToScene(point);
9073 const auto *itemWindow = item->window();
9074 const auto *thisWindow = window();
9075 if (thisWindow && itemWindow && itemWindow != thisWindow)
9076 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
9078 p = item->mapFromScene(p);
9084
9085
9086
9087
9088
9089
9090
9091
9092QPointF QQuickItem::mapToScene(
const QPointF &point)
const
9094 Q_D(
const QQuickItem);
9095 return d->itemToWindowTransform().map(point);
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
9117 Q_D(
const QQuickItem);
9119 if (Q_UNLIKELY(d->window ==
nullptr))
9120 return mapToScene(point);
9122 QPoint renderOffset;
9123 QWindow *renderWindow = d->renderWindow(&renderOffset);
9124 return renderWindow->mapToGlobal((mapToScene(point) + renderOffset));
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
9141 Q_D(
const QQuickItem);
9142 QTransform t = d->itemToWindowTransform();
9144 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
9145 return t.mapRect(rect);
9149
9150
9151
9152
9153
9154
9155
9156
9157QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
9159 Q_D(
const QQuickItem);
9160 return d->itemToWindowTransform().mapRect(rect);
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9179 p = item->mapToScene(point);
9180 const auto *itemWindow = item->window();
9181 const auto *thisWindow = window();
9182 if (thisWindow && itemWindow && itemWindow != thisWindow)
9183 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9185 return mapFromScene(p);
9189
9190
9191
9192
9193
9194
9195
9196
9197QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9199 Q_D(
const QQuickItem);
9200 return d->windowToItemTransform().map(point);
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9228 Q_D(
const QQuickItem);
9231 if (Q_LIKELY(d->window)) {
9232 QPoint renderOffset;
9233 QWindow *renderWindow = d->renderWindow();
9234 scenePoint = renderWindow->mapFromGlobal(point) - renderOffset;
9239 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9240 if (
auto sceneTransform = da->sceneTransform())
9241 scenePoint = sceneTransform->map(scenePoint);
9243 return mapFromScene(scenePoint);
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9260 Q_D(
const QQuickItem);
9261 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9262 t *= d->windowToItemTransform();
9263 return t.mapRect(rect);
9267
9268
9269
9270
9271
9272
9273
9274
9275QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9277 Q_D(
const QQuickItem);
9278 return d->windowToItemTransform().mapRect(rect);
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347int QQuickItem::mutabilityGroup()
const
9349 Q_D(
const QQuickItem);
9350 if (d->extra.isAllocated())
9351 return d->extra->mutabilityGroup;
9352 return int(QQuickItem::AutoMutabilityGroup);
9355void QQuickItem::setMutabilityGroup(
int mutabilityGroup)
9359 const int clampedGroup = qBound(
int(AutoMutabilityGroup),
9361 int(DynamicMutabilityGroup));
9362 if (Q_UNLIKELY(clampedGroup != mutabilityGroup)) {
9363 qCDebug(QSG_LOG_RENDERLOOP) <<
"QQuickItem::setMutabilityGroup: Invalid group"
9369 if (clampedGroup ==
this->mutabilityGroup())
9372 d->extra.value().mutabilityGroup = clampedGroup;
9373 d->extra.value().mutabilityGroupSet =
true;
9374 d->dirty(QQuickItemPrivate::Content);
9375 emit mutabilityGroupChanged();
9379
9380
9381
9384
9385
9386
9389
9390
9391
9394
9395
9396
9399
9400
9401
9404
9405
9406
9409
9410
9411
9414
9415
9416
9419
9420
9421
9424
9425
9426
9429
9430
9431bool QQuickItem::event(QEvent *ev)
9435 switch (ev->type()) {
9437 case QEvent::InputMethodQuery: {
9438 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9439 Qt::InputMethodQueries queries = query->queries();
9440 for (uint i = 0; i < 32; ++i) {
9441 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9443 QVariant v = inputMethodQuery(q);
9444 query->setValue(q, v);
9450 case QEvent::InputMethod:
9451 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9454 case QEvent::TouchBegin:
9455 case QEvent::TouchUpdate:
9456 case QEvent::TouchEnd:
9457 case QEvent::TouchCancel:
9458 case QEvent::MouseButtonPress:
9459 case QEvent::MouseButtonRelease:
9460 case QEvent::MouseButtonDblClick:
9461#if QT_CONFIG(wheelevent)
9464 d->deliverPointerEvent(ev);
9466 case QEvent::StyleAnimationUpdate:
9472 case QEvent::HoverEnter:
9473 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9475 case QEvent::HoverLeave:
9476 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9478 case QEvent::HoverMove:
9479 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9481 case QEvent::KeyPress:
9482 case QEvent::KeyRelease:
9483 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9485 case QEvent::ShortcutOverride:
9486 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9488 case QEvent::FocusIn:
9489 focusInEvent(
static_cast<QFocusEvent*>(ev));
9491 case QEvent::FocusOut:
9492 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9494 case QEvent::MouseMove:
9495 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9497#if QT_CONFIG(quick_draganddrop)
9498 case QEvent::DragEnter:
9499 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9501 case QEvent::DragLeave:
9502 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9504 case QEvent::DragMove:
9505 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9508 dropEvent(
static_cast<QDropEvent*>(ev));
9511#if QT_CONFIG(gestures)
9512 case QEvent::NativeGesture:
9516 case QEvent::LanguageChange:
9517 case QEvent::LocaleChange:
9518 for (QQuickItem *item : std::as_const(d->childItems))
9519 QCoreApplication::sendEvent(item, ev);
9521 case QEvent::WindowActivate:
9522 case QEvent::WindowDeactivate:
9523 if (d->providesPalette())
9524 d->setCurrentColorGroup();
9525 for (QQuickItem *item : std::as_const(d->childItems))
9526 QCoreApplication::sendEvent(item, ev);
9528 case QEvent::ApplicationPaletteChange:
9529 for (QQuickItem *item : std::as_const(d->childItems))
9530 QCoreApplication::sendEvent(item, ev);
9532 case QEvent::ContextMenu:
9534 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9537 return QObject::event(ev);
9543#ifndef QT_NO_DEBUG_STREAM
9545#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9550 QDebugStateSaver saver(debug);
9553 debug <<
"QQuickItem(nullptr)";
9557 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9559 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9563 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9564 if (QQmlContext *context = qmlContext(item)) {
9565 const auto objectId = context->nameForObject(item);
9566 if (!objectId.isEmpty())
9567 debug <<
", id=" << objectId;
9570 if (!item->objectName().isEmpty())
9571 debug <<
", name=" << item->objectName();
9572 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9574 QtDebugUtils::formatQRect(debug, rect);
9575 if (
const qreal z = item->z())
9576 debug <<
", z=" << z;
9577 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9578 debug <<
" \U0001f5bc";
9579 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9587
9588
9589
9590
9591
9592
9593
9595bool QQuickItem::isTextureProvider()
const
9597#if QT_CONFIG(quick_shadereffect)
9598 Q_D(
const QQuickItem);
9599 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9600 d->extra->layer->effectSource()->isTextureProvider() :
false;
9607
9608
9609
9610
9611
9612
9613
9615QSGTextureProvider *QQuickItem::textureProvider()
const
9617#if QT_CONFIG(quick_shadereffect)
9618 Q_D(
const QQuickItem);
9619 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9620 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9668#if QT_CONFIG(quick_shadereffect)
9670
9671
9672
9673QQuickItemLayer *QQuickItemPrivate::layer()
const
9675 if (!extra.isAllocated() || !extra->layer) {
9676 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9677 if (!componentComplete)
9678 extra->layer->classBegin();
9680 return extra->layer;
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9704 QList<QEventPoint> touchPoints;
9705 QEventPoint::States eventStates;
9707 bool anyPressOrReleaseInside =
false;
9708 bool anyGrabber =
false;
9709 for (
auto &p : event->points()) {
9714 auto pointGrabber = event->exclusiveGrabber(p);
9715 bool isGrabber = (pointGrabber == q);
9716 if (!isGrabber && pointGrabber && isFiltering) {
9717 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9718 if (handlerGrabber && handlerGrabber->parentItem() == q)
9725 const auto localPos = q->mapFromScene(p.scenePosition());
9726 bool isInside = q->contains(localPos);
9727 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9729 if (isFiltering && !pointGrabber) {
9730 const auto pg = event->passiveGrabbers(p);
9731 if (!pg.isEmpty()) {
9735 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9737 pointGrabber = handler->parentItem();
9742 bool grabberIsChild =
false;
9743 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9744 while (isFiltering && parent) {
9746 grabberIsChild =
true;
9749 parent = parent->parentItem();
9752 bool filterRelevant = isFiltering && grabberIsChild;
9753 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9755 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9756 anyPressOrReleaseInside =
true;
9757 QEventPoint pCopy(p);
9758 eventStates |= p.state();
9759 if (p.state() == QEventPoint::State::Released)
9760 QMutableEventPoint::detach(pCopy);
9761 QMutableEventPoint::setPosition(pCopy, localPos);
9762 touchPoints.append(std::move(pCopy));
9767 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9768 *localized = QMutableTouchEvent(QEvent::None);
9773 QEvent::Type eventType = event->type();
9774 switch (eventStates) {
9775 case QEventPoint::State::Pressed:
9776 eventType = QEvent::TouchBegin;
9778 case QEventPoint::State::Released:
9779 eventType = QEvent::TouchEnd;
9782 eventType = QEvent::TouchUpdate;
9786 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9788 ret.setTimestamp(event->timestamp());
9793bool QQuickItemPrivate::hasPointerHandlers()
const
9795 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9798bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9800 if (!hasPointerHandlers())
9802 for (QQuickPointerHandler *h : extra->pointerHandlers)
9803 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9808void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9814 extra.value().acceptedMouseButtons = Qt::AllButtons;
9815 auto &handlers = extra.value().pointerHandlers;
9816 if (!handlers.contains(h))
9817 handlers.prepend(h);
9818 auto &res = extra.value().resourcesList;
9819 if (!res.contains(h)) {
9821 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9822 _q_resourceObjectDeleted(o);
9827void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9831 auto &handlers = extra.value().pointerHandlers;
9832 handlers.removeOne(h);
9833 auto &res = extra.value().resourcesList;
9835 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9836 if (handlers.isEmpty())
9837 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9841
9842
9843
9844QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9846 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9847 extra.value().contextMenu = menu;
9851QtPrivate::QQuickAttachedPropertyPropagator *QQuickItemPrivate::attachedPropertyPropagator_parent(
9852 const QMetaObject *attachedType)
9855 qCDebug(lcAttachedPropertyPropagator).noquote() <<
"- attachedPropertyPropagator_parent called on"
9856 << q <<
"with attachedType" << attachedType->metaType().name();
9858 QQuickItem *parent = q->parentItem();
9859 if (
auto *attached = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(attachedType, parent)) {
9860 qCDebug(lcAttachedPropertyPropagator).noquote() <<
" - parent item has attached object"
9861 << attached <<
"- returning";
9868#if QT_CONFIG(quick_shadereffect)
9869QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9875 , m_componentComplete(
true)
9876 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9877 , m_format(QQuickShaderEffectSource::RGBA8)
9879 , m_effectComponent(
nullptr)
9881 , m_effectSource(
nullptr)
9882 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9887QQuickItemLayer::~QQuickItemLayer()
9889 delete m_effectSource;
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907void QQuickItemLayer::setEnabled(
bool e)
9912 if (m_componentComplete) {
9919 emit enabledChanged(e);
9922void QQuickItemLayer::classBegin()
9924 Q_ASSERT(!m_effectSource);
9925 Q_ASSERT(!m_effect);
9926 m_componentComplete =
false;
9929void QQuickItemLayer::componentComplete()
9931 Q_ASSERT(!m_componentComplete);
9932 m_componentComplete =
true;
9937void QQuickItemLayer::activate()
9939 Q_ASSERT(!m_effectSource);
9940 m_effectSource =
new QQuickShaderEffectSource();
9941 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9943 QQuickItem *parentItem = m_item->parentItem();
9945 m_effectSource->setParentItem(parentItem);
9946 m_effectSource->stackAfter(m_item);
9949 m_effectSource->setSourceItem(m_item);
9950 m_effectSource->setHideSource(
true);
9951 m_effectSource->setSmooth(m_smooth);
9952 m_effectSource->setLive(m_live);
9953 m_effectSource->setTextureSize(m_size);
9954 m_effectSource->setSourceRect(m_sourceRect);
9955 m_effectSource->setMipmap(m_mipmap);
9956 m_effectSource->setWrapMode(m_wrapMode);
9957 m_effectSource->setFormat(m_format);
9958 m_effectSource->setTextureMirroring(m_textureMirroring);
9959 m_effectSource->setSamples(m_samples);
9961 if (m_effectComponent)
9964 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9971 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9972 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9975void QQuickItemLayer::deactivate()
9977 Q_ASSERT(m_effectSource);
9979 if (m_effectComponent)
9982 delete m_effectSource;
9983 m_effectSource =
nullptr;
9985 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9986 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9989void QQuickItemLayer::activateEffect()
9991 Q_ASSERT(m_effectSource);
9992 Q_ASSERT(m_effectComponent);
9993 Q_ASSERT(!m_effect);
9995 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9996 m_effect = qobject_cast<QQuickItem *>(created);
9998 qWarning(
"Item: layer.effect is not a QML Item.");
9999 m_effectComponent->completeCreate();
10003 QQuickItem *parentItem = m_item->parentItem();
10005 m_effect->setParentItem(parentItem);
10006 m_effect->stackAfter(m_effectSource);
10008 m_effect->setVisible(m_item->isVisible());
10009 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
10010 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
10011 m_effectComponent->completeCreate();
10014void QQuickItemLayer::deactivateEffect()
10016 Q_ASSERT(m_effectSource);
10017 Q_ASSERT(m_effectComponent);
10020 m_effect =
nullptr;
10025
10026
10027
10028
10029
10030
10031
10032
10033
10035void QQuickItemLayer::setEffect(QQmlComponent *component)
10037 if (component == m_effectComponent)
10040 bool updateNeeded =
false;
10041 if (m_effectSource && m_effectComponent) {
10042 deactivateEffect();
10043 updateNeeded =
true;
10046 m_effectComponent = component;
10048 if (m_effectSource && m_effectComponent) {
10050 updateNeeded =
true;
10053 if (updateNeeded) {
10058 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
10061 emit effectChanged(component);
10066
10067
10068
10069
10070
10071
10072
10073
10074
10076void QQuickItemLayer::setMipmap(
bool mipmap)
10078 if (mipmap == m_mipmap)
10082 if (m_effectSource)
10083 m_effectSource->setMipmap(m_mipmap);
10085 emit mipmapChanged(mipmap);
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10106void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
10112 if (m_effectSource)
10113 m_effectSource->setFormat(m_format);
10115 emit formatChanged(m_format);
10120
10121
10122
10123
10124
10125
10126
10127
10128
10130void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
10132 if (sourceRect == m_sourceRect)
10134 m_sourceRect = sourceRect;
10136 if (m_effectSource)
10137 m_effectSource->setSourceRect(m_sourceRect);
10139 emit sourceRectChanged(sourceRect);
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10154void QQuickItemLayer::setSmooth(
bool s)
10160 if (m_effectSource)
10161 m_effectSource->setSmooth(m_smooth);
10163 emit smoothChanged(s);
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10178void QQuickItemLayer::setLive(
bool live)
10180 if (m_live == live)
10184 if (m_effectSource)
10185 m_effectSource->setLive(m_live);
10187 emit liveChanged(live);
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10203void QQuickItemLayer::setSize(
const QSize &size)
10205 if (size == m_size)
10209 if (m_effectSource)
10210 m_effectSource->setTextureSize(size);
10212 emit sizeChanged(size);
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10233void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
10235 if (mode == m_wrapMode)
10239 if (m_effectSource)
10240 m_effectSource->setWrapMode(m_wrapMode);
10242 emit wrapModeChanged(mode);
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10260void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
10262 if (mirroring == m_textureMirroring)
10264 m_textureMirroring = mirroring;
10266 if (m_effectSource)
10267 m_effectSource->setTextureMirroring(m_textureMirroring);
10269 emit textureMirroringChanged(mirroring);
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10297void QQuickItemLayer::setSamples(
int count)
10299 if (m_samples == count)
10304 if (m_effectSource)
10305 m_effectSource->setSamples(m_samples);
10307 emit samplesChanged(count);
10311
10312
10313
10314
10315
10316
10317
10318
10319
10321void QQuickItemLayer::setName(
const QByteArray &name) {
10322 if (m_name == name)
10325 m_effect->setProperty(m_name, QVariant());
10326 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10329 emit nameChanged(name);
10332void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10338void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10343void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10346 Q_ASSERT(item == m_item);
10347 Q_ASSERT(parent != m_effectSource);
10348 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10350 m_effectSource->setParentItem(parent);
10352 m_effectSource->stackAfter(m_item);
10355 m_effect->setParentItem(parent);
10357 m_effect->stackAfter(m_effectSource);
10361void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10363 m_effectSource->stackAfter(m_item);
10365 m_effect->stackAfter(m_effectSource);
10368void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10370 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10373 l->setVisible(m_item->isVisible());
10376void QQuickItemLayer::updateZ()
10378 if (!m_componentComplete || !m_enabled)
10380 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10383 l->setZ(m_item->z());
10386void QQuickItemLayer::updateOpacity()
10388 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10391 l->setOpacity(m_item->opacity());
10394void QQuickItemLayer::updateGeometry()
10396 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10401 QRectF bounds = m_item->QQuickItem::boundingRect();
10402 l->setSize(bounds.size());
10403 l->setPosition(bounds.topLeft() + m_item->position());
10406void QQuickItemLayer::updateMatrix()
10410 if (!m_componentComplete || !m_enabled)
10412 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10415 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10416 l->setScale(m_item->scale());
10417 l->setRotation(m_item->rotation());
10418 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10419 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10420 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10421 ld->dirty(QQuickItemPrivate::Transform);
10425QQuickItemPrivate::ExtraData::ExtraData()
10426: z(0), scale(1), rotation(0), opacity(1), biggestPointerHandlerMarginCache(-1),
10427 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10428 enterKeyAttached(
nullptr),
10429 keyHandler(
nullptr), contextMenu(
nullptr),
10430#if QT_CONFIG(quick_shadereffect)
10433 effectRefCount(0), hideRefCount(0),
10434 recursiveEffectRefCount(0),
10435 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10436 origin(QQuickItem::Center),
10437 transparentForPositioner(
false),
10438 mutabilityGroup(uint(QQuickItem::AutoMutabilityGroup)),
10439 mutabilityGroupSet(
false)
10441#ifdef QT_BUILD_INTERNAL
10442 ++QQuickItemPrivate::itemExtra_counter;
10447#if QT_CONFIG(accessibility)
10448QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10450 auto role = QAccessible::NoRole;
10451 if (!inDestructor) {
10452 Q_Q(
const QQuickItem);
10453 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10454 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10455 role = accessibleAttached->role();
10456 if (role == QAccessible::NoRole)
10457 role = accessibleRole();
10462QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10464 return QAccessible::NoRole;
10473 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10486 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10487 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10488 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10489 QV4::QObjectWrapper::markWrapper(child, markStack);
10491 QObjectWrapper::markObjects(that, markStack);
10494quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10496 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10501 QDebugStateSaver stateSaver(debug);
10502 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10507QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10508{
return mapFromItem(item, QPointF(x, y) ); }
10511QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10512{
return mapRectFromItem(item, rect); }
10515QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10516{
return mapFromItem(item, QRectF(x, y, width, height)); }
10519QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10520{
return mapToItem(item, QPointF(x, y)); }
10523QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10524{
return mapRectToItem(item, rect); }
10527QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10528{
return mapToItem(item, QRectF(x, y, width, height)); }
10531QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10532{
return mapToGlobal(QPointF(x, y)); }
10535QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10536{
return mapFromGlobal(QPointF(x, y)); }
10539QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10543#include <moc_qquickitem.cpp>
10545#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)