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
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1481
1482
1483
1484
1485
1486
1487
1490QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(
nullptr)
1492 if (QQuickItem *item = qobject_cast<QQuickItem *>(parent))
1493 itemPrivate = QQuickItemPrivate::get(item);
1494 else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent))
1495 itemPrivate = QQuickItemPrivate::get(window->contentItem());
1498 itemPrivate->extra.value().layoutDirectionAttached =
this;
1500 qmlWarning(parent) << tr(
"LayoutMirroring attached property only works with Items and Windows");
1503QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object)
1505 return new QQuickLayoutMirroringAttached(object);
1508bool QQuickLayoutMirroringAttached::enabled()
const
1510 return itemPrivate ? itemPrivate->effectiveLayoutMirror :
false;
1513void QQuickLayoutMirroringAttached::setEnabled(
bool enabled)
1518 itemPrivate->isMirrorImplicit =
false;
1519 if (enabled != itemPrivate->effectiveLayoutMirror) {
1520 itemPrivate->setLayoutMirror(enabled);
1521 if (itemPrivate->inheritMirrorFromItem)
1522 itemPrivate->resolveLayoutMirror();
1526void QQuickLayoutMirroringAttached::resetEnabled()
1528 if (itemPrivate && !itemPrivate->isMirrorImplicit) {
1529 itemPrivate->isMirrorImplicit =
true;
1530 itemPrivate->resolveLayoutMirror();
1534bool QQuickLayoutMirroringAttached::childrenInherit()
const
1536 return itemPrivate ? itemPrivate->inheritMirrorFromItem :
false;
1539void QQuickLayoutMirroringAttached::setChildrenInherit(
bool childrenInherit) {
1540 if (itemPrivate && childrenInherit != itemPrivate->inheritMirrorFromItem) {
1541 itemPrivate->inheritMirrorFromItem = childrenInherit;
1542 itemPrivate->resolveLayoutMirror();
1543 childrenInheritChanged();
1547void QQuickItemPrivate::resolveLayoutMirror()
1550 if (QQuickItem *parentItem = q->parentItem()) {
1551 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parentItem);
1552 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
1554 setImplicitLayoutMirror(isMirrorImplicit ?
false : effectiveLayoutMirror, inheritMirrorFromItem);
1558void QQuickItemPrivate::setImplicitLayoutMirror(
bool mirror,
bool inherit)
1560 inherit = inherit || inheritMirrorFromItem;
1561 if (!isMirrorImplicit && inheritMirrorFromItem)
1562 mirror = effectiveLayoutMirror;
1563 if (mirror == inheritedLayoutMirror && inherit == inheritMirrorFromParent)
1566 inheritMirrorFromParent = inherit;
1567 inheritedLayoutMirror = inheritMirrorFromParent ? mirror :
false;
1569 if (isMirrorImplicit)
1570 setLayoutMirror(inherit ? inheritedLayoutMirror :
false);
1571 for (
int i = 0; i < childItems.size(); ++i) {
1572 if (QQuickItem *child = qmlobject_cast<QQuickItem *>(childItems.at(i))) {
1573 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
1574 childPrivate->setImplicitLayoutMirror(inheritedLayoutMirror, inheritMirrorFromParent);
1579void QQuickItemPrivate::setLayoutMirror(
bool mirror)
1581 if (mirror != effectiveLayoutMirror) {
1582 effectiveLayoutMirror = mirror;
1584 QQuickAnchorsPrivate *anchor_d = QQuickAnchorsPrivate::get(_anchors);
1585 anchor_d->fillChanged();
1586 anchor_d->centerInChanged();
1587 anchor_d->updateHorizontalAnchors();
1590 if (extra.isAllocated() && extra->layoutDirectionAttached) {
1591 emit extra->layoutDirectionAttached->enabledChanged();
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1643QQuickEnterKeyAttached::QQuickEnterKeyAttached(QObject *parent)
1644 : QObject(parent), itemPrivate(
nullptr), keyType(Qt::EnterKeyDefault)
1646 if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) {
1647 itemPrivate = QQuickItemPrivate::get(item);
1648 itemPrivate->extra.value().enterKeyAttached =
this;
1650 qmlWarning(parent) << tr(
"EnterKey attached property only works with Items");
1653QQuickEnterKeyAttached *QQuickEnterKeyAttached::qmlAttachedProperties(QObject *object)
1655 return new QQuickEnterKeyAttached(object);
1658Qt::EnterKeyType QQuickEnterKeyAttached::type()
const
1663void QQuickEnterKeyAttached::setType(Qt::EnterKeyType type)
1665 if (keyType != type) {
1668 if (itemPrivate && itemPrivate->activeFocus)
1669 QGuiApplication::inputMethod()->update(Qt::ImEnterKeyType);
1675void QQuickItemPrivate::setAccessible()
1677 isAccessible =
true;
1681
1682
1683
1684
1685void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope,
bool focus)
1690 QQuickItemPrivate *scopePrivate = QQuickItemPrivate::get(scope);
1692 QQuickItem *oldSubFocusItem = scopePrivate->subFocusItem;
1694 if (oldSubFocusItem) {
1695 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1696 while (sfi && sfi != scope) {
1697 QQuickItemPrivate::get(sfi)->subFocusItem =
nullptr;
1698 sfi = sfi->parentItem();
1703 scopePrivate->subFocusItem = q;
1704 QQuickItem *sfi = scopePrivate->subFocusItem->parentItem();
1705 while (sfi && sfi != scope) {
1706 QQuickItemPrivate::get(sfi)->subFocusItem = q;
1707 sfi = sfi->parentItem();
1710 scopePrivate->subFocusItem =
nullptr;
1715bool QQuickItemPrivate::setFocusIfNeeded(QEvent::Type eventType)
1718 const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
1719 Qt::FocusPolicy policy = Qt::ClickFocus;
1721 switch (eventType) {
1722 case QEvent::MouseButtonPress:
1723 case QEvent::MouseButtonDblClick:
1724 case QEvent::TouchBegin:
1725 if (setFocusOnRelease)
1728 case QEvent::MouseButtonRelease:
1729 case QEvent::TouchEnd:
1730 if (!setFocusOnRelease)
1734 policy = Qt::WheelFocus;
1740 if ((focusPolicy & policy) == policy) {
1741 setActiveFocus(q, Qt::MouseFocusReason);
1748Qt::FocusReason QQuickItemPrivate::lastFocusChangeReason()
const
1750 return static_cast<Qt::FocusReason>(focusReason);
1753bool QQuickItemPrivate::setLastFocusChangeReason(Qt::FocusReason reason)
1755 if (focusReason == reason)
1758 focusReason = reason;
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2152
2153
2154
2155
2156
2157
2158
2159
2160
2163
2164
2165
2168
2169
2170
2173
2174
2175
2178
2179
2180
2183
2184
2185
2186
2187
2188
2189
2192
2193
2194
2195
2196
2197
2200
2201
2202
2203
2204
2207
2208
2209
2210
2211
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2232
2233
2234
2237
2238
2239
2242
2243
2244
2247
2248
2249
2252
2253
2254
2257
2258
2259
2262
2263
2264
2267
2268
2269
2272
2273
2274
2277
2278
2279
2282
2283
2284
2287
2288
2289
2292
2293
2294
2297
2298
2299
2302
2303
2304
2307
2308
2309
2312
2313
2314
2317
2318
2319
2322
2323
2324
2327
2328
2329
2332
2333
2334
2337
2338
2339
2342
2343
2344
2347
2348
2349
2352
2353
2354
2357
2358
2359
2362
2363
2364
2367
2368
2369
2370
2371
2372
2373
2374QQuickItem::QQuickItem(QQuickItem* parent)
2375: QObject(*(
new QQuickItemPrivate), parent)
2382
2383QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2384: QObject(dd, parent)
2391
2392
2393QQuickItem::~QQuickItem()
2396 d->inDestructor =
true;
2398#if QT_CONFIG(accessibility)
2399 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
2400 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
2402 d->isAccessible =
false;
2405 if (d->windowRefCount > 1)
2406 d->windowRefCount = 1;
2408 setParentItem(
nullptr);
2412 for (QQuickItem *child : std::as_const(d->childItems))
2413 child->setParentItem(
nullptr);
2414 d->childItems.clear();
2416 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2417 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2419 anchor->clearItem(
this);
2422
2423
2424
2425 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2426 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2427 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2430 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2431 d->changeListeners.clear();
2434
2435
2436
2437
2438 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2439 QQuickTransform *t = d->transforms.at(ii);
2440 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2441 tp->items.removeOne(
this);
2444 if (d->extra.isAllocated()) {
2445 delete d->extra->contents; d->extra->contents =
nullptr;
2446#if QT_CONFIG(quick_shadereffect)
2447 delete d->extra->layer; d->extra->layer =
nullptr;
2451 delete d->_anchors; d->_anchors =
nullptr;
2452 delete d->_stateGroup; d->_stateGroup =
nullptr;
2454 d->isQuickItem =
false;
2458
2459
2460bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2462 if (!item->window())
2465 if (item == item->window()->contentItem())
2468 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2469 if (tabFocus == Qt::NoTabFocus)
2471 if (tabFocus == Qt::TabFocusAllControls)
2474 QVariant editable = item->property(
"editable");
2475 if (editable.isValid())
2476 return editable.toBool();
2478 QVariant readonly = item->property(
"readOnly");
2479 if (readonly.isValid())
2480 return !readonly.toBool() && item->property(
"text").isValid();
2482#if QT_CONFIG(accessibility)
2483 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2484 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2486 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2487 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2488 return iface->state().editable;
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2507 QQuickWindow *window = item->window();
2508 const bool wrap = !window || window->isTopLevel();
2510 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2515 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2517 if (!wrap && !next) {
2521 Q_ASSERT(window->parent());
2524 qt_window_private(window->parent())->setFocusToTarget(
2525 forward ? QWindowPrivate::FocusTarget::Next
2526 : QWindowPrivate::FocusTarget::Prev,
2528 window->parent()->requestActivate();
2532 next->forceActiveFocus(reason);
2537QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2540 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2543 const QList<QQuickItem *> &children = item->childItems();
2544 const int count = children.size();
2545 if (start < 0 || start >= count) {
2546 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2549 while (start < count) {
2550 QQuickItem *child = children.at(start);
2551 if (!child->d_func()->isTabFence)
2558QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2561 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2564 const QList<QQuickItem *> &children = item->childItems();
2565 const int count = children.size();
2568 if (start < 0 || start >= count) {
2569 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2572 while (start >= 0) {
2573 QQuickItem *child = children.at(start);
2574 if (!child->d_func()->isTabFence)
2581QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2584 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2586 if (!item->window())
2588 const QQuickItem *
const contentItem = item->window()->contentItem();
2592 QQuickItem *from =
nullptr;
2593 bool isTabFence = item->d_func()->isTabFence;
2596 from = item->parentItem();
2598 if (!item->childItems().isEmpty())
2599 from = item->d_func()->childItems.constFirst();
2600 else if (!isTabFence)
2601 from = item->parentItem();
2605 QQuickItem *startItem = item;
2606 QQuickItem *originalStartItem = startItem;
2611 while (startItem && !startItem->isVisible()) {
2612 startItem = startItem->parentItem();
2617 QQuickItem *firstFromItem = from;
2618 QQuickItem *current = item;
2619 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2620 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2621 QDuplicateTracker<QQuickItem *> cycleDetector;
2623 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2624 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2626 QQuickItem *last = current;
2628 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2629 QQuickItem *firstChild =
nullptr;
2630 QQuickItem *lastChild =
nullptr;
2632 firstChild = nextTabChildItem(current, 0);
2634 hasChildren =
false;
2636 lastChild = prevTabChildItem(current, -1);
2638 isTabFence = current->d_func()->isTabFence;
2639 if (isTabFence && !hasChildren)
2643 if (hasChildren && from == current->parentItem()) {
2645 current = firstChild;
2647 current = lastChild;
2648 if (!current->childItems().isEmpty())
2651 }
else if (hasChildren && forward && from != lastChild) {
2653 int nextChild = current->childItems().indexOf(from) + 1;
2654 current = nextTabChildItem(current, nextChild);
2655 }
else if (hasChildren && !forward && from != firstChild) {
2657 int prevChild = current->childItems().indexOf(from) - 1;
2658 current = prevTabChildItem(current, prevChild);
2659 if (!current->childItems().isEmpty())
2662 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2666 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2667 if (last != firstSibling
2668 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2672 }
else if (hasChildren) {
2673 if (!wrap && !isTabFence) {
2674 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2675 <<
"Focus chain about to wrap but we're outside a tab fence and wrapping was set to false."
2682 current = firstChild;
2683 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2684 <<
"wrapping from last to first:" << current;
2686 current = lastChild;
2687 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2688 <<
"wrapping from first to last:" << current;
2689 if (!current->childItems().isEmpty())
2701 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2702 (!skip && cycleDetector.hasSeen(current))) {
2704 if (item == contentItem) {
2705 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2708 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2712 if (!firstFromItem) {
2713 if (startItem->d_func()->isTabFence) {
2714 if (current == startItem)
2715 firstFromItem = from;
2717 startItem = current;
2718 firstFromItem = from;
2721 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2722 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2728
2729
2730
2731
2732
2733
2734
2735
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751QQuickItem *QQuickItem::parentItem()
const
2753 Q_D(
const QQuickItem);
2754 return d->parentItem;
2757void QQuickItem::setParentItem(QQuickItem *parentItem)
2760 if (parentItem == d->parentItem)
2764 QQuickItem *itemAncestor = parentItem;
2765 while (itemAncestor !=
nullptr) {
2766 if (Q_UNLIKELY(itemAncestor ==
this)) {
2767 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2770 itemAncestor = itemAncestor->parentItem();
2772 auto engine = qmlEngine(
this);
2774 QV4::ExecutionEngine *v4 = engine->handle();
2775 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2776 QV4::QObjectWrapper::markWrapper(
this, ms);
2781 d->removeFromDirtyList();
2783 QQuickItem *oldParentItem = d->parentItem;
2784 QQuickItem *scopeFocusedItem =
nullptr;
2786 if (oldParentItem) {
2787 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2789 QQuickItem *scopeItem =
nullptr;
2791 if (hasFocus() || op->subFocusItem ==
this)
2792 scopeFocusedItem =
this;
2793 else if (!isFocusScope() && d->subFocusItem)
2794 scopeFocusedItem = d->subFocusItem;
2796 if (scopeFocusedItem) {
2797 scopeItem = oldParentItem;
2798 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2799 scopeItem = scopeItem->parentItem();
2801 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2802 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2803 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2805 if (scopeFocusedItem !=
this)
2806 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2808 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2812 const bool wasVisible = isVisible();
2813 op->removeChild(
this);
2814 if (wasVisible && !op->inDestructor)
2815 emit oldParentItem->visibleChildrenChanged();
2816 }
else if (d->window) {
2817 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2820 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2821 bool alreadyAddedChild =
false;
2822 if (d->window == parentWindow) {
2824 d->parentItem = parentItem;
2826 auto oldParentItem = d->parentItem;
2827 d->parentItem = parentItem;
2828 if (d->parentItem) {
2829 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2830 alreadyAddedChild =
true;
2838 if (!oldParentItem && d->window) {
2839 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2843 d->refWindow(parentWindow);
2846 d->dirty(QQuickItemPrivate::ParentChanged);
2848 if (d->parentItem && !alreadyAddedChild)
2849 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2850 else if (d->window && !alreadyAddedChild)
2851 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2853 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2854 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2856 if (d->parentItem) {
2857 if (!scopeFocusedItem) {
2859 scopeFocusedItem =
this;
2860 else if (!isFocusScope() && d->subFocusItem)
2861 scopeFocusedItem = d->subFocusItem;
2864 if (scopeFocusedItem) {
2866 QQuickItem *scopeItem = d->parentItem;
2867 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2868 scopeItem = scopeItem->parentItem();
2870 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2871 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2872 if (scopeFocusedItem !=
this)
2873 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2874 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2875 emit scopeFocusedItem->focusChanged(
false);
2878 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2879 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2880 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2883 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2890 d->resolveLayoutMirror();
2892 d->itemChange(ItemParentHasChanged, d->parentItem);
2894 if (!d->inDestructor)
2895 emit parentChanged(d->parentItem);
2896 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2897 emit d->parentItem->visibleChildrenChanged();
2899#if QT_CONFIG(accessibility)
2900 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2901 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2902 QAccessible::updateAccessibility(&qaEvent);
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925void QQuickItem::stackBefore(
const QQuickItem *sibling)
2928 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2929 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2930 <<
this <<
" before " << sibling <<
", which must be a sibling";
2934 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2936 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2937 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2939 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2941 if (myIndex == siblingIndex - 1)
2944 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2946 parentPrivate->markSortedChildrenDirty(
this);
2947 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2949 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2950 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971void QQuickItem::stackAfter(
const QQuickItem *sibling)
2974 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2975 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2976 <<
this <<
" after " << sibling <<
", which must be a sibling";
2980 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2982 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2983 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2985 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2987 if (myIndex == siblingIndex + 1)
2990 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2992 parentPrivate->markSortedChildrenDirty(
this);
2993 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2995 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2996 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
3000
3001
3004
3005
3006
3007
3008
3009
3010QQuickWindow *QQuickItem::window()
const
3012 Q_D(
const QQuickItem);
3018 return lhs->z() < rhs->z();
3021QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3023 if (sortedChildItems)
3024 return *sortedChildItems;
3029 for (
int i = 0; i < childItems.size(); ++i) {
3030 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3036 sortedChildItems =
new QList<QQuickItem*>(childItems);
3037 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3038 return *sortedChildItems;
3041 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3046void QQuickItemPrivate::addChild(QQuickItem *child)
3050 Q_ASSERT(!childItems.contains(child));
3052 childItems.append(child);
3054 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3056#if QT_CONFIG(cursor)
3059 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3060 setHasCursorInChild(
true);
3063 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3064 setHasHoverInChild(
true);
3066 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3067 markSortedChildrenDirty(child);
3068 dirty(QQuickItemPrivate::ChildrenChanged);
3070 itemChange(QQuickItem::ItemChildAddedChange, child);
3072 emit q->childrenChanged();
3075void QQuickItemPrivate::removeChild(QQuickItem *child)
3080 if (!inDestructor) {
3082 Q_ASSERT(childItems.contains(child));
3083 childItems.removeOne(child);
3084 Q_ASSERT(!childItems.contains(child));
3087 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3089#if QT_CONFIG(cursor)
3091 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3092 setHasCursorInChild(
false);
3095 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3096 setHasHoverInChild(
false);
3098 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3099 if (!inDestructor) {
3100 markSortedChildrenDirty(child);
3101 dirty(QQuickItemPrivate::ChildrenChanged);
3104 itemChange(QQuickItem::ItemChildRemovedChange, child);
3107 emit q->childrenChanged();
3110void QQuickItemPrivate::refWindow(QQuickWindow *c)
3122 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3124 if (++windowRefCount > 1) {
3126 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3130 Q_ASSERT(window ==
nullptr);
3133 if (polishScheduled)
3134 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3137 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3139 for (
int ii = 0; ii < childItems.size(); ++ii) {
3140 QQuickItem *child = childItems.at(ii);
3141 QQuickItemPrivate::get(child)->refWindow(c);
3146 if (extra.isAllocated() && extra->screenAttached)
3147 extra->screenAttached->windowChanged(c);
3148 itemChange(QQuickItem::ItemSceneChange, c);
3151void QQuickItemPrivate::derefWindow()
3154 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3159 if (--windowRefCount > 0)
3162 q->releaseResources();
3163 removeFromDirtyList();
3164 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3165 if (polishScheduled)
3166 c->itemsToPolish.removeOne(q);
3167#if QT_CONFIG(cursor)
3168 if (c->cursorItem == q) {
3169 c->cursorItem =
nullptr;
3170 window->unsetCursor();
3173 if (itemNodeInstance)
3174 c->cleanup(itemNodeInstance);
3176 c->parentlessItems.remove(q);
3178 if (
auto *da = deliveryAgentPrivate()) {
3179 if (da->activeFocusItem == q) {
3180 qCDebug(lcFocus) <<
"Removing active focus item from window's delivery agent";
3181 da->activeFocusItem =
nullptr;
3186 itemNodeInstance =
nullptr;
3188 if (extra.isAllocated()) {
3189 extra->opacityNode =
nullptr;
3190 extra->clipNode =
nullptr;
3191 extra->rootNode =
nullptr;
3194 paintNode =
nullptr;
3196 for (
int ii = 0; ii < childItems.size(); ++ii) {
3197 if (QQuickItem *child = childItems.at(ii))
3198 QQuickItemPrivate::get(child)->derefWindow();
3203 if (extra.isAllocated() && extra->screenAttached)
3204 extra->screenAttached->windowChanged(
nullptr);
3205 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3208qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3210 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3214
3215
3216QTransform QQuickItemPrivate::windowToItemTransform()
const
3219#ifdef QT_BUILD_INTERNAL
3220 ++windowToItemTransform_counter;
3222 return itemToWindowTransform().inverted();
3226
3227
3228QTransform QQuickItemPrivate::itemToWindowTransform()
const
3230#ifdef QT_BUILD_INTERNAL
3231 ++itemToWindowTransform_counter;
3234 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3235 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3236 itemToParentTransform(&rv);
3241
3242
3243void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3245#ifdef QT_BUILD_INTERNAL
3246 ++itemToParentTransform_counter;
3249
3250
3251
3252
3253
3255 qreal x =
this->x.valueBypassingBindings();
3256 qreal y =
this->y.valueBypassingBindings();
3260 if (!transforms.isEmpty()) {
3262 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3263 transforms.at(ii)->applyTo(&m);
3264 *t = m.toTransform();
3267 if (scale() != 1. || rotation() != 0.) {
3268 QPointF tp = computeTransformOrigin();
3269 t->translate(tp.x(), tp.y());
3270 t->scale(scale(), scale());
3271 t->rotate(rotation());
3272 t->translate(-tp.x(), -tp.y());
3277
3278
3279
3280
3281
3282
3283
3284
3285bool QQuickItem::isComponentComplete()
const
3287 Q_D(
const QQuickItem);
3288 return d->componentComplete;
3291QQuickItemPrivate::QQuickItemPrivate()
3293 , _stateGroup(
nullptr)
3295 , widthValidFlag(
false)
3296 , heightValidFlag(
false)
3297 , componentComplete(
true)
3300 , hoverEnabled(
false)
3302 , antialiasing(
false)
3304 , activeFocus(
false)
3305 , notifiedFocus(
false)
3306 , notifiedActiveFocus(
false)
3307 , filtersChildMouseEvents(
false)
3308 , explicitVisible(
true)
3309 , effectiveVisible(
true)
3310 , explicitEnable(
true)
3311 , effectiveEnable(
true)
3312 , polishScheduled(
false)
3313 , inheritedLayoutMirror(
false)
3314 , effectiveLayoutMirror(
false)
3315 , isMirrorImplicit(
true)
3316 , inheritMirrorFromParent(
false)
3317 , inheritMirrorFromItem(
false)
3318 , isAccessible(
false)
3321 , subtreeCursorEnabled(
false)
3322 , subtreeHoverEnabled(
false)
3323 , activeFocusOnTab(
false)
3324 , implicitAntialiasing(
false)
3325 , antialiasingValid(
false)
3327 , replayingPressEvent(
false)
3328 , touchEnabled(
false)
3329 , hasCursorHandler(
false)
3330 , maybeHasSubsceneDeliveryAgent(
true)
3331 , subtreeTransformChangedEnabled(
true)
3332 , inDestructor(
false)
3333 , focusReason(Qt::OtherFocusReason)
3334 , focusPolicy(Qt::NoFocus)
3335 , eventHandlingChildrenWithinBounds(
false)
3336 , eventHandlingChildrenWithinBoundsSet(
false)
3337 , customOverlay(
false)
3338 , dirtyAttributes(0)
3339 , nextDirtyItem(
nullptr)
3340 , prevDirtyItem(
nullptr)
3343 , parentItem(
nullptr)
3344 , sortedChildItems(&childItems)
3345 , subFocusItem(
nullptr)
3353 , itemNodeInstance(
nullptr)
3354 , paintNode(
nullptr)
3355 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3357#ifdef QT_BUILD_INTERNAL
3362QQuickItemPrivate::~QQuickItemPrivate()
3364 if (sortedChildItems != &childItems)
3365 delete sortedChildItems;
3368void QQuickItemPrivate::init(QQuickItem *parent)
3374 baselineOffset = 0.0;
3377 q->setParentItem(parent);
3378 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3379 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3383QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3388void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3390 szPolicy.setHorizontalPolicy(horizontalPolicy);
3391 szPolicy.setVerticalPolicy(verticalPolicy);
3394void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3399 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3401 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3402 item->setParentItem(that);
3403 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3404 if (pointerHandler->parent() != that) {
3405 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3406 pointerHandler->setParent(that);
3408 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3411 resources_append(prop, o);
3416
3417
3418
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
3450qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3452 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3453 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3454 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3455 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3457 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3460QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3462 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3463 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3464 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3465 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3467 qsizetype resourcesCount = resources_count(&resourcesProperty);
3468 if (i < resourcesCount)
3469 return resources_at(&resourcesProperty, i);
3470 const qsizetype j = i - resourcesCount;
3471 if (j < children_count(&childrenProperty))
3472 return children_at(&childrenProperty, j);
3476void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3478 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3479 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3480 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3481 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3483 resources_clear(&resourcesProperty);
3484 children_clear(&childrenProperty);
3487void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3489 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3490 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3492 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3493 if (children_count(&childrenProperty) > 0) {
3494 children_removeLast(&childrenProperty);
3498 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3499 if (resources_count(&resourcesProperty) > 0)
3500 resources_removeLast(&resourcesProperty);
3503QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3505 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3506 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3509void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3511 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3512 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3513 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3514 quickItemPrivate->extra.value().resourcesList.append(object);
3515 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3516 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3520qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3522 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3523 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3526void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3528 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3529 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3530 if (quickItemPrivate->extra.isAllocated()) {
3531 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3532 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3533 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3535 quickItemPrivate->extra->resourcesList.clear();
3539void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3541 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3542 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3543 if (quickItemPrivate->extra.isAllocated()) {
3544 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3545 if (resources->isEmpty())
3548 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3549 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3550 resources->removeLast();
3554QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3556 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3557 if (index >= p->childItems.size() || index < 0)
3560 return p->childItems.at(index);
3563void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3568 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3569 if (o->parentItem() == that)
3570 o->setParentItem(
nullptr);
3572 o->setParentItem(that);
3575qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3577 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3578 return p->childItems.size();
3581void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3583 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3584 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3585 while (!p->childItems.isEmpty())
3586 p->childItems.at(0)->setParentItem(
nullptr);
3589void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3591 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3592 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3593 if (!p->childItems.isEmpty())
3594 p->childItems.last()->setParentItem(
nullptr);
3597qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3599 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3600 qsizetype visibleCount = 0;
3601 qsizetype c = p->childItems.size();
3603 if (p->childItems.at(c)->isVisible()) visibleCount++;
3606 return visibleCount;
3609QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3611 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3612 const qsizetype childCount = p->childItems.size();
3613 if (index >= childCount || index < 0)
3616 qsizetype visibleCount = -1;
3617 for (qsizetype i = 0; i < childCount; i++) {
3618 if (p->childItems.at(i)->isVisible()) visibleCount++;
3619 if (visibleCount == index)
return p->childItems.at(i);
3624qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3626 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3627 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3629 return p->transforms.size();
3632void QQuickTransform::appendToItem(QQuickItem *item)
3634 Q_D(QQuickTransform);
3638 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3640 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3641 p->transforms.removeOne(
this);
3642 p->transforms.append(
this);
3644 p->transforms.append(
this);
3645 d->items.append(item);
3648 p->dirty(QQuickItemPrivate::Transform);
3651void QQuickTransform::prependToItem(QQuickItem *item)
3653 Q_D(QQuickTransform);
3657 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3659 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3660 p->transforms.removeOne(
this);
3661 p->transforms.prepend(
this);
3663 p->transforms.prepend(
this);
3664 d->items.append(item);
3667 p->dirty(QQuickItemPrivate::Transform);
3670void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3675 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3676 transform->appendToItem(that);
3679QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3681 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3682 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3684 if (idx < 0 || idx >= p->transforms.size())
3687 return p->transforms.at(idx);
3690void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3692 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3693 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3695 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3696 QQuickTransform *t = p->transforms.at(ii);
3697 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3698 tp->items.removeOne(that);
3701 p->transforms.clear();
3703 p->dirty(QQuickItemPrivate::Transform);
3706void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3708 if (extra.isAllocated() && extra->resourcesList.contains(object))
3709 extra->resourcesList.removeAll(object);
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806QQuickAnchors *QQuickItemPrivate::anchors()
const
3809 Q_Q(
const QQuickItem);
3810 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3811 if (!componentComplete)
3812 _anchors->classBegin();
3817void QQuickItemPrivate::siblingOrderChanged()
3820 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3823QQmlListProperty<QObject> QQuickItemPrivate::data()
3827 QQmlListProperty<QObject> result;
3828 result.object = q_func();
3829 result.append = QQuickItemPrivate::data_append;
3830 result.count = QQuickItemPrivate::data_count;
3831 result.at = QQuickItemPrivate::data_at;
3832 result.clear = QQuickItemPrivate::data_clear;
3833 result.removeLast = QQuickItemPrivate::data_removeLast;
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868QRectF QQuickItem::childrenRect()
3871 if (!d->extra.isAllocated() || !d->extra->contents) {
3872 d->extra.value().contents =
new QQuickContents(
this);
3873 if (d->componentComplete)
3874 d->extra->contents->complete();
3876 return d->extra->contents->rectF();
3880
3881
3882QList<QQuickItem *> QQuickItem::childItems()
const
3884 Q_D(
const QQuickItem);
3885 return d->childItems;
3889
3890
3891
3892
3893
3894
3895
3896
3897
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916bool QQuickItem::clip()
const
3918 return flags() & ItemClipsChildrenToShape;
3921void QQuickItem::setClip(
bool c)
3926 setFlag(ItemClipsChildrenToShape, c);
3928 setFlag(ItemIsViewport);
3929 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3930 setFlag(ItemIsViewport,
false);
3932 emit clipChanged(c);
3936
3937
3938
3939
3940
3941
3942
3943
3944void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3949 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3951 QQuickGeometryChange change;
3952 change.setXChange(newGeometry.x() != oldGeometry.x());
3953 change.setYChange(newGeometry.y() != oldGeometry.y());
3954 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3955 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3957 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3958 if (change.matches(listener.gTypes))
3959 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3964 if (change.xChange())
3966 if (change.yChange())
3968 if (change.widthChange())
3970 if (change.heightChange())
3972#if QT_CONFIG(accessibility)
3973 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3974 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3975 QAccessible::updateAccessibility(&ev);
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4034QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4036 Q_UNUSED(updatePaintNodeData);
4041QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4042: transformNode(
nullptr)
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4063void QQuickItem::releaseResources()
4067QSGTransformNode *QQuickItemPrivate::createTransformNode()
4069 return new QSGTransformNode;
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082void QQuickItem::updatePolish()
4086#define PRINT_LISTENERS() do
4088 qDebug().nospace() << q_func() << " (" << this
4089 << ") now has the following listeners:";
4090 for (const auto &listener : std::as_const(changeListeners)) {
4091 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4092 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4094}while
4097void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4100 changeListeners.append(ChangeListener(listener, types));
4101 listener->addSourceItem(q);
4103 if (lcChangeListeners().isDebugEnabled())
4107void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4111 const ChangeListener changeListener(listener, types);
4112 const int index = changeListeners.indexOf(changeListener);
4114 changeListeners[index].types = changeListener.types;
4116 changeListeners.append(changeListener);
4117 listener->addSourceItem(q);
4120 if (lcChangeListeners().isDebugEnabled())
4124void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4128 ChangeListener change(listener, types);
4129 changeListeners.removeOne(change);
4130 listener->removeSourceItem(q);
4132 if (lcChangeListeners().isDebugEnabled())
4136void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4137 QQuickGeometryChange types)
4141 ChangeListener change(listener, types);
4142 int index = changeListeners.indexOf(change);
4144 changeListeners[index].gTypes = change.gTypes;
4146 changeListeners.append(change);
4147 listener->addSourceItem(q);
4150 if (lcChangeListeners().isDebugEnabled())
4154void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4155 QQuickGeometryChange types)
4159 ChangeListener change(listener, types);
4160 if (types.noChange()) {
4161 changeListeners.removeOne(change);
4162 listener->removeSourceItem(q);
4164 int index = changeListeners.indexOf(change);
4166 changeListeners[index].gTypes = change.gTypes;
4169 if (lcChangeListeners().isDebugEnabled())
4174
4175
4176
4177
4178
4179
4180void QQuickItem::keyPressEvent(QKeyEvent *event)
4186
4187
4188
4189
4190
4191
4192void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4199
4200
4201
4202
4203
4204
4205void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221void QQuickItem::focusInEvent(QFocusEvent *event)
4224#if QT_CONFIG(accessibility)
4225 if (QAccessible::isActive()) {
4226 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4227 QAccessibleEvent ev(acc, QAccessible::Focus);
4228 QAccessible::updateAccessibility(&ev);
4232 d->setLastFocusChangeReason(event->reason());
4236
4237
4238
4239
4240
4241
4242void QQuickItem::focusOutEvent(QFocusEvent *event)
4245 d->setLastFocusChangeReason(event->reason());
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258void QQuickItem::mousePressEvent(QMouseEvent *event)
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4296
4297
4298
4299
4300
4301
4302void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4308
4309
4310
4311void QQuickItem::mouseUngrabEvent()
4317
4318
4319
4320void QQuickItem::touchUngrabEvent()
4325#if QT_CONFIG(wheelevent)
4327
4328
4329
4330
4331
4332
4333void QQuickItem::wheelEvent(QWheelEvent *event)
4340
4341
4342
4343
4344
4345
4346void QQuickItem::touchEvent(QTouchEvent *event)
4352
4353
4354
4355
4356
4357
4358
4359
4360void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4366
4367
4368
4369
4370
4371
4372
4373
4374void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4380
4381
4382
4383
4384
4385
4386
4387
4388void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4393#if QT_CONFIG(quick_draganddrop)
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457void QQuickItem::dropEvent(QDropEvent *event)
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4502
4503
4504
4505
4506
4507
4508
4509QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4511 Q_D(
const QQuickItem);
4516 v = (
bool)(flags() & ItemAcceptsInputMethod);
4519 case Qt::ImAnchorRectangle:
4520 case Qt::ImCursorRectangle:
4522 case Qt::ImCursorPosition:
4523 case Qt::ImSurroundingText:
4524 case Qt::ImCurrentSelection:
4525 case Qt::ImMaximumTextLength:
4526 case Qt::ImAnchorPosition:
4527 case Qt::ImPreferredLanguage:
4528 case Qt::ImReadOnly:
4529 if (d->extra.isAllocated() && d->extra->keyHandler)
4530 v = d->extra->keyHandler->inputMethodQuery(query);
4532 case Qt::ImEnterKeyType:
4533 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4534 v = d->extra->enterKeyAttached->type();
4536 case Qt::ImInputItemClipRectangle:
4537 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4538 QRectF rect = QRectF(0,0, width(), height());
4539 const QQuickItem *par =
this;
4540 while (QQuickItem *parpar = par->parentItem()) {
4541 rect = parpar->mapRectFromItem(par, rect);
4543 rect = rect.intersected(parpar->clipRect());
4546 rect = par->mapRectToScene(rect);
4548 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4550 v = mapRectFromScene(rect);
4561QQuickAnchorLine QQuickItemPrivate::left()
const
4563 Q_Q(
const QQuickItem);
4564 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4567QQuickAnchorLine QQuickItemPrivate::right()
const
4569 Q_Q(
const QQuickItem);
4570 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4573QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4575 Q_Q(
const QQuickItem);
4576 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4579QQuickAnchorLine QQuickItemPrivate::top()
const
4581 Q_Q(
const QQuickItem);
4582 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4585QQuickAnchorLine QQuickItemPrivate::bottom()
const
4587 Q_Q(
const QQuickItem);
4588 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4591QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4593 Q_Q(
const QQuickItem);
4594 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4597QQuickAnchorLine QQuickItemPrivate::baseline()
const
4599 Q_Q(
const QQuickItem);
4600 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625qreal QQuickItem::baselineOffset()
const
4627 Q_D(
const QQuickItem);
4628 return d->baselineOffset;
4631void QQuickItem::setBaselineOffset(qreal offset)
4634 if (offset == d->baselineOffset)
4637 d->baselineOffset = offset;
4639 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4640 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4642 anchor->updateVerticalAnchors();
4645 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4646 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4648 emit baselineOffsetChanged(offset);
4653
4654
4655
4656
4657
4658
4659
4660
4661void QQuickItem::update()
4664 if (!(flags() & ItemHasContents)) {
4666 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4670 d->dirty(QQuickItemPrivate::Content);
4674
4675
4676
4677
4678
4679
4680
4681void QQuickItem::polish()
4684 if (!d->polishScheduled) {
4685 d->polishScheduled =
true;
4687 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4688 bool maybeupdate = p->itemsToPolish.isEmpty();
4689 p->itemsToPolish.append(
this);
4690 if (maybeupdate) d->window->maybeUpdate();
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710void QQuickItem::ensurePolished()
4715#if QT_DEPRECATED_SINCE(6
, 5
)
4716static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4717 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4719 QV4::ExecutionEngine *v4 = args->v4engine();
4720 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4721 v4->throwTypeError();
4725 QV4::Scope scope(v4);
4726 QV4::ScopedValue item(scope, (*args)[0]);
4729 if (!item->isNull()) {
4730 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4732 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4735 if (!(*itemObj) && !item->isNull()) {
4736 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4737 <<
"\" which is neither null nor an Item";
4738 v4->throwTypeError();
4744 if (args->length() == 2) {
4745 QV4::ScopedValue sv(scope, (*args)[1]);
4747 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4748 <<
"\" which is neither a point nor a rect";
4749 v4->throwTypeError();
4752 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4753 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4754 if (v.canConvert<QPointF>()) {
4755 const QPointF p = v.toPointF();
4758 }
else if (v.canConvert<QRectF>()) {
4759 const QRectF r = v.toRectF();
4766 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4767 <<
"\" which is neither a point nor a rect";
4768 v4->throwTypeError();
4772 QV4::ScopedValue vx(scope, (*args)[1]);
4773 QV4::ScopedValue vy(scope, (*args)[2]);
4775 if (!vx->isNumber() || !vy->isNumber()) {
4776 v4->throwTypeError();
4780 *x = vx->asDouble();
4781 *y = vy->asDouble();
4783 if (args->length() > 3) {
4784 QV4::ScopedValue vw(scope, (*args)[3]);
4785 QV4::ScopedValue vh(scope, (*args)[4]);
4786 if (!vw->isNumber() || !vh->isNumber()) {
4787 v4->throwTypeError();
4790 *w = vw->asDouble();
4791 *h = vh->asDouble();
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4818#if QT_DEPRECATED_SINCE(6
, 5
)
4820
4821
4822void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4824 QV4::ExecutionEngine *v4 = args->v4engine();
4825 QV4::Scope scope(v4);
4829 QQuickItem *itemObj;
4830 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4833 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4834 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4836 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4837 args->setReturnValue(rv.asReturnedValue());
4842
4843
4844QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4846 Q_D(
const QQuickItem);
4852 QTransform t = d->itemToWindowTransform();
4853 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4876#if QT_DEPRECATED_SINCE(6
, 5
)
4878
4879
4880void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4882 QV4::ExecutionEngine *v4 = args->v4engine();
4883 QV4::Scope scope(v4);
4887 QQuickItem *itemObj;
4888 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4891 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4892 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4894 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4895 args->setReturnValue(rv.asReturnedValue());
4898static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4900 QV4::ExecutionEngine *v4 = args->v4engine();
4901 if (args->length() != 1 && args->length() != 2) {
4902 v4->throwTypeError();
4906 QV4::Scope scope(v4);
4908 if (args->length() == 1) {
4909 QV4::ScopedValue sv(scope, (*args)[0]);
4911 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4912 <<
"\" which is not a point";
4913 v4->throwTypeError();
4916 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4917 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4918 if (v.canConvert<QPointF>()) {
4919 const QPointF p = v.toPointF();
4923 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4924 <<
"\" which is not a point";
4925 v4->throwTypeError();
4929 QV4::ScopedValue vx(scope, (*args)[0]);
4930 QV4::ScopedValue vy(scope, (*args)[1]);
4932 if (!vx->isNumber() || !vy->isNumber()) {
4933 v4->throwTypeError();
4937 *x = vx->asDouble();
4938 *y = vy->asDouble();
4945
4946
4947
4948
4949
4950
4951
4952
4954
4955
4956void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4958 QV4::ExecutionEngine *v4 = args->v4engine();
4959 QV4::Scope scope(v4);
4962 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4965 QVariant result = mapFromGlobal(QPointF(x, y));
4967 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4968 args->setReturnValue(rv.asReturnedValue());
4973
4974
4975
4976
4977
4978
4979
4980
4982#if QT_DEPRECATED_SINCE(6
, 5
)
4984
4985
4986void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4988 QV4::ExecutionEngine *v4 = args->v4engine();
4989 QV4::Scope scope(v4);
4992 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4995 QVariant result = mapToGlobal(QPointF(x, y));
4997 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4998 args->setReturnValue(rv.asReturnedValue());
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028void QQuickItem::forceActiveFocus()
5030 forceActiveFocus(Qt::OtherFocusReason);
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5058void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5060 setFocus(
true, reason);
5061 QQuickItem *parent = parentItem();
5062 QQuickItem *scope =
nullptr;
5064 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5065 parent->setFocus(
true, reason);
5069 parent = parent->parentItem();
5074
5075
5076
5077
5078
5079
5080
5081
5082
5084
5085
5086
5087
5088
5090QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5092 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5096
5097
5098
5099
5100
5101
5102
5104
5105
5106
5107
5108
5109QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5111 const QList<QQuickItem *> children = childItems();
5112 for (
int i = children.size()-1; i >= 0; --i) {
5113 QQuickItem *child = children.at(i);
5115 QPointF point = mapToItem(child, QPointF(x, y));
5116 if (child->isVisible() && child->contains(point))
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163void QQuickItem::dumpItemTree()
const
5165 Q_D(
const QQuickItem);
5169void QQuickItemPrivate::dumpItemTree(
int indent)
const
5171 Q_Q(
const QQuickItem);
5173 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5174 qDebug().nospace().noquote() << indentStr <<
5175#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5176 const_cast<QQuickItem *>(q);
5180 if (extra.isAllocated()) {
5181 for (
const auto handler : extra->pointerHandlers)
5182 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5184 for (
const QQuickItem *ch : childItems) {
5185 auto itemPriv = QQuickItemPrivate::get(ch);
5186 itemPriv->dumpItemTree(indent + 1);
5190QQmlListProperty<QObject> QQuickItemPrivate::resources()
5194 QQmlListProperty<QObject> result;
5195 result.object = q_func();
5196 result.append = QQuickItemPrivate::resources_append;
5197 result.count = QQuickItemPrivate::resources_count;
5198 result.at = QQuickItemPrivate::resources_at;
5199 result.clear = QQuickItemPrivate::resources_clear;
5200 result.removeLast = QQuickItemPrivate::resources_removeLast;
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5218
5219
5220
5221QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5225 QQmlListProperty<QQuickItem> result;
5226 result.object = q_func();
5227 result.append = QQuickItemPrivate::children_append;
5228 result.count = QQuickItemPrivate::children_count;
5229 result.at = QQuickItemPrivate::children_at;
5230 result.clear = QQuickItemPrivate::children_clear;
5231 result.removeLast = QQuickItemPrivate::children_removeLast;
5236
5237
5238
5239
5240
5242
5243
5244
5245QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5247 return QQmlListProperty<QQuickItem>(q_func(),
5249 QQuickItemPrivate::visibleChildren_count,
5250 QQuickItemPrivate::visibleChildren_at);
5255
5256
5257
5258
5259
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
5291
5292
5293
5294QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5296 return _states()->statesProperty();
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5328
5329
5330
5331QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5333 return _states()->transitionsProperty();
5336QString QQuickItemPrivate::state()
const
5341 return _stateGroup->state();
5344void QQuickItemPrivate::setState(
const QString &state)
5346 _states()->setState(state);
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371QString QQuickItem::state()
const
5373 Q_D(
const QQuickItem);
5377void QQuickItem::setState(
const QString &state)
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5396
5397
5398
5400
5401
5402QQmlListProperty<QQuickTransform> QQuickItem::transform()
5404 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5405 QQuickItemPrivate::transform_count,
5406 QQuickItemPrivate::transform_at,
5407 QQuickItemPrivate::transform_clear);
5411
5412
5413
5414
5415void QQuickItem::classBegin()
5418 d->componentComplete =
false;
5420 d->_stateGroup->classBegin();
5422 d->_anchors->classBegin();
5423#if QT_CONFIG(quick_shadereffect)
5424 if (d->extra.isAllocated() && d->extra->layer)
5425 d->extra->layer->classBegin();
5430
5431
5432
5433
5434void QQuickItem::componentComplete()
5437 d->componentComplete =
true;
5439 d->_stateGroup->componentComplete();
5441 d->_anchors->componentComplete();
5442 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5445 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5446 safeArea->updateSafeArea();
5448 if (d->extra.isAllocated()) {
5449#if QT_CONFIG(quick_shadereffect)
5450 if (d->extra->layer)
5451 d->extra->layer->componentComplete();
5454 if (d->extra->keyHandler)
5455 d->extra->keyHandler->componentComplete();
5457 if (d->extra->contents)
5458 d->extra->contents->complete();
5461 if (d->window && d->dirtyAttributes) {
5462 d->addToDirtyList();
5463 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5466#if QT_CONFIG(accessibility)
5467 if (d->isAccessible && d->effectiveVisible) {
5468 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5469 QAccessible::updateAccessibility(&ev);
5474QQuickStateGroup *QQuickItemPrivate::_states()
5478 _stateGroup =
new QQuickStateGroup;
5479 if (!componentComplete)
5480 _stateGroup->classBegin();
5481 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5482 q, QQuickItem, SIGNAL(stateChanged(QString)));
5488bool QQuickItemPrivate::customOverlayRequested =
false;
5490void QQuickItemPrivate::requestCustomOverlay()
5492 customOverlayRequested =
true;
5493 customOverlay =
true;
5496QPointF QQuickItemPrivate::computeTransformOrigin()
const
5500 case QQuickItem::TopLeft:
5501 return QPointF(0, 0);
5502 case QQuickItem::Top:
5503 return QPointF(width / 2., 0);
5504 case QQuickItem::TopRight:
5505 return QPointF(width, 0);
5506 case QQuickItem::Left:
5507 return QPointF(0, height / 2.);
5508 case QQuickItem::Center:
5509 return QPointF(width / 2., height / 2.);
5510 case QQuickItem::Right:
5511 return QPointF(width, height / 2.);
5512 case QQuickItem::BottomLeft:
5513 return QPointF(0, height);
5514 case QQuickItem::Bottom:
5515 return QPointF(width / 2., height);
5516 case QQuickItem::BottomRight:
5517 return QPointF(width, height);
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5539#if QT_CONFIG(quick_shadereffect)
5540 if (q == transformedItem) {
5541 if (extra.isAllocated() && extra->layer)
5542 extra->layer->updateMatrix();
5546 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5548 bool childWantsIt =
false;
5549 if (subtreeTransformChangedEnabled) {
5552 const auto children = paintOrderChildItems();
5553 for (QQuickItem *child : children)
5554 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5557 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5558 const bool ret = childWantsIt || thisWantsIt;
5559 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5560 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5561 subtreeTransformChangedEnabled =
false;
5565 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5566 dirty(QQuickItemPrivate::Clip);
5571 QQuickItemPrivate *itemPriv =
this;
5572 while (itemPriv->parentItem) {
5573 auto *parentPriv = QQuickItemPrivate::get(itemPriv->parentItem);
5574 if (parentPriv->eventHandlingChildrenWithinBounds) {
5575 Q_ASSERT(parentPriv->eventHandlingChildrenWithinBoundsSet);
5576 if (itemPriv->parentFullyContains())
5579 parentPriv->eventHandlingChildrenWithinBounds =
false;
5581 itemPriv = parentPriv;
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5604 const QPointF &startPos,
5605 const QVector2D &activeTranslation,
5608 qreal startRotation,
5609 qreal activeRotation)
5612 QVector3D xformOrigin(q->transformOriginPoint());
5613 QMatrix4x4 startMatrix;
5614 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5615 startMatrix.translate(xformOrigin);
5616 startMatrix.scale(
float(startScale));
5617 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5618 startMatrix.translate(-xformOrigin);
5620 const QVector3D centroidParentVector(centroidParentPos);
5622 mat.translate(centroidParentVector);
5623 mat.rotate(
float(activeRotation), 0, 0, 1);
5624 mat.scale(
float(activeScale));
5625 mat.translate(-centroidParentVector);
5626 mat.translate(QVector3D(activeTranslation));
5628 mat = mat * startMatrix;
5630 QPointF xformOriginPoint = q->transformOriginPoint();
5631 QPointF pos = mat.map(xformOriginPoint);
5632 pos -= xformOriginPoint;
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5662 if (maybeHasSubsceneDeliveryAgent) {
5663 QQuickItemPrivate *p =
this;
5665 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5670 maybeHasSubsceneDeliveryAgent =
false;
5673 if (p->extra.isAllocated()) {
5674 if (
auto da = p->extra->subsceneDeliveryAgent)
5677 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5681 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5684 return QQuickWindowPrivate::get(window)->deliveryAgent;
5688QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5690 auto da = deliveryAgent();
5691 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5695
5696
5697
5698
5699
5700
5701
5702QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5708 maybeHasSubsceneDeliveryAgent =
true;
5709 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5710 return extra->subsceneDeliveryAgent;
5711 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5712 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5715 q->setFlag(QQuickItem::ItemIsFocusScope);
5716 return extra->subsceneDeliveryAgent;
5719bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5721 if (!extra.isAllocated() || !extra->keyHandler)
5727 if (e->type() == QEvent::KeyPress)
5728 extra->keyHandler->keyPressed(e, post);
5730 extra->keyHandler->keyReleased(e, post);
5732 return e->isAccepted();
5735void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5738 const auto eventType = event->type();
5739 const bool focusAccepted = setFocusIfNeeded(eventType);
5741 switch (eventType) {
5742 case QEvent::MouseButtonPress:
5743 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5745 case QEvent::MouseButtonRelease:
5746 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5748 case QEvent::MouseButtonDblClick:
5749 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5751#if QT_CONFIG(wheelevent)
5753 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5756 case QEvent::TouchBegin:
5757 case QEvent::TouchUpdate:
5758 case QEvent::TouchEnd:
5759 case QEvent::TouchCancel:
5760 q->touchEvent(
static_cast<QTouchEvent *>(event));
5770void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5774 Q_ASSERT(e->isAccepted());
5775 if (filterKeyEvent(e,
false))
5780 if (e->type() == QEvent::KeyPress)
5781 q->keyPressEvent(e);
5783 q->keyReleaseEvent(e);
5785 if (e->isAccepted())
5788 if (filterKeyEvent(e,
true) || !q->window())
5792 if (e->type() == QEvent::KeyPress &&
5793 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5795 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5796 if (e->key() == Qt::Key_Backtab
5797 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5798 res = QQuickItemPrivate::focusNextPrev(q,
false);
5799 else if (e->key() == Qt::Key_Tab)
5800 res = QQuickItemPrivate::focusNextPrev(q,
true);
5802 e->setAccepted(
true);
5808void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5812 Q_ASSERT(e->isAccepted());
5813 if (extra.isAllocated() && extra->keyHandler) {
5814 extra->keyHandler->inputMethodEvent(e,
false);
5816 if (e->isAccepted())
5822 q->inputMethodEvent(e);
5824 if (e->isAccepted())
5827 if (extra.isAllocated() && extra->keyHandler) {
5830 extra->keyHandler->inputMethodEvent(e,
true);
5835void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5837 if (extra.isAllocated() && extra->keyHandler)
5838 extra->keyHandler->shortcutOverrideEvent(event);
5843bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5845 if (!hasPointerHandlers())
5847 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5848 if (handler->wantsEventPoint(event, point))
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5870 bool delivered =
false;
5871 if (extra.isAllocated()) {
5872 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5873 bool avoidThisHandler =
false;
5874 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5875 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5876 avoidThisHandler =
true;
5877 }
else if (avoidGrabbers) {
5878 for (
auto &p : event->points()) {
5879 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5880 avoidThisHandler =
true;
5885 if (!avoidThisHandler &&
5886 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5887 handler->handlePointerEvent(event);
5895#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5896bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5898bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5901 if (extra.isAllocated() && extra->contextMenu)
5902 return extra->contextMenu->event(event);
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5922 if (change == ItemSceneChange)
5923 emit windowChanged(value.window);
5928
5929
5930
5931void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5933 if (hasActiveFocus())
5934 QGuiApplication::inputMethod()->update(queries);
5939
5940
5941
5942QRectF QQuickItem::boundingRect()
const
5944 Q_D(
const QQuickItem);
5945 return QRectF(0, 0, d->width, d->height);
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969QRectF QQuickItem::clipRect()
const
5971 Q_D(
const QQuickItem);
5972 QRectF ret(0, 0, d->width.valueBypassingBindings(), d->height.valueBypassingBindings());
5973 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5974 if (QQuickItem *viewport = viewportItem()) {
5977 if (viewport ==
this)
5979 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5980 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5981 return mappedViewportRect.intersected(ret);
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998QQuickItem *QQuickItem::viewportItem()
const
6000 if (flags().testFlag(ItemObservesViewport)) {
6001 QQuickItem *par = parentItem();
6003 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
6005 par = par->parentItem();
6008 return (window() ? window()->contentItem() :
nullptr);
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6033
6034
6035
6036
6037
6038
6039
6040
6041QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6043 Q_D(
const QQuickItem);
6047void QQuickItem::setTransformOrigin(TransformOrigin origin)
6050 if (origin == d->origin())
6053 d->extra.value().origin = origin;
6054 d->dirty(QQuickItemPrivate::TransformOrigin);
6056 emit transformOriginChanged(d->origin());
6060
6061
6062
6064
6065
6066QPointF QQuickItem::transformOriginPoint()
const
6068 Q_D(
const QQuickItem);
6069 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6070 return d->extra->userTransformOriginPoint;
6071 return d->computeTransformOrigin();
6075
6076
6077void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6080 if (d->extra.value().userTransformOriginPoint == point)
6083 d->extra->userTransformOriginPoint = point;
6084 d->dirty(QQuickItemPrivate::TransformOrigin);
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
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
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
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
6241qreal QQuickItem::z()
const
6243 Q_D(
const QQuickItem);
6247void QQuickItem::setZ(qreal v)
6253 d->extra.value().z = v;
6255 d->dirty(QQuickItemPrivate::ZValue);
6256 if (d->parentItem) {
6257 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6258 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6263#if QT_CONFIG(quick_shadereffect)
6264 if (d->extra.isAllocated() && d->extra->layer)
6265 d->extra->layer->updateZ();
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321qreal QQuickItem::rotation()
const
6323 Q_D(
const QQuickItem);
6324 return d->rotation();
6327void QQuickItem::setRotation(qreal r)
6330 if (d->rotation() == r)
6333 d->extra.value().rotation = r;
6335 d->dirty(QQuickItemPrivate::BasicTransform);
6337 d->itemChange(ItemRotationHasChanged, r);
6339 emit rotationChanged();
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421qreal QQuickItem::scale()
const
6423 Q_D(
const QQuickItem);
6427void QQuickItem::setScale(qreal s)
6430 if (d->scale() == s)
6433 d->extra.value().scale = s;
6435 d->dirty(QQuickItemPrivate::BasicTransform);
6437 d->itemChange(ItemScaleHasChanged, s);
6439 emit scaleChanged();
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
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
6552qreal QQuickItem::opacity()
const
6554 Q_D(
const QQuickItem);
6555 return d->opacity();
6558void QQuickItem::setOpacity(qreal newOpacity)
6561 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6562 if (d->opacity() == o)
6565 d->extra.value().opacity = o;
6567 d->dirty(QQuickItemPrivate::OpacityValue);
6569 d->itemChange(ItemOpacityHasChanged, o);
6571 emit opacityChanged();
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638bool QQuickItem::isVisible()
const
6640 Q_D(
const QQuickItem);
6641 return d->effectiveVisible;
6644void QQuickItemPrivate::setVisible(
bool visible)
6646 if (visible == explicitVisible)
6649 explicitVisible = visible;
6651 dirty(QQuickItemPrivate::Visible);
6653 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6654 if (childVisibilityChanged && parentItem)
6655 emit parentItem->visibleChildrenChanged();
6658void QQuickItem::setVisible(
bool v)
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713bool QQuickItem::isEnabled()
const
6715 Q_D(
const QQuickItem);
6716 return d->effectiveEnable;
6719void QQuickItem::setEnabled(
bool e)
6722 if (e == d->explicitEnable)
6725 d->explicitEnable = e;
6727 QQuickItem *scope = parentItem();
6728 while (scope && !scope->isFocusScope())
6729 scope = scope->parentItem();
6731 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6734bool QQuickItemPrivate::calcEffectiveVisible()
const
6737 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6740bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6744 if (newEffectiveVisible && !explicitVisible) {
6749 if (newEffectiveVisible == effectiveVisible) {
6754 effectiveVisible = newEffectiveVisible;
6757 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6759 if (
auto agent = deliveryAgentPrivate())
6760 agent->removeGrabber(q,
true,
true,
true);
6763 bool childVisibilityChanged =
false;
6764 for (
int ii = 0; ii < childItems.size(); ++ii)
6765 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6767 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6768#if QT_CONFIG(accessibility)
6770 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6771 QAccessible::updateAccessibility(&ev);
6774 if (!inDestructor) {
6775 emit q->visibleChanged();
6776 if (childVisibilityChanged)
6777 emit q->visibleChildrenChanged();
6783bool QQuickItemPrivate::calcEffectiveEnable()
const
6788 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6791void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6795 if (newEffectiveEnable && !explicitEnable) {
6800 if (newEffectiveEnable == effectiveEnable) {
6805 effectiveEnable = newEffectiveEnable;
6807 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6809 da->removeGrabber(q,
true,
true,
true);
6810 if (scope && !effectiveEnable && activeFocus) {
6811 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6812 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6813 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6817 for (
int ii = 0; ii < childItems.size(); ++ii) {
6818 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6819 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6822 if (scope && effectiveEnable && focus && da) {
6823 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6824 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6825 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6828 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6829#if QT_CONFIG(accessibility)
6831 QAccessible::State changedState;
6832 changedState.disabled =
true;
6833 changedState.focusable =
true;
6834 QAccessibleStateChangeEvent ev(q, changedState);
6835 QAccessible::updateAccessibility(&ev);
6838 emit q->enabledChanged();
6842
6843
6844
6845qreal QQuickItemPrivate::biggestPointerHandlerMargin()
const
6847 if (hasPointerHandlers()) {
6848 if (extra->biggestPointerHandlerMarginCache < 0) {
6849 const auto maxMarginIt = std::max_element(extra->pointerHandlers.constBegin(),
6850 extra->pointerHandlers.constEnd(),
6851 [](
const QQuickPointerHandler *a,
const QQuickPointerHandler *b) {
6852 return a->margin() < b->margin(); });
6853 Q_ASSERT(maxMarginIt != extra->pointerHandlers.constEnd());
6854 extra->biggestPointerHandlerMarginCache = (*maxMarginIt)->margin();
6856 return extra->biggestPointerHandlerMarginCache;
6862
6863
6864
6865
6866
6867
6868QRectF QQuickItemPrivate::eventHandlingBounds(qreal margin)
const
6870 const qreal biggestMargin = margin > 0 ? margin : biggestPointerHandlerMargin();
6871 return QRectF(-biggestMargin, -biggestMargin, width + biggestMargin * 2, height + biggestMargin * 2);
6875
6876
6877
6878bool QQuickItemPrivate::parentFullyContains()
const
6880 Q_Q(
const QQuickItem);
6884 itemToParentTransform(&t);
6885 const auto bounds = eventHandlingBounds();
6886 const auto boundsInParent = t.mapRect(bounds);
6887 const bool ret = parentItem->clipRect().contains(boundsInParent);
6888 qCDebug(lcEffClip) <<
"in parent bounds?" << ret << q << boundsInParent << parentItem << parentItem->clipRect();
6893
6894
6895
6896bool QQuickItemPrivate::effectivelyClipsEventHandlingChildren()
const
6898 Q_Q(
const QQuickItem);
6900 if (flags & QQuickItem::ItemClipsChildrenToShape) {
6901 qCDebug(lcEffClip) << q <<
"result: true because clip is true";
6904 if (!eventHandlingChildrenWithinBoundsSet) {
6906 eventHandlingChildrenWithinBounds =
true;
6907 for (
const auto *child : childItems) {
6908 const auto *childPriv = QQuickItemPrivate::get(child);
6912 if (childPriv->childItems.isEmpty() &&
6913 !(childPriv->hoverEnabled || childPriv->subtreeHoverEnabled || childPriv->touchEnabled ||
6914 childPriv->hasCursor || childPriv->hasCursorHandler || child->acceptedMouseButtons() ||
6915 childPriv->hasPointerHandlers())) {
6916 qCDebug(lcEffClip) << child <<
"doesn't handle pointer events";
6919 if (!childPriv->parentFullyContains()) {
6920 eventHandlingChildrenWithinBounds =
false;
6921 qCDebug(lcEffClip) <<
"child goes outside: giving up" << child;
6924 if (!childPriv->eventHandlingChildrenWithinBoundsSet) {
6925 eventHandlingChildrenWithinBounds = childPriv->effectivelyClipsEventHandlingChildren();
6926 if (!eventHandlingChildrenWithinBounds)
6927 qCDebug(lcEffClip) <<
"child has children that go outside: giving up" << child;
6930#ifdef QT_BUILD_INTERNAL
6931 if (!eventHandlingChildrenWithinBoundsSet && eventHandlingChildrenWithinBounds)
6932 ++eventHandlingChildrenWithinBounds_counter;
6935 eventHandlingChildrenWithinBoundsSet =
true;
6936 qCDebug(lcEffClip) << q << q->clipRect() <<
"result:" <<
static_cast<
bool>(eventHandlingChildrenWithinBounds);
6938 return eventHandlingChildrenWithinBounds;
6941bool QQuickItemPrivate::isTransparentForPositioner()
const
6943 return extra.isAllocated() && extra.value().transparentForPositioner;
6946void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6948 extra.value().transparentForPositioner = transparent;
6952QString QQuickItemPrivate::dirtyToString()
const
6954#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6956 rv.append(QLatin1Char('|'));
6957 rv.append(QLatin1String(#value)); \
6958}
6985void QQuickItemPrivate::dirty(DirtyType type)
6988 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6989 dirtyAttributes |= type;
6990 if (window && componentComplete) {
6992 QQuickWindowPrivate::get(window)->dirtyItem(q,
true);
6995 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6996 transformChanged(q);
6999void QQuickItemPrivate::addToDirtyList()
7004 if (!prevDirtyItem) {
7005 Q_ASSERT(!nextDirtyItem);
7007 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
7008 nextDirtyItem = p->dirtyItemList;
7009 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
7010 prevDirtyItem = &p->dirtyItemList;
7011 p->dirtyItemList = q;
7012 p->dirtyItem(q,
true);
7014 Q_ASSERT(prevDirtyItem);
7017void QQuickItemPrivate::removeFromDirtyList()
7019 if (prevDirtyItem) {
7020 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
7021 *prevDirtyItem = nextDirtyItem;
7022 prevDirtyItem =
nullptr;
7023 nextDirtyItem =
nullptr;
7025 Q_ASSERT(!prevDirtyItem);
7026 Q_ASSERT(!nextDirtyItem);
7029void QQuickItemPrivate::refFromEffectItem(
bool hide)
7031 ++extra.value().effectRefCount;
7032 if (extra->effectRefCount == 1) {
7033 dirty(EffectReference);
7035 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7038 if (++extra->hideRefCount == 1)
7039 dirty(HideReference);
7041 recursiveRefFromEffectItem(1);
7044void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
7049 extra.value().recursiveEffectRefCount += refs;
7050 for (
int ii = 0; ii < childItems.size(); ++ii) {
7051 QQuickItem *child = childItems.at(ii);
7052 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
7056 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
7060void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
7062 Q_ASSERT(extra->effectRefCount);
7063 --extra->effectRefCount;
7064 if (extra->effectRefCount == 0) {
7065 dirty(EffectReference);
7067 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7070 if (--extra->hideRefCount == 0)
7071 dirty(HideReference);
7073 recursiveRefFromEffectItem(-1);
7076void QQuickItemPrivate::setCulled(
bool cull)
7082 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
7083 dirty(HideReference);
7086void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
7090 case QQuickItem::ItemChildAddedChange: {
7091 q->itemChange(change, data);
7097 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
7098 if (!subtreeTransformChangedEnabled) {
7099 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
7100 subtreeTransformChangedEnabled =
true;
7102 enableSubtreeChangeNotificationsForParentHierachy();
7104 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
7107 case QQuickItem::ItemChildRemovedChange: {
7108 q->itemChange(change, data);
7109 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
7112 case QQuickItem::ItemSceneChange:
7113 q->itemChange(change, data);
7115 case QQuickItem::ItemVisibleHasChanged: {
7116 q->itemChange(change, data);
7117 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
7120 case QQuickItem::ItemEnabledHasChanged: {
7121 q->itemChange(change, data);
7122 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
7125 case QQuickItem::ItemParentHasChanged: {
7126 q->itemChange(change, data);
7127 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
7130 case QQuickItem::ItemOpacityHasChanged: {
7131 q->itemChange(change, data);
7132 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
7135 case QQuickItem::ItemActiveFocusHasChanged:
7136 q->itemChange(change, data);
7138 case QQuickItem::ItemRotationHasChanged: {
7139 q->itemChange(change, data);
7140 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7143 case QQuickItem::ItemScaleHasChanged: {
7144 q->itemChange(change, data);
7145 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7148 case QQuickItem::ItemTransformHasChanged: {
7149 q->itemChange(change, data);
7150 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7153 case QQuickItem::ItemAntialiasingHasChanged:
7155 case QQuickItem::ItemDevicePixelRatioHasChanged:
7156 q->itemChange(change, data);
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184bool QQuickItem::smooth()
const
7186 Q_D(
const QQuickItem);
7189void QQuickItem::setSmooth(
bool smooth)
7192 if (d->smooth == smooth)
7196 d->dirty(QQuickItemPrivate::Smooth);
7198 emit smoothChanged(smooth);
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7240bool QQuickItem::activeFocusOnTab()
const
7242 Q_D(
const QQuickItem);
7243 return d->activeFocusOnTab;
7245void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7248 if (d->activeFocusOnTab == activeFocusOnTab)
7252 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7253 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7258 d->activeFocusOnTab = activeFocusOnTab;
7260 emit activeFocusOnTabChanged(activeFocusOnTab);
7264
7265
7266
7267
7268
7269
7270
7271
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282bool QQuickItem::antialiasing()
const
7284 Q_D(
const QQuickItem);
7285 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7288void QQuickItem::setAntialiasing(
bool aa)
7292 if (!d->antialiasingValid) {
7293 d->antialiasingValid =
true;
7294 d->antialiasing = d->implicitAntialiasing;
7297 if (aa == d->antialiasing)
7300 d->antialiasing = aa;
7301 d->dirty(QQuickItemPrivate::Antialiasing);
7303 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7305 emit antialiasingChanged(antialiasing());
7308void QQuickItem::resetAntialiasing()
7311 if (!d->antialiasingValid)
7314 d->antialiasingValid =
false;
7316 if (d->implicitAntialiasing != d->antialiasing)
7317 emit antialiasingChanged(antialiasing());
7320void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7323 bool prev = q->antialiasing();
7324 implicitAntialiasing = antialiasing;
7325 if (componentComplete && (q->antialiasing() != prev))
7326 emit q->antialiasingChanged(q->antialiasing());
7330
7331
7332
7333
7334QQuickItem::Flags QQuickItem::flags()
const
7336 Q_D(
const QQuickItem);
7337 return (QQuickItem::Flags)d->flags;
7341
7342
7343
7344
7345
7346
7347
7348void QQuickItem::setFlag(Flag flag,
bool enabled)
7352 setFlags((Flags)(d->flags | (quint32)flag));
7354 setFlags((Flags)(d->flags & ~(quint32)flag));
7358 if (enabled && flag == ItemObservesViewport)
7359 d->enableSubtreeChangeNotificationsForParentHierachy();
7362void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7366 QQuickItem *par = q->parentItem();
7368 auto parPriv = QQuickItemPrivate::get(par);
7369 if (!parPriv->subtreeTransformChangedEnabled)
7370 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7371 parPriv->subtreeTransformChangedEnabled =
true;
7372 par = par->parentItem();
7377
7378
7379
7380
7381void QQuickItem::setFlags(Flags flags)
7385 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7386 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7387 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7388 flags &= ~ItemIsFocusScope;
7389 }
else if (d->flags & ItemIsFocusScope) {
7390 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7391 flags |= ItemIsFocusScope;
7395 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7396 d->dirty(QQuickItemPrivate::Clip);
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7417
7418
7419
7420
7422
7423
7424
7425
7426qreal QQuickItem::x()
const
7428 Q_D(
const QQuickItem);
7432qreal QQuickItem::y()
const
7434 Q_D(
const QQuickItem);
7439
7440
7441QPointF QQuickItem::position()
const
7443 Q_D(
const QQuickItem);
7444 return QPointF(d->x, d->y);
7447void QQuickItem::setX(qreal v)
7451
7452
7453
7454
7455
7456
7457
7458
7459 d->x.removeBindingUnlessInWrapper();
7463 const qreal oldx = d->x.valueBypassingBindings();
7467 d->x.setValueBypassingBindings(v);
7469 d->dirty(QQuickItemPrivate::Position);
7471 const qreal y = d->y.valueBypassingBindings();
7472 const qreal w = d->width.valueBypassingBindings();
7473 const qreal h = d->height.valueBypassingBindings();
7474 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7477void QQuickItem::setY(qreal v)
7480 d->y.removeBindingUnlessInWrapper();
7484 const qreal oldy = d->y.valueBypassingBindings();
7488 d->y.setValueBypassingBindings(v);
7490 d->dirty(QQuickItemPrivate::Position);
7494 const qreal x = d->x.valueBypassingBindings();
7495 const qreal w = d->width.valueBypassingBindings();
7496 const qreal h = d->height.valueBypassingBindings();
7497 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7501
7502
7503void QQuickItem::setPosition(
const QPointF &pos)
7507 const qreal oldx = d->x.valueBypassingBindings();
7508 const qreal oldy = d->y.valueBypassingBindings();
7510 if (QPointF(oldx, oldy) == pos)
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7526 d->x.setValueBypassingBindings(pos.x());
7527 d->y.setValueBypassingBindings(pos.y());
7529 d->dirty(QQuickItemPrivate::Position);
7531 const qreal w = d->width.valueBypassingBindings();
7532 const qreal h = d->height.valueBypassingBindings();
7533 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7537
7538
7539QBindable<qreal> QQuickItem::bindableX()
7541 return QBindable<qreal>(&d_func()->x);
7544QBindable<qreal> QQuickItem::bindableY()
7546 return QBindable<qreal>(&d_func()->y);
7550
7551
7552
7553
7554qreal QQuickItem::width()
const
7556 Q_D(
const QQuickItem);
7560void QQuickItem::setWidth(qreal w)
7563 d->width.removeBindingUnlessInWrapper();
7567 d->widthValidFlag =
true;
7568 const qreal oldWidth = d->width.valueBypassingBindings();
7572 d->width.setValueBypassingBindings(w);
7574 d->dirty(QQuickItemPrivate::Size);
7576 const qreal x = d->x.valueBypassingBindings();
7577 const qreal y = d->y.valueBypassingBindings();
7578 const qreal h = d->height.valueBypassingBindings();
7579 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7582void QQuickItem::resetWidth()
7585 d->width.takeBinding();
7586 d->widthValidFlag =
false;
7587 setImplicitWidth(implicitWidth());
7590void QQuickItemPrivate::implicitWidthChanged()
7593 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7594 emit q->implicitWidthChanged();
7597qreal QQuickItemPrivate::getImplicitWidth()
const
7599 return implicitWidth;
7602
7603
7604qreal QQuickItem::implicitWidth()
const
7606 Q_D(
const QQuickItem);
7607 return d->getImplicitWidth();
7610QBindable<qreal> QQuickItem::bindableWidth()
7612 return QBindable<qreal>(&d_func()->width);
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697void QQuickItem::setImplicitWidth(qreal w)
7700 bool changed = w != d->implicitWidth;
7701 d->implicitWidth = w;
7703 if (d->width.valueBypassingBindings() == w || widthValid()) {
7705 d->implicitWidthChanged();
7706 if (d->width.valueBypassingBindings() == w || widthValid())
7711 const qreal oldWidth = d->width.valueBypassingBindings();
7712 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7714 d->width.setValueBypassingBindings(w);
7716 d->dirty(QQuickItemPrivate::Size);
7718 const qreal x = d->x.valueBypassingBindings();
7719 const qreal y = d->y.valueBypassingBindings();
7720 const qreal width = w;
7721 const qreal height = d->height.valueBypassingBindings();
7722 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7725 d->implicitWidthChanged();
7729
7730
7731bool QQuickItem::widthValid()
const
7733 Q_D(
const QQuickItem);
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7751 return d->widthValid();
7755
7756
7757
7758
7759qreal QQuickItem::height()
const
7761 Q_D(
const QQuickItem);
7765void QQuickItem::setHeight(qreal h)
7771 d->height.removeBindingUnlessInWrapper();
7775 d->heightValidFlag =
true;
7776 const qreal oldHeight = d->height.valueBypassingBindings();
7780 d->height.setValueBypassingBindings(h);
7782 d->dirty(QQuickItemPrivate::Size);
7784 const qreal x = d->x.valueBypassingBindings();
7785 const qreal y = d->y.valueBypassingBindings();
7786 const qreal w = d->width.valueBypassingBindings();
7787 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7790void QQuickItem::resetHeight()
7796 d->height.takeBinding();
7797 d->heightValidFlag =
false;
7798 setImplicitHeight(implicitHeight());
7801void QQuickItemPrivate::implicitHeightChanged()
7804 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7805 emit q->implicitHeightChanged();
7808qreal QQuickItemPrivate::getImplicitHeight()
const
7810 return implicitHeight;
7813qreal QQuickItem::implicitHeight()
const
7815 Q_D(
const QQuickItem);
7816 return d->getImplicitHeight();
7819QBindable<qreal> QQuickItem::bindableHeight()
7821 return QBindable<qreal>(&d_func()->height);
7824void QQuickItem::setImplicitHeight(qreal h)
7827 bool changed = h != d->implicitHeight;
7828 d->implicitHeight = h;
7829 if (d->height.valueBypassingBindings() == h || heightValid()) {
7831 d->implicitHeightChanged();
7832 if (d->height.valueBypassingBindings() == h || heightValid())
7837 const qreal oldHeight = d->height.valueBypassingBindings();
7838 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7840 d->height.setValueBypassingBindings(h);
7842 d->dirty(QQuickItemPrivate::Size);
7844 const qreal x = d->x.valueBypassingBindings();
7845 const qreal y = d->y.valueBypassingBindings();
7846 const qreal width = d->width.valueBypassingBindings();
7847 const qreal height = d->height.valueBypassingBindings();
7848 geometryChange(QRectF(x, y, width, height),
7849 QRectF(x, y, width, oldHeight));
7852 d->implicitHeightChanged();
7856
7857
7858void QQuickItem::setImplicitSize(qreal w, qreal h)
7861 bool wChanged = w != d->implicitWidth;
7862 bool hChanged = h != d->implicitHeight;
7864 d->implicitWidth = w;
7865 d->implicitHeight = h;
7869 qreal width = d->width.valueBypassingBindings();
7870 qreal height = d->height.valueBypassingBindings();
7871 if (width == w || widthValid()) {
7873 d->implicitWidthChanged();
7874 wDone = width == w || widthValid();
7877 if (height == h || heightValid()) {
7879 d->implicitHeightChanged();
7880 hDone = height == h || heightValid();
7886 const qreal oldWidth = width;
7887 const qreal oldHeight = height;
7890 d->width.setValueBypassingBindings(w);
7894 d->height.setValueBypassingBindings(h);
7897 d->dirty(QQuickItemPrivate::Size);
7899 const qreal x = d->x.valueBypassingBindings();
7900 const qreal y = d->y.valueBypassingBindings();
7901 geometryChange(QRectF(x, y, width, height),
7902 QRectF(x, y, oldWidth, oldHeight));
7904 if (!wDone && wChanged)
7905 d->implicitWidthChanged();
7906 if (!hDone && hChanged)
7907 d->implicitHeightChanged();
7911
7912
7913bool QQuickItem::heightValid()
const
7915 Q_D(
const QQuickItem);
7916 return d->heightValid();
7920
7921
7922
7923
7924
7925
7927QSizeF QQuickItem::size()
const
7929 Q_D(
const QQuickItem);
7930 return QSizeF(d->width, d->height);
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944void QQuickItem::setSize(
const QSizeF &size)
7947 d->heightValidFlag =
true;
7948 d->widthValidFlag =
true;
7950 const qreal oldHeight = d->height.valueBypassingBindings();
7951 const qreal oldWidth = d->width.valueBypassingBindings();
7953 if (oldWidth == size.width() && oldHeight == size.height())
7956 d->height.setValueBypassingBindings(size.height());
7957 d->width.setValueBypassingBindings(size.width());
7959 d->dirty(QQuickItemPrivate::Size);
7961 const qreal x = d->x.valueBypassingBindings();
7962 const qreal y = d->y.valueBypassingBindings();
7963 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035bool QQuickItem::hasActiveFocus()
const
8037 Q_D(
const QQuickItem);
8038 return d->activeFocus;
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129bool QQuickItem::hasFocus()
const
8131 Q_D(
const QQuickItem);
8135void QQuickItem::setFocus(
bool focus)
8137 setFocus(focus, Qt::OtherFocusReason);
8140void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8144 QQuickItem *scope = parentItem();
8145 while (scope && !scope->isFocusScope() && scope->parentItem())
8146 scope = scope->parentItem();
8148 if (d->focus == focus && d->activeFocus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8151 bool notifyListeners =
false;
8152 if (d->window || d->parentItem) {
8154 auto da = d->deliveryAgentPrivate();
8157 da->setFocusInScope(scope,
this, reason);
8159 da->clearFocusInScope(scope,
this, reason);
8163 QVarLengthArray<QQuickItem *, 20> changed;
8164 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8165 if (oldSubFocusItem) {
8166 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8167 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8168 changed << oldSubFocusItem;
8169 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8170 QQuickItemPrivate::get(scope)->focus =
false;
8173 d->updateSubFocusItem(scope, focus);
8177 notifyListeners =
true;
8178 emit focusChanged(focus);
8180 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8183 QVarLengthArray<QQuickItem *, 20> changed;
8184 QQuickItem *oldSubFocusItem = d->subFocusItem;
8185 if (!isFocusScope() && oldSubFocusItem) {
8186 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8187 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8188 changed << oldSubFocusItem;
8193 notifyListeners =
true;
8194 emit focusChanged(focus);
8196 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8198 if (notifyListeners)
8199 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8203
8204
8205bool QQuickItem::isFocusScope()
const
8207 return flags() & ItemIsFocusScope;
8211
8212
8213
8214
8215
8216QQuickItem *QQuickItem::scopedFocusItem()
const
8218 Q_D(
const QQuickItem);
8219 if (!isFocusScope())
8222 return d->subFocusItem;
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8240
8241
8242
8243
8244
8245
8246Qt::FocusPolicy QQuickItem::focusPolicy()
const
8248 Q_D(
const QQuickItem);
8249 uint policy = d->focusPolicy;
8250 if (activeFocusOnTab())
8251 policy |= Qt::TabFocus;
8252 return static_cast<Qt::FocusPolicy>(policy);
8256
8257
8258
8259
8260void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8263 if (d->focusPolicy == policy)
8266 d->focusPolicy = policy;
8267 setActiveFocusOnTab(policy & Qt::TabFocus);
8268 emit focusPolicyChanged(policy);
8272
8273
8274
8275
8276
8277
8278
8279bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8281 if (!child || child ==
this)
8283 const QQuickItem *ancestor = child;
8284 while ((ancestor = ancestor->parentItem())) {
8285 if (ancestor ==
this)
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8304 Q_D(
const QQuickItem);
8305 return d->acceptedMouseButtons();
8309
8310
8311
8312
8313
8314
8315
8316
8317void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8320 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8322 buttons &= ~Qt::LeftButton;
8323 if (buttons || d->extra.isAllocated()) {
8324 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8325 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340bool QQuickItem::filtersChildMouseEvents()
const
8342 Q_D(
const QQuickItem);
8343 return d->filtersChildMouseEvents;
8347
8348
8349
8350
8351
8352
8353
8354
8355void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8358 d->filtersChildMouseEvents = filter;
8362
8363
8364bool QQuickItem::isUnderMouse()
const
8366 Q_D(
const QQuickItem);
8373 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8376 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8377 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8381
8382
8383
8384
8385
8386
8387
8388bool QQuickItem::acceptHoverEvents()
const
8390 Q_D(
const QQuickItem);
8391 return d->hoverEnabled;
8395
8396
8397
8398
8399
8400void QQuickItem::setAcceptHoverEvents(
bool enabled)
8407 d->hoverEnabled = enabled;
8413 d->setHasHoverInChild(enabled);
8417 d->dirty(QQuickItemPrivate::Content);
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430bool QQuickItem::acceptTouchEvents()
const
8432 Q_D(
const QQuickItem);
8433 return d->touchEnabled;
8437
8438
8439
8440
8441
8442
8443
8444void QQuickItem::setAcceptTouchEvents(
bool enabled)
8447 d->touchEnabled = enabled;
8450void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8452#if QT_CONFIG(cursor)
8457 if (!hc && subtreeCursorEnabled) {
8458 if (hasCursor || hasCursorHandler)
8460 for (QQuickItem *otherChild : std::as_const(childItems)) {
8461 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8462 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8467 subtreeCursorEnabled = hc;
8468 QQuickItem *parent = q->parentItem();
8470 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8471 parentPrivate->setHasCursorInChild(hc);
8478void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8484 if (!hasHover && subtreeHoverEnabled) {
8487 if (hasEnabledHoverHandlers())
8490 for (QQuickItem *otherChild : std::as_const(childItems)) {
8491 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8492 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8494 if (otherChildPrivate->hasEnabledHoverHandlers())
8499 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8500 subtreeHoverEnabled = hasHover;
8501 QQuickItem *parent = q->parentItem();
8503 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8504 parentPrivate->setHasHoverInChild(hasHover);
8508#if QT_CONFIG(cursor)
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8524QCursor QQuickItem::cursor()
const
8526 Q_D(
const QQuickItem);
8527 return d->extra.isAllocated()
8533
8534
8535
8536
8538void QQuickItem::setCursor(
const QCursor &cursor)
8542 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8543 qCDebug(lcHoverCursor) << oldShape <<
"->" << cursor.shape();
8545 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8546 d->extra.value().cursor = cursor;
8548 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8549 QWindow *window = renderWindow ? renderWindow : d->window;
8550 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8551 window->setCursor(cursor);
8555 QPointF updateCursorPos;
8556 if (!d->hasCursor) {
8557 d->hasCursor =
true;
8559 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8560 QWindow *window = renderWindow ? renderWindow : d->window;
8561 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8562 if (contains(mapFromScene(pos)))
8563 updateCursorPos = pos;
8566 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8567 if (!updateCursorPos.isNull())
8568 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8572
8573
8574
8575
8577void QQuickItem::unsetCursor()
8580 qCDebug(lcHoverTrace) <<
"clearing cursor";
8583 d->hasCursor =
false;
8584 d->setHasCursorInChild(d->hasCursorHandler);
8585 if (d->extra.isAllocated())
8586 d->extra->cursor = QCursor();
8589 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8590 if (windowPrivate->cursorItem ==
this) {
8591 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8592 windowPrivate->updateCursor(pos);
8598
8599
8600
8601
8602
8603
8604QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8606 Q_Q(
const QQuickItem);
8609 bool hoverCursorSet =
false;
8610 QCursor hoverCursor;
8611 bool activeCursorSet =
false;
8612 QCursor activeCursor;
8613 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8614 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8615 hoverCursor = hoverHandler->cursorShape();
8616 }
else if (handler->active()) {
8617 activeCursorSet = handler->isCursorShapeExplicitlySet();
8618 activeCursor = handler->cursorShape();
8620 if (activeCursorSet)
8621 return activeCursor;
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8649 if (!hasPointerHandlers())
8651 QQuickPointerHandler* activeHandler =
nullptr;
8652 QQuickPointerHandler* mouseHandler =
nullptr;
8653 QQuickPointerHandler* nonMouseHandler =
nullptr;
8654 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8655 if (!h->isCursorShapeExplicitlySet())
8657 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8662 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8663 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8664 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8666 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8667 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8668 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8670 mouseHandler = hoverHandler;
8673 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8674 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8675 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8677 nonMouseHandler = hoverHandler;
8680 if (!hoverHandler && h->active())
8683 if (activeHandler) {
8684 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8685 return activeHandler;
8691 if (nonMouseHandler) {
8693 const bool beforeTimeout =
8694 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8695 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8696 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8697 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8698 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8699 <<
"choosing cursor according to" << winner << winner->cursorShape();
8702 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8703 return nonMouseHandler;
8706 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8707 return mouseHandler;
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726void QQuickItem::grabMouse()
8731 auto da = d->deliveryAgentPrivate();
8733 auto eventInDelivery = da->eventInDelivery();
8734 if (!eventInDelivery) {
8735 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8738 auto epd = da->mousePointData();
8739 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753void QQuickItem::ungrabMouse()
8758 auto da = d->deliveryAgentPrivate();
8760 auto eventInDelivery = da->eventInDelivery();
8761 if (!eventInDelivery) {
8763 da->removeGrabber(
this);
8766 const auto &eventPoint = da->mousePointData()->eventPoint;
8767 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8768 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8772
8773
8774
8775
8776bool QQuickItem::keepMouseGrab()
const
8778 Q_D(
const QQuickItem);
8779 return d->keepMouse;
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798void QQuickItem::setKeepMouseGrab(
bool keep)
8801 d->keepMouse = keep;
8805
8806
8807
8808
8809
8810
8811
8812
8813void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8816 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8817 if (Q_UNLIKELY(!event)) {
8818 qWarning() <<
"cannot grab: no event is currently being delivered";
8821 for (
auto pt : event->points()) {
8822 if (ids.contains(pt.id()))
8823 event->setExclusiveGrabber(pt,
this);
8828
8829
8830
8831void QQuickItem::ungrabTouchPoints()
8836 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8837 da->removeGrabber(
this,
false,
true);
8841
8842
8843
8844
8845
8846bool QQuickItem::keepTouchGrab()
const
8848 Q_D(
const QQuickItem);
8849 return d->keepTouch;
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869void QQuickItem::setKeepTouchGrab(
bool keep)
8872 d->keepTouch = keep;
8876
8877
8878
8879
8880
8881
8882
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894bool QQuickItem::contains(
const QPointF &point)
const
8896 Q_D(
const QQuickItem);
8897 if (d->extra.isAllocated() && d->extra->mask) {
8898 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8899 return quickMask->contains(point - quickMask->position());
8902 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8903 maskContains.invoke(d->extra->mask,
8904 Qt::DirectConnection,
8905 Q_RETURN_ARG(
bool, res),
8906 Q_ARG(QPointF, point));
8910 qreal x = point.x();
8911 qreal y = point.y();
8912 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978QObject *QQuickItem::containmentMask()
const
8980 Q_D(
const QQuickItem);
8981 if (!d->extra.isAllocated())
8983 return d->extra->mask.data();
8986void QQuickItem::setContainmentMask(QObject *mask)
8989 const bool extraDataExists = d->extra.isAllocated();
8991 if (mask ==
static_cast<QObject *>(
this))
8994 if (!extraDataExists && !mask)
8997 if (extraDataExists && d->extra->mask == mask)
9000 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
9003 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9004 maskPrivate->registerAsContainmentMask(
this,
false);
9007 if (!extraDataExists)
9010 int methodIndex = mask->metaObject()->indexOfMethod(
"contains(QPointF)");
9011 if (methodIndex < 0) {
9012 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
9015 d->extra->maskContainsIndex = methodIndex;
9017 d->extra->mask = mask;
9018 quickMask = qobject_cast<QQuickItem *>(mask);
9020 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9021 maskPrivate->registerAsContainmentMask(
this,
true);
9023 emit containmentMaskChanged();
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
9040 QPointF p = mapToScene(point);
9042 const auto *itemWindow = item->window();
9043 const auto *thisWindow = window();
9044 if (thisWindow && itemWindow && itemWindow != thisWindow)
9045 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
9047 p = item->mapFromScene(p);
9053
9054
9055
9056
9057
9058
9059
9060
9061QPointF QQuickItem::mapToScene(
const QPointF &point)
const
9063 Q_D(
const QQuickItem);
9064 return d->itemToWindowTransform().map(point);
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
9086 Q_D(
const QQuickItem);
9088 if (Q_UNLIKELY(d->window ==
nullptr))
9089 return mapToScene(point);
9091 QPoint renderOffset;
9092 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9093 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9094 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
9111 Q_D(
const QQuickItem);
9112 QTransform t = d->itemToWindowTransform();
9114 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
9115 return t.mapRect(rect);
9119
9120
9121
9122
9123
9124
9125
9126
9127QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
9129 Q_D(
const QQuickItem);
9130 return d->itemToWindowTransform().mapRect(rect);
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9149 p = item->mapToScene(point);
9150 const auto *itemWindow = item->window();
9151 const auto *thisWindow = window();
9152 if (thisWindow && itemWindow && itemWindow != thisWindow)
9153 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9155 return mapFromScene(p);
9159
9160
9161
9162
9163
9164
9165
9166
9167QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9169 Q_D(
const QQuickItem);
9170 return d->windowToItemTransform().map(point);
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9198 Q_D(
const QQuickItem);
9201 if (Q_LIKELY(d->window)) {
9202 QPoint renderOffset;
9203 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9204 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9205 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9210 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9211 if (
auto sceneTransform = da->sceneTransform())
9212 scenePoint = sceneTransform->map(scenePoint);
9214 return mapFromScene(scenePoint);
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9231 Q_D(
const QQuickItem);
9232 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9233 t *= d->windowToItemTransform();
9234 return t.mapRect(rect);
9238
9239
9240
9241
9242
9243
9244
9245
9246QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9248 Q_D(
const QQuickItem);
9249 return d->windowToItemTransform().mapRect(rect);
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318int QQuickItem::mutabilityGroup()
const
9320 Q_D(
const QQuickItem);
9321 if (d->extra.isAllocated())
9322 return d->extra->mutabilityGroup;
9323 return int(QQuickItem::AutoMutabilityGroup);
9326void QQuickItem::setMutabilityGroup(
int mutabilityGroup)
9330 const int clampedGroup = qBound(
int(AutoMutabilityGroup),
9332 int(DynamicMutabilityGroup));
9333 if (Q_UNLIKELY(clampedGroup != mutabilityGroup)) {
9334 qCDebug(QSG_LOG_RENDERLOOP) <<
"QQuickItem::setMutabilityGroup: Invalid group"
9340 if (clampedGroup ==
this->mutabilityGroup())
9343 d->extra.value().mutabilityGroup = clampedGroup;
9344 d->extra.value().mutabilityGroupSet =
true;
9345 d->dirty(QQuickItemPrivate::Content);
9346 emit mutabilityGroupChanged();
9350
9351
9352
9355
9356
9357
9360
9361
9362
9365
9366
9367
9370
9371
9372
9375
9376
9377
9380
9381
9382
9385
9386
9387
9390
9391
9392
9395
9396
9397
9400
9401
9402bool QQuickItem::event(QEvent *ev)
9406 switch (ev->type()) {
9408 case QEvent::InputMethodQuery: {
9409 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9410 Qt::InputMethodQueries queries = query->queries();
9411 for (uint i = 0; i < 32; ++i) {
9412 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9414 QVariant v = inputMethodQuery(q);
9415 query->setValue(q, v);
9421 case QEvent::InputMethod:
9422 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9425 case QEvent::TouchBegin:
9426 case QEvent::TouchUpdate:
9427 case QEvent::TouchEnd:
9428 case QEvent::TouchCancel:
9429 case QEvent::MouseButtonPress:
9430 case QEvent::MouseButtonRelease:
9431 case QEvent::MouseButtonDblClick:
9432#if QT_CONFIG(wheelevent)
9435 d->deliverPointerEvent(ev);
9437 case QEvent::StyleAnimationUpdate:
9443 case QEvent::HoverEnter:
9444 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9446 case QEvent::HoverLeave:
9447 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9449 case QEvent::HoverMove:
9450 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9452 case QEvent::KeyPress:
9453 case QEvent::KeyRelease:
9454 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9456 case QEvent::ShortcutOverride:
9457 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9459 case QEvent::FocusIn:
9460 focusInEvent(
static_cast<QFocusEvent*>(ev));
9462 case QEvent::FocusOut:
9463 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9465 case QEvent::MouseMove:
9466 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9468#if QT_CONFIG(quick_draganddrop)
9469 case QEvent::DragEnter:
9470 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9472 case QEvent::DragLeave:
9473 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9475 case QEvent::DragMove:
9476 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9479 dropEvent(
static_cast<QDropEvent*>(ev));
9482#if QT_CONFIG(gestures)
9483 case QEvent::NativeGesture:
9487 case QEvent::LanguageChange:
9488 case QEvent::LocaleChange:
9489 for (QQuickItem *item : std::as_const(d->childItems))
9490 QCoreApplication::sendEvent(item, ev);
9492 case QEvent::WindowActivate:
9493 case QEvent::WindowDeactivate:
9494 if (d->providesPalette())
9495 d->setCurrentColorGroup();
9496 for (QQuickItem *item : std::as_const(d->childItems))
9497 QCoreApplication::sendEvent(item, ev);
9499 case QEvent::ApplicationPaletteChange:
9500 for (QQuickItem *item : std::as_const(d->childItems))
9501 QCoreApplication::sendEvent(item, ev);
9503 case QEvent::ContextMenu:
9505 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9508 return QObject::event(ev);
9514#ifndef QT_NO_DEBUG_STREAM
9516#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9521 QDebugStateSaver saver(debug);
9524 debug <<
"QQuickItem(nullptr)";
9528 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9530 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9534 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9535 if (QQmlContext *context = qmlContext(item)) {
9536 const auto objectId = context->nameForObject(item);
9537 if (!objectId.isEmpty())
9538 debug <<
", id=" << objectId;
9541 if (!item->objectName().isEmpty())
9542 debug <<
", name=" << item->objectName();
9543 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9545 QtDebugUtils::formatQRect(debug, rect);
9546 if (
const qreal z = item->z())
9547 debug <<
", z=" << z;
9548 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9549 debug <<
" \U0001f5bc";
9550 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9558
9559
9560
9561
9562
9563
9564
9566bool QQuickItem::isTextureProvider()
const
9568#if QT_CONFIG(quick_shadereffect)
9569 Q_D(
const QQuickItem);
9570 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9571 d->extra->layer->effectSource()->isTextureProvider() :
false;
9578
9579
9580
9581
9582
9583
9584
9586QSGTextureProvider *QQuickItem::textureProvider()
const
9588#if QT_CONFIG(quick_shadereffect)
9589 Q_D(
const QQuickItem);
9590 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9591 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9639#if QT_CONFIG(quick_shadereffect)
9641
9642
9643
9644QQuickItemLayer *QQuickItemPrivate::layer()
const
9646 if (!extra.isAllocated() || !extra->layer) {
9647 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9648 if (!componentComplete)
9649 extra->layer->classBegin();
9651 return extra->layer;
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9675 QList<QEventPoint> touchPoints;
9676 QEventPoint::States eventStates;
9678 bool anyPressOrReleaseInside =
false;
9679 bool anyGrabber =
false;
9680 for (
auto &p : event->points()) {
9685 auto pointGrabber = event->exclusiveGrabber(p);
9686 bool isGrabber = (pointGrabber == q);
9687 if (!isGrabber && pointGrabber && isFiltering) {
9688 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9689 if (handlerGrabber && handlerGrabber->parentItem() == q)
9696 const auto localPos = q->mapFromScene(p.scenePosition());
9697 bool isInside = q->contains(localPos);
9698 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9700 if (isFiltering && !pointGrabber) {
9701 const auto pg = event->passiveGrabbers(p);
9702 if (!pg.isEmpty()) {
9706 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9708 pointGrabber = handler->parentItem();
9713 bool grabberIsChild =
false;
9714 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9715 while (isFiltering && parent) {
9717 grabberIsChild =
true;
9720 parent = parent->parentItem();
9723 bool filterRelevant = isFiltering && grabberIsChild;
9724 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9726 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9727 anyPressOrReleaseInside =
true;
9728 QEventPoint pCopy(p);
9729 eventStates |= p.state();
9730 if (p.state() == QEventPoint::State::Released)
9731 QMutableEventPoint::detach(pCopy);
9732 QMutableEventPoint::setPosition(pCopy, localPos);
9733 touchPoints.append(std::move(pCopy));
9738 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9739 *localized = QMutableTouchEvent(QEvent::None);
9744 QEvent::Type eventType = event->type();
9745 switch (eventStates) {
9746 case QEventPoint::State::Pressed:
9747 eventType = QEvent::TouchBegin;
9749 case QEventPoint::State::Released:
9750 eventType = QEvent::TouchEnd;
9753 eventType = QEvent::TouchUpdate;
9757 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9759 ret.setTimestamp(event->timestamp());
9764bool QQuickItemPrivate::hasPointerHandlers()
const
9766 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9769bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9771 if (!hasPointerHandlers())
9773 for (QQuickPointerHandler *h : extra->pointerHandlers)
9774 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9779void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9785 extra.value().acceptedMouseButtons = Qt::AllButtons;
9786 auto &handlers = extra.value().pointerHandlers;
9787 if (!handlers.contains(h))
9788 handlers.prepend(h);
9789 auto &res = extra.value().resourcesList;
9790 if (!res.contains(h)) {
9792 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9793 _q_resourceObjectDeleted(o);
9798void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9802 auto &handlers = extra.value().pointerHandlers;
9803 handlers.removeOne(h);
9804 auto &res = extra.value().resourcesList;
9806 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9807 if (handlers.isEmpty())
9808 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9812
9813
9814
9815QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9817 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9818 extra.value().contextMenu = menu;
9822QtPrivate::QQuickAttachedPropertyPropagator *QQuickItemPrivate::attachedPropertyPropagator_parent(
9823 const QMetaObject *attachedType)
9826 qCDebug(lcAttachedPropertyPropagator).noquote() <<
"- attachedPropertyPropagator_parent called on"
9827 << q <<
"with attachedType" << attachedType->metaType().name();
9829 QQuickItem *parent = q->parentItem();
9830 if (
auto *attached = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(attachedType, parent)) {
9831 qCDebug(lcAttachedPropertyPropagator).noquote() <<
" - parent item has attached object"
9832 << attached <<
"- returning";
9839#if QT_CONFIG(quick_shadereffect)
9840QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9846 , m_componentComplete(
true)
9847 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9848 , m_format(QQuickShaderEffectSource::RGBA8)
9850 , m_effectComponent(
nullptr)
9852 , m_effectSource(
nullptr)
9853 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9858QQuickItemLayer::~QQuickItemLayer()
9860 delete m_effectSource;
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878void QQuickItemLayer::setEnabled(
bool e)
9883 if (m_componentComplete) {
9890 emit enabledChanged(e);
9893void QQuickItemLayer::classBegin()
9895 Q_ASSERT(!m_effectSource);
9896 Q_ASSERT(!m_effect);
9897 m_componentComplete =
false;
9900void QQuickItemLayer::componentComplete()
9902 Q_ASSERT(!m_componentComplete);
9903 m_componentComplete =
true;
9908void QQuickItemLayer::activate()
9910 Q_ASSERT(!m_effectSource);
9911 m_effectSource =
new QQuickShaderEffectSource();
9912 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9914 QQuickItem *parentItem = m_item->parentItem();
9916 m_effectSource->setParentItem(parentItem);
9917 m_effectSource->stackAfter(m_item);
9920 m_effectSource->setSourceItem(m_item);
9921 m_effectSource->setHideSource(
true);
9922 m_effectSource->setSmooth(m_smooth);
9923 m_effectSource->setLive(m_live);
9924 m_effectSource->setTextureSize(m_size);
9925 m_effectSource->setSourceRect(m_sourceRect);
9926 m_effectSource->setMipmap(m_mipmap);
9927 m_effectSource->setWrapMode(m_wrapMode);
9928 m_effectSource->setFormat(m_format);
9929 m_effectSource->setTextureMirroring(m_textureMirroring);
9930 m_effectSource->setSamples(m_samples);
9932 if (m_effectComponent)
9935 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9942 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9943 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9946void QQuickItemLayer::deactivate()
9948 Q_ASSERT(m_effectSource);
9950 if (m_effectComponent)
9953 delete m_effectSource;
9954 m_effectSource =
nullptr;
9956 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9957 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9960void QQuickItemLayer::activateEffect()
9962 Q_ASSERT(m_effectSource);
9963 Q_ASSERT(m_effectComponent);
9964 Q_ASSERT(!m_effect);
9966 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9967 m_effect = qobject_cast<QQuickItem *>(created);
9969 qWarning(
"Item: layer.effect is not a QML Item.");
9970 m_effectComponent->completeCreate();
9974 QQuickItem *parentItem = m_item->parentItem();
9976 m_effect->setParentItem(parentItem);
9977 m_effect->stackAfter(m_effectSource);
9979 m_effect->setVisible(m_item->isVisible());
9980 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9981 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9982 m_effectComponent->completeCreate();
9985void QQuickItemLayer::deactivateEffect()
9987 Q_ASSERT(m_effectSource);
9988 Q_ASSERT(m_effectComponent);
9996
9997
9998
9999
10000
10001
10002
10003
10004
10006void QQuickItemLayer::setEffect(QQmlComponent *component)
10008 if (component == m_effectComponent)
10011 bool updateNeeded =
false;
10012 if (m_effectSource && m_effectComponent) {
10013 deactivateEffect();
10014 updateNeeded =
true;
10017 m_effectComponent = component;
10019 if (m_effectSource && m_effectComponent) {
10021 updateNeeded =
true;
10024 if (updateNeeded) {
10029 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
10032 emit effectChanged(component);
10037
10038
10039
10040
10041
10042
10043
10044
10045
10047void QQuickItemLayer::setMipmap(
bool mipmap)
10049 if (mipmap == m_mipmap)
10053 if (m_effectSource)
10054 m_effectSource->setMipmap(m_mipmap);
10056 emit mipmapChanged(mipmap);
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10077void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
10083 if (m_effectSource)
10084 m_effectSource->setFormat(m_format);
10086 emit formatChanged(m_format);
10091
10092
10093
10094
10095
10096
10097
10098
10099
10101void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
10103 if (sourceRect == m_sourceRect)
10105 m_sourceRect = sourceRect;
10107 if (m_effectSource)
10108 m_effectSource->setSourceRect(m_sourceRect);
10110 emit sourceRectChanged(sourceRect);
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10125void QQuickItemLayer::setSmooth(
bool s)
10131 if (m_effectSource)
10132 m_effectSource->setSmooth(m_smooth);
10134 emit smoothChanged(s);
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10149void QQuickItemLayer::setLive(
bool live)
10151 if (m_live == live)
10155 if (m_effectSource)
10156 m_effectSource->setLive(m_live);
10158 emit liveChanged(live);
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10174void QQuickItemLayer::setSize(
const QSize &size)
10176 if (size == m_size)
10180 if (m_effectSource)
10181 m_effectSource->setTextureSize(size);
10183 emit sizeChanged(size);
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10204void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
10206 if (mode == m_wrapMode)
10210 if (m_effectSource)
10211 m_effectSource->setWrapMode(m_wrapMode);
10213 emit wrapModeChanged(mode);
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10231void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
10233 if (mirroring == m_textureMirroring)
10235 m_textureMirroring = mirroring;
10237 if (m_effectSource)
10238 m_effectSource->setTextureMirroring(m_textureMirroring);
10240 emit textureMirroringChanged(mirroring);
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10268void QQuickItemLayer::setSamples(
int count)
10270 if (m_samples == count)
10275 if (m_effectSource)
10276 m_effectSource->setSamples(m_samples);
10278 emit samplesChanged(count);
10282
10283
10284
10285
10286
10287
10288
10289
10290
10292void QQuickItemLayer::setName(
const QByteArray &name) {
10293 if (m_name == name)
10296 m_effect->setProperty(m_name, QVariant());
10297 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10300 emit nameChanged(name);
10303void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10309void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10314void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10317 Q_ASSERT(item == m_item);
10318 Q_ASSERT(parent != m_effectSource);
10319 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10321 m_effectSource->setParentItem(parent);
10323 m_effectSource->stackAfter(m_item);
10326 m_effect->setParentItem(parent);
10328 m_effect->stackAfter(m_effectSource);
10332void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10334 m_effectSource->stackAfter(m_item);
10336 m_effect->stackAfter(m_effectSource);
10339void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10341 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10344 l->setVisible(m_item->isVisible());
10347void QQuickItemLayer::updateZ()
10349 if (!m_componentComplete || !m_enabled)
10351 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10354 l->setZ(m_item->z());
10357void QQuickItemLayer::updateOpacity()
10359 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10362 l->setOpacity(m_item->opacity());
10365void QQuickItemLayer::updateGeometry()
10367 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10372 QRectF bounds = m_item->QQuickItem::boundingRect();
10373 l->setSize(bounds.size());
10374 l->setPosition(bounds.topLeft() + m_item->position());
10377void QQuickItemLayer::updateMatrix()
10381 if (!m_componentComplete || !m_enabled)
10383 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10386 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10387 l->setScale(m_item->scale());
10388 l->setRotation(m_item->rotation());
10389 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10390 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10391 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10392 ld->dirty(QQuickItemPrivate::Transform);
10396QQuickItemPrivate::ExtraData::ExtraData()
10397: z(0), scale(1), rotation(0), opacity(1), biggestPointerHandlerMarginCache(-1),
10398 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10399 enterKeyAttached(
nullptr),
10400 keyHandler(
nullptr), contextMenu(
nullptr),
10401#if QT_CONFIG(quick_shadereffect)
10404 effectRefCount(0), hideRefCount(0),
10405 recursiveEffectRefCount(0),
10406 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10407 origin(QQuickItem::Center),
10408 transparentForPositioner(
false),
10409 mutabilityGroup(uint(QQuickItem::AutoMutabilityGroup)),
10410 mutabilityGroupSet(
false)
10412#ifdef QT_BUILD_INTERNAL
10413 ++QQuickItemPrivate::itemExtra_counter;
10418#if QT_CONFIG(accessibility)
10419QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10421 auto role = QAccessible::NoRole;
10422 if (!inDestructor) {
10423 Q_Q(
const QQuickItem);
10424 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10425 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10426 role = accessibleAttached->role();
10427 if (role == QAccessible::NoRole)
10428 role = accessibleRole();
10433QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10435 return QAccessible::NoRole;
10444 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10457 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10458 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10459 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10460 QV4::QObjectWrapper::markWrapper(child, markStack);
10462 QObjectWrapper::markObjects(that, markStack);
10465quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10467 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10472 QDebugStateSaver stateSaver(debug);
10473 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10478QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10479{
return mapFromItem(item, QPointF(x, y) ); }
10482QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10483{
return mapRectFromItem(item, rect); }
10486QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10487{
return mapFromItem(item, QRectF(x, y, width, height)); }
10490QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10491{
return mapToItem(item, QPointF(x, y)); }
10494QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10495{
return mapRectToItem(item, rect); }
10498QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10499{
return mapToItem(item, QRectF(x, y, width, height)); }
10502QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10503{
return mapToGlobal(QPointF(x, y)); }
10506QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10507{
return mapFromGlobal(QPointF(x, y)); }
10510QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10514#include <moc_qquickitem.cpp>
10516#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)