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
2365
2366
2367
2368
2369QQuickItem::QQuickItem(QQuickItem* parent)
2370: QObject(*(
new QQuickItemPrivate), parent)
2377
2378QQuickItem::QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent)
2379: QObject(dd, parent)
2386
2387
2388QQuickItem::~QQuickItem()
2391 d->inDestructor =
true;
2393#if QT_CONFIG(accessibility)
2394 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && QAccessible::isActive())
2395 QAccessibleCache::instance()->sendObjectDestroyedEvent(
this);
2397 d->isAccessible =
false;
2400 if (d->windowRefCount > 1)
2401 d->windowRefCount = 1;
2403 setParentItem(
nullptr);
2407 for (QQuickItem *child : std::as_const(d->childItems))
2408 child->setParentItem(
nullptr);
2409 d->childItems.clear();
2411 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2412 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2414 anchor->clearItem(
this);
2417
2418
2419
2420 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2421 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2422 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2425 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2426 d->changeListeners.clear();
2429
2430
2431
2432
2433 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2434 QQuickTransform *t = d->transforms.at(ii);
2435 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2436 tp->items.removeOne(
this);
2439 if (d->extra.isAllocated()) {
2440 delete d->extra->contents; d->extra->contents =
nullptr;
2441#if QT_CONFIG(quick_shadereffect)
2442 delete d->extra->layer; d->extra->layer =
nullptr;
2446 delete d->_anchors; d->_anchors =
nullptr;
2447 delete d->_stateGroup; d->_stateGroup =
nullptr;
2449 d->isQuickItem =
false;
2453
2454
2455bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2457 if (!item->window())
2460 if (item == item->window()->contentItem())
2463 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2464 if (tabFocus == Qt::NoTabFocus)
2466 if (tabFocus == Qt::TabFocusAllControls)
2469 QVariant editable = item->property(
"editable");
2470 if (editable.isValid())
2471 return editable.toBool();
2473 QVariant readonly = item->property(
"readOnly");
2474 if (readonly.isValid())
2475 return !readonly.toBool() && item->property(
"text").isValid();
2477#if QT_CONFIG(accessibility)
2478 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2479 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2481 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2482 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2483 return iface->state().editable;
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2502 QQuickWindow *window = item->window();
2503 const bool wrap = !window || window->isTopLevel();
2505 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2510 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2512 if (!wrap && !next) {
2516 Q_ASSERT(window->parent());
2519 qt_window_private(window->parent())->setFocusToTarget(
2520 forward ? QWindowPrivate::FocusTarget::Next
2521 : QWindowPrivate::FocusTarget::Prev,
2523 window->parent()->requestActivate();
2527 next->forceActiveFocus(reason);
2532QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2535 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2538 const QList<QQuickItem *> &children = item->childItems();
2539 const int count = children.size();
2540 if (start < 0 || start >= count) {
2541 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2544 while (start < count) {
2545 QQuickItem *child = children.at(start);
2546 if (!child->d_func()->isTabFence)
2553QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2556 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2559 const QList<QQuickItem *> &children = item->childItems();
2560 const int count = children.size();
2563 if (start < 0 || start >= count) {
2564 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2567 while (start >= 0) {
2568 QQuickItem *child = children.at(start);
2569 if (!child->d_func()->isTabFence)
2576QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2579 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2581 if (!item->window())
2583 const QQuickItem *
const contentItem = item->window()->contentItem();
2587 QQuickItem *from =
nullptr;
2588 bool isTabFence = item->d_func()->isTabFence;
2591 from = item->parentItem();
2593 if (!item->childItems().isEmpty())
2594 from = item->d_func()->childItems.constFirst();
2595 else if (!isTabFence)
2596 from = item->parentItem();
2600 QQuickItem *startItem = item;
2601 QQuickItem *originalStartItem = startItem;
2606 while (startItem && !startItem->isVisible()) {
2607 startItem = startItem->parentItem();
2612 QQuickItem *firstFromItem = from;
2613 QQuickItem *current = item;
2614 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2615 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2616 QDuplicateTracker<QQuickItem *> cycleDetector;
2618 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2619 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2621 QQuickItem *last = current;
2623 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2624 QQuickItem *firstChild =
nullptr;
2625 QQuickItem *lastChild =
nullptr;
2627 firstChild = nextTabChildItem(current, 0);
2629 hasChildren =
false;
2631 lastChild = prevTabChildItem(current, -1);
2633 isTabFence = current->d_func()->isTabFence;
2634 if (isTabFence && !hasChildren)
2638 if (hasChildren && from == current->parentItem()) {
2640 current = firstChild;
2642 current = lastChild;
2643 if (!current->childItems().isEmpty())
2646 }
else if (hasChildren && forward && from != lastChild) {
2648 int nextChild = current->childItems().indexOf(from) + 1;
2649 current = nextTabChildItem(current, nextChild);
2650 }
else if (hasChildren && !forward && from != firstChild) {
2652 int prevChild = current->childItems().indexOf(from) - 1;
2653 current = prevTabChildItem(current, prevChild);
2654 if (!current->childItems().isEmpty())
2657 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2661 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2662 if (last != firstSibling
2663 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2667 }
else if (hasChildren) {
2669 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2670 <<
"Focus chain about to wrap but wrapping was set to false."
2677 current = firstChild;
2678 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2679 <<
"wrapping from last to first:" << current;
2681 current = lastChild;
2682 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2683 <<
"wrapping from first to last:" << current;
2684 if (!current->childItems().isEmpty())
2696 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2697 (!skip && cycleDetector.hasSeen(current))) {
2699 if (item == contentItem) {
2700 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2703 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2707 if (!firstFromItem) {
2708 if (startItem->d_func()->isTabFence) {
2709 if (current == startItem)
2710 firstFromItem = from;
2712 startItem = current;
2713 firstFromItem = from;
2716 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2717 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2723
2724
2725
2726
2727
2728
2729
2730
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746QQuickItem *QQuickItem::parentItem()
const
2748 Q_D(
const QQuickItem);
2749 return d->parentItem;
2752void QQuickItem::setParentItem(QQuickItem *parentItem)
2755 if (parentItem == d->parentItem)
2759 QQuickItem *itemAncestor = parentItem;
2760 while (itemAncestor !=
nullptr) {
2761 if (Q_UNLIKELY(itemAncestor ==
this)) {
2762 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2765 itemAncestor = itemAncestor->parentItem();
2767 auto engine = qmlEngine(
this);
2769 QV4::ExecutionEngine *v4 = engine->handle();
2770 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2771 QV4::QObjectWrapper::markWrapper(
this, ms);
2776 d->removeFromDirtyList();
2778 QQuickItem *oldParentItem = d->parentItem;
2779 QQuickItem *scopeFocusedItem =
nullptr;
2781 if (oldParentItem) {
2782 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2784 QQuickItem *scopeItem =
nullptr;
2786 if (hasFocus() || op->subFocusItem ==
this)
2787 scopeFocusedItem =
this;
2788 else if (!isFocusScope() && d->subFocusItem)
2789 scopeFocusedItem = d->subFocusItem;
2791 if (scopeFocusedItem) {
2792 scopeItem = oldParentItem;
2793 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2794 scopeItem = scopeItem->parentItem();
2796 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2797 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2798 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2800 if (scopeFocusedItem !=
this)
2801 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2803 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2807 const bool wasVisible = isVisible();
2808 op->removeChild(
this);
2809 if (wasVisible && !op->inDestructor)
2810 emit oldParentItem->visibleChildrenChanged();
2811 }
else if (d->window) {
2812 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2815 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2816 bool alreadyAddedChild =
false;
2817 if (d->window == parentWindow) {
2819 d->parentItem = parentItem;
2821 auto oldParentItem = d->parentItem;
2822 d->parentItem = parentItem;
2823 if (d->parentItem) {
2824 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2825 alreadyAddedChild =
true;
2833 if (!oldParentItem && d->window) {
2834 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2838 d->refWindow(parentWindow);
2841 d->dirty(QQuickItemPrivate::ParentChanged);
2843 if (d->parentItem && !alreadyAddedChild)
2844 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2845 else if (d->window && !alreadyAddedChild)
2846 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2848 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2849 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2851 if (d->parentItem) {
2852 if (!scopeFocusedItem) {
2854 scopeFocusedItem =
this;
2855 else if (!isFocusScope() && d->subFocusItem)
2856 scopeFocusedItem = d->subFocusItem;
2859 if (scopeFocusedItem) {
2861 QQuickItem *scopeItem = d->parentItem;
2862 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2863 scopeItem = scopeItem->parentItem();
2865 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2866 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2867 if (scopeFocusedItem !=
this)
2868 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2869 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2870 emit scopeFocusedItem->focusChanged(
false);
2873 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2874 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2875 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2878 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2885 d->resolveLayoutMirror();
2887 d->itemChange(ItemParentHasChanged, d->parentItem);
2889 if (!d->inDestructor)
2890 emit parentChanged(d->parentItem);
2891 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2892 emit d->parentItem->visibleChildrenChanged();
2894#if QT_CONFIG(accessibility)
2895 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2896 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2897 QAccessible::updateAccessibility(&qaEvent);
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920void QQuickItem::stackBefore(
const QQuickItem *sibling)
2923 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2924 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2925 <<
this <<
" before " << sibling <<
", which must be a sibling";
2929 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2931 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2932 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2934 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2936 if (myIndex == siblingIndex - 1)
2939 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2941 parentPrivate->markSortedChildrenDirty(
this);
2942 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2944 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2945 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966void QQuickItem::stackAfter(
const QQuickItem *sibling)
2969 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2970 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2971 <<
this <<
" after " << sibling <<
", which must be a sibling";
2975 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2977 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2978 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2980 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2982 if (myIndex == siblingIndex + 1)
2985 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2987 parentPrivate->markSortedChildrenDirty(
this);
2988 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2990 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2991 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2995
2996
2999
3000
3001
3002
3003
3004
3005QQuickWindow *QQuickItem::window()
const
3007 Q_D(
const QQuickItem);
3013 return lhs->z() < rhs->z();
3016QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3018 if (sortedChildItems)
3019 return *sortedChildItems;
3024 for (
int i = 0; i < childItems.size(); ++i) {
3025 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3031 sortedChildItems =
new QList<QQuickItem*>(childItems);
3032 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3033 return *sortedChildItems;
3036 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3041void QQuickItemPrivate::addChild(QQuickItem *child)
3045 Q_ASSERT(!childItems.contains(child));
3047 childItems.append(child);
3049 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3051#if QT_CONFIG(cursor)
3054 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3055 setHasCursorInChild(
true);
3058 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3059 setHasHoverInChild(
true);
3061 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3062 markSortedChildrenDirty(child);
3063 dirty(QQuickItemPrivate::ChildrenChanged);
3065 itemChange(QQuickItem::ItemChildAddedChange, child);
3067 emit q->childrenChanged();
3070void QQuickItemPrivate::removeChild(QQuickItem *child)
3075 if (!inDestructor) {
3077 Q_ASSERT(childItems.contains(child));
3078 childItems.removeOne(child);
3079 Q_ASSERT(!childItems.contains(child));
3082 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3084#if QT_CONFIG(cursor)
3086 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3087 setHasCursorInChild(
false);
3090 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3091 setHasHoverInChild(
false);
3093 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3094 if (!inDestructor) {
3095 markSortedChildrenDirty(child);
3096 dirty(QQuickItemPrivate::ChildrenChanged);
3099 itemChange(QQuickItem::ItemChildRemovedChange, child);
3102 emit q->childrenChanged();
3105void QQuickItemPrivate::refWindow(QQuickWindow *c)
3117 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3119 if (++windowRefCount > 1) {
3121 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3125 Q_ASSERT(window ==
nullptr);
3128 if (polishScheduled)
3129 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3132 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3134 for (
int ii = 0; ii < childItems.size(); ++ii) {
3135 QQuickItem *child = childItems.at(ii);
3136 QQuickItemPrivate::get(child)->refWindow(c);
3141 if (extra.isAllocated() && extra->screenAttached)
3142 extra->screenAttached->windowChanged(c);
3143 itemChange(QQuickItem::ItemSceneChange, c);
3146void QQuickItemPrivate::derefWindow()
3149 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3154 if (--windowRefCount > 0)
3157 q->releaseResources();
3158 removeFromDirtyList();
3159 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3160 if (polishScheduled)
3161 c->itemsToPolish.removeOne(q);
3162#if QT_CONFIG(cursor)
3163 if (c->cursorItem == q) {
3164 c->cursorItem =
nullptr;
3165 window->unsetCursor();
3168 if (itemNodeInstance)
3169 c->cleanup(itemNodeInstance);
3171 c->parentlessItems.remove(q);
3173 if (
auto *da = deliveryAgentPrivate()) {
3174 if (da->activeFocusItem == q) {
3175 qCDebug(lcFocus) <<
"Removing active focus item from window's delivery agent";
3176 da->activeFocusItem =
nullptr;
3181 itemNodeInstance =
nullptr;
3183 if (extra.isAllocated()) {
3184 extra->opacityNode =
nullptr;
3185 extra->clipNode =
nullptr;
3186 extra->rootNode =
nullptr;
3189 paintNode =
nullptr;
3191 for (
int ii = 0; ii < childItems.size(); ++ii) {
3192 if (QQuickItem *child = childItems.at(ii))
3193 QQuickItemPrivate::get(child)->derefWindow();
3198 if (extra.isAllocated() && extra->screenAttached)
3199 extra->screenAttached->windowChanged(
nullptr);
3200 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3203qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3205 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3209
3210
3211QTransform QQuickItemPrivate::windowToItemTransform()
const
3214#ifdef QT_BUILD_INTERNAL
3215 ++windowToItemTransform_counter;
3217 return itemToWindowTransform().inverted();
3221
3222
3223QTransform QQuickItemPrivate::itemToWindowTransform()
const
3225#ifdef QT_BUILD_INTERNAL
3226 ++itemToWindowTransform_counter;
3229 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3230 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3231 itemToParentTransform(&rv);
3236
3237
3238void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3240#ifdef QT_BUILD_INTERNAL
3241 ++itemToParentTransform_counter;
3244
3245
3246
3247
3248
3250 qreal x =
this->x.valueBypassingBindings();
3251 qreal y =
this->y.valueBypassingBindings();
3255 if (!transforms.isEmpty()) {
3257 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3258 transforms.at(ii)->applyTo(&m);
3259 *t = m.toTransform();
3262 if (scale() != 1. || rotation() != 0.) {
3263 QPointF tp = computeTransformOrigin();
3264 t->translate(tp.x(), tp.y());
3265 t->scale(scale(), scale());
3266 t->rotate(rotation());
3267 t->translate(-tp.x(), -tp.y());
3272
3273
3274
3275
3276
3277
3278
3279
3280bool QQuickItem::isComponentComplete()
const
3282 Q_D(
const QQuickItem);
3283 return d->componentComplete;
3286QQuickItemPrivate::QQuickItemPrivate()
3288 , _stateGroup(
nullptr)
3290 , widthValidFlag(
false)
3291 , heightValidFlag(
false)
3292 , componentComplete(
true)
3295 , hoverEnabled(
false)
3297 , antialiasing(
false)
3299 , activeFocus(
false)
3300 , notifiedFocus(
false)
3301 , notifiedActiveFocus(
false)
3302 , filtersChildMouseEvents(
false)
3303 , explicitVisible(
true)
3304 , effectiveVisible(
true)
3305 , explicitEnable(
true)
3306 , effectiveEnable(
true)
3307 , polishScheduled(
false)
3308 , inheritedLayoutMirror(
false)
3309 , effectiveLayoutMirror(
false)
3310 , isMirrorImplicit(
true)
3311 , inheritMirrorFromParent(
false)
3312 , inheritMirrorFromItem(
false)
3313 , isAccessible(
false)
3316 , subtreeCursorEnabled(
false)
3317 , subtreeHoverEnabled(
false)
3318 , activeFocusOnTab(
false)
3319 , implicitAntialiasing(
false)
3320 , antialiasingValid(
false)
3322 , replayingPressEvent(
false)
3323 , touchEnabled(
false)
3324 , hasCursorHandler(
false)
3325 , maybeHasSubsceneDeliveryAgent(
true)
3326 , subtreeTransformChangedEnabled(
true)
3327 , inDestructor(
false)
3328 , focusReason(Qt::OtherFocusReason)
3329 , focusPolicy(Qt::NoFocus)
3330 , eventHandlingChildrenWithinBounds(
false)
3331 , eventHandlingChildrenWithinBoundsSet(
false)
3332 , customOverlay(
false)
3333 , dirtyAttributes(0)
3334 , nextDirtyItem(
nullptr)
3335 , prevDirtyItem(
nullptr)
3338 , parentItem(
nullptr)
3339 , sortedChildItems(&childItems)
3340 , subFocusItem(
nullptr)
3348 , itemNodeInstance(
nullptr)
3349 , paintNode(
nullptr)
3350 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3352#ifdef QT_BUILD_INTERNAL
3357QQuickItemPrivate::~QQuickItemPrivate()
3359 if (sortedChildItems != &childItems)
3360 delete sortedChildItems;
3363void QQuickItemPrivate::init(QQuickItem *parent)
3369 baselineOffset = 0.0;
3372 q->setParentItem(parent);
3373 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3374 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3378QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3383void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3385 szPolicy.setHorizontalPolicy(horizontalPolicy);
3386 szPolicy.setVerticalPolicy(verticalPolicy);
3389void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3394 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3396 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3397 item->setParentItem(that);
3398 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3399 if (pointerHandler->parent() != that) {
3400 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3401 pointerHandler->setParent(that);
3403 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3406 resources_append(prop, o);
3411
3412
3413
3414
3415
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
3445qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3447 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3448 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3449 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3450 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3452 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3455QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3457 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3458 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3459 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3460 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3462 qsizetype resourcesCount = resources_count(&resourcesProperty);
3463 if (i < resourcesCount)
3464 return resources_at(&resourcesProperty, i);
3465 const qsizetype j = i - resourcesCount;
3466 if (j < children_count(&childrenProperty))
3467 return children_at(&childrenProperty, j);
3471void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3473 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3474 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3475 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3476 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3478 resources_clear(&resourcesProperty);
3479 children_clear(&childrenProperty);
3482void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3484 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3485 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3487 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3488 if (children_count(&childrenProperty) > 0) {
3489 children_removeLast(&childrenProperty);
3493 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3494 if (resources_count(&resourcesProperty) > 0)
3495 resources_removeLast(&resourcesProperty);
3498QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3500 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3501 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3504void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3506 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3507 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3508 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3509 quickItemPrivate->extra.value().resourcesList.append(object);
3510 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3511 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3515qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3517 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3518 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3521void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3523 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3524 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3525 if (quickItemPrivate->extra.isAllocated()) {
3526 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3527 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3528 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3530 quickItemPrivate->extra->resourcesList.clear();
3534void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3536 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3537 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3538 if (quickItemPrivate->extra.isAllocated()) {
3539 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3540 if (resources->isEmpty())
3543 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3544 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3545 resources->removeLast();
3549QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3551 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3552 if (index >= p->childItems.size() || index < 0)
3555 return p->childItems.at(index);
3558void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3563 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3564 if (o->parentItem() == that)
3565 o->setParentItem(
nullptr);
3567 o->setParentItem(that);
3570qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3572 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3573 return p->childItems.size();
3576void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3578 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3579 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3580 while (!p->childItems.isEmpty())
3581 p->childItems.at(0)->setParentItem(
nullptr);
3584void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3586 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3587 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3588 if (!p->childItems.isEmpty())
3589 p->childItems.last()->setParentItem(
nullptr);
3592qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3594 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3595 qsizetype visibleCount = 0;
3596 qsizetype c = p->childItems.size();
3598 if (p->childItems.at(c)->isVisible()) visibleCount++;
3601 return visibleCount;
3604QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3606 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3607 const qsizetype childCount = p->childItems.size();
3608 if (index >= childCount || index < 0)
3611 qsizetype visibleCount = -1;
3612 for (qsizetype i = 0; i < childCount; i++) {
3613 if (p->childItems.at(i)->isVisible()) visibleCount++;
3614 if (visibleCount == index)
return p->childItems.at(i);
3619qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3621 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3622 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3624 return p->transforms.size();
3627void QQuickTransform::appendToItem(QQuickItem *item)
3629 Q_D(QQuickTransform);
3633 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3635 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3636 p->transforms.removeOne(
this);
3637 p->transforms.append(
this);
3639 p->transforms.append(
this);
3640 d->items.append(item);
3643 p->dirty(QQuickItemPrivate::Transform);
3646void QQuickTransform::prependToItem(QQuickItem *item)
3648 Q_D(QQuickTransform);
3652 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3654 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3655 p->transforms.removeOne(
this);
3656 p->transforms.prepend(
this);
3658 p->transforms.prepend(
this);
3659 d->items.append(item);
3662 p->dirty(QQuickItemPrivate::Transform);
3665void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3670 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3671 transform->appendToItem(that);
3674QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3676 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3677 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3679 if (idx < 0 || idx >= p->transforms.size())
3682 return p->transforms.at(idx);
3685void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3687 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3688 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3690 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3691 QQuickTransform *t = p->transforms.at(ii);
3692 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3693 tp->items.removeOne(that);
3696 p->transforms.clear();
3698 p->dirty(QQuickItemPrivate::Transform);
3701void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3703 if (extra.isAllocated() && extra->resourcesList.contains(object))
3704 extra->resourcesList.removeAll(object);
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801QQuickAnchors *QQuickItemPrivate::anchors()
const
3804 Q_Q(
const QQuickItem);
3805 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3806 if (!componentComplete)
3807 _anchors->classBegin();
3812void QQuickItemPrivate::siblingOrderChanged()
3815 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3818QQmlListProperty<QObject> QQuickItemPrivate::data()
3822 QQmlListProperty<QObject> result;
3823 result.object = q_func();
3824 result.append = QQuickItemPrivate::data_append;
3825 result.count = QQuickItemPrivate::data_count;
3826 result.at = QQuickItemPrivate::data_at;
3827 result.clear = QQuickItemPrivate::data_clear;
3828 result.removeLast = QQuickItemPrivate::data_removeLast;
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863QRectF QQuickItem::childrenRect()
3866 if (!d->extra.isAllocated() || !d->extra->contents) {
3867 d->extra.value().contents =
new QQuickContents(
this);
3868 if (d->componentComplete)
3869 d->extra->contents->complete();
3871 return d->extra->contents->rectF();
3875
3876
3877QList<QQuickItem *> QQuickItem::childItems()
const
3879 Q_D(
const QQuickItem);
3880 return d->childItems;
3884
3885
3886
3887
3888
3889
3890
3891
3892
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911bool QQuickItem::clip()
const
3913 return flags() & ItemClipsChildrenToShape;
3916void QQuickItem::setClip(
bool c)
3921 setFlag(ItemClipsChildrenToShape, c);
3923 setFlag(ItemIsViewport);
3924 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3925 setFlag(ItemIsViewport,
false);
3927 emit clipChanged(c);
3931
3932
3933
3934
3935
3936
3937
3938
3939void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3944 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3946 QQuickGeometryChange change;
3947 change.setXChange(newGeometry.x() != oldGeometry.x());
3948 change.setYChange(newGeometry.y() != oldGeometry.y());
3949 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3950 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3952 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3953 if (change.matches(listener.gTypes))
3954 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3959 if (change.xChange())
3961 if (change.yChange())
3963 if (change.widthChange())
3965 if (change.heightChange())
3967#if QT_CONFIG(accessibility)
3968 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3969 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3970 QAccessible::updateAccessibility(&ev);
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4029QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4031 Q_UNUSED(updatePaintNodeData);
4036QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4037: transformNode(
nullptr)
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4058void QQuickItem::releaseResources()
4062QSGTransformNode *QQuickItemPrivate::createTransformNode()
4064 return new QSGTransformNode;
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077void QQuickItem::updatePolish()
4081#define PRINT_LISTENERS() do
4083 qDebug().nospace() << q_func() << " (" << this
4084 << ") now has the following listeners:";
4085 for (const auto &listener : std::as_const(changeListeners)) {
4086 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4087 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4089}while
4092void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4095 changeListeners.append(ChangeListener(listener, types));
4096 listener->addSourceItem(q);
4098 if (lcChangeListeners().isDebugEnabled())
4102void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4106 const ChangeListener changeListener(listener, types);
4107 const int index = changeListeners.indexOf(changeListener);
4109 changeListeners[index].types = changeListener.types;
4111 changeListeners.append(changeListener);
4112 listener->addSourceItem(q);
4115 if (lcChangeListeners().isDebugEnabled())
4119void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4123 ChangeListener change(listener, types);
4124 changeListeners.removeOne(change);
4125 listener->removeSourceItem(q);
4127 if (lcChangeListeners().isDebugEnabled())
4131void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4132 QQuickGeometryChange types)
4136 ChangeListener change(listener, types);
4137 int index = changeListeners.indexOf(change);
4139 changeListeners[index].gTypes = change.gTypes;
4141 changeListeners.append(change);
4142 listener->addSourceItem(q);
4145 if (lcChangeListeners().isDebugEnabled())
4149void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4150 QQuickGeometryChange types)
4154 ChangeListener change(listener, types);
4155 if (types.noChange()) {
4156 changeListeners.removeOne(change);
4157 listener->removeSourceItem(q);
4159 int index = changeListeners.indexOf(change);
4161 changeListeners[index].gTypes = change.gTypes;
4164 if (lcChangeListeners().isDebugEnabled())
4169
4170
4171
4172
4173
4174
4175void QQuickItem::keyPressEvent(QKeyEvent *event)
4181
4182
4183
4184
4185
4186
4187void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4194
4195
4196
4197
4198
4199
4200void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216void QQuickItem::focusInEvent(QFocusEvent *event)
4219#if QT_CONFIG(accessibility)
4220 if (QAccessible::isActive()) {
4221 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4222 QAccessibleEvent ev(acc, QAccessible::Focus);
4223 QAccessible::updateAccessibility(&ev);
4227 d->setLastFocusChangeReason(event->reason());
4231
4232
4233
4234
4235
4236
4237void QQuickItem::focusOutEvent(QFocusEvent *event)
4240 d->setLastFocusChangeReason(event->reason());
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253void QQuickItem::mousePressEvent(QMouseEvent *event)
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4291
4292
4293
4294
4295
4296
4297void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4303
4304
4305
4306void QQuickItem::mouseUngrabEvent()
4312
4313
4314
4315void QQuickItem::touchUngrabEvent()
4320#if QT_CONFIG(wheelevent)
4322
4323
4324
4325
4326
4327
4328void QQuickItem::wheelEvent(QWheelEvent *event)
4335
4336
4337
4338
4339
4340
4341void QQuickItem::touchEvent(QTouchEvent *event)
4347
4348
4349
4350
4351
4352
4353
4354
4355void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4361
4362
4363
4364
4365
4366
4367
4368
4369void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4375
4376
4377
4378
4379
4380
4381
4382
4383void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4388#if QT_CONFIG(quick_draganddrop)
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452void QQuickItem::dropEvent(QDropEvent *event)
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4497
4498
4499
4500
4501
4502
4503
4504QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4506 Q_D(
const QQuickItem);
4511 v = (
bool)(flags() & ItemAcceptsInputMethod);
4514 case Qt::ImAnchorRectangle:
4515 case Qt::ImCursorRectangle:
4517 case Qt::ImCursorPosition:
4518 case Qt::ImSurroundingText:
4519 case Qt::ImCurrentSelection:
4520 case Qt::ImMaximumTextLength:
4521 case Qt::ImAnchorPosition:
4522 case Qt::ImPreferredLanguage:
4523 case Qt::ImReadOnly:
4524 if (d->extra.isAllocated() && d->extra->keyHandler)
4525 v = d->extra->keyHandler->inputMethodQuery(query);
4527 case Qt::ImEnterKeyType:
4528 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4529 v = d->extra->enterKeyAttached->type();
4531 case Qt::ImInputItemClipRectangle:
4532 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4533 QRectF rect = QRectF(0,0, width(), height());
4534 const QQuickItem *par =
this;
4535 while (QQuickItem *parpar = par->parentItem()) {
4536 rect = parpar->mapRectFromItem(par, rect);
4538 rect = rect.intersected(parpar->clipRect());
4541 rect = par->mapRectToScene(rect);
4543 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4545 v = mapRectFromScene(rect);
4556QQuickAnchorLine QQuickItemPrivate::left()
const
4558 Q_Q(
const QQuickItem);
4559 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4562QQuickAnchorLine QQuickItemPrivate::right()
const
4564 Q_Q(
const QQuickItem);
4565 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4568QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4570 Q_Q(
const QQuickItem);
4571 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4574QQuickAnchorLine QQuickItemPrivate::top()
const
4576 Q_Q(
const QQuickItem);
4577 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4580QQuickAnchorLine QQuickItemPrivate::bottom()
const
4582 Q_Q(
const QQuickItem);
4583 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4586QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4588 Q_Q(
const QQuickItem);
4589 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4592QQuickAnchorLine QQuickItemPrivate::baseline()
const
4594 Q_Q(
const QQuickItem);
4595 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620qreal QQuickItem::baselineOffset()
const
4622 Q_D(
const QQuickItem);
4623 return d->baselineOffset;
4626void QQuickItem::setBaselineOffset(qreal offset)
4629 if (offset == d->baselineOffset)
4632 d->baselineOffset = offset;
4634 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4635 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4637 anchor->updateVerticalAnchors();
4640 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4641 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4643 emit baselineOffsetChanged(offset);
4648
4649
4650
4651
4652
4653
4654
4655
4656void QQuickItem::update()
4659 if (!(flags() & ItemHasContents)) {
4661 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4665 d->dirty(QQuickItemPrivate::Content);
4669
4670
4671
4672
4673
4674
4675
4676void QQuickItem::polish()
4679 if (!d->polishScheduled) {
4680 d->polishScheduled =
true;
4682 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4683 bool maybeupdate = p->itemsToPolish.isEmpty();
4684 p->itemsToPolish.append(
this);
4685 if (maybeupdate) d->window->maybeUpdate();
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705void QQuickItem::ensurePolished()
4710#if QT_DEPRECATED_SINCE(6
, 5
)
4711static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4712 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4714 QV4::ExecutionEngine *v4 = args->v4engine();
4715 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4716 v4->throwTypeError();
4720 QV4::Scope scope(v4);
4721 QV4::ScopedValue item(scope, (*args)[0]);
4724 if (!item->isNull()) {
4725 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4727 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4730 if (!(*itemObj) && !item->isNull()) {
4731 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4732 <<
"\" which is neither null nor an Item";
4733 v4->throwTypeError();
4739 if (args->length() == 2) {
4740 QV4::ScopedValue sv(scope, (*args)[1]);
4742 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4743 <<
"\" which is neither a point nor a rect";
4744 v4->throwTypeError();
4747 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4748 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4749 if (v.canConvert<QPointF>()) {
4750 const QPointF p = v.toPointF();
4753 }
else if (v.canConvert<QRectF>()) {
4754 const QRectF r = v.toRectF();
4761 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4762 <<
"\" which is neither a point nor a rect";
4763 v4->throwTypeError();
4767 QV4::ScopedValue vx(scope, (*args)[1]);
4768 QV4::ScopedValue vy(scope, (*args)[2]);
4770 if (!vx->isNumber() || !vy->isNumber()) {
4771 v4->throwTypeError();
4775 *x = vx->asDouble();
4776 *y = vy->asDouble();
4778 if (args->length() > 3) {
4779 QV4::ScopedValue vw(scope, (*args)[3]);
4780 QV4::ScopedValue vh(scope, (*args)[4]);
4781 if (!vw->isNumber() || !vh->isNumber()) {
4782 v4->throwTypeError();
4785 *w = vw->asDouble();
4786 *h = vh->asDouble();
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4813#if QT_DEPRECATED_SINCE(6
, 5
)
4815
4816
4817void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4819 QV4::ExecutionEngine *v4 = args->v4engine();
4820 QV4::Scope scope(v4);
4824 QQuickItem *itemObj;
4825 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4828 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4829 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4831 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4832 args->setReturnValue(rv.asReturnedValue());
4837
4838
4839QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4841 Q_D(
const QQuickItem);
4847 QTransform t = d->itemToWindowTransform();
4848 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4871#if QT_DEPRECATED_SINCE(6
, 5
)
4873
4874
4875void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4877 QV4::ExecutionEngine *v4 = args->v4engine();
4878 QV4::Scope scope(v4);
4882 QQuickItem *itemObj;
4883 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4886 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4887 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4889 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4890 args->setReturnValue(rv.asReturnedValue());
4893static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4895 QV4::ExecutionEngine *v4 = args->v4engine();
4896 if (args->length() != 1 && args->length() != 2) {
4897 v4->throwTypeError();
4901 QV4::Scope scope(v4);
4903 if (args->length() == 1) {
4904 QV4::ScopedValue sv(scope, (*args)[0]);
4906 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4907 <<
"\" which is not a point";
4908 v4->throwTypeError();
4911 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4912 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4913 if (v.canConvert<QPointF>()) {
4914 const QPointF p = v.toPointF();
4918 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4919 <<
"\" which is not a point";
4920 v4->throwTypeError();
4924 QV4::ScopedValue vx(scope, (*args)[0]);
4925 QV4::ScopedValue vy(scope, (*args)[1]);
4927 if (!vx->isNumber() || !vy->isNumber()) {
4928 v4->throwTypeError();
4932 *x = vx->asDouble();
4933 *y = vy->asDouble();
4940
4941
4942
4943
4944
4945
4946
4947
4949
4950
4951void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4953 QV4::ExecutionEngine *v4 = args->v4engine();
4954 QV4::Scope scope(v4);
4957 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4960 QVariant result = mapFromGlobal(QPointF(x, y));
4962 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4963 args->setReturnValue(rv.asReturnedValue());
4968
4969
4970
4971
4972
4973
4974
4975
4977#if QT_DEPRECATED_SINCE(6
, 5
)
4979
4980
4981void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4983 QV4::ExecutionEngine *v4 = args->v4engine();
4984 QV4::Scope scope(v4);
4987 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4990 QVariant result = mapToGlobal(QPointF(x, y));
4992 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4993 args->setReturnValue(rv.asReturnedValue());
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023void QQuickItem::forceActiveFocus()
5025 forceActiveFocus(Qt::OtherFocusReason);
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5053void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5055 setFocus(
true, reason);
5056 QQuickItem *parent = parentItem();
5057 QQuickItem *scope =
nullptr;
5059 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5060 parent->setFocus(
true, reason);
5064 parent = parent->parentItem();
5069
5070
5071
5072
5073
5074
5075
5076
5077
5079
5080
5081
5082
5083
5085QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5087 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5091
5092
5093
5094
5095
5096
5097
5099
5100
5101
5102
5103
5104QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5106 const QList<QQuickItem *> children = childItems();
5107 for (
int i = children.size()-1; i >= 0; --i) {
5108 QQuickItem *child = children.at(i);
5110 QPointF point = mapToItem(child, QPointF(x, y));
5111 if (child->isVisible() && child->contains(point))
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158void QQuickItem::dumpItemTree()
const
5160 Q_D(
const QQuickItem);
5164void QQuickItemPrivate::dumpItemTree(
int indent)
const
5166 Q_Q(
const QQuickItem);
5168 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5169 qDebug().nospace().noquote() << indentStr <<
5170#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5171 const_cast<QQuickItem *>(q);
5175 if (extra.isAllocated()) {
5176 for (
const auto handler : extra->pointerHandlers)
5177 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5179 for (
const QQuickItem *ch : childItems) {
5180 auto itemPriv = QQuickItemPrivate::get(ch);
5181 itemPriv->dumpItemTree(indent + 1);
5185QQmlListProperty<QObject> QQuickItemPrivate::resources()
5189 QQmlListProperty<QObject> result;
5190 result.object = q_func();
5191 result.append = QQuickItemPrivate::resources_append;
5192 result.count = QQuickItemPrivate::resources_count;
5193 result.at = QQuickItemPrivate::resources_at;
5194 result.clear = QQuickItemPrivate::resources_clear;
5195 result.removeLast = QQuickItemPrivate::resources_removeLast;
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5213
5214
5215
5216QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5220 QQmlListProperty<QQuickItem> result;
5221 result.object = q_func();
5222 result.append = QQuickItemPrivate::children_append;
5223 result.count = QQuickItemPrivate::children_count;
5224 result.at = QQuickItemPrivate::children_at;
5225 result.clear = QQuickItemPrivate::children_clear;
5226 result.removeLast = QQuickItemPrivate::children_removeLast;
5231
5232
5233
5234
5235
5237
5238
5239
5240QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5242 return QQmlListProperty<QQuickItem>(q_func(),
5244 QQuickItemPrivate::visibleChildren_count,
5245 QQuickItemPrivate::visibleChildren_at);
5250
5251
5252
5253
5254
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
5286
5287
5288
5289QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5291 return _states()->statesProperty();
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5323
5324
5325
5326QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5328 return _states()->transitionsProperty();
5331QString QQuickItemPrivate::state()
const
5336 return _stateGroup->state();
5339void QQuickItemPrivate::setState(
const QString &state)
5341 _states()->setState(state);
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366QString QQuickItem::state()
const
5368 Q_D(
const QQuickItem);
5372void QQuickItem::setState(
const QString &state)
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5391
5392
5393
5395
5396
5397QQmlListProperty<QQuickTransform> QQuickItem::transform()
5399 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5400 QQuickItemPrivate::transform_count,
5401 QQuickItemPrivate::transform_at,
5402 QQuickItemPrivate::transform_clear);
5406
5407
5408
5409
5410void QQuickItem::classBegin()
5413 d->componentComplete =
false;
5415 d->_stateGroup->classBegin();
5417 d->_anchors->classBegin();
5418#if QT_CONFIG(quick_shadereffect)
5419 if (d->extra.isAllocated() && d->extra->layer)
5420 d->extra->layer->classBegin();
5425
5426
5427
5428
5429void QQuickItem::componentComplete()
5432 d->componentComplete =
true;
5434 d->_stateGroup->componentComplete();
5436 d->_anchors->componentComplete();
5437 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5440 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5441 safeArea->updateSafeArea();
5443 if (d->extra.isAllocated()) {
5444#if QT_CONFIG(quick_shadereffect)
5445 if (d->extra->layer)
5446 d->extra->layer->componentComplete();
5449 if (d->extra->keyHandler)
5450 d->extra->keyHandler->componentComplete();
5452 if (d->extra->contents)
5453 d->extra->contents->complete();
5456 if (d->window && d->dirtyAttributes) {
5457 d->addToDirtyList();
5458 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5461#if QT_CONFIG(accessibility)
5462 if (d->isAccessible && d->effectiveVisible) {
5463 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5464 QAccessible::updateAccessibility(&ev);
5469QQuickStateGroup *QQuickItemPrivate::_states()
5473 _stateGroup =
new QQuickStateGroup;
5474 if (!componentComplete)
5475 _stateGroup->classBegin();
5476 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5477 q, QQuickItem, SIGNAL(stateChanged(QString)));
5483bool QQuickItemPrivate::customOverlayRequested =
false;
5485void QQuickItemPrivate::requestCustomOverlay()
5487 customOverlayRequested =
true;
5488 customOverlay =
true;
5491QPointF QQuickItemPrivate::computeTransformOrigin()
const
5495 case QQuickItem::TopLeft:
5496 return QPointF(0, 0);
5497 case QQuickItem::Top:
5498 return QPointF(width / 2., 0);
5499 case QQuickItem::TopRight:
5500 return QPointF(width, 0);
5501 case QQuickItem::Left:
5502 return QPointF(0, height / 2.);
5503 case QQuickItem::Center:
5504 return QPointF(width / 2., height / 2.);
5505 case QQuickItem::Right:
5506 return QPointF(width, height / 2.);
5507 case QQuickItem::BottomLeft:
5508 return QPointF(0, height);
5509 case QQuickItem::Bottom:
5510 return QPointF(width / 2., height);
5511 case QQuickItem::BottomRight:
5512 return QPointF(width, height);
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5534#if QT_CONFIG(quick_shadereffect)
5535 if (q == transformedItem) {
5536 if (extra.isAllocated() && extra->layer)
5537 extra->layer->updateMatrix();
5541 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5543 bool childWantsIt =
false;
5544 if (subtreeTransformChangedEnabled) {
5547 const auto children = paintOrderChildItems();
5548 for (QQuickItem *child : children)
5549 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5552 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5553 const bool ret = childWantsIt || thisWantsIt;
5554 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5555 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5556 subtreeTransformChangedEnabled =
false;
5560 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5561 dirty(QQuickItemPrivate::Clip);
5566 QQuickItemPrivate *itemPriv =
this;
5567 while (itemPriv->parentItem) {
5568 auto *parentPriv = QQuickItemPrivate::get(itemPriv->parentItem);
5569 if (parentPriv->eventHandlingChildrenWithinBounds) {
5570 Q_ASSERT(parentPriv->eventHandlingChildrenWithinBoundsSet);
5571 if (itemPriv->parentFullyContains())
5574 parentPriv->eventHandlingChildrenWithinBounds =
false;
5576 itemPriv = parentPriv;
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5599 const QPointF &startPos,
5600 const QVector2D &activeTranslation,
5603 qreal startRotation,
5604 qreal activeRotation)
5607 QVector3D xformOrigin(q->transformOriginPoint());
5608 QMatrix4x4 startMatrix;
5609 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5610 startMatrix.translate(xformOrigin);
5611 startMatrix.scale(
float(startScale));
5612 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5613 startMatrix.translate(-xformOrigin);
5615 const QVector3D centroidParentVector(centroidParentPos);
5617 mat.translate(centroidParentVector);
5618 mat.rotate(
float(activeRotation), 0, 0, 1);
5619 mat.scale(
float(activeScale));
5620 mat.translate(-centroidParentVector);
5621 mat.translate(QVector3D(activeTranslation));
5623 mat = mat * startMatrix;
5625 QPointF xformOriginPoint = q->transformOriginPoint();
5626 QPointF pos = mat.map(xformOriginPoint);
5627 pos -= xformOriginPoint;
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5657 if (maybeHasSubsceneDeliveryAgent) {
5658 QQuickItemPrivate *p =
this;
5660 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5665 maybeHasSubsceneDeliveryAgent =
false;
5668 if (p->extra.isAllocated()) {
5669 if (
auto da = p->extra->subsceneDeliveryAgent)
5672 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5676 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5679 return QQuickWindowPrivate::get(window)->deliveryAgent;
5683QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5685 auto da = deliveryAgent();
5686 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5690
5691
5692
5693
5694
5695
5696
5697QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5703 maybeHasSubsceneDeliveryAgent =
true;
5704 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5705 return extra->subsceneDeliveryAgent;
5706 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5707 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5710 q->setFlag(QQuickItem::ItemIsFocusScope);
5711 return extra->subsceneDeliveryAgent;
5714bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5716 if (!extra.isAllocated() || !extra->keyHandler)
5722 if (e->type() == QEvent::KeyPress)
5723 extra->keyHandler->keyPressed(e, post);
5725 extra->keyHandler->keyReleased(e, post);
5727 return e->isAccepted();
5730void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5733 const auto eventType = event->type();
5734 const bool focusAccepted = setFocusIfNeeded(eventType);
5736 switch (eventType) {
5737 case QEvent::MouseButtonPress:
5738 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5740 case QEvent::MouseButtonRelease:
5741 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5743 case QEvent::MouseButtonDblClick:
5744 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5746#if QT_CONFIG(wheelevent)
5748 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5751 case QEvent::TouchBegin:
5752 case QEvent::TouchUpdate:
5753 case QEvent::TouchEnd:
5754 case QEvent::TouchCancel:
5755 q->touchEvent(
static_cast<QTouchEvent *>(event));
5765void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5769 Q_ASSERT(e->isAccepted());
5770 if (filterKeyEvent(e,
false))
5775 if (e->type() == QEvent::KeyPress)
5776 q->keyPressEvent(e);
5778 q->keyReleaseEvent(e);
5780 if (e->isAccepted())
5783 if (filterKeyEvent(e,
true) || !q->window())
5787 if (e->type() == QEvent::KeyPress &&
5788 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5790 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5791 if (e->key() == Qt::Key_Backtab
5792 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5793 res = QQuickItemPrivate::focusNextPrev(q,
false);
5794 else if (e->key() == Qt::Key_Tab)
5795 res = QQuickItemPrivate::focusNextPrev(q,
true);
5797 e->setAccepted(
true);
5803void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5807 Q_ASSERT(e->isAccepted());
5808 if (extra.isAllocated() && extra->keyHandler) {
5809 extra->keyHandler->inputMethodEvent(e,
false);
5811 if (e->isAccepted())
5817 q->inputMethodEvent(e);
5819 if (e->isAccepted())
5822 if (extra.isAllocated() && extra->keyHandler) {
5825 extra->keyHandler->inputMethodEvent(e,
true);
5830void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5832 if (extra.isAllocated() && extra->keyHandler)
5833 extra->keyHandler->shortcutOverrideEvent(event);
5838bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5840 if (!hasPointerHandlers())
5842 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5843 if (handler->wantsEventPoint(event, point))
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5865 bool delivered =
false;
5866 if (extra.isAllocated()) {
5867 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5868 bool avoidThisHandler =
false;
5869 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5870 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5871 avoidThisHandler =
true;
5872 }
else if (avoidGrabbers) {
5873 for (
auto &p : event->points()) {
5874 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5875 avoidThisHandler =
true;
5880 if (!avoidThisHandler &&
5881 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5882 handler->handlePointerEvent(event);
5890#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5891bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5893bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5896 if (extra.isAllocated() && extra->contextMenu)
5897 return extra->contextMenu->event(event);
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5917 if (change == ItemSceneChange)
5918 emit windowChanged(value.window);
5923
5924
5925
5926void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5928 if (hasActiveFocus())
5929 QGuiApplication::inputMethod()->update(queries);
5934
5935
5936
5937QRectF QQuickItem::boundingRect()
const
5939 Q_D(
const QQuickItem);
5940 return QRectF(0, 0, d->width, d->height);
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964QRectF QQuickItem::clipRect()
const
5966 Q_D(
const QQuickItem);
5967 QRectF ret(0, 0, d->width.valueBypassingBindings(), d->height.valueBypassingBindings());
5968 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5969 if (QQuickItem *viewport = viewportItem()) {
5972 if (viewport ==
this)
5974 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5975 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5976 return mappedViewportRect.intersected(ret);
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993QQuickItem *QQuickItem::viewportItem()
const
5995 if (flags().testFlag(ItemObservesViewport)) {
5996 QQuickItem *par = parentItem();
5998 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
6000 par = par->parentItem();
6003 return (window() ? window()->contentItem() :
nullptr);
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6028
6029
6030
6031
6032
6033
6034
6035
6036QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6038 Q_D(
const QQuickItem);
6042void QQuickItem::setTransformOrigin(TransformOrigin origin)
6045 if (origin == d->origin())
6048 d->extra.value().origin = origin;
6049 d->dirty(QQuickItemPrivate::TransformOrigin);
6051 emit transformOriginChanged(d->origin());
6055
6056
6057
6059
6060
6061QPointF QQuickItem::transformOriginPoint()
const
6063 Q_D(
const QQuickItem);
6064 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6065 return d->extra->userTransformOriginPoint;
6066 return d->computeTransformOrigin();
6070
6071
6072void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6075 if (d->extra.value().userTransformOriginPoint == point)
6078 d->extra->userTransformOriginPoint = point;
6079 d->dirty(QQuickItemPrivate::TransformOrigin);
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
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
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
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
6236qreal QQuickItem::z()
const
6238 Q_D(
const QQuickItem);
6242void QQuickItem::setZ(qreal v)
6248 d->extra.value().z = v;
6250 d->dirty(QQuickItemPrivate::ZValue);
6251 if (d->parentItem) {
6252 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6253 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6258#if QT_CONFIG(quick_shadereffect)
6259 if (d->extra.isAllocated() && d->extra->layer)
6260 d->extra->layer->updateZ();
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316qreal QQuickItem::rotation()
const
6318 Q_D(
const QQuickItem);
6319 return d->rotation();
6322void QQuickItem::setRotation(qreal r)
6325 if (d->rotation() == r)
6328 d->extra.value().rotation = r;
6330 d->dirty(QQuickItemPrivate::BasicTransform);
6332 d->itemChange(ItemRotationHasChanged, r);
6334 emit rotationChanged();
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416qreal QQuickItem::scale()
const
6418 Q_D(
const QQuickItem);
6422void QQuickItem::setScale(qreal s)
6425 if (d->scale() == s)
6428 d->extra.value().scale = s;
6430 d->dirty(QQuickItemPrivate::BasicTransform);
6432 d->itemChange(ItemScaleHasChanged, s);
6434 emit scaleChanged();
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
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
6547qreal QQuickItem::opacity()
const
6549 Q_D(
const QQuickItem);
6550 return d->opacity();
6553void QQuickItem::setOpacity(qreal newOpacity)
6556 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6557 if (d->opacity() == o)
6560 d->extra.value().opacity = o;
6562 d->dirty(QQuickItemPrivate::OpacityValue);
6564 d->itemChange(ItemOpacityHasChanged, o);
6566 emit opacityChanged();
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633bool QQuickItem::isVisible()
const
6635 Q_D(
const QQuickItem);
6636 return d->effectiveVisible;
6639void QQuickItemPrivate::setVisible(
bool visible)
6641 if (visible == explicitVisible)
6644 explicitVisible = visible;
6646 dirty(QQuickItemPrivate::Visible);
6648 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6649 if (childVisibilityChanged && parentItem)
6650 emit parentItem->visibleChildrenChanged();
6653void QQuickItem::setVisible(
bool v)
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708bool QQuickItem::isEnabled()
const
6710 Q_D(
const QQuickItem);
6711 return d->effectiveEnable;
6714void QQuickItem::setEnabled(
bool e)
6717 if (e == d->explicitEnable)
6720 d->explicitEnable = e;
6722 QQuickItem *scope = parentItem();
6723 while (scope && !scope->isFocusScope())
6724 scope = scope->parentItem();
6726 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6729bool QQuickItemPrivate::calcEffectiveVisible()
const
6732 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6735bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6739 if (newEffectiveVisible && !explicitVisible) {
6744 if (newEffectiveVisible == effectiveVisible) {
6749 effectiveVisible = newEffectiveVisible;
6752 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6754 if (
auto agent = deliveryAgentPrivate())
6755 agent->removeGrabber(q,
true,
true,
true);
6758 bool childVisibilityChanged =
false;
6759 for (
int ii = 0; ii < childItems.size(); ++ii)
6760 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6762 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6763#if QT_CONFIG(accessibility)
6765 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6766 QAccessible::updateAccessibility(&ev);
6769 if (!inDestructor) {
6770 emit q->visibleChanged();
6771 if (childVisibilityChanged)
6772 emit q->visibleChildrenChanged();
6778bool QQuickItemPrivate::calcEffectiveEnable()
const
6783 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6786void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6790 if (newEffectiveEnable && !explicitEnable) {
6795 if (newEffectiveEnable == effectiveEnable) {
6800 effectiveEnable = newEffectiveEnable;
6802 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6804 da->removeGrabber(q,
true,
true,
true);
6805 if (scope && !effectiveEnable && activeFocus) {
6806 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6807 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6808 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6812 for (
int ii = 0; ii < childItems.size(); ++ii) {
6813 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6814 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6817 if (scope && effectiveEnable && focus && da) {
6818 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6819 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6820 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6823 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6824#if QT_CONFIG(accessibility)
6826 QAccessible::State changedState;
6827 changedState.disabled =
true;
6828 changedState.focusable =
true;
6829 QAccessibleStateChangeEvent ev(q, changedState);
6830 QAccessible::updateAccessibility(&ev);
6833 emit q->enabledChanged();
6837
6838
6839
6840qreal QQuickItemPrivate::biggestPointerHandlerMargin()
const
6842 if (hasPointerHandlers()) {
6843 if (extra->biggestPointerHandlerMarginCache < 0) {
6844 const auto maxMarginIt = std::max_element(extra->pointerHandlers.constBegin(),
6845 extra->pointerHandlers.constEnd(),
6846 [](
const QQuickPointerHandler *a,
const QQuickPointerHandler *b) {
6847 return a->margin() < b->margin(); });
6848 Q_ASSERT(maxMarginIt != extra->pointerHandlers.constEnd());
6849 extra->biggestPointerHandlerMarginCache = (*maxMarginIt)->margin();
6851 return extra->biggestPointerHandlerMarginCache;
6857
6858
6859
6860
6861
6862
6863QRectF QQuickItemPrivate::eventHandlingBounds(qreal margin)
const
6865 const qreal biggestMargin = margin > 0 ? margin : biggestPointerHandlerMargin();
6866 return QRectF(-biggestMargin, -biggestMargin, width + biggestMargin * 2, height + biggestMargin * 2);
6870
6871
6872
6873bool QQuickItemPrivate::parentFullyContains()
const
6875 Q_Q(
const QQuickItem);
6879 itemToParentTransform(&t);
6880 const auto bounds = eventHandlingBounds();
6881 const auto boundsInParent = t.mapRect(bounds);
6882 const bool ret = parentItem->clipRect().contains(boundsInParent);
6883 qCDebug(lcEffClip) <<
"in parent bounds?" << ret << q << boundsInParent << parentItem << parentItem->clipRect();
6888
6889
6890
6891bool QQuickItemPrivate::effectivelyClipsEventHandlingChildren()
const
6893 Q_Q(
const QQuickItem);
6895 if (flags & QQuickItem::ItemClipsChildrenToShape) {
6896 qCDebug(lcEffClip) << q <<
"result: true because clip is true";
6899 if (!eventHandlingChildrenWithinBoundsSet) {
6901 eventHandlingChildrenWithinBounds =
true;
6902 for (
const auto *child : childItems) {
6903 const auto *childPriv = QQuickItemPrivate::get(child);
6907 if (childPriv->childItems.isEmpty() &&
6908 !(childPriv->hoverEnabled || childPriv->subtreeHoverEnabled || childPriv->touchEnabled ||
6909 childPriv->hasCursor || childPriv->hasCursorHandler || child->acceptedMouseButtons() ||
6910 childPriv->hasPointerHandlers())) {
6911 qCDebug(lcEffClip) << child <<
"doesn't handle pointer events";
6914 if (!childPriv->parentFullyContains()) {
6915 eventHandlingChildrenWithinBounds =
false;
6916 qCDebug(lcEffClip) <<
"child goes outside: giving up" << child;
6919 if (!childPriv->eventHandlingChildrenWithinBoundsSet) {
6920 eventHandlingChildrenWithinBounds = childPriv->effectivelyClipsEventHandlingChildren();
6921 if (!eventHandlingChildrenWithinBounds)
6922 qCDebug(lcEffClip) <<
"child has children that go outside: giving up" << child;
6925#ifdef QT_BUILD_INTERNAL
6926 if (!eventHandlingChildrenWithinBoundsSet && eventHandlingChildrenWithinBounds)
6927 ++eventHandlingChildrenWithinBounds_counter;
6930 eventHandlingChildrenWithinBoundsSet =
true;
6931 qCDebug(lcEffClip) << q << q->clipRect() <<
"result:" <<
static_cast<
bool>(eventHandlingChildrenWithinBounds);
6933 return eventHandlingChildrenWithinBounds;
6936bool QQuickItemPrivate::isTransparentForPositioner()
const
6938 return extra.isAllocated() && extra.value().transparentForPositioner;
6941void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6943 extra.value().transparentForPositioner = transparent;
6947QString QQuickItemPrivate::dirtyToString()
const
6949#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6951 rv.append(QLatin1Char('|'));
6952 rv.append(QLatin1String(#value)); \
6953}
6980void QQuickItemPrivate::dirty(DirtyType type)
6983 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6984 dirtyAttributes |= type;
6985 if (window && componentComplete) {
6987 QQuickWindowPrivate::get(window)->dirtyItem(q);
6990 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6991 transformChanged(q);
6994void QQuickItemPrivate::addToDirtyList()
6999 if (!prevDirtyItem) {
7000 Q_ASSERT(!nextDirtyItem);
7002 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
7003 nextDirtyItem = p->dirtyItemList;
7004 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
7005 prevDirtyItem = &p->dirtyItemList;
7006 p->dirtyItemList = q;
7009 Q_ASSERT(prevDirtyItem);
7012void QQuickItemPrivate::removeFromDirtyList()
7014 if (prevDirtyItem) {
7015 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
7016 *prevDirtyItem = nextDirtyItem;
7017 prevDirtyItem =
nullptr;
7018 nextDirtyItem =
nullptr;
7020 Q_ASSERT(!prevDirtyItem);
7021 Q_ASSERT(!nextDirtyItem);
7024void QQuickItemPrivate::refFromEffectItem(
bool hide)
7026 ++extra.value().effectRefCount;
7027 if (extra->effectRefCount == 1) {
7028 dirty(EffectReference);
7030 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7033 if (++extra->hideRefCount == 1)
7034 dirty(HideReference);
7036 recursiveRefFromEffectItem(1);
7039void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
7044 extra.value().recursiveEffectRefCount += refs;
7045 for (
int ii = 0; ii < childItems.size(); ++ii) {
7046 QQuickItem *child = childItems.at(ii);
7047 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
7051 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
7055void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
7057 Q_ASSERT(extra->effectRefCount);
7058 --extra->effectRefCount;
7059 if (extra->effectRefCount == 0) {
7060 dirty(EffectReference);
7062 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7065 if (--extra->hideRefCount == 0)
7066 dirty(HideReference);
7068 recursiveRefFromEffectItem(-1);
7071void QQuickItemPrivate::setCulled(
bool cull)
7077 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
7078 dirty(HideReference);
7081void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
7085 case QQuickItem::ItemChildAddedChange: {
7086 q->itemChange(change, data);
7092 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
7093 if (!subtreeTransformChangedEnabled) {
7094 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
7095 subtreeTransformChangedEnabled =
true;
7097 enableSubtreeChangeNotificationsForParentHierachy();
7099 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
7102 case QQuickItem::ItemChildRemovedChange: {
7103 q->itemChange(change, data);
7104 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
7107 case QQuickItem::ItemSceneChange:
7108 q->itemChange(change, data);
7110 case QQuickItem::ItemVisibleHasChanged: {
7111 q->itemChange(change, data);
7112 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
7115 case QQuickItem::ItemEnabledHasChanged: {
7116 q->itemChange(change, data);
7117 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
7120 case QQuickItem::ItemParentHasChanged: {
7121 q->itemChange(change, data);
7122 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
7125 case QQuickItem::ItemOpacityHasChanged: {
7126 q->itemChange(change, data);
7127 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
7130 case QQuickItem::ItemActiveFocusHasChanged:
7131 q->itemChange(change, data);
7133 case QQuickItem::ItemRotationHasChanged: {
7134 q->itemChange(change, data);
7135 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7138 case QQuickItem::ItemScaleHasChanged: {
7139 q->itemChange(change, data);
7140 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7143 case QQuickItem::ItemTransformHasChanged: {
7144 q->itemChange(change, data);
7145 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7148 case QQuickItem::ItemAntialiasingHasChanged:
7150 case QQuickItem::ItemDevicePixelRatioHasChanged:
7151 q->itemChange(change, data);
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179bool QQuickItem::smooth()
const
7181 Q_D(
const QQuickItem);
7184void QQuickItem::setSmooth(
bool smooth)
7187 if (d->smooth == smooth)
7191 d->dirty(QQuickItemPrivate::Smooth);
7193 emit smoothChanged(smooth);
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7235bool QQuickItem::activeFocusOnTab()
const
7237 Q_D(
const QQuickItem);
7238 return d->activeFocusOnTab;
7240void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7243 if (d->activeFocusOnTab == activeFocusOnTab)
7247 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7248 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7253 d->activeFocusOnTab = activeFocusOnTab;
7255 emit activeFocusOnTabChanged(activeFocusOnTab);
7259
7260
7261
7262
7263
7264
7265
7266
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277bool QQuickItem::antialiasing()
const
7279 Q_D(
const QQuickItem);
7280 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7283void QQuickItem::setAntialiasing(
bool aa)
7287 if (!d->antialiasingValid) {
7288 d->antialiasingValid =
true;
7289 d->antialiasing = d->implicitAntialiasing;
7292 if (aa == d->antialiasing)
7295 d->antialiasing = aa;
7296 d->dirty(QQuickItemPrivate::Antialiasing);
7298 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7300 emit antialiasingChanged(antialiasing());
7303void QQuickItem::resetAntialiasing()
7306 if (!d->antialiasingValid)
7309 d->antialiasingValid =
false;
7311 if (d->implicitAntialiasing != d->antialiasing)
7312 emit antialiasingChanged(antialiasing());
7315void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7318 bool prev = q->antialiasing();
7319 implicitAntialiasing = antialiasing;
7320 if (componentComplete && (q->antialiasing() != prev))
7321 emit q->antialiasingChanged(q->antialiasing());
7325
7326
7327
7328
7329QQuickItem::Flags QQuickItem::flags()
const
7331 Q_D(
const QQuickItem);
7332 return (QQuickItem::Flags)d->flags;
7336
7337
7338
7339
7340
7341
7342
7343void QQuickItem::setFlag(Flag flag,
bool enabled)
7347 setFlags((Flags)(d->flags | (quint32)flag));
7349 setFlags((Flags)(d->flags & ~(quint32)flag));
7353 if (enabled && flag == ItemObservesViewport)
7354 d->enableSubtreeChangeNotificationsForParentHierachy();
7357void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7361 QQuickItem *par = q->parentItem();
7363 auto parPriv = QQuickItemPrivate::get(par);
7364 if (!parPriv->subtreeTransformChangedEnabled)
7365 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7366 parPriv->subtreeTransformChangedEnabled =
true;
7367 par = par->parentItem();
7372
7373
7374
7375
7376void QQuickItem::setFlags(Flags flags)
7380 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7381 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7382 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7383 flags &= ~ItemIsFocusScope;
7384 }
else if (d->flags & ItemIsFocusScope) {
7385 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7386 flags |= ItemIsFocusScope;
7390 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7391 d->dirty(QQuickItemPrivate::Clip);
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7412
7413
7414
7415
7417
7418
7419
7420
7421qreal QQuickItem::x()
const
7423 Q_D(
const QQuickItem);
7427qreal QQuickItem::y()
const
7429 Q_D(
const QQuickItem);
7434
7435
7436QPointF QQuickItem::position()
const
7438 Q_D(
const QQuickItem);
7439 return QPointF(d->x, d->y);
7442void QQuickItem::setX(qreal v)
7446
7447
7448
7449
7450
7451
7452
7453
7454 d->x.removeBindingUnlessInWrapper();
7458 const qreal oldx = d->x.valueBypassingBindings();
7462 d->x.setValueBypassingBindings(v);
7464 d->dirty(QQuickItemPrivate::Position);
7466 const qreal y = d->y.valueBypassingBindings();
7467 const qreal w = d->width.valueBypassingBindings();
7468 const qreal h = d->height.valueBypassingBindings();
7469 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7472void QQuickItem::setY(qreal v)
7475 d->y.removeBindingUnlessInWrapper();
7479 const qreal oldy = d->y.valueBypassingBindings();
7483 d->y.setValueBypassingBindings(v);
7485 d->dirty(QQuickItemPrivate::Position);
7489 const qreal x = d->x.valueBypassingBindings();
7490 const qreal w = d->width.valueBypassingBindings();
7491 const qreal h = d->height.valueBypassingBindings();
7492 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7496
7497
7498void QQuickItem::setPosition(
const QPointF &pos)
7502 const qreal oldx = d->x.valueBypassingBindings();
7503 const qreal oldy = d->y.valueBypassingBindings();
7505 if (QPointF(oldx, oldy) == pos)
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7521 d->x.setValueBypassingBindings(pos.x());
7522 d->y.setValueBypassingBindings(pos.y());
7524 d->dirty(QQuickItemPrivate::Position);
7526 const qreal w = d->width.valueBypassingBindings();
7527 const qreal h = d->height.valueBypassingBindings();
7528 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7532
7533
7534QBindable<qreal> QQuickItem::bindableX()
7536 return QBindable<qreal>(&d_func()->x);
7539QBindable<qreal> QQuickItem::bindableY()
7541 return QBindable<qreal>(&d_func()->y);
7545
7546
7547
7548
7549qreal QQuickItem::width()
const
7551 Q_D(
const QQuickItem);
7555void QQuickItem::setWidth(qreal w)
7558 d->width.removeBindingUnlessInWrapper();
7562 d->widthValidFlag =
true;
7563 const qreal oldWidth = d->width.valueBypassingBindings();
7567 d->width.setValueBypassingBindings(w);
7569 d->dirty(QQuickItemPrivate::Size);
7571 const qreal x = d->x.valueBypassingBindings();
7572 const qreal y = d->y.valueBypassingBindings();
7573 const qreal h = d->height.valueBypassingBindings();
7574 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7577void QQuickItem::resetWidth()
7580 d->width.takeBinding();
7581 d->widthValidFlag =
false;
7582 setImplicitWidth(implicitWidth());
7585void QQuickItemPrivate::implicitWidthChanged()
7588 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7589 emit q->implicitWidthChanged();
7592qreal QQuickItemPrivate::getImplicitWidth()
const
7594 return implicitWidth;
7597
7598
7599qreal QQuickItem::implicitWidth()
const
7601 Q_D(
const QQuickItem);
7602 return d->getImplicitWidth();
7605QBindable<qreal> QQuickItem::bindableWidth()
7607 return QBindable<qreal>(&d_func()->width);
7611
7612
7613
7614
7615
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
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692void QQuickItem::setImplicitWidth(qreal w)
7695 bool changed = w != d->implicitWidth;
7696 d->implicitWidth = w;
7698 if (d->width.valueBypassingBindings() == w || widthValid()) {
7700 d->implicitWidthChanged();
7701 if (d->width.valueBypassingBindings() == w || widthValid())
7706 const qreal oldWidth = d->width.valueBypassingBindings();
7707 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7709 d->width.setValueBypassingBindings(w);
7711 d->dirty(QQuickItemPrivate::Size);
7713 const qreal x = d->x.valueBypassingBindings();
7714 const qreal y = d->y.valueBypassingBindings();
7715 const qreal width = w;
7716 const qreal height = d->height.valueBypassingBindings();
7717 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7720 d->implicitWidthChanged();
7724
7725
7726bool QQuickItem::widthValid()
const
7728 Q_D(
const QQuickItem);
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7746 return d->widthValid();
7750
7751
7752
7753
7754qreal QQuickItem::height()
const
7756 Q_D(
const QQuickItem);
7760void QQuickItem::setHeight(qreal h)
7766 d->height.removeBindingUnlessInWrapper();
7770 d->heightValidFlag =
true;
7771 const qreal oldHeight = d->height.valueBypassingBindings();
7775 d->height.setValueBypassingBindings(h);
7777 d->dirty(QQuickItemPrivate::Size);
7779 const qreal x = d->x.valueBypassingBindings();
7780 const qreal y = d->y.valueBypassingBindings();
7781 const qreal w = d->width.valueBypassingBindings();
7782 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7785void QQuickItem::resetHeight()
7791 d->height.takeBinding();
7792 d->heightValidFlag =
false;
7793 setImplicitHeight(implicitHeight());
7796void QQuickItemPrivate::implicitHeightChanged()
7799 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7800 emit q->implicitHeightChanged();
7803qreal QQuickItemPrivate::getImplicitHeight()
const
7805 return implicitHeight;
7808qreal QQuickItem::implicitHeight()
const
7810 Q_D(
const QQuickItem);
7811 return d->getImplicitHeight();
7814QBindable<qreal> QQuickItem::bindableHeight()
7816 return QBindable<qreal>(&d_func()->height);
7819void QQuickItem::setImplicitHeight(qreal h)
7822 bool changed = h != d->implicitHeight;
7823 d->implicitHeight = h;
7824 if (d->height.valueBypassingBindings() == h || heightValid()) {
7826 d->implicitHeightChanged();
7827 if (d->height.valueBypassingBindings() == h || heightValid())
7832 const qreal oldHeight = d->height.valueBypassingBindings();
7833 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7835 d->height.setValueBypassingBindings(h);
7837 d->dirty(QQuickItemPrivate::Size);
7839 const qreal x = d->x.valueBypassingBindings();
7840 const qreal y = d->y.valueBypassingBindings();
7841 const qreal width = d->width.valueBypassingBindings();
7842 const qreal height = d->height.valueBypassingBindings();
7843 geometryChange(QRectF(x, y, width, height),
7844 QRectF(x, y, width, oldHeight));
7847 d->implicitHeightChanged();
7851
7852
7853void QQuickItem::setImplicitSize(qreal w, qreal h)
7856 bool wChanged = w != d->implicitWidth;
7857 bool hChanged = h != d->implicitHeight;
7859 d->implicitWidth = w;
7860 d->implicitHeight = h;
7864 qreal width = d->width.valueBypassingBindings();
7865 qreal height = d->height.valueBypassingBindings();
7866 if (width == w || widthValid()) {
7868 d->implicitWidthChanged();
7869 wDone = width == w || widthValid();
7872 if (height == h || heightValid()) {
7874 d->implicitHeightChanged();
7875 hDone = height == h || heightValid();
7881 const qreal oldWidth = width;
7882 const qreal oldHeight = height;
7885 d->width.setValueBypassingBindings(w);
7889 d->height.setValueBypassingBindings(h);
7892 d->dirty(QQuickItemPrivate::Size);
7894 const qreal x = d->x.valueBypassingBindings();
7895 const qreal y = d->y.valueBypassingBindings();
7896 geometryChange(QRectF(x, y, width, height),
7897 QRectF(x, y, oldWidth, oldHeight));
7899 if (!wDone && wChanged)
7900 d->implicitWidthChanged();
7901 if (!hDone && hChanged)
7902 d->implicitHeightChanged();
7906
7907
7908bool QQuickItem::heightValid()
const
7910 Q_D(
const QQuickItem);
7911 return d->heightValid();
7915
7916
7917
7918
7919
7920
7922QSizeF QQuickItem::size()
const
7924 Q_D(
const QQuickItem);
7925 return QSizeF(d->width, d->height);
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939void QQuickItem::setSize(
const QSizeF &size)
7942 d->heightValidFlag =
true;
7943 d->widthValidFlag =
true;
7945 const qreal oldHeight = d->height.valueBypassingBindings();
7946 const qreal oldWidth = d->width.valueBypassingBindings();
7948 if (oldWidth == size.width() && oldHeight == size.height())
7951 d->height.setValueBypassingBindings(size.height());
7952 d->width.setValueBypassingBindings(size.width());
7954 d->dirty(QQuickItemPrivate::Size);
7956 const qreal x = d->x.valueBypassingBindings();
7957 const qreal y = d->y.valueBypassingBindings();
7958 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030bool QQuickItem::hasActiveFocus()
const
8032 Q_D(
const QQuickItem);
8033 return d->activeFocus;
8037
8038
8039
8040
8041
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
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124bool QQuickItem::hasFocus()
const
8126 Q_D(
const QQuickItem);
8130void QQuickItem::setFocus(
bool focus)
8132 setFocus(focus, Qt::OtherFocusReason);
8135void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8139 QQuickItem *scope = parentItem();
8140 while (scope && !scope->isFocusScope() && scope->parentItem())
8141 scope = scope->parentItem();
8143 if (d->focus == focus && d->activeFocus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8146 bool notifyListeners =
false;
8147 if (d->window || d->parentItem) {
8149 auto da = d->deliveryAgentPrivate();
8152 da->setFocusInScope(scope,
this, reason);
8154 da->clearFocusInScope(scope,
this, reason);
8158 QVarLengthArray<QQuickItem *, 20> changed;
8159 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8160 if (oldSubFocusItem) {
8161 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8162 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8163 changed << oldSubFocusItem;
8164 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8165 QQuickItemPrivate::get(scope)->focus =
false;
8168 d->updateSubFocusItem(scope, focus);
8172 notifyListeners =
true;
8173 emit focusChanged(focus);
8175 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8178 QVarLengthArray<QQuickItem *, 20> changed;
8179 QQuickItem *oldSubFocusItem = d->subFocusItem;
8180 if (!isFocusScope() && oldSubFocusItem) {
8181 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8182 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8183 changed << oldSubFocusItem;
8188 notifyListeners =
true;
8189 emit focusChanged(focus);
8191 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8193 if (notifyListeners)
8194 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8198
8199
8200bool QQuickItem::isFocusScope()
const
8202 return flags() & ItemIsFocusScope;
8206
8207
8208
8209
8210
8211QQuickItem *QQuickItem::scopedFocusItem()
const
8213 Q_D(
const QQuickItem);
8214 if (!isFocusScope())
8217 return d->subFocusItem;
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8235
8236
8237
8238
8239
8240
8241Qt::FocusPolicy QQuickItem::focusPolicy()
const
8243 Q_D(
const QQuickItem);
8244 uint policy = d->focusPolicy;
8245 if (activeFocusOnTab())
8246 policy |= Qt::TabFocus;
8247 return static_cast<Qt::FocusPolicy>(policy);
8251
8252
8253
8254
8255void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8258 if (d->focusPolicy == policy)
8261 d->focusPolicy = policy;
8262 setActiveFocusOnTab(policy & Qt::TabFocus);
8263 emit focusPolicyChanged(policy);
8267
8268
8269
8270
8271
8272
8273
8274bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8276 if (!child || child ==
this)
8278 const QQuickItem *ancestor = child;
8279 while ((ancestor = ancestor->parentItem())) {
8280 if (ancestor ==
this)
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8299 Q_D(
const QQuickItem);
8300 return d->acceptedMouseButtons();
8304
8305
8306
8307
8308
8309
8310
8311
8312void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8315 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8317 buttons &= ~Qt::LeftButton;
8318 if (buttons || d->extra.isAllocated()) {
8319 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8320 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335bool QQuickItem::filtersChildMouseEvents()
const
8337 Q_D(
const QQuickItem);
8338 return d->filtersChildMouseEvents;
8342
8343
8344
8345
8346
8347
8348
8349
8350void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8353 d->filtersChildMouseEvents = filter;
8357
8358
8359bool QQuickItem::isUnderMouse()
const
8361 Q_D(
const QQuickItem);
8368 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8371 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8372 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8376
8377
8378
8379
8380
8381
8382
8383bool QQuickItem::acceptHoverEvents()
const
8385 Q_D(
const QQuickItem);
8386 return d->hoverEnabled;
8390
8391
8392
8393
8394
8395void QQuickItem::setAcceptHoverEvents(
bool enabled)
8402 d->hoverEnabled = enabled;
8408 d->setHasHoverInChild(enabled);
8412 d->dirty(QQuickItemPrivate::Content);
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425bool QQuickItem::acceptTouchEvents()
const
8427 Q_D(
const QQuickItem);
8428 return d->touchEnabled;
8432
8433
8434
8435
8436
8437
8438
8439void QQuickItem::setAcceptTouchEvents(
bool enabled)
8442 d->touchEnabled = enabled;
8445void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8447#if QT_CONFIG(cursor)
8452 if (!hc && subtreeCursorEnabled) {
8453 if (hasCursor || hasCursorHandler)
8455 for (QQuickItem *otherChild : std::as_const(childItems)) {
8456 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8457 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8462 subtreeCursorEnabled = hc;
8463 QQuickItem *parent = q->parentItem();
8465 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8466 parentPrivate->setHasCursorInChild(hc);
8473void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8479 if (!hasHover && subtreeHoverEnabled) {
8482 if (hasEnabledHoverHandlers())
8485 for (QQuickItem *otherChild : std::as_const(childItems)) {
8486 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8487 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8489 if (otherChildPrivate->hasEnabledHoverHandlers())
8494 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8495 subtreeHoverEnabled = hasHover;
8496 QQuickItem *parent = q->parentItem();
8498 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8499 parentPrivate->setHasHoverInChild(hasHover);
8503#if QT_CONFIG(cursor)
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8519QCursor QQuickItem::cursor()
const
8521 Q_D(
const QQuickItem);
8522 return d->extra.isAllocated()
8528
8529
8530
8531
8533void QQuickItem::setCursor(
const QCursor &cursor)
8537 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8538 qCDebug(lcHoverCursor) << oldShape <<
"->" << cursor.shape();
8540 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8541 d->extra.value().cursor = cursor;
8543 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8544 QWindow *window = renderWindow ? renderWindow : d->window;
8545 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8546 window->setCursor(cursor);
8550 QPointF updateCursorPos;
8551 if (!d->hasCursor) {
8552 d->hasCursor =
true;
8554 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8555 QWindow *window = renderWindow ? renderWindow : d->window;
8556 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8557 if (contains(mapFromScene(pos)))
8558 updateCursorPos = pos;
8561 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8562 if (!updateCursorPos.isNull())
8563 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8567
8568
8569
8570
8572void QQuickItem::unsetCursor()
8575 qCDebug(lcHoverTrace) <<
"clearing cursor";
8578 d->hasCursor =
false;
8579 d->setHasCursorInChild(d->hasCursorHandler);
8580 if (d->extra.isAllocated())
8581 d->extra->cursor = QCursor();
8584 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8585 if (windowPrivate->cursorItem ==
this) {
8586 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8587 windowPrivate->updateCursor(pos);
8593
8594
8595
8596
8597
8598
8599QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8601 Q_Q(
const QQuickItem);
8604 bool hoverCursorSet =
false;
8605 QCursor hoverCursor;
8606 bool activeCursorSet =
false;
8607 QCursor activeCursor;
8608 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8609 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8610 hoverCursor = hoverHandler->cursorShape();
8611 }
else if (handler->active()) {
8612 activeCursorSet = handler->isCursorShapeExplicitlySet();
8613 activeCursor = handler->cursorShape();
8615 if (activeCursorSet)
8616 return activeCursor;
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8644 if (!hasPointerHandlers())
8646 QQuickPointerHandler* activeHandler =
nullptr;
8647 QQuickPointerHandler* mouseHandler =
nullptr;
8648 QQuickPointerHandler* nonMouseHandler =
nullptr;
8649 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8650 if (!h->isCursorShapeExplicitlySet())
8652 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8657 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8658 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8659 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8661 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8662 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8663 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8665 mouseHandler = hoverHandler;
8668 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8669 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8670 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8672 nonMouseHandler = hoverHandler;
8675 if (!hoverHandler && h->active())
8678 if (activeHandler) {
8679 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8680 return activeHandler;
8686 if (nonMouseHandler) {
8688 const bool beforeTimeout =
8689 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8690 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8691 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8692 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8693 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8694 <<
"choosing cursor according to" << winner << winner->cursorShape();
8697 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8698 return nonMouseHandler;
8701 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8702 return mouseHandler;
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721void QQuickItem::grabMouse()
8726 auto da = d->deliveryAgentPrivate();
8728 auto eventInDelivery = da->eventInDelivery();
8729 if (!eventInDelivery) {
8730 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8733 auto epd = da->mousePointData();
8734 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748void QQuickItem::ungrabMouse()
8753 auto da = d->deliveryAgentPrivate();
8755 auto eventInDelivery = da->eventInDelivery();
8756 if (!eventInDelivery) {
8758 da->removeGrabber(
this);
8761 const auto &eventPoint = da->mousePointData()->eventPoint;
8762 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8763 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8767
8768
8769
8770
8771bool QQuickItem::keepMouseGrab()
const
8773 Q_D(
const QQuickItem);
8774 return d->keepMouse;
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793void QQuickItem::setKeepMouseGrab(
bool keep)
8796 d->keepMouse = keep;
8800
8801
8802
8803
8804
8805
8806
8807
8808void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8811 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8812 if (Q_UNLIKELY(!event)) {
8813 qWarning() <<
"cannot grab: no event is currently being delivered";
8816 for (
auto pt : event->points()) {
8817 if (ids.contains(pt.id()))
8818 event->setExclusiveGrabber(pt,
this);
8823
8824
8825
8826void QQuickItem::ungrabTouchPoints()
8831 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8832 da->removeGrabber(
this,
false,
true);
8836
8837
8838
8839
8840
8841bool QQuickItem::keepTouchGrab()
const
8843 Q_D(
const QQuickItem);
8844 return d->keepTouch;
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864void QQuickItem::setKeepTouchGrab(
bool keep)
8867 d->keepTouch = keep;
8871
8872
8873
8874
8875
8876
8877
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889bool QQuickItem::contains(
const QPointF &point)
const
8891 Q_D(
const QQuickItem);
8892 if (d->extra.isAllocated() && d->extra->mask) {
8893 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8894 return quickMask->contains(point - quickMask->position());
8897 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8898 maskContains.invoke(d->extra->mask,
8899 Qt::DirectConnection,
8900 Q_RETURN_ARG(
bool, res),
8901 Q_ARG(QPointF, point));
8905 qreal x = point.x();
8906 qreal y = point.y();
8907 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8911
8912
8913
8914
8915
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
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973QObject *QQuickItem::containmentMask()
const
8975 Q_D(
const QQuickItem);
8976 if (!d->extra.isAllocated())
8978 return d->extra->mask.data();
8981void QQuickItem::setContainmentMask(QObject *mask)
8984 const bool extraDataExists = d->extra.isAllocated();
8986 if (mask ==
static_cast<QObject *>(
this))
8989 if (!extraDataExists && !mask)
8992 if (extraDataExists && d->extra->mask == mask)
8995 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8998 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8999 maskPrivate->registerAsContainmentMask(
this,
false);
9002 if (!extraDataExists)
9005 int methodIndex = mask->metaObject()->indexOfMethod(
"contains(QPointF)");
9006 if (methodIndex < 0) {
9007 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
9010 d->extra->maskContainsIndex = methodIndex;
9012 d->extra->mask = mask;
9013 quickMask = qobject_cast<QQuickItem *>(mask);
9015 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9016 maskPrivate->registerAsContainmentMask(
this,
true);
9018 emit containmentMaskChanged();
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
9035 QPointF p = mapToScene(point);
9037 const auto *itemWindow = item->window();
9038 const auto *thisWindow = window();
9039 if (thisWindow && itemWindow && itemWindow != thisWindow)
9040 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
9042 p = item->mapFromScene(p);
9048
9049
9050
9051
9052
9053
9054
9055
9056QPointF QQuickItem::mapToScene(
const QPointF &point)
const
9058 Q_D(
const QQuickItem);
9059 return d->itemToWindowTransform().map(point);
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
9081 Q_D(
const QQuickItem);
9083 if (Q_UNLIKELY(d->window ==
nullptr))
9084 return mapToScene(point);
9086 QPoint renderOffset;
9087 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9088 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9089 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
9106 Q_D(
const QQuickItem);
9107 QTransform t = d->itemToWindowTransform();
9109 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
9110 return t.mapRect(rect);
9114
9115
9116
9117
9118
9119
9120
9121
9122QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
9124 Q_D(
const QQuickItem);
9125 return d->itemToWindowTransform().mapRect(rect);
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9144 p = item->mapToScene(point);
9145 const auto *itemWindow = item->window();
9146 const auto *thisWindow = window();
9147 if (thisWindow && itemWindow && itemWindow != thisWindow)
9148 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9150 return mapFromScene(p);
9154
9155
9156
9157
9158
9159
9160
9161
9162QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9164 Q_D(
const QQuickItem);
9165 return d->windowToItemTransform().map(point);
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9193 Q_D(
const QQuickItem);
9196 if (Q_LIKELY(d->window)) {
9197 QPoint renderOffset;
9198 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9199 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9200 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9205 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9206 if (
auto sceneTransform = da->sceneTransform())
9207 scenePoint = sceneTransform->map(scenePoint);
9209 return mapFromScene(scenePoint);
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9226 Q_D(
const QQuickItem);
9227 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9228 t *= d->windowToItemTransform();
9229 return t.mapRect(rect);
9233
9234
9235
9236
9237
9238
9239
9240
9241QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9243 Q_D(
const QQuickItem);
9244 return d->windowToItemTransform().mapRect(rect);
9248
9249
9250
9253
9254
9255
9258
9259
9260
9263
9264
9265
9268
9269
9270
9273
9274
9275
9278
9279
9280
9283
9284
9285
9288
9289
9290
9293
9294
9295
9298
9299
9300bool QQuickItem::event(QEvent *ev)
9304 switch (ev->type()) {
9306 case QEvent::InputMethodQuery: {
9307 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9308 Qt::InputMethodQueries queries = query->queries();
9309 for (uint i = 0; i < 32; ++i) {
9310 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9312 QVariant v = inputMethodQuery(q);
9313 query->setValue(q, v);
9319 case QEvent::InputMethod:
9320 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9323 case QEvent::TouchBegin:
9324 case QEvent::TouchUpdate:
9325 case QEvent::TouchEnd:
9326 case QEvent::TouchCancel:
9327 case QEvent::MouseButtonPress:
9328 case QEvent::MouseButtonRelease:
9329 case QEvent::MouseButtonDblClick:
9330#if QT_CONFIG(wheelevent)
9333 d->deliverPointerEvent(ev);
9335 case QEvent::StyleAnimationUpdate:
9341 case QEvent::HoverEnter:
9342 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9344 case QEvent::HoverLeave:
9345 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9347 case QEvent::HoverMove:
9348 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9350 case QEvent::KeyPress:
9351 case QEvent::KeyRelease:
9352 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9354 case QEvent::ShortcutOverride:
9355 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9357 case QEvent::FocusIn:
9358 focusInEvent(
static_cast<QFocusEvent*>(ev));
9360 case QEvent::FocusOut:
9361 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9363 case QEvent::MouseMove:
9364 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9366#if QT_CONFIG(quick_draganddrop)
9367 case QEvent::DragEnter:
9368 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9370 case QEvent::DragLeave:
9371 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9373 case QEvent::DragMove:
9374 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9377 dropEvent(
static_cast<QDropEvent*>(ev));
9380#if QT_CONFIG(gestures)
9381 case QEvent::NativeGesture:
9385 case QEvent::LanguageChange:
9386 case QEvent::LocaleChange:
9387 for (QQuickItem *item : std::as_const(d->childItems))
9388 QCoreApplication::sendEvent(item, ev);
9390 case QEvent::WindowActivate:
9391 case QEvent::WindowDeactivate:
9392 if (d->providesPalette())
9393 d->setCurrentColorGroup();
9394 for (QQuickItem *item : std::as_const(d->childItems))
9395 QCoreApplication::sendEvent(item, ev);
9397 case QEvent::ApplicationPaletteChange:
9398 for (QQuickItem *item : std::as_const(d->childItems))
9399 QCoreApplication::sendEvent(item, ev);
9401 case QEvent::ContextMenu:
9403 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9406 return QObject::event(ev);
9412#ifndef QT_NO_DEBUG_STREAM
9414#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9419 QDebugStateSaver saver(debug);
9422 debug <<
"QQuickItem(nullptr)";
9426 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9428 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9432 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9433 if (QQmlContext *context = qmlContext(item)) {
9434 const auto objectId = context->nameForObject(item);
9435 if (!objectId.isEmpty())
9436 debug <<
", id=" << objectId;
9439 if (!item->objectName().isEmpty())
9440 debug <<
", name=" << item->objectName();
9441 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9443 QtDebugUtils::formatQRect(debug, rect);
9444 if (
const qreal z = item->z())
9445 debug <<
", z=" << z;
9446 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9447 debug <<
" \U0001f5bc";
9448 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9456
9457
9458
9459
9460
9461
9462
9464bool QQuickItem::isTextureProvider()
const
9466#if QT_CONFIG(quick_shadereffect)
9467 Q_D(
const QQuickItem);
9468 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9469 d->extra->layer->effectSource()->isTextureProvider() :
false;
9476
9477
9478
9479
9480
9481
9482
9484QSGTextureProvider *QQuickItem::textureProvider()
const
9486#if QT_CONFIG(quick_shadereffect)
9487 Q_D(
const QQuickItem);
9488 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9489 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9537#if QT_CONFIG(quick_shadereffect)
9539
9540
9541
9542QQuickItemLayer *QQuickItemPrivate::layer()
const
9544 if (!extra.isAllocated() || !extra->layer) {
9545 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9546 if (!componentComplete)
9547 extra->layer->classBegin();
9549 return extra->layer;
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9573 QList<QEventPoint> touchPoints;
9574 QEventPoint::States eventStates;
9576 bool anyPressOrReleaseInside =
false;
9577 bool anyGrabber =
false;
9578 for (
auto &p : event->points()) {
9583 auto pointGrabber = event->exclusiveGrabber(p);
9584 bool isGrabber = (pointGrabber == q);
9585 if (!isGrabber && pointGrabber && isFiltering) {
9586 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9587 if (handlerGrabber && handlerGrabber->parentItem() == q)
9594 const auto localPos = q->mapFromScene(p.scenePosition());
9595 bool isInside = q->contains(localPos);
9596 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9598 if (isFiltering && !pointGrabber) {
9599 const auto pg = event->passiveGrabbers(p);
9600 if (!pg.isEmpty()) {
9604 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9606 pointGrabber = handler->parentItem();
9611 bool grabberIsChild =
false;
9612 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9613 while (isFiltering && parent) {
9615 grabberIsChild =
true;
9618 parent = parent->parentItem();
9621 bool filterRelevant = isFiltering && grabberIsChild;
9622 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9624 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9625 anyPressOrReleaseInside =
true;
9626 QEventPoint pCopy(p);
9627 eventStates |= p.state();
9628 if (p.state() == QEventPoint::State::Released)
9629 QMutableEventPoint::detach(pCopy);
9630 QMutableEventPoint::setPosition(pCopy, localPos);
9631 touchPoints.append(std::move(pCopy));
9636 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9637 *localized = QMutableTouchEvent(QEvent::None);
9642 QEvent::Type eventType = event->type();
9643 switch (eventStates) {
9644 case QEventPoint::State::Pressed:
9645 eventType = QEvent::TouchBegin;
9647 case QEventPoint::State::Released:
9648 eventType = QEvent::TouchEnd;
9651 eventType = QEvent::TouchUpdate;
9655 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9657 ret.setTimestamp(event->timestamp());
9662bool QQuickItemPrivate::hasPointerHandlers()
const
9664 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9667bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9669 if (!hasPointerHandlers())
9671 for (QQuickPointerHandler *h : extra->pointerHandlers)
9672 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9677void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9683 extra.value().acceptedMouseButtons = Qt::AllButtons;
9684 auto &handlers = extra.value().pointerHandlers;
9685 if (!handlers.contains(h))
9686 handlers.prepend(h);
9687 auto &res = extra.value().resourcesList;
9688 if (!res.contains(h)) {
9690 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9691 _q_resourceObjectDeleted(o);
9696void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9700 auto &handlers = extra.value().pointerHandlers;
9701 handlers.removeOne(h);
9702 auto &res = extra.value().resourcesList;
9704 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9705 if (handlers.isEmpty())
9706 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9710
9711
9712
9713QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9715 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9716 extra.value().contextMenu = menu;
9720QtPrivate::QQuickAttachedPropertyPropagator *QQuickItemPrivate::attachedPropertyPropagator_parent(
9721 const QMetaObject *attachedType)
9724 qCDebug(lcAttachedPropertyPropagator).noquote() <<
"- attachedPropertyPropagator_parent called on"
9725 << q <<
"with attachedType" << attachedType->metaType().name();
9727 QQuickItem *parent = q->parentItem();
9728 if (
auto *attached = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(attachedType, parent)) {
9729 qCDebug(lcAttachedPropertyPropagator).noquote() <<
" - parent item has attached object"
9730 << attached <<
"- returning";
9737#if QT_CONFIG(quick_shadereffect)
9738QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9744 , m_componentComplete(
true)
9745 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9746 , m_format(QQuickShaderEffectSource::RGBA8)
9748 , m_effectComponent(
nullptr)
9750 , m_effectSource(
nullptr)
9751 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9756QQuickItemLayer::~QQuickItemLayer()
9758 delete m_effectSource;
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776void QQuickItemLayer::setEnabled(
bool e)
9781 if (m_componentComplete) {
9788 emit enabledChanged(e);
9791void QQuickItemLayer::classBegin()
9793 Q_ASSERT(!m_effectSource);
9794 Q_ASSERT(!m_effect);
9795 m_componentComplete =
false;
9798void QQuickItemLayer::componentComplete()
9800 Q_ASSERT(!m_componentComplete);
9801 m_componentComplete =
true;
9806void QQuickItemLayer::activate()
9808 Q_ASSERT(!m_effectSource);
9809 m_effectSource =
new QQuickShaderEffectSource();
9810 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9812 QQuickItem *parentItem = m_item->parentItem();
9814 m_effectSource->setParentItem(parentItem);
9815 m_effectSource->stackAfter(m_item);
9818 m_effectSource->setSourceItem(m_item);
9819 m_effectSource->setHideSource(
true);
9820 m_effectSource->setSmooth(m_smooth);
9821 m_effectSource->setLive(m_live);
9822 m_effectSource->setTextureSize(m_size);
9823 m_effectSource->setSourceRect(m_sourceRect);
9824 m_effectSource->setMipmap(m_mipmap);
9825 m_effectSource->setWrapMode(m_wrapMode);
9826 m_effectSource->setFormat(m_format);
9827 m_effectSource->setTextureMirroring(m_textureMirroring);
9828 m_effectSource->setSamples(m_samples);
9830 if (m_effectComponent)
9833 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9840 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9841 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9844void QQuickItemLayer::deactivate()
9846 Q_ASSERT(m_effectSource);
9848 if (m_effectComponent)
9851 delete m_effectSource;
9852 m_effectSource =
nullptr;
9854 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9855 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9858void QQuickItemLayer::activateEffect()
9860 Q_ASSERT(m_effectSource);
9861 Q_ASSERT(m_effectComponent);
9862 Q_ASSERT(!m_effect);
9864 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9865 m_effect = qobject_cast<QQuickItem *>(created);
9867 qWarning(
"Item: layer.effect is not a QML Item.");
9868 m_effectComponent->completeCreate();
9872 QQuickItem *parentItem = m_item->parentItem();
9874 m_effect->setParentItem(parentItem);
9875 m_effect->stackAfter(m_effectSource);
9877 m_effect->setVisible(m_item->isVisible());
9878 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9879 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9880 m_effectComponent->completeCreate();
9883void QQuickItemLayer::deactivateEffect()
9885 Q_ASSERT(m_effectSource);
9886 Q_ASSERT(m_effectComponent);
9894
9895
9896
9897
9898
9899
9900
9901
9902
9904void QQuickItemLayer::setEffect(QQmlComponent *component)
9906 if (component == m_effectComponent)
9909 bool updateNeeded =
false;
9910 if (m_effectSource && m_effectComponent) {
9912 updateNeeded =
true;
9915 m_effectComponent = component;
9917 if (m_effectSource && m_effectComponent) {
9919 updateNeeded =
true;
9927 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9930 emit effectChanged(component);
9935
9936
9937
9938
9939
9940
9941
9942
9943
9945void QQuickItemLayer::setMipmap(
bool mipmap)
9947 if (mipmap == m_mipmap)
9952 m_effectSource->setMipmap(m_mipmap);
9954 emit mipmapChanged(mipmap);
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9975void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9982 m_effectSource->setFormat(m_format);
9984 emit formatChanged(m_format);
9989
9990
9991
9992
9993
9994
9995
9996
9997
9999void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
10001 if (sourceRect == m_sourceRect)
10003 m_sourceRect = sourceRect;
10005 if (m_effectSource)
10006 m_effectSource->setSourceRect(m_sourceRect);
10008 emit sourceRectChanged(sourceRect);
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10023void QQuickItemLayer::setSmooth(
bool s)
10029 if (m_effectSource)
10030 m_effectSource->setSmooth(m_smooth);
10032 emit smoothChanged(s);
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10047void QQuickItemLayer::setLive(
bool live)
10049 if (m_live == live)
10053 if (m_effectSource)
10054 m_effectSource->setLive(m_live);
10056 emit liveChanged(live);
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10072void QQuickItemLayer::setSize(
const QSize &size)
10074 if (size == m_size)
10078 if (m_effectSource)
10079 m_effectSource->setTextureSize(size);
10081 emit sizeChanged(size);
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10102void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
10104 if (mode == m_wrapMode)
10108 if (m_effectSource)
10109 m_effectSource->setWrapMode(m_wrapMode);
10111 emit wrapModeChanged(mode);
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10129void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
10131 if (mirroring == m_textureMirroring)
10133 m_textureMirroring = mirroring;
10135 if (m_effectSource)
10136 m_effectSource->setTextureMirroring(m_textureMirroring);
10138 emit textureMirroringChanged(mirroring);
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10166void QQuickItemLayer::setSamples(
int count)
10168 if (m_samples == count)
10173 if (m_effectSource)
10174 m_effectSource->setSamples(m_samples);
10176 emit samplesChanged(count);
10180
10181
10182
10183
10184
10185
10186
10187
10188
10190void QQuickItemLayer::setName(
const QByteArray &name) {
10191 if (m_name == name)
10194 m_effect->setProperty(m_name, QVariant());
10195 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10198 emit nameChanged(name);
10201void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10207void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10212void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10215 Q_ASSERT(item == m_item);
10216 Q_ASSERT(parent != m_effectSource);
10217 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10219 m_effectSource->setParentItem(parent);
10221 m_effectSource->stackAfter(m_item);
10224 m_effect->setParentItem(parent);
10226 m_effect->stackAfter(m_effectSource);
10230void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10232 m_effectSource->stackAfter(m_item);
10234 m_effect->stackAfter(m_effectSource);
10237void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10239 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10242 l->setVisible(m_item->isVisible());
10245void QQuickItemLayer::updateZ()
10247 if (!m_componentComplete || !m_enabled)
10249 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10252 l->setZ(m_item->z());
10255void QQuickItemLayer::updateOpacity()
10257 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10260 l->setOpacity(m_item->opacity());
10263void QQuickItemLayer::updateGeometry()
10265 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10270 QRectF bounds = m_item->QQuickItem::boundingRect();
10271 l->setSize(bounds.size());
10272 l->setPosition(bounds.topLeft() + m_item->position());
10275void QQuickItemLayer::updateMatrix()
10279 if (!m_componentComplete || !m_enabled)
10281 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10284 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10285 l->setScale(m_item->scale());
10286 l->setRotation(m_item->rotation());
10287 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10288 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10289 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10290 ld->dirty(QQuickItemPrivate::Transform);
10294QQuickItemPrivate::ExtraData::ExtraData()
10295: z(0), scale(1), rotation(0), opacity(1), biggestPointerHandlerMarginCache(-1),
10296 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10297 enterKeyAttached(
nullptr),
10298 keyHandler(
nullptr), contextMenu(
nullptr),
10299#if QT_CONFIG(quick_shadereffect)
10302 effectRefCount(0), hideRefCount(0),
10303 recursiveEffectRefCount(0),
10304 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10305 origin(QQuickItem::Center),
10306 transparentForPositioner(
false)
10308#ifdef QT_BUILD_INTERNAL
10309 ++QQuickItemPrivate::itemExtra_counter;
10314#if QT_CONFIG(accessibility)
10315QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10317 Q_Q(
const QQuickItem);
10318 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10319 auto role = QAccessible::NoRole;
10320 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10321 role = accessibleAttached->role();
10322 if (role == QAccessible::NoRole)
10323 role = accessibleRole();
10327QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10329 return QAccessible::NoRole;
10338 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10351 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10352 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10353 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10354 QV4::QObjectWrapper::markWrapper(child, markStack);
10356 QObjectWrapper::markObjects(that, markStack);
10359quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10361 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10366 QDebugStateSaver stateSaver(debug);
10367 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10372QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10373{
return mapFromItem(item, QPointF(x, y) ); }
10376QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10377{
return mapRectFromItem(item, rect); }
10380QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10381{
return mapFromItem(item, QRectF(x, y, width, height)); }
10384QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10385{
return mapToItem(item, QPointF(x, y)); }
10388QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10389{
return mapRectToItem(item, rect); }
10392QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10393{
return mapToItem(item, QRectF(x, y, width, height)); }
10396QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10397{
return mapToGlobal(QPointF(x, y)); }
10400QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10401{
return mapFromGlobal(QPointF(x, y)); }
10404QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10408#include <moc_qquickitem.cpp>
10410#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)