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);
2398 if (d->windowRefCount > 1)
2399 d->windowRefCount = 1;
2401 setParentItem(
nullptr);
2405 for (QQuickItem *child : std::as_const(d->childItems))
2406 child->setParentItem(
nullptr);
2407 d->childItems.clear();
2409 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2410 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2412 anchor->clearItem(
this);
2415
2416
2417
2418 d->notifyChangeListeners(QQuickItemPrivate::AllChanges, [
this](
const QQuickItemPrivate::ChangeListener &change){
2419 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
2420 if (anchor && anchor->item && anchor->item->parentItem() && anchor->item->parentItem() !=
this)
2423 d->notifyChangeListeners(QQuickItemPrivate::Destroyed, &QQuickItemChangeListener::itemDestroyed,
this);
2424 d->changeListeners.clear();
2427
2428
2429
2430
2431 for (
int ii = 0; ii < d->transforms.size(); ++ii) {
2432 QQuickTransform *t = d->transforms.at(ii);
2433 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
2434 tp->items.removeOne(
this);
2437 if (d->extra.isAllocated()) {
2438 delete d->extra->contents; d->extra->contents =
nullptr;
2439#if QT_CONFIG(quick_shadereffect)
2440 delete d->extra->layer; d->extra->layer =
nullptr;
2444 delete d->_anchors; d->_anchors =
nullptr;
2445 delete d->_stateGroup; d->_stateGroup =
nullptr;
2447 d->isQuickItem =
false;
2451
2452
2453bool QQuickItemPrivate::canAcceptTabFocus(QQuickItem *item)
2455 if (!item->window())
2458 if (item == item->window()->contentItem())
2461 const auto tabFocus = QGuiApplication::styleHints()->tabFocusBehavior();
2462 if (tabFocus == Qt::NoTabFocus)
2464 if (tabFocus == Qt::TabFocusAllControls)
2467 QVariant editable = item->property(
"editable");
2468 if (editable.isValid())
2469 return editable.toBool();
2471 QVariant readonly = item->property(
"readOnly");
2472 if (readonly.isValid())
2473 return !readonly.toBool() && item->property(
"text").isValid();
2475#if QT_CONFIG(accessibility)
2476 QAccessible::Role role = QQuickItemPrivate::get(item)->effectiveAccessibleRole();
2477 if (role == QAccessible::EditableText || role == QAccessible::Table || role == QAccessible::List) {
2479 }
else if (role == QAccessible::ComboBox || role == QAccessible::SpinBox) {
2480 if (QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item))
2481 return iface->state().editable;
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498bool QQuickItemPrivate::focusNextPrev(QQuickItem *item,
bool forward)
2500 QQuickWindow *window = item->window();
2501 const bool wrap = !window || window->isTopLevel();
2503 QQuickItem *next = QQuickItemPrivate::nextPrevItemInTabFocusChain(item, forward, wrap);
2508 const auto reason = forward ? Qt::TabFocusReason : Qt::BacktabFocusReason;
2510 if (!wrap && !next) {
2514 Q_ASSERT(window->parent());
2517 qt_window_private(window->parent())->setFocusToTarget(
2518 forward ? QWindowPrivate::FocusTarget::Next
2519 : QWindowPrivate::FocusTarget::Prev,
2521 window->parent()->requestActivate();
2525 next->forceActiveFocus(reason);
2530QQuickItem *QQuickItemPrivate::nextTabChildItem(
const QQuickItem *item,
int start)
2533 qWarning() <<
"QQuickItemPrivate::nextTabChildItem called with null item.";
2536 const QList<QQuickItem *> &children = item->childItems();
2537 const int count = children.size();
2538 if (start < 0 || start >= count) {
2539 qWarning() <<
"QQuickItemPrivate::nextTabChildItem: Start index value out of range for item" << item;
2542 while (start < count) {
2543 QQuickItem *child = children.at(start);
2544 if (!child->d_func()->isTabFence)
2551QQuickItem *QQuickItemPrivate::prevTabChildItem(
const QQuickItem *item,
int start)
2554 qWarning() <<
"QQuickItemPrivate::prevTabChildItem called with null item.";
2557 const QList<QQuickItem *> &children = item->childItems();
2558 const int count = children.size();
2561 if (start < 0 || start >= count) {
2562 qWarning() <<
"QQuickItemPrivate::prevTabChildItem: Start index value out of range for item" << item;
2565 while (start >= 0) {
2566 QQuickItem *child = children.at(start);
2567 if (!child->d_func()->isTabFence)
2574QQuickItem* QQuickItemPrivate::nextPrevItemInTabFocusChain(QQuickItem *item,
bool forward,
bool wrap)
2577 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: item:" << item <<
", forward:" << forward;
2579 if (!item->window())
2581 const QQuickItem *
const contentItem = item->window()->contentItem();
2585 QQuickItem *from =
nullptr;
2586 bool isTabFence = item->d_func()->isTabFence;
2589 from = item->parentItem();
2591 if (!item->childItems().isEmpty())
2592 from = item->d_func()->childItems.constFirst();
2593 else if (!isTabFence)
2594 from = item->parentItem();
2598 QQuickItem *startItem = item;
2599 QQuickItem *originalStartItem = startItem;
2604 while (startItem && !startItem->isVisible()) {
2605 startItem = startItem->parentItem();
2610 QQuickItem *firstFromItem = from;
2611 QQuickItem *current = item;
2612 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: startItem:" << startItem;
2613 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: firstFromItem:" << firstFromItem;
2614 QDuplicateTracker<QQuickItem *> cycleDetector;
2616 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: current:" << current;
2617 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: from:" << from;
2619 QQuickItem *last = current;
2621 bool hasChildren = !current->childItems().isEmpty() && current->isEnabled() && current->isVisible();
2622 QQuickItem *firstChild =
nullptr;
2623 QQuickItem *lastChild =
nullptr;
2625 firstChild = nextTabChildItem(current, 0);
2627 hasChildren =
false;
2629 lastChild = prevTabChildItem(current, -1);
2631 isTabFence = current->d_func()->isTabFence;
2632 if (isTabFence && !hasChildren)
2636 if (hasChildren && from == current->parentItem()) {
2638 current = firstChild;
2640 current = lastChild;
2641 if (!current->childItems().isEmpty())
2644 }
else if (hasChildren && forward && from != lastChild) {
2646 int nextChild = current->childItems().indexOf(from) + 1;
2647 current = nextTabChildItem(current, nextChild);
2648 }
else if (hasChildren && !forward && from != firstChild) {
2650 int prevChild = current->childItems().indexOf(from) - 1;
2651 current = prevTabChildItem(current, prevChild);
2652 if (!current->childItems().isEmpty())
2655 }
else if (QQuickItem *parent = !isTabFence ? current->parentItem() :
nullptr) {
2659 }
else if (QQuickItem *firstSibling = !forward ? nextTabChildItem(parent, 0) :
nullptr) {
2660 if (last != firstSibling
2661 || (parent->isFocusScope() && parent->activeFocusOnTab() && parent->hasActiveFocus()))
2665 }
else if (hasChildren) {
2667 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2668 <<
"Focus chain about to wrap but wrapping was set to false."
2675 current = firstChild;
2676 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2677 <<
"wrapping from last to first:" << current;
2679 current = lastChild;
2680 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain:"
2681 <<
"wrapping from first to last:" << current;
2682 if (!current->childItems().isEmpty())
2694 if (((current == startItem || current == originalStartItem) && from == firstFromItem) ||
2695 (!skip && cycleDetector.hasSeen(current))) {
2697 if (item == contentItem) {
2698 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return contentItem";
2701 qCDebug(lcFocus) <<
"QQuickItemPrivate::nextPrevItemInTabFocusChain: looped, return " << startItem;
2705 if (!firstFromItem) {
2706 if (startItem->d_func()->isTabFence) {
2707 if (current == startItem)
2708 firstFromItem = from;
2710 startItem = current;
2711 firstFromItem = from;
2714 }
while (skip || !current->activeFocusOnTab() || !current->isEnabled() || !current->isVisible()
2715 || !(QQuickItemPrivate::canAcceptTabFocus(current)));
2721
2722
2723
2724
2725
2726
2727
2728
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744QQuickItem *QQuickItem::parentItem()
const
2746 Q_D(
const QQuickItem);
2747 return d->parentItem;
2750void QQuickItem::setParentItem(QQuickItem *parentItem)
2753 if (parentItem == d->parentItem)
2757 QQuickItem *itemAncestor = parentItem;
2758 while (itemAncestor !=
nullptr) {
2759 if (Q_UNLIKELY(itemAncestor ==
this)) {
2760 qWarning() <<
"QQuickItem::setParentItem: Parent" << parentItem <<
"is already part of the subtree of" <<
this;
2763 itemAncestor = itemAncestor->parentItem();
2765 auto engine = qmlEngine(
this);
2767 QV4::ExecutionEngine *v4 = engine->handle();
2768 QV4::WriteBarrier::markCustom(v4, [
this](QV4::MarkStack *ms){
2769 QV4::QObjectWrapper::markWrapper(
this, ms);
2774 d->removeFromDirtyList();
2776 QQuickItem *oldParentItem = d->parentItem;
2777 QQuickItem *scopeFocusedItem =
nullptr;
2779 if (oldParentItem) {
2780 QQuickItemPrivate *op = QQuickItemPrivate::get(oldParentItem);
2782 QQuickItem *scopeItem =
nullptr;
2784 if (hasFocus() || op->subFocusItem ==
this)
2785 scopeFocusedItem =
this;
2786 else if (!isFocusScope() && d->subFocusItem)
2787 scopeFocusedItem = d->subFocusItem;
2789 if (scopeFocusedItem) {
2790 scopeItem = oldParentItem;
2791 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2792 scopeItem = scopeItem->parentItem();
2794 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2795 da->clearFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2796 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2798 if (scopeFocusedItem !=
this)
2799 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
true);
2801 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
false);
2805 const bool wasVisible = isVisible();
2806 op->removeChild(
this);
2807 if (wasVisible && !op->inDestructor)
2808 emit oldParentItem->visibleChildrenChanged();
2809 }
else if (d->window) {
2810 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2813 QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window :
nullptr;
2814 bool alreadyAddedChild =
false;
2815 if (d->window == parentWindow) {
2817 d->parentItem = parentItem;
2819 auto oldParentItem = d->parentItem;
2820 d->parentItem = parentItem;
2821 if (d->parentItem) {
2822 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2823 alreadyAddedChild =
true;
2831 if (!oldParentItem && d->window) {
2832 QQuickWindowPrivate::get(d->window)->parentlessItems.remove(
this);
2836 d->refWindow(parentWindow);
2839 d->dirty(QQuickItemPrivate::ParentChanged);
2841 if (d->parentItem && !alreadyAddedChild)
2842 QQuickItemPrivate::get(d->parentItem)->addChild(
this);
2843 else if (d->window && !alreadyAddedChild)
2844 QQuickWindowPrivate::get(d->window)->parentlessItems.insert(
this);
2846 d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
2847 d->setEffectiveEnableRecur(
nullptr, d->calcEffectiveEnable());
2849 if (d->parentItem) {
2850 if (!scopeFocusedItem) {
2852 scopeFocusedItem =
this;
2853 else if (!isFocusScope() && d->subFocusItem)
2854 scopeFocusedItem = d->subFocusItem;
2857 if (scopeFocusedItem) {
2859 QQuickItem *scopeItem = d->parentItem;
2860 while (!scopeItem->isFocusScope() && scopeItem->parentItem())
2861 scopeItem = scopeItem->parentItem();
2863 if (QQuickItemPrivate::get(scopeItem)->subFocusItem
2864 || (!scopeItem->isFocusScope() && scopeItem->hasFocus())) {
2865 if (scopeFocusedItem !=
this)
2866 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(
this,
false);
2867 QQuickItemPrivate::get(scopeFocusedItem)->focus =
false;
2868 emit scopeFocusedItem->focusChanged(
false);
2871 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate()) {
2872 da->setFocusInScope(scopeItem, scopeFocusedItem, Qt::OtherFocusReason,
2873 QQuickDeliveryAgentPrivate::DontChangeFocusProperty);
2876 QQuickItemPrivate::get(scopeFocusedItem)->updateSubFocusItem(scopeItem,
true);
2883 d->resolveLayoutMirror();
2885 d->itemChange(ItemParentHasChanged, d->parentItem);
2887 if (!d->inDestructor)
2888 emit parentChanged(d->parentItem);
2889 if (isVisible() && d->parentItem && !QQuickItemPrivate::get(d->parentItem)->inDestructor)
2890 emit d->parentItem->visibleChildrenChanged();
2892#if QT_CONFIG(accessibility)
2893 if (QGuiApplicationPrivate::is_app_running && !QGuiApplicationPrivate::is_app_closing && d->isAccessible && QAccessible::isActive()) {
2894 QAccessibleEvent qaEvent(
this, QAccessible::ParentChanged);
2895 QAccessible::updateAccessibility(&qaEvent);
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918void QQuickItem::stackBefore(
const QQuickItem *sibling)
2921 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2922 qWarning().nospace() <<
"QQuickItem::stackBefore: Cannot stack "
2923 <<
this <<
" before " << sibling <<
", which must be a sibling";
2927 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2929 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2930 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2932 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2934 if (myIndex == siblingIndex - 1)
2937 parentPrivate->childItems.move(myIndex, myIndex < siblingIndex ? siblingIndex - 1 : siblingIndex);
2939 parentPrivate->markSortedChildrenDirty(
this);
2940 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2942 for (
int ii = qMin(siblingIndex, myIndex); ii < parentPrivate->childItems.size(); ++ii)
2943 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964void QQuickItem::stackAfter(
const QQuickItem *sibling)
2967 if (!sibling || sibling ==
this || !d->parentItem || d->parentItem != QQuickItemPrivate::get(sibling)->parentItem) {
2968 qWarning().nospace() <<
"QQuickItem::stackAfter: Cannot stack "
2969 <<
this <<
" after " << sibling <<
", which must be a sibling";
2973 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(d->parentItem);
2975 int myIndex = parentPrivate->childItems.lastIndexOf(
this);
2976 int siblingIndex = parentPrivate->childItems.lastIndexOf(
const_cast<QQuickItem *>(sibling));
2978 Q_ASSERT(myIndex != -1 && siblingIndex != -1);
2980 if (myIndex == siblingIndex + 1)
2983 parentPrivate->childItems.move(myIndex, myIndex > siblingIndex ? siblingIndex + 1 : siblingIndex);
2985 parentPrivate->markSortedChildrenDirty(
this);
2986 parentPrivate->dirty(QQuickItemPrivate::ChildrenStackingChanged);
2988 for (
int ii = qMin(myIndex, siblingIndex + 1); ii < parentPrivate->childItems.size(); ++ii)
2989 QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
2993
2994
2997
2998
2999
3000
3001
3002
3003QQuickWindow *QQuickItem::window()
const
3005 Q_D(
const QQuickItem);
3011 return lhs->z() < rhs->z();
3014QList<QQuickItem *> QQuickItemPrivate::paintOrderChildItems()
const
3016 if (sortedChildItems)
3017 return *sortedChildItems;
3022 for (
int i = 0; i < childItems.size(); ++i) {
3023 if (QQuickItemPrivate::get(childItems.at(i))->z() != 0.) {
3029 sortedChildItems =
new QList<QQuickItem*>(childItems);
3030 std::stable_sort(sortedChildItems->begin(), sortedChildItems->end(), itemZOrder_sort);
3031 return *sortedChildItems;
3034 sortedChildItems =
const_cast<QList<QQuickItem*>*>(&childItems);
3039void QQuickItemPrivate::addChild(QQuickItem *child)
3043 Q_ASSERT(!childItems.contains(child));
3045 childItems.append(child);
3047 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3049#if QT_CONFIG(cursor)
3052 if (childPrivate->subtreeCursorEnabled && !subtreeCursorEnabled)
3053 setHasCursorInChild(
true);
3056 if (childPrivate->subtreeHoverEnabled && !subtreeHoverEnabled)
3057 setHasHoverInChild(
true);
3059 childPrivate->recursiveRefFromEffectItem(extra.value().recursiveEffectRefCount);
3060 markSortedChildrenDirty(child);
3061 dirty(QQuickItemPrivate::ChildrenChanged);
3063 itemChange(QQuickItem::ItemChildAddedChange, child);
3065 emit q->childrenChanged();
3068void QQuickItemPrivate::removeChild(QQuickItem *child)
3073 if (!inDestructor) {
3075 Q_ASSERT(childItems.contains(child));
3076 childItems.removeOne(child);
3077 Q_ASSERT(!childItems.contains(child));
3080 QQuickItemPrivate *childPrivate = QQuickItemPrivate::get(child);
3082#if QT_CONFIG(cursor)
3084 if (childPrivate->subtreeCursorEnabled && subtreeCursorEnabled)
3085 setHasCursorInChild(
false);
3088 if (childPrivate->subtreeHoverEnabled && subtreeHoverEnabled)
3089 setHasHoverInChild(
false);
3091 childPrivate->recursiveRefFromEffectItem(-extra.value().recursiveEffectRefCount);
3092 if (!inDestructor) {
3093 markSortedChildrenDirty(child);
3094 dirty(QQuickItemPrivate::ChildrenChanged);
3097 itemChange(QQuickItem::ItemChildRemovedChange, child);
3100 emit q->childrenChanged();
3103void QQuickItemPrivate::refWindow(QQuickWindow *c)
3115 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3117 if (++windowRefCount > 1) {
3119 qWarning(
"QQuickItem: Cannot use same item on different windows at the same time.");
3123 Q_ASSERT(window ==
nullptr);
3126 if (polishScheduled)
3127 QQuickWindowPrivate::get(window)->itemsToPolish.append(q);
3130 QQuickWindowPrivate::get(window)->parentlessItems.insert(q);
3132 for (
int ii = 0; ii < childItems.size(); ++ii) {
3133 QQuickItem *child = childItems.at(ii);
3134 QQuickItemPrivate::get(child)->refWindow(c);
3139 if (extra.isAllocated() && extra->screenAttached)
3140 extra->screenAttached->windowChanged(c);
3141 itemChange(QQuickItem::ItemSceneChange, c);
3144void QQuickItemPrivate::derefWindow()
3147 Q_ASSERT((window !=
nullptr) == (windowRefCount > 0));
3152 if (--windowRefCount > 0)
3155 q->releaseResources();
3156 removeFromDirtyList();
3157 QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
3158 if (polishScheduled)
3159 c->itemsToPolish.removeOne(q);
3160#if QT_CONFIG(cursor)
3161 if (c->cursorItem == q) {
3162 c->cursorItem =
nullptr;
3163 window->unsetCursor();
3166 if (itemNodeInstance)
3167 c->cleanup(itemNodeInstance);
3169 c->parentlessItems.remove(q);
3173 itemNodeInstance =
nullptr;
3175 if (extra.isAllocated()) {
3176 extra->opacityNode =
nullptr;
3177 extra->clipNode =
nullptr;
3178 extra->rootNode =
nullptr;
3181 paintNode =
nullptr;
3183 for (
int ii = 0; ii < childItems.size(); ++ii) {
3184 if (QQuickItem *child = childItems.at(ii))
3185 QQuickItemPrivate::get(child)->derefWindow();
3190 if (extra.isAllocated() && extra->screenAttached)
3191 extra->screenAttached->windowChanged(
nullptr);
3192 itemChange(QQuickItem::ItemSceneChange, (QQuickWindow *)
nullptr);
3195qreal QQuickItemPrivate::effectiveDevicePixelRatio()
const
3197 return (window ? window->effectiveDevicePixelRatio() : qApp->devicePixelRatio());
3201
3202
3203QTransform QQuickItemPrivate::windowToItemTransform()
const
3206#ifdef QT_BUILD_INTERNAL
3207 ++windowToItemTransform_counter;
3209 return itemToWindowTransform().inverted();
3213
3214
3215QTransform QQuickItemPrivate::itemToWindowTransform()
const
3217#ifdef QT_BUILD_INTERNAL
3218 ++itemToWindowTransform_counter;
3221 Q_ASSERT(!parentItem || QQuickItemPrivate::get(parentItem) !=
this);
3222 QTransform rv = parentItem ? QQuickItemPrivate::get(parentItem)->itemToWindowTransform() : QTransform();
3223 itemToParentTransform(&rv);
3228
3229
3230void QQuickItemPrivate::itemToParentTransform(QTransform *t)
const
3232#ifdef QT_BUILD_INTERNAL
3233 ++itemToParentTransform_counter;
3236
3237
3238
3239
3240
3242 qreal x =
this->x.valueBypassingBindings();
3243 qreal y =
this->y.valueBypassingBindings();
3247 if (!transforms.isEmpty()) {
3249 for (
int ii = transforms.size() - 1; ii >= 0; --ii)
3250 transforms.at(ii)->applyTo(&m);
3251 *t = m.toTransform();
3254 if (scale() != 1. || rotation() != 0.) {
3255 QPointF tp = computeTransformOrigin();
3256 t->translate(tp.x(), tp.y());
3257 t->scale(scale(), scale());
3258 t->rotate(rotation());
3259 t->translate(-tp.x(), -tp.y());
3264
3265
3266
3267
3268
3269
3270
3271
3272bool QQuickItem::isComponentComplete()
const
3274 Q_D(
const QQuickItem);
3275 return d->componentComplete;
3278QQuickItemPrivate::QQuickItemPrivate()
3280 , _stateGroup(
nullptr)
3282 , widthValidFlag(
false)
3283 , heightValidFlag(
false)
3284 , componentComplete(
true)
3287 , hoverEnabled(
false)
3289 , antialiasing(
false)
3291 , activeFocus(
false)
3292 , notifiedFocus(
false)
3293 , notifiedActiveFocus(
false)
3294 , filtersChildMouseEvents(
false)
3295 , explicitVisible(
true)
3296 , effectiveVisible(
true)
3297 , explicitEnable(
true)
3298 , effectiveEnable(
true)
3299 , polishScheduled(
false)
3300 , inheritedLayoutMirror(
false)
3301 , effectiveLayoutMirror(
false)
3302 , isMirrorImplicit(
true)
3303 , inheritMirrorFromParent(
false)
3304 , inheritMirrorFromItem(
false)
3305 , isAccessible(
false)
3308 , subtreeCursorEnabled(
false)
3309 , subtreeHoverEnabled(
false)
3310 , activeFocusOnTab(
false)
3311 , implicitAntialiasing(
false)
3312 , antialiasingValid(
false)
3314 , replayingPressEvent(
false)
3315 , touchEnabled(
false)
3316 , hasCursorHandler(
false)
3317 , maybeHasSubsceneDeliveryAgent(
true)
3318 , subtreeTransformChangedEnabled(
true)
3319 , inDestructor(
false)
3320 , focusReason(Qt::OtherFocusReason)
3321 , focusPolicy(Qt::NoFocus)
3322 , eventHandlingChildrenWithinBounds(
false)
3323 , eventHandlingChildrenWithinBoundsSet(
false)
3324 , customOverlay(
false)
3325 , dirtyAttributes(0)
3326 , nextDirtyItem(
nullptr)
3327 , prevDirtyItem(
nullptr)
3330 , parentItem(
nullptr)
3331 , sortedChildItems(&childItems)
3332 , subFocusItem(
nullptr)
3340 , itemNodeInstance(
nullptr)
3341 , paintNode(
nullptr)
3342 , szPolicy(QLayoutPolicy::Fixed, QLayoutPolicy::Fixed)
3344#ifdef QT_BUILD_INTERNAL
3349QQuickItemPrivate::~QQuickItemPrivate()
3351 if (sortedChildItems != &childItems)
3352 delete sortedChildItems;
3355void QQuickItemPrivate::init(QQuickItem *parent)
3361 baselineOffset = 0.0;
3364 q->setParentItem(parent);
3365 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
3366 setImplicitLayoutMirror(parentPrivate->inheritedLayoutMirror, parentPrivate->inheritMirrorFromParent);
3370QLayoutPolicy QQuickItemPrivate::sizePolicy()
const
3375void QQuickItemPrivate::setSizePolicy(
const QLayoutPolicy::Policy& horizontalPolicy,
const QLayoutPolicy::Policy& verticalPolicy)
3377 szPolicy.setHorizontalPolicy(horizontalPolicy);
3378 szPolicy.setVerticalPolicy(verticalPolicy);
3381void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
3386 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3388 if (QQuickItem *item = qmlobject_cast<QQuickItem *>(o)) {
3389 item->setParentItem(that);
3390 }
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
3391 if (pointerHandler->parent() != that) {
3392 qCDebug(lcHandlerParent) <<
"reparenting handler" << pointerHandler <<
":" << pointerHandler->parent() <<
"->" << that;
3393 pointerHandler->setParent(that);
3395 QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
3398 resources_append(prop, o);
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3437qsizetype QQuickItemPrivate::data_count(QQmlListProperty<QObject> *property)
3439 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3440 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3441 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3442 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3444 return resources_count(&resourcesProperty) + children_count(&childrenProperty);
3447QObject *QQuickItemPrivate::data_at(QQmlListProperty<QObject> *property, qsizetype i)
3449 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3450 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3451 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3452 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3454 qsizetype resourcesCount = resources_count(&resourcesProperty);
3455 if (i < resourcesCount)
3456 return resources_at(&resourcesProperty, i);
3457 const qsizetype j = i - resourcesCount;
3458 if (j < children_count(&childrenProperty))
3459 return children_at(&childrenProperty, j);
3463void QQuickItemPrivate::data_clear(QQmlListProperty<QObject> *property)
3465 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3466 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3467 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3468 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3470 resources_clear(&resourcesProperty);
3471 children_clear(&childrenProperty);
3474void QQuickItemPrivate::data_removeLast(QQmlListProperty<QObject> *property)
3476 QQuickItem *item =
static_cast<QQuickItem*>(property->object);
3477 QQuickItemPrivate *privateItem = QQuickItemPrivate::get(item);
3479 QQmlListProperty<QQuickItem> childrenProperty = privateItem->children();
3480 if (children_count(&childrenProperty) > 0) {
3481 children_removeLast(&childrenProperty);
3485 QQmlListProperty<QObject> resourcesProperty = privateItem->resources();
3486 if (resources_count(&resourcesProperty) > 0)
3487 resources_removeLast(&resourcesProperty);
3490QObject *QQuickItemPrivate::resources_at(QQmlListProperty<QObject> *prop, qsizetype index)
3492 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3493 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.value(index) : 0;
3496void QQuickItemPrivate::resources_append(QQmlListProperty<QObject> *prop, QObject *object)
3498 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3499 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3500 if (!quickItemPrivate->extra.value().resourcesList.contains(object)) {
3501 quickItemPrivate->extra.value().resourcesList.append(object);
3502 qmlobject_connect(object, QObject, SIGNAL(destroyed(QObject*)),
3503 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3507qsizetype QQuickItemPrivate::resources_count(QQmlListProperty<QObject> *prop)
3509 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3510 return quickItemPrivate->extra.isAllocated() ? quickItemPrivate->extra->resourcesList.size() : 0;
3513void QQuickItemPrivate::resources_clear(QQmlListProperty<QObject> *prop)
3515 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3516 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3517 if (quickItemPrivate->extra.isAllocated()) {
3518 for (QObject *object : std::as_const(quickItemPrivate->extra->resourcesList)) {
3519 qmlobject_disconnect(object, QObject, SIGNAL(destroyed(QObject*)),
3520 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3522 quickItemPrivate->extra->resourcesList.clear();
3526void QQuickItemPrivate::resources_removeLast(QQmlListProperty<QObject> *prop)
3528 QQuickItem *quickItem =
static_cast<QQuickItem *>(prop->object);
3529 QQuickItemPrivate *quickItemPrivate = QQuickItemPrivate::get(quickItem);
3530 if (quickItemPrivate->extra.isAllocated()) {
3531 QList<QObject *> *resources = &quickItemPrivate->extra->resourcesList;
3532 if (resources->isEmpty())
3535 qmlobject_disconnect(resources->last(), QObject, SIGNAL(destroyed(QObject*)),
3536 quickItem, QQuickItem, SLOT(_q_resourceObjectDeleted(QObject*)));
3537 resources->removeLast();
3541QQuickItem *QQuickItemPrivate::children_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3543 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3544 if (index >= p->childItems.size() || index < 0)
3547 return p->childItems.at(index);
3550void QQuickItemPrivate::children_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o)
3555 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3556 if (o->parentItem() == that)
3557 o->setParentItem(
nullptr);
3559 o->setParentItem(that);
3562qsizetype QQuickItemPrivate::children_count(QQmlListProperty<QQuickItem> *prop)
3564 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3565 return p->childItems.size();
3568void QQuickItemPrivate::children_clear(QQmlListProperty<QQuickItem> *prop)
3570 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3571 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3572 while (!p->childItems.isEmpty())
3573 p->childItems.at(0)->setParentItem(
nullptr);
3576void QQuickItemPrivate::children_removeLast(QQmlListProperty<QQuickItem> *prop)
3578 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3579 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3580 if (!p->childItems.isEmpty())
3581 p->childItems.last()->setParentItem(
nullptr);
3584qsizetype QQuickItemPrivate::visibleChildren_count(QQmlListProperty<QQuickItem> *prop)
3586 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3587 qsizetype visibleCount = 0;
3588 qsizetype c = p->childItems.size();
3590 if (p->childItems.at(c)->isVisible()) visibleCount++;
3593 return visibleCount;
3596QQuickItem *QQuickItemPrivate::visibleChildren_at(QQmlListProperty<QQuickItem> *prop, qsizetype index)
3598 QQuickItemPrivate *p = QQuickItemPrivate::get(
static_cast<QQuickItem *>(prop->object));
3599 const qsizetype childCount = p->childItems.size();
3600 if (index >= childCount || index < 0)
3603 qsizetype visibleCount = -1;
3604 for (qsizetype i = 0; i < childCount; i++) {
3605 if (p->childItems.at(i)->isVisible()) visibleCount++;
3606 if (visibleCount == index)
return p->childItems.at(i);
3611qsizetype QQuickItemPrivate::transform_count(QQmlListProperty<QQuickTransform> *prop)
3613 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3614 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3616 return p->transforms.size();
3619void QQuickTransform::appendToItem(QQuickItem *item)
3621 Q_D(QQuickTransform);
3625 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3627 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3628 p->transforms.removeOne(
this);
3629 p->transforms.append(
this);
3631 p->transforms.append(
this);
3632 d->items.append(item);
3635 p->dirty(QQuickItemPrivate::Transform);
3638void QQuickTransform::prependToItem(QQuickItem *item)
3640 Q_D(QQuickTransform);
3644 QQuickItemPrivate *p = QQuickItemPrivate::get(item);
3646 if (!d->items.isEmpty() && !p->transforms.isEmpty() && p->transforms.contains(
this)) {
3647 p->transforms.removeOne(
this);
3648 p->transforms.prepend(
this);
3650 p->transforms.prepend(
this);
3651 d->items.append(item);
3654 p->dirty(QQuickItemPrivate::Transform);
3657void QQuickItemPrivate::transform_append(QQmlListProperty<QQuickTransform> *prop, QQuickTransform *transform)
3662 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3663 transform->appendToItem(that);
3666QQuickTransform *QQuickItemPrivate::transform_at(QQmlListProperty<QQuickTransform> *prop, qsizetype idx)
3668 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3669 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3671 if (idx < 0 || idx >= p->transforms.size())
3674 return p->transforms.at(idx);
3677void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
3679 QQuickItem *that =
static_cast<QQuickItem *>(prop->object);
3680 QQuickItemPrivate *p = QQuickItemPrivate::get(that);
3682 for (qsizetype ii = 0; ii < p->transforms.size(); ++ii) {
3683 QQuickTransform *t = p->transforms.at(ii);
3684 QQuickTransformPrivate *tp = QQuickTransformPrivate::get(t);
3685 tp->items.removeOne(that);
3688 p->transforms.clear();
3690 p->dirty(QQuickItemPrivate::Transform);
3693void QQuickItemPrivate::_q_resourceObjectDeleted(QObject *object)
3695 if (extra.isAllocated() && extra->resourcesList.contains(object))
3696 extra->resourcesList.removeAll(object);
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793QQuickAnchors *QQuickItemPrivate::anchors()
const
3796 Q_Q(
const QQuickItem);
3797 _anchors =
new QQuickAnchors(
const_cast<QQuickItem *>(q));
3798 if (!componentComplete)
3799 _anchors->classBegin();
3804void QQuickItemPrivate::siblingOrderChanged()
3807 notifyChangeListeners(QQuickItemPrivate::SiblingOrder, &QQuickItemChangeListener::itemSiblingOrderChanged, q);
3810QQmlListProperty<QObject> QQuickItemPrivate::data()
3814 QQmlListProperty<QObject> result;
3815 result.object = q_func();
3816 result.append = QQuickItemPrivate::data_append;
3817 result.count = QQuickItemPrivate::data_count;
3818 result.at = QQuickItemPrivate::data_at;
3819 result.clear = QQuickItemPrivate::data_clear;
3820 result.removeLast = QQuickItemPrivate::data_removeLast;
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855QRectF QQuickItem::childrenRect()
3858 if (!d->extra.isAllocated() || !d->extra->contents) {
3859 d->extra.value().contents =
new QQuickContents(
this);
3860 if (d->componentComplete)
3861 d->extra->contents->complete();
3863 return d->extra->contents->rectF();
3867
3868
3869QList<QQuickItem *> QQuickItem::childItems()
const
3871 Q_D(
const QQuickItem);
3872 return d->childItems;
3876
3877
3878
3879
3880
3881
3882
3883
3884
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903bool QQuickItem::clip()
const
3905 return flags() & ItemClipsChildrenToShape;
3908void QQuickItem::setClip(
bool c)
3913 setFlag(ItemClipsChildrenToShape, c);
3915 setFlag(ItemIsViewport);
3916 else if (!(inherits(
"QQuickFlickable") || inherits(
"QQuickRootItem")))
3917 setFlag(ItemIsViewport,
false);
3919 emit clipChanged(c);
3923
3924
3925
3926
3927
3928
3929
3930
3931void QQuickItem::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
3936 QQuickAnchorsPrivate::get(d->_anchors)->updateMe();
3938 QQuickGeometryChange change;
3939 change.setXChange(newGeometry.x() != oldGeometry.x());
3940 change.setYChange(newGeometry.y() != oldGeometry.y());
3941 change.setWidthChange(newGeometry.width() != oldGeometry.width());
3942 change.setHeightChange(newGeometry.height() != oldGeometry.height());
3944 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [&](
const QQuickItemPrivate::ChangeListener &listener){
3945 if (change.matches(listener.gTypes))
3946 listener.listener->itemGeometryChanged(
this, change, oldGeometry);
3951 if (change.xChange())
3953 if (change.yChange())
3955 if (change.widthChange())
3957 if (change.heightChange())
3959#if QT_CONFIG(accessibility)
3960 if (d->isAccessible && QAccessible::isActive() && d->effectiveVisible) {
3961 QAccessibleEvent ev(
this, QAccessible::LocationChanged);
3962 QAccessible::updateAccessibility(&ev);
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4021QSGNode *QQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
4023 Q_UNUSED(updatePaintNodeData);
4028QQuickItem::UpdatePaintNodeData::UpdatePaintNodeData()
4029: transformNode(
nullptr)
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4050void QQuickItem::releaseResources()
4054QSGTransformNode *QQuickItemPrivate::createTransformNode()
4056 return new QSGTransformNode;
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069void QQuickItem::updatePolish()
4073#define PRINT_LISTENERS() do
4075 qDebug().nospace() << q_func() << " (" << this
4076 << ") now has the following listeners:";
4077 for (const auto &listener : std::as_const(changeListeners)) {
4078 const auto objectPrivate = dynamic_cast<QObjectPrivate*>(listener.listener);
4079 qDebug().nospace() << "- " << listener << " (QObject: " << (objectPrivate ? objectPrivate->q_func() : nullptr) << ")";
4081}while
4084void QQuickItemPrivate::addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4087 changeListeners.append(ChangeListener(listener, types));
4088 listener->addSourceItem(q);
4090 if (lcChangeListeners().isDebugEnabled())
4094void QQuickItemPrivate::updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4098 const ChangeListener changeListener(listener, types);
4099 const int index = changeListeners.indexOf(changeListener);
4101 changeListeners[index].types = changeListener.types;
4103 changeListeners.append(changeListener);
4104 listener->addSourceItem(q);
4107 if (lcChangeListeners().isDebugEnabled())
4111void QQuickItemPrivate::removeItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
4115 ChangeListener change(listener, types);
4116 changeListeners.removeOne(change);
4117 listener->removeSourceItem(q);
4119 if (lcChangeListeners().isDebugEnabled())
4123void QQuickItemPrivate::updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener,
4124 QQuickGeometryChange types)
4128 ChangeListener change(listener, types);
4129 int index = changeListeners.indexOf(change);
4131 changeListeners[index].gTypes = change.gTypes;
4133 changeListeners.append(change);
4134 listener->addSourceItem(q);
4137 if (lcChangeListeners().isDebugEnabled())
4141void QQuickItemPrivate::updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener,
4142 QQuickGeometryChange types)
4146 ChangeListener change(listener, types);
4147 if (types.noChange()) {
4148 changeListeners.removeOne(change);
4149 listener->removeSourceItem(q);
4151 int index = changeListeners.indexOf(change);
4153 changeListeners[index].gTypes = change.gTypes;
4156 if (lcChangeListeners().isDebugEnabled())
4161
4162
4163
4164
4165
4166
4167void QQuickItem::keyPressEvent(QKeyEvent *event)
4173
4174
4175
4176
4177
4178
4179void QQuickItem::keyReleaseEvent(QKeyEvent *event)
4186
4187
4188
4189
4190
4191
4192void QQuickItem::inputMethodEvent(QInputMethodEvent *event)
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208void QQuickItem::focusInEvent(QFocusEvent *event)
4211#if QT_CONFIG(accessibility)
4212 if (QAccessible::isActive()) {
4213 if (QObject *acc = QQuickAccessibleAttached::findAccessible(
this)) {
4214 QAccessibleEvent ev(acc, QAccessible::Focus);
4215 QAccessible::updateAccessibility(&ev);
4219 d->setLastFocusChangeReason(event->reason());
4223
4224
4225
4226
4227
4228
4229void QQuickItem::focusOutEvent(QFocusEvent *event)
4232 d->setLastFocusChangeReason(event->reason());
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245void QQuickItem::mousePressEvent(QMouseEvent *event)
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261void QQuickItem::mouseMoveEvent(QMouseEvent *event)
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277void QQuickItem::mouseReleaseEvent(QMouseEvent *event)
4283
4284
4285
4286
4287
4288
4289void QQuickItem::mouseDoubleClickEvent(QMouseEvent *event)
4295
4296
4297
4298void QQuickItem::mouseUngrabEvent()
4304
4305
4306
4307void QQuickItem::touchUngrabEvent()
4312#if QT_CONFIG(wheelevent)
4314
4315
4316
4317
4318
4319
4320void QQuickItem::wheelEvent(QWheelEvent *event)
4327
4328
4329
4330
4331
4332
4333void QQuickItem::touchEvent(QTouchEvent *event)
4339
4340
4341
4342
4343
4344
4345
4346
4347void QQuickItem::hoverEnterEvent(QHoverEvent *event)
4353
4354
4355
4356
4357
4358
4359
4360
4361void QQuickItem::hoverMoveEvent(QHoverEvent *event)
4367
4368
4369
4370
4371
4372
4373
4374
4375void QQuickItem::hoverLeaveEvent(QHoverEvent *event)
4380#if QT_CONFIG(quick_draganddrop)
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393void QQuickItem::dragEnterEvent(QDragEnterEvent *event)
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410void QQuickItem::dragMoveEvent(QDragMoveEvent *event)
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427void QQuickItem::dragLeaveEvent(QDragLeaveEvent *event)
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444void QQuickItem::dropEvent(QDropEvent *event)
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480bool QQuickItem::childMouseEventFilter(QQuickItem *item, QEvent *event)
4489
4490
4491
4492
4493
4494
4495
4496QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query)
const
4498 Q_D(
const QQuickItem);
4503 v = (
bool)(flags() & ItemAcceptsInputMethod);
4506 case Qt::ImAnchorRectangle:
4507 case Qt::ImCursorRectangle:
4509 case Qt::ImCursorPosition:
4510 case Qt::ImSurroundingText:
4511 case Qt::ImCurrentSelection:
4512 case Qt::ImMaximumTextLength:
4513 case Qt::ImAnchorPosition:
4514 case Qt::ImPreferredLanguage:
4515 case Qt::ImReadOnly:
4516 if (d->extra.isAllocated() && d->extra->keyHandler)
4517 v = d->extra->keyHandler->inputMethodQuery(query);
4519 case Qt::ImEnterKeyType:
4520 if (d->extra.isAllocated() && d->extra->enterKeyAttached)
4521 v = d->extra->enterKeyAttached->type();
4523 case Qt::ImInputItemClipRectangle:
4524 if (!(!window() ||!isVisible() || qFuzzyIsNull(opacity()))) {
4525 QRectF rect = QRectF(0,0, width(), height());
4526 const QQuickItem *par =
this;
4527 while (QQuickItem *parpar = par->parentItem()) {
4528 rect = parpar->mapRectFromItem(par, rect);
4530 rect = rect.intersected(parpar->clipRect());
4533 rect = par->mapRectToScene(rect);
4535 rect = rect.intersected(QRectF(QPoint(0,0), window()->size()));
4537 v = mapRectFromScene(rect);
4548QQuickAnchorLine QQuickItemPrivate::left()
const
4550 Q_Q(
const QQuickItem);
4551 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::LeftAnchor);
4554QQuickAnchorLine QQuickItemPrivate::right()
const
4556 Q_Q(
const QQuickItem);
4557 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::RightAnchor);
4560QQuickAnchorLine QQuickItemPrivate::horizontalCenter()
const
4562 Q_Q(
const QQuickItem);
4563 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::HCenterAnchor);
4566QQuickAnchorLine QQuickItemPrivate::top()
const
4568 Q_Q(
const QQuickItem);
4569 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::TopAnchor);
4572QQuickAnchorLine QQuickItemPrivate::bottom()
const
4574 Q_Q(
const QQuickItem);
4575 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BottomAnchor);
4578QQuickAnchorLine QQuickItemPrivate::verticalCenter()
const
4580 Q_Q(
const QQuickItem);
4581 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::VCenterAnchor);
4584QQuickAnchorLine QQuickItemPrivate::baseline()
const
4586 Q_Q(
const QQuickItem);
4587 return QQuickAnchorLine(
const_cast<QQuickItem *>(q), QQuickAnchors::BaselineAnchor);
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612qreal QQuickItem::baselineOffset()
const
4614 Q_D(
const QQuickItem);
4615 return d->baselineOffset;
4618void QQuickItem::setBaselineOffset(qreal offset)
4621 if (offset == d->baselineOffset)
4624 d->baselineOffset = offset;
4626 d->notifyChangeListeners(QQuickItemPrivate::Geometry, [](
const QQuickItemPrivate::ChangeListener &change){
4627 QQuickAnchorsPrivate *anchor = change.listener->anchorPrivate();
4629 anchor->updateVerticalAnchors();
4632 if (d->_anchors && (d->_anchors->usedAnchors() & QQuickAnchors::BaselineAnchor))
4633 QQuickAnchorsPrivate::get(d->_anchors)->updateVerticalAnchors();
4635 emit baselineOffsetChanged(offset);
4640
4641
4642
4643
4644
4645
4646
4647
4648void QQuickItem::update()
4651 if (!(flags() & ItemHasContents)) {
4653 qWarning() << metaObject()->className() <<
": Update called for a item without content";
4657 d->dirty(QQuickItemPrivate::Content);
4661
4662
4663
4664
4665
4666
4667
4668void QQuickItem::polish()
4671 if (!d->polishScheduled) {
4672 d->polishScheduled =
true;
4674 QQuickWindowPrivate *p = QQuickWindowPrivate::get(d->window);
4675 bool maybeupdate = p->itemsToPolish.isEmpty();
4676 p->itemsToPolish.append(
this);
4677 if (maybeupdate) d->window->maybeUpdate();
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697void QQuickItem::ensurePolished()
4702#if QT_DEPRECATED_SINCE(6
, 5
)
4703static bool unwrapMapFromToFromItemArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning,
4704 QQuickItem **itemObj, qreal *x, qreal *y, qreal *w, qreal *h,
bool *isRect)
4706 QV4::ExecutionEngine *v4 = args->v4engine();
4707 if (args->length() != 2 && args->length() != 3 && args->length() != 5) {
4708 v4->throwTypeError();
4712 QV4::Scope scope(v4);
4713 QV4::ScopedValue item(scope, (*args)[0]);
4716 if (!item->isNull()) {
4717 QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, item->as<QV4::QObjectWrapper>());
4719 *itemObj = qobject_cast<QQuickItem*>(qobjectWrapper->object());
4722 if (!(*itemObj) && !item->isNull()) {
4723 qmlWarning(itemForWarning) << functionNameForWarning <<
" given argument \"" << item->toQStringNoThrow()
4724 <<
"\" which is neither null nor an Item";
4725 v4->throwTypeError();
4731 if (args->length() == 2) {
4732 QV4::ScopedValue sv(scope, (*args)[1]);
4734 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4735 <<
"\" which is neither a point nor a rect";
4736 v4->throwTypeError();
4739 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4740 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4741 if (v.canConvert<QPointF>()) {
4742 const QPointF p = v.toPointF();
4745 }
else if (v.canConvert<QRectF>()) {
4746 const QRectF r = v.toRectF();
4753 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4754 <<
"\" which is neither a point nor a rect";
4755 v4->throwTypeError();
4759 QV4::ScopedValue vx(scope, (*args)[1]);
4760 QV4::ScopedValue vy(scope, (*args)[2]);
4762 if (!vx->isNumber() || !vy->isNumber()) {
4763 v4->throwTypeError();
4767 *x = vx->asDouble();
4768 *y = vy->asDouble();
4770 if (args->length() > 3) {
4771 QV4::ScopedValue vw(scope, (*args)[3]);
4772 QV4::ScopedValue vh(scope, (*args)[4]);
4773 if (!vw->isNumber() || !vh->isNumber()) {
4774 v4->throwTypeError();
4777 *w = vw->asDouble();
4778 *h = vh->asDouble();
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4805#if QT_DEPRECATED_SINCE(6
, 5
)
4807
4808
4809void QQuickItem::mapFromItem(QQmlV4FunctionPtr args)
const
4811 QV4::ExecutionEngine *v4 = args->v4engine();
4812 QV4::Scope scope(v4);
4816 QQuickItem *itemObj;
4817 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapFromItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4820 const QVariant result = isRect ? QVariant(mapRectFromItem(itemObj, QRectF(x, y, w, h)))
4821 : QVariant(mapFromItem(itemObj, QPointF(x, y)));
4823 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4824 args->setReturnValue(rv.asReturnedValue());
4829
4830
4831QTransform QQuickItem::itemTransform(QQuickItem *other,
bool *ok)
const
4833 Q_D(
const QQuickItem);
4839 QTransform t = d->itemToWindowTransform();
4840 if (other) t *= QQuickItemPrivate::get(other)->windowToItemTransform();
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4863#if QT_DEPRECATED_SINCE(6
, 5
)
4865
4866
4867void QQuickItem::mapToItem(QQmlV4FunctionPtr args)
const
4869 QV4::ExecutionEngine *v4 = args->v4engine();
4870 QV4::Scope scope(v4);
4874 QQuickItem *itemObj;
4875 if (!unwrapMapFromToFromItemArgs(args,
this, QStringLiteral(
"mapToItem()"), &itemObj, &x, &y, &w, &h, &isRect))
4878 const QVariant result = isRect ? QVariant(mapRectToItem(itemObj, QRectF(x, y, w, h)))
4879 : QVariant(mapToItem(itemObj, QPointF(x, y)));
4881 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4882 args->setReturnValue(rv.asReturnedValue());
4885static bool unwrapMapFromToFromGlobalArgs(QQmlV4FunctionPtr args,
const QQuickItem *itemForWarning,
const QString &functionNameForWarning, qreal *x, qreal *y)
4887 QV4::ExecutionEngine *v4 = args->v4engine();
4888 if (args->length() != 1 && args->length() != 2) {
4889 v4->throwTypeError();
4893 QV4::Scope scope(v4);
4895 if (args->length() == 1) {
4896 QV4::ScopedValue sv(scope, (*args)[0]);
4898 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4899 <<
"\" which is not a point";
4900 v4->throwTypeError();
4903 const QV4::Scoped<QV4::QQmlValueTypeWrapper> variantWrapper(scope, sv->as<QV4::QQmlValueTypeWrapper>());
4904 const QVariant v = variantWrapper ? variantWrapper->toVariant() : QVariant();
4905 if (v.canConvert<QPointF>()) {
4906 const QPointF p = v.toPointF();
4910 qmlWarning(itemForWarning) << functionNameForWarning <<
"given argument \"" << sv->toQStringNoThrow()
4911 <<
"\" which is not a point";
4912 v4->throwTypeError();
4916 QV4::ScopedValue vx(scope, (*args)[0]);
4917 QV4::ScopedValue vy(scope, (*args)[1]);
4919 if (!vx->isNumber() || !vy->isNumber()) {
4920 v4->throwTypeError();
4924 *x = vx->asDouble();
4925 *y = vy->asDouble();
4932
4933
4934
4935
4936
4937
4938
4939
4941
4942
4943void QQuickItem::mapFromGlobal(QQmlV4FunctionPtr args)
const
4945 QV4::ExecutionEngine *v4 = args->v4engine();
4946 QV4::Scope scope(v4);
4949 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4952 QVariant result = mapFromGlobal(QPointF(x, y));
4954 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4955 args->setReturnValue(rv.asReturnedValue());
4960
4961
4962
4963
4964
4965
4966
4967
4969#if QT_DEPRECATED_SINCE(6
, 5
)
4971
4972
4973void QQuickItem::mapToGlobal(QQmlV4FunctionPtr args)
const
4975 QV4::ExecutionEngine *v4 = args->v4engine();
4976 QV4::Scope scope(v4);
4979 if (!unwrapMapFromToFromGlobalArgs(args,
this, QStringLiteral(
"mapFromGlobal()"), &x, &y))
4982 QVariant result = mapToGlobal(QPointF(x, y));
4984 QV4::ScopedObject rv(scope, v4->fromVariant(result));
4985 args->setReturnValue(rv.asReturnedValue());
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015void QQuickItem::forceActiveFocus()
5017 forceActiveFocus(Qt::OtherFocusReason);
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5045void QQuickItem::forceActiveFocus(Qt::FocusReason reason)
5047 setFocus(
true, reason);
5048 QQuickItem *parent = parentItem();
5049 QQuickItem *scope =
nullptr;
5051 if (parent->flags() & QQuickItem::ItemIsFocusScope) {
5052 parent->setFocus(
true, reason);
5056 parent = parent->parentItem();
5061
5062
5063
5064
5065
5066
5067
5068
5069
5071
5072
5073
5074
5075
5077QQuickItem *QQuickItem::nextItemInFocusChain(
bool forward)
5079 return QQuickItemPrivate::nextPrevItemInTabFocusChain(
this, forward);
5083
5084
5085
5086
5087
5088
5089
5091
5092
5093
5094
5095
5096QQuickItem *QQuickItem::childAt(qreal x, qreal y)
const
5098 const QList<QQuickItem *> children = childItems();
5099 for (
int i = children.size()-1; i >= 0; --i) {
5100 QQuickItem *child = children.at(i);
5102 QPointF point = mapToItem(child, QPointF(x, y));
5103 if (child->isVisible() && child->contains(point))
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150void QQuickItem::dumpItemTree()
const
5152 Q_D(
const QQuickItem);
5156void QQuickItemPrivate::dumpItemTree(
int indent)
const
5158 Q_Q(
const QQuickItem);
5160 const auto indentStr = QString(indent * 4, QLatin1Char(
' '));
5161 qDebug().nospace().noquote() << indentStr <<
5162#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5163 const_cast<QQuickItem *>(q);
5167 if (extra.isAllocated()) {
5168 for (
const auto handler : extra->pointerHandlers)
5169 qDebug().nospace().noquote() << indentStr << u" \u26ee " << handler;
5171 for (
const QQuickItem *ch : childItems) {
5172 auto itemPriv = QQuickItemPrivate::get(ch);
5173 itemPriv->dumpItemTree(indent + 1);
5177QQmlListProperty<QObject> QQuickItemPrivate::resources()
5181 QQmlListProperty<QObject> result;
5182 result.object = q_func();
5183 result.append = QQuickItemPrivate::resources_append;
5184 result.count = QQuickItemPrivate::resources_count;
5185 result.at = QQuickItemPrivate::resources_at;
5186 result.clear = QQuickItemPrivate::resources_clear;
5187 result.removeLast = QQuickItemPrivate::resources_removeLast;
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5205
5206
5207
5208QQmlListProperty<QQuickItem> QQuickItemPrivate::children()
5212 QQmlListProperty<QQuickItem> result;
5213 result.object = q_func();
5214 result.append = QQuickItemPrivate::children_append;
5215 result.count = QQuickItemPrivate::children_count;
5216 result.at = QQuickItemPrivate::children_at;
5217 result.clear = QQuickItemPrivate::children_clear;
5218 result.removeLast = QQuickItemPrivate::children_removeLast;
5223
5224
5225
5226
5227
5229
5230
5231
5232QQmlListProperty<QQuickItem> QQuickItemPrivate::visibleChildren()
5234 return QQmlListProperty<QQuickItem>(q_func(),
5236 QQuickItemPrivate::visibleChildren_count,
5237 QQuickItemPrivate::visibleChildren_at);
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5278
5279
5280
5281QQmlListProperty<QQuickState> QQuickItemPrivate::states()
5283 return _states()->statesProperty();
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5315
5316
5317
5318QQmlListProperty<QQuickTransition> QQuickItemPrivate::transitions()
5320 return _states()->transitionsProperty();
5323QString QQuickItemPrivate::state()
const
5328 return _stateGroup->state();
5331void QQuickItemPrivate::setState(
const QString &state)
5333 _states()->setState(state);
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358QString QQuickItem::state()
const
5360 Q_D(
const QQuickItem);
5364void QQuickItem::setState(
const QString &state)
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5383
5384
5385
5387
5388
5389QQmlListProperty<QQuickTransform> QQuickItem::transform()
5391 return QQmlListProperty<QQuickTransform>(
this,
nullptr, QQuickItemPrivate::transform_append,
5392 QQuickItemPrivate::transform_count,
5393 QQuickItemPrivate::transform_at,
5394 QQuickItemPrivate::transform_clear);
5398
5399
5400
5401
5402void QQuickItem::classBegin()
5405 d->componentComplete =
false;
5407 d->_stateGroup->classBegin();
5409 d->_anchors->classBegin();
5410#if QT_CONFIG(quick_shadereffect)
5411 if (d->extra.isAllocated() && d->extra->layer)
5412 d->extra->layer->classBegin();
5417
5418
5419
5420
5421void QQuickItem::componentComplete()
5424 d->componentComplete =
true;
5426 d->_stateGroup->componentComplete();
5428 d->_anchors->componentComplete();
5429 QQuickAnchorsPrivate::get(d->_anchors)->updateOnComplete();
5432 if (
auto *safeArea = findChild<QQuickSafeArea*>(Qt::FindDirectChildrenOnly))
5433 safeArea->updateSafeArea();
5435 if (d->extra.isAllocated()) {
5436#if QT_CONFIG(quick_shadereffect)
5437 if (d->extra->layer)
5438 d->extra->layer->componentComplete();
5441 if (d->extra->keyHandler)
5442 d->extra->keyHandler->componentComplete();
5444 if (d->extra->contents)
5445 d->extra->contents->complete();
5448 if (d->window && d->dirtyAttributes) {
5449 d->addToDirtyList();
5450 QQuickWindowPrivate::get(d->window)->dirtyItem(
this);
5453#if QT_CONFIG(accessibility)
5454 if (d->isAccessible && d->effectiveVisible) {
5455 QAccessibleEvent ev(
this, QAccessible::ObjectShow);
5456 QAccessible::updateAccessibility(&ev);
5461QQuickStateGroup *QQuickItemPrivate::_states()
5465 _stateGroup =
new QQuickStateGroup;
5466 if (!componentComplete)
5467 _stateGroup->classBegin();
5468 qmlobject_connect(_stateGroup, QQuickStateGroup, SIGNAL(stateChanged(QString)),
5469 q, QQuickItem, SIGNAL(stateChanged(QString)));
5475bool QQuickItemPrivate::customOverlayRequested =
false;
5477void QQuickItemPrivate::requestCustomOverlay()
5479 customOverlayRequested =
true;
5480 customOverlay =
true;
5483QPointF QQuickItemPrivate::computeTransformOrigin()
const
5487 case QQuickItem::TopLeft:
5488 return QPointF(0, 0);
5489 case QQuickItem::Top:
5490 return QPointF(width / 2., 0);
5491 case QQuickItem::TopRight:
5492 return QPointF(width, 0);
5493 case QQuickItem::Left:
5494 return QPointF(0, height / 2.);
5495 case QQuickItem::Center:
5496 return QPointF(width / 2., height / 2.);
5497 case QQuickItem::Right:
5498 return QPointF(width, height / 2.);
5499 case QQuickItem::BottomLeft:
5500 return QPointF(0, height);
5501 case QQuickItem::Bottom:
5502 return QPointF(width / 2., height);
5503 case QQuickItem::BottomRight:
5504 return QPointF(width, height);
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522bool QQuickItemPrivate::transformChanged(QQuickItem *transformedItem)
5526#if QT_CONFIG(quick_shadereffect)
5527 if (q == transformedItem) {
5528 if (extra.isAllocated() && extra->layer)
5529 extra->layer->updateMatrix();
5533 itemChange(QQuickItem::ItemTransformHasChanged, transformedItem);
5535 bool childWantsIt =
false;
5536 if (subtreeTransformChangedEnabled) {
5539 const auto children = paintOrderChildItems();
5540 for (QQuickItem *child : children)
5541 childWantsIt |= QQuickItemPrivate::get(child)->transformChanged(transformedItem);
5544 const bool thisWantsIt = q->flags().testFlag(QQuickItem::ItemObservesViewport);
5545 const bool ret = childWantsIt || thisWantsIt;
5546 if (!ret && componentComplete && subtreeTransformChangedEnabled) {
5547 qCDebug(lcVP) <<
"turned off subtree transformChanged notification after checking all children of" << q;
5548 subtreeTransformChangedEnabled =
false;
5552 if (thisWantsIt && q->clip() && !(dirtyAttributes & QQuickItemPrivate::Clip))
5553 dirty(QQuickItemPrivate::Clip);
5558 QQuickItemPrivate *itemPriv =
this;
5559 while (itemPriv->parentItem) {
5560 auto *parentPriv = QQuickItemPrivate::get(itemPriv->parentItem);
5561 if (parentPriv->eventHandlingChildrenWithinBounds) {
5562 Q_ASSERT(parentPriv->eventHandlingChildrenWithinBoundsSet);
5563 if (itemPriv->parentFullyContains())
5566 parentPriv->eventHandlingChildrenWithinBounds =
false;
5568 itemPriv = parentPriv;
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590QPointF QQuickItemPrivate::adjustedPosForTransform(
const QPointF ¢roidParentPos,
5591 const QPointF &startPos,
5592 const QVector2D &activeTranslation,
5595 qreal startRotation,
5596 qreal activeRotation)
5599 QVector3D xformOrigin(q->transformOriginPoint());
5600 QMatrix4x4 startMatrix;
5601 startMatrix.translate(
float(startPos.x()),
float(startPos.y()));
5602 startMatrix.translate(xformOrigin);
5603 startMatrix.scale(
float(startScale));
5604 startMatrix.rotate(
float(startRotation), 0, 0, -1);
5605 startMatrix.translate(-xformOrigin);
5607 const QVector3D centroidParentVector(centroidParentPos);
5609 mat.translate(centroidParentVector);
5610 mat.rotate(
float(activeRotation), 0, 0, 1);
5611 mat.scale(
float(activeScale));
5612 mat.translate(-centroidParentVector);
5613 mat.translate(QVector3D(activeTranslation));
5615 mat = mat * startMatrix;
5617 QPointF xformOriginPoint = q->transformOriginPoint();
5618 QPointF pos = mat.map(xformOriginPoint);
5619 pos -= xformOriginPoint;
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646QQuickDeliveryAgent *QQuickItemPrivate::deliveryAgent()
5649 if (maybeHasSubsceneDeliveryAgent) {
5650 QQuickItemPrivate *p =
this;
5652 if (qmlobject_cast<QQuickRootItem *>(p->q_ptr)) {
5657 maybeHasSubsceneDeliveryAgent =
false;
5660 if (p->extra.isAllocated()) {
5661 if (
auto da = p->extra->subsceneDeliveryAgent)
5664 p = p->parentItem ? QQuickItemPrivate::get(p->parentItem) :
nullptr;
5668 qCDebug(lcPtr) <<
"detached root of" << q <<
"is not a QQuickRootItem and also does not have its own DeliveryAgent";
5671 return QQuickWindowPrivate::get(window)->deliveryAgent;
5675QQuickDeliveryAgentPrivate *QQuickItemPrivate::deliveryAgentPrivate()
5677 auto da = deliveryAgent();
5678 return da ?
static_cast<QQuickDeliveryAgentPrivate *>(QQuickDeliveryAgentPrivate::get(da)) :
nullptr;
5682
5683
5684
5685
5686
5687
5688
5689QQuickDeliveryAgent *QQuickItemPrivate::ensureSubsceneDeliveryAgent()
5695 maybeHasSubsceneDeliveryAgent =
true;
5696 if (extra.isAllocated() && extra->subsceneDeliveryAgent)
5697 return extra->subsceneDeliveryAgent;
5698 extra.value().subsceneDeliveryAgent =
new QQuickDeliveryAgent(q);
5699 qCDebug(lcPtr) <<
"created new" << extra->subsceneDeliveryAgent;
5702 q->setFlag(QQuickItem::ItemIsFocusScope);
5703 return extra->subsceneDeliveryAgent;
5706bool QQuickItemPrivate::filterKeyEvent(QKeyEvent *e,
bool post)
5708 if (!extra.isAllocated() || !extra->keyHandler)
5714 if (e->type() == QEvent::KeyPress)
5715 extra->keyHandler->keyPressed(e, post);
5717 extra->keyHandler->keyReleased(e, post);
5719 return e->isAccepted();
5722void QQuickItemPrivate::deliverPointerEvent(QEvent *event)
5725 const auto eventType = event->type();
5726 const bool focusAccepted = setFocusIfNeeded(eventType);
5728 switch (eventType) {
5729 case QEvent::MouseButtonPress:
5730 q->mousePressEvent(
static_cast<QMouseEvent *>(event));
5732 case QEvent::MouseButtonRelease:
5733 q->mouseReleaseEvent(
static_cast<QMouseEvent *>(event));
5735 case QEvent::MouseButtonDblClick:
5736 q->mouseDoubleClickEvent(
static_cast<QMouseEvent *>(event));
5738#if QT_CONFIG(wheelevent)
5740 q->wheelEvent(
static_cast<QWheelEvent*>(event));
5743 case QEvent::TouchBegin:
5744 case QEvent::TouchUpdate:
5745 case QEvent::TouchEnd:
5746 case QEvent::TouchCancel:
5747 q->touchEvent(
static_cast<QTouchEvent *>(event));
5757void QQuickItemPrivate::deliverKeyEvent(QKeyEvent *e)
5761 Q_ASSERT(e->isAccepted());
5762 if (filterKeyEvent(e,
false))
5767 if (e->type() == QEvent::KeyPress)
5768 q->keyPressEvent(e);
5770 q->keyReleaseEvent(e);
5772 if (e->isAccepted())
5775 if (filterKeyEvent(e,
true) || !q->window())
5779 if (e->type() == QEvent::KeyPress &&
5780 (q == q->window()->contentItem() || q->activeFocusOnTab())) {
5782 if (!(e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
5783 if (e->key() == Qt::Key_Backtab
5784 || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier)))
5785 res = QQuickItemPrivate::focusNextPrev(q,
false);
5786 else if (e->key() == Qt::Key_Tab)
5787 res = QQuickItemPrivate::focusNextPrev(q,
true);
5789 e->setAccepted(
true);
5795void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e)
5799 Q_ASSERT(e->isAccepted());
5800 if (extra.isAllocated() && extra->keyHandler) {
5801 extra->keyHandler->inputMethodEvent(e,
false);
5803 if (e->isAccepted())
5809 q->inputMethodEvent(e);
5811 if (e->isAccepted())
5814 if (extra.isAllocated() && extra->keyHandler) {
5817 extra->keyHandler->inputMethodEvent(e,
true);
5822void QQuickItemPrivate::deliverShortcutOverrideEvent(QKeyEvent *event)
5824 if (extra.isAllocated() && extra->keyHandler)
5825 extra->keyHandler->shortcutOverrideEvent(event);
5830bool QQuickItemPrivate::anyPointerHandlerWants(
const QPointerEvent *event,
const QEventPoint &point)
const
5832 if (!hasPointerHandlers())
5834 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5835 if (handler->wantsEventPoint(event, point))
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855bool QQuickItemPrivate::handlePointerEvent(QPointerEvent *event,
bool avoidGrabbers)
5857 bool delivered =
false;
5858 if (extra.isAllocated()) {
5859 for (QQuickPointerHandler *handler : extra->pointerHandlers) {
5860 bool avoidThisHandler =
false;
5861 if (QQuickDeliveryAgentPrivate::isMouseOrWheelEvent(event) &&
5862 qmlobject_cast<
const QQuickHoverHandler *>(handler)) {
5863 avoidThisHandler =
true;
5864 }
else if (avoidGrabbers) {
5865 for (
auto &p : event->points()) {
5866 if (event->exclusiveGrabber(p) == handler || event->passiveGrabbers(p).contains(handler)) {
5867 avoidThisHandler =
true;
5872 if (!avoidThisHandler &&
5873 !QQuickPointerHandlerPrivate::deviceDeliveryTargets(event->device()).contains(handler)) {
5874 handler->handlePointerEvent(event);
5882#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
5883bool QQuickItemPrivate::handleContextMenuEvent(QContextMenuEvent *event)
5885bool QQuickItem::contextMenuEvent(QContextMenuEvent *event)
5888 if (extra.isAllocated() && extra->contextMenu)
5889 return extra->contextMenu->event(event);
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907void QQuickItem::itemChange(ItemChange change,
const ItemChangeData &value)
5909 if (change == ItemSceneChange)
5910 emit windowChanged(value.window);
5915
5916
5917
5918void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
5920 if (hasActiveFocus())
5921 QGuiApplication::inputMethod()->update(queries);
5926
5927
5928
5929QRectF QQuickItem::boundingRect()
const
5931 Q_D(
const QQuickItem);
5932 return QRectF(0, 0, d->width, d->height);
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956QRectF QQuickItem::clipRect()
const
5958 Q_D(
const QQuickItem);
5959 QRectF ret(0, 0, d->width.valueBypassingBindings(), d->height.valueBypassingBindings());
5960 if (flags().testFlag(QQuickItem::ItemObservesViewport)) {
5961 if (QQuickItem *viewport = viewportItem()) {
5964 if (viewport ==
this)
5966 const auto mappedViewportRect = mapRectFromItem(viewport, viewport->clipRect());
5967 qCDebug(lcVP) <<
this <<
"intersecting" << viewport << mappedViewportRect << ret <<
"->" << mappedViewportRect.intersected(ret);
5968 return mappedViewportRect.intersected(ret);
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985QQuickItem *QQuickItem::viewportItem()
const
5987 if (flags().testFlag(ItemObservesViewport)) {
5988 QQuickItem *par = parentItem();
5990 if (par->flags().testFlag(QQuickItem::ItemIsViewport))
5992 par = par->parentItem();
5995 return (window() ? window()->contentItem() :
nullptr);
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6020
6021
6022
6023
6024
6025
6026
6027
6028QQuickItem::TransformOrigin QQuickItem::transformOrigin()
const
6030 Q_D(
const QQuickItem);
6034void QQuickItem::setTransformOrigin(TransformOrigin origin)
6037 if (origin == d->origin())
6040 d->extra.value().origin = origin;
6041 d->dirty(QQuickItemPrivate::TransformOrigin);
6043 emit transformOriginChanged(d->origin());
6047
6048
6049
6051
6052
6053QPointF QQuickItem::transformOriginPoint()
const
6055 Q_D(
const QQuickItem);
6056 if (d->extra.isAllocated() && !d->extra->userTransformOriginPoint.isNull())
6057 return d->extra->userTransformOriginPoint;
6058 return d->computeTransformOrigin();
6062
6063
6064void QQuickItem::setTransformOriginPoint(
const QPointF &point)
6067 if (d->extra.value().userTransformOriginPoint == point)
6070 d->extra->userTransformOriginPoint = point;
6071 d->dirty(QQuickItemPrivate::TransformOrigin);
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
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
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
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
6228qreal QQuickItem::z()
const
6230 Q_D(
const QQuickItem);
6234void QQuickItem::setZ(qreal v)
6240 d->extra.value().z = v;
6242 d->dirty(QQuickItemPrivate::ZValue);
6243 if (d->parentItem) {
6244 QQuickItemPrivate::get(d->parentItem)->markSortedChildrenDirty(
this);
6245 QQuickItemPrivate::get(d->parentItem)->dirty(QQuickItemPrivate::ChildrenStackingChanged);
6250#if QT_CONFIG(quick_shadereffect)
6251 if (d->extra.isAllocated() && d->extra->layer)
6252 d->extra->layer->updateZ();
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308qreal QQuickItem::rotation()
const
6310 Q_D(
const QQuickItem);
6311 return d->rotation();
6314void QQuickItem::setRotation(qreal r)
6317 if (d->rotation() == r)
6320 d->extra.value().rotation = r;
6322 d->dirty(QQuickItemPrivate::BasicTransform);
6324 d->itemChange(ItemRotationHasChanged, r);
6326 emit rotationChanged();
6330
6331
6332
6333
6334
6335
6336
6337
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
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408qreal QQuickItem::scale()
const
6410 Q_D(
const QQuickItem);
6414void QQuickItem::setScale(qreal s)
6417 if (d->scale() == s)
6420 d->extra.value().scale = s;
6422 d->dirty(QQuickItemPrivate::BasicTransform);
6424 d->itemChange(ItemScaleHasChanged, s);
6426 emit scaleChanged();
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539qreal QQuickItem::opacity()
const
6541 Q_D(
const QQuickItem);
6542 return d->opacity();
6545void QQuickItem::setOpacity(qreal newOpacity)
6548 qreal o = std::clamp(newOpacity, qreal(0.0), qreal(1.0));
6549 if (d->opacity() == o)
6552 d->extra.value().opacity = o;
6554 d->dirty(QQuickItemPrivate::OpacityValue);
6556 d->itemChange(ItemOpacityHasChanged, o);
6558 emit opacityChanged();
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6589
6590
6591
6592
6593
6594
6595
6596
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
6625bool QQuickItem::isVisible()
const
6627 Q_D(
const QQuickItem);
6628 return d->effectiveVisible;
6631void QQuickItemPrivate::setVisible(
bool visible)
6633 if (visible == explicitVisible)
6636 explicitVisible = visible;
6638 dirty(QQuickItemPrivate::Visible);
6640 const bool childVisibilityChanged = setEffectiveVisibleRecur(calcEffectiveVisible());
6641 if (childVisibilityChanged && parentItem)
6642 emit parentItem->visibleChildrenChanged();
6645void QQuickItem::setVisible(
bool v)
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700bool QQuickItem::isEnabled()
const
6702 Q_D(
const QQuickItem);
6703 return d->effectiveEnable;
6706void QQuickItem::setEnabled(
bool e)
6709 if (e == d->explicitEnable)
6712 d->explicitEnable = e;
6714 QQuickItem *scope = parentItem();
6715 while (scope && !scope->isFocusScope())
6716 scope = scope->parentItem();
6718 d->setEffectiveEnableRecur(scope, d->calcEffectiveEnable());
6721bool QQuickItemPrivate::calcEffectiveVisible()
const
6724 return explicitVisible && parentItem && QQuickItemPrivate::get(parentItem)->effectiveVisible;
6727bool QQuickItemPrivate::setEffectiveVisibleRecur(
bool newEffectiveVisible)
6731 if (newEffectiveVisible && !explicitVisible) {
6736 if (newEffectiveVisible == effectiveVisible) {
6741 effectiveVisible = newEffectiveVisible;
6744 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
6746 if (
auto agent = deliveryAgentPrivate())
6747 agent->removeGrabber(q,
true,
true,
true);
6750 bool childVisibilityChanged =
false;
6751 for (
int ii = 0; ii < childItems.size(); ++ii)
6752 childVisibilityChanged |= QQuickItemPrivate::get(childItems.at(ii))->setEffectiveVisibleRecur(newEffectiveVisible);
6754 itemChange(QQuickItem::ItemVisibleHasChanged,
bool(effectiveVisible));
6755#if QT_CONFIG(accessibility)
6757 QAccessibleEvent ev(q, effectiveVisible ? QAccessible::ObjectShow : QAccessible::ObjectHide);
6758 QAccessible::updateAccessibility(&ev);
6761 if (!inDestructor) {
6762 emit q->visibleChanged();
6763 if (childVisibilityChanged)
6764 emit q->visibleChildrenChanged();
6770bool QQuickItemPrivate::calcEffectiveEnable()
const
6775 return explicitEnable && (!parentItem || QQuickItemPrivate::get(parentItem)->effectiveEnable);
6778void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope,
bool newEffectiveEnable)
6782 if (newEffectiveEnable && !explicitEnable) {
6787 if (newEffectiveEnable == effectiveEnable) {
6792 effectiveEnable = newEffectiveEnable;
6794 QQuickDeliveryAgentPrivate *da = deliveryAgentPrivate();
6796 da->removeGrabber(q,
true,
true,
true);
6797 if (scope && !effectiveEnable && activeFocus) {
6798 da->clearFocusInScope(scope, q, Qt::OtherFocusReason,
6799 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6800 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6804 for (
int ii = 0; ii < childItems.size(); ++ii) {
6805 QQuickItemPrivate::get(childItems.at(ii))->setEffectiveEnableRecur(
6806 (flags & QQuickItem::ItemIsFocusScope) && scope ? q : scope, newEffectiveEnable);
6809 if (scope && effectiveEnable && focus && da) {
6810 da->setFocusInScope(scope, q, Qt::OtherFocusReason,
6811 QQuickDeliveryAgentPrivate::DontChangeFocusProperty |
6812 QQuickDeliveryAgentPrivate::DontChangeSubFocusItem);
6815 itemChange(QQuickItem::ItemEnabledHasChanged,
bool(effectiveEnable));
6816#if QT_CONFIG(accessibility)
6818 QAccessible::State changedState;
6819 changedState.disabled =
true;
6820 changedState.focusable =
true;
6821 QAccessibleStateChangeEvent ev(q, changedState);
6822 QAccessible::updateAccessibility(&ev);
6825 emit q->enabledChanged();
6829
6830
6831
6832qreal QQuickItemPrivate::biggestPointerHandlerMargin()
const
6834 if (hasPointerHandlers()) {
6835 if (extra->biggestPointerHandlerMarginCache < 0) {
6836 const auto maxMarginIt = std::max_element(extra->pointerHandlers.constBegin(),
6837 extra->pointerHandlers.constEnd(),
6838 [](
const QQuickPointerHandler *a,
const QQuickPointerHandler *b) {
6839 return a->margin() < b->margin(); });
6840 Q_ASSERT(maxMarginIt != extra->pointerHandlers.constEnd());
6841 extra->biggestPointerHandlerMarginCache = (*maxMarginIt)->margin();
6843 return extra->biggestPointerHandlerMarginCache;
6849
6850
6851
6852
6853
6854
6855QRectF QQuickItemPrivate::eventHandlingBounds(qreal margin)
const
6857 const qreal biggestMargin = margin > 0 ? margin : biggestPointerHandlerMargin();
6858 return QRectF(-biggestMargin, -biggestMargin, width + biggestMargin * 2, height + biggestMargin * 2);
6862
6863
6864
6865bool QQuickItemPrivate::parentFullyContains()
const
6867 Q_Q(
const QQuickItem);
6871 itemToParentTransform(&t);
6872 const auto bounds = eventHandlingBounds();
6873 const auto boundsInParent = t.mapRect(bounds);
6874 const bool ret = parentItem->clipRect().contains(boundsInParent);
6875 qCDebug(lcEffClip) <<
"in parent bounds?" << ret << q << boundsInParent << parentItem << parentItem->clipRect();
6880
6881
6882
6883bool QQuickItemPrivate::effectivelyClipsEventHandlingChildren()
const
6885 Q_Q(
const QQuickItem);
6887 if (flags & QQuickItem::ItemClipsChildrenToShape) {
6888 qCDebug(lcEffClip) << q <<
"result: true because clip is true";
6891 if (!eventHandlingChildrenWithinBoundsSet) {
6893 eventHandlingChildrenWithinBounds =
true;
6894 for (
const auto *child : childItems) {
6895 const auto *childPriv = QQuickItemPrivate::get(child);
6899 if (childPriv->childItems.isEmpty() &&
6900 !(childPriv->hoverEnabled || childPriv->subtreeHoverEnabled || childPriv->touchEnabled ||
6901 childPriv->hasCursor || childPriv->hasCursorHandler || child->acceptedMouseButtons() ||
6902 childPriv->hasPointerHandlers())) {
6903 qCDebug(lcEffClip) << child <<
"doesn't handle pointer events";
6906 if (!childPriv->parentFullyContains()) {
6907 eventHandlingChildrenWithinBounds =
false;
6908 qCDebug(lcEffClip) <<
"child goes outside: giving up" << child;
6911 if (!childPriv->eventHandlingChildrenWithinBoundsSet) {
6912 eventHandlingChildrenWithinBounds = childPriv->effectivelyClipsEventHandlingChildren();
6913 qCDebug(lcEffClip) <<
"child has children that go outside: giving up" << child;
6916#ifdef QT_BUILD_INTERNAL
6917 if (!eventHandlingChildrenWithinBoundsSet && eventHandlingChildrenWithinBounds)
6918 ++eventHandlingChildrenWithinBounds_counter;
6921 eventHandlingChildrenWithinBoundsSet =
true;
6922 qCDebug(lcEffClip) << q << q->clipRect() <<
"result:" <<
static_cast<
bool>(eventHandlingChildrenWithinBounds);
6924 return eventHandlingChildrenWithinBounds;
6927bool QQuickItemPrivate::isTransparentForPositioner()
const
6929 return extra.isAllocated() && extra.value().transparentForPositioner;
6932void QQuickItemPrivate::setTransparentForPositioner(
bool transparent)
6934 extra.value().transparentForPositioner = transparent;
6938QString QQuickItemPrivate::dirtyToString()
const
6940#define DIRTY_TO_STRING(value) if (dirtyAttributes & value) {
6942 rv.append(QLatin1Char('|'));
6943 rv.append(QLatin1String(#value)); \
6944}
6971void QQuickItemPrivate::dirty(DirtyType type)
6974 if (!(dirtyAttributes & type) || (window && !prevDirtyItem)) {
6975 dirtyAttributes |= type;
6976 if (window && componentComplete) {
6978 QQuickWindowPrivate::get(window)->dirtyItem(q);
6981 if (type & (TransformOrigin | Transform | BasicTransform | Position | Size | Clip))
6982 transformChanged(q);
6985void QQuickItemPrivate::addToDirtyList()
6990 if (!prevDirtyItem) {
6991 Q_ASSERT(!nextDirtyItem);
6993 QQuickWindowPrivate *p = QQuickWindowPrivate::get(window);
6994 nextDirtyItem = p->dirtyItemList;
6995 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = &nextDirtyItem;
6996 prevDirtyItem = &p->dirtyItemList;
6997 p->dirtyItemList = q;
7000 Q_ASSERT(prevDirtyItem);
7003void QQuickItemPrivate::removeFromDirtyList()
7005 if (prevDirtyItem) {
7006 if (nextDirtyItem) QQuickItemPrivate::get(nextDirtyItem)->prevDirtyItem = prevDirtyItem;
7007 *prevDirtyItem = nextDirtyItem;
7008 prevDirtyItem =
nullptr;
7009 nextDirtyItem =
nullptr;
7011 Q_ASSERT(!prevDirtyItem);
7012 Q_ASSERT(!nextDirtyItem);
7015void QQuickItemPrivate::refFromEffectItem(
bool hide)
7017 ++extra.value().effectRefCount;
7018 if (extra->effectRefCount == 1) {
7019 dirty(EffectReference);
7021 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7024 if (++extra->hideRefCount == 1)
7025 dirty(HideReference);
7027 recursiveRefFromEffectItem(1);
7030void QQuickItemPrivate::recursiveRefFromEffectItem(
int refs)
7035 extra.value().recursiveEffectRefCount += refs;
7036 for (
int ii = 0; ii < childItems.size(); ++ii) {
7037 QQuickItem *child = childItems.at(ii);
7038 QQuickItemPrivate::get(child)->recursiveRefFromEffectItem(refs);
7042 if (!effectiveVisible && refs > 0 && extra.value().recursiveEffectRefCount == 1)
7046void QQuickItemPrivate::derefFromEffectItem(
bool unhide)
7048 Q_ASSERT(extra->effectRefCount);
7049 --extra->effectRefCount;
7050 if (extra->effectRefCount == 0) {
7051 dirty(EffectReference);
7053 QQuickItemPrivate::get(parentItem)->dirty(ChildrenStackingChanged);
7056 if (--extra->hideRefCount == 0)
7057 dirty(HideReference);
7059 recursiveRefFromEffectItem(-1);
7062void QQuickItemPrivate::setCulled(
bool cull)
7068 if ((cull && ++extra.value().hideRefCount == 1) || (!cull && --extra.value().hideRefCount == 0))
7069 dirty(HideReference);
7072void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change,
const QQuickItem::ItemChangeData &data)
7076 case QQuickItem::ItemChildAddedChange: {
7077 q->itemChange(change, data);
7083 if (QQuickItemPrivate::get(data.item)->transformChanged(q)) {
7084 if (!subtreeTransformChangedEnabled) {
7085 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << q;
7086 subtreeTransformChangedEnabled =
true;
7088 enableSubtreeChangeNotificationsForParentHierachy();
7090 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildAdded, q, data.item);
7093 case QQuickItem::ItemChildRemovedChange: {
7094 q->itemChange(change, data);
7095 notifyChangeListeners(QQuickItemPrivate::Children, &QQuickItemChangeListener::itemChildRemoved, q, data.item);
7098 case QQuickItem::ItemSceneChange:
7099 q->itemChange(change, data);
7101 case QQuickItem::ItemVisibleHasChanged: {
7102 q->itemChange(change, data);
7103 notifyChangeListeners(QQuickItemPrivate::Visibility, &QQuickItemChangeListener::itemVisibilityChanged, q);
7106 case QQuickItem::ItemEnabledHasChanged: {
7107 q->itemChange(change, data);
7108 notifyChangeListeners(QQuickItemPrivate::Enabled, &QQuickItemChangeListener::itemEnabledChanged, q);
7111 case QQuickItem::ItemParentHasChanged: {
7112 q->itemChange(change, data);
7113 notifyChangeListeners(QQuickItemPrivate::Parent, &QQuickItemChangeListener::itemParentChanged, q, data.item);
7116 case QQuickItem::ItemOpacityHasChanged: {
7117 q->itemChange(change, data);
7118 notifyChangeListeners(QQuickItemPrivate::Opacity, &QQuickItemChangeListener::itemOpacityChanged, q);
7121 case QQuickItem::ItemActiveFocusHasChanged:
7122 q->itemChange(change, data);
7124 case QQuickItem::ItemRotationHasChanged: {
7125 q->itemChange(change, data);
7126 notifyChangeListeners(QQuickItemPrivate::Rotation, &QQuickItemChangeListener::itemRotationChanged, q);
7129 case QQuickItem::ItemScaleHasChanged: {
7130 q->itemChange(change, data);
7131 notifyChangeListeners(QQuickItemPrivate::Scale, &QQuickItemChangeListener::itemScaleChanged, q);
7134 case QQuickItem::ItemTransformHasChanged: {
7135 q->itemChange(change, data);
7136 notifyChangeListeners(QQuickItemPrivate::Matrix, &QQuickItemChangeListener::itemTransformChanged, q, data.item);
7139 case QQuickItem::ItemAntialiasingHasChanged:
7141 case QQuickItem::ItemDevicePixelRatioHasChanged:
7142 q->itemChange(change, data);
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170bool QQuickItem::smooth()
const
7172 Q_D(
const QQuickItem);
7175void QQuickItem::setSmooth(
bool smooth)
7178 if (d->smooth == smooth)
7182 d->dirty(QQuickItemPrivate::Smooth);
7184 emit smoothChanged(smooth);
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7226bool QQuickItem::activeFocusOnTab()
const
7228 Q_D(
const QQuickItem);
7229 return d->activeFocusOnTab;
7231void QQuickItem::setActiveFocusOnTab(
bool activeFocusOnTab)
7234 if (d->activeFocusOnTab == activeFocusOnTab)
7238 if ((
this == window()->activeFocusItem()) &&
this != window()->contentItem() && !activeFocusOnTab) {
7239 qWarning(
"QQuickItem: Cannot set activeFocusOnTab to false once item is the active focus item.");
7244 d->activeFocusOnTab = activeFocusOnTab;
7246 emit activeFocusOnTabChanged(activeFocusOnTab);
7250
7251
7252
7253
7254
7255
7256
7257
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268bool QQuickItem::antialiasing()
const
7270 Q_D(
const QQuickItem);
7271 return d->antialiasingValid ? d->antialiasing : d->implicitAntialiasing;
7274void QQuickItem::setAntialiasing(
bool aa)
7278 if (!d->antialiasingValid) {
7279 d->antialiasingValid =
true;
7280 d->antialiasing = d->implicitAntialiasing;
7283 if (aa == d->antialiasing)
7286 d->antialiasing = aa;
7287 d->dirty(QQuickItemPrivate::Antialiasing);
7289 d->itemChange(ItemAntialiasingHasChanged,
bool(d->antialiasing));
7291 emit antialiasingChanged(antialiasing());
7294void QQuickItem::resetAntialiasing()
7297 if (!d->antialiasingValid)
7300 d->antialiasingValid =
false;
7302 if (d->implicitAntialiasing != d->antialiasing)
7303 emit antialiasingChanged(antialiasing());
7306void QQuickItemPrivate::setImplicitAntialiasing(
bool antialiasing)
7309 bool prev = q->antialiasing();
7310 implicitAntialiasing = antialiasing;
7311 if (componentComplete && (q->antialiasing() != prev))
7312 emit q->antialiasingChanged(q->antialiasing());
7316
7317
7318
7319
7320QQuickItem::Flags QQuickItem::flags()
const
7322 Q_D(
const QQuickItem);
7323 return (QQuickItem::Flags)d->flags;
7327
7328
7329
7330
7331
7332
7333
7334void QQuickItem::setFlag(Flag flag,
bool enabled)
7338 setFlags((Flags)(d->flags | (quint32)flag));
7340 setFlags((Flags)(d->flags & ~(quint32)flag));
7344 if (enabled && flag == ItemObservesViewport)
7345 d->enableSubtreeChangeNotificationsForParentHierachy();
7348void QQuickItemPrivate::enableSubtreeChangeNotificationsForParentHierachy()
7352 QQuickItem *par = q->parentItem();
7354 auto parPriv = QQuickItemPrivate::get(par);
7355 if (!parPriv->subtreeTransformChangedEnabled)
7356 qCDebug(lcVP) <<
"turned on transformChanged notification for subtree of" << par;
7357 parPriv->subtreeTransformChangedEnabled =
true;
7358 par = par->parentItem();
7363
7364
7365
7366
7367void QQuickItem::setFlags(Flags flags)
7371 if (
int(flags & ItemIsFocusScope) !=
int(d->flags & ItemIsFocusScope)) {
7372 if (flags & ItemIsFocusScope && !d->childItems.isEmpty() && d->window) {
7373 qWarning(
"QQuickItem: Cannot set FocusScope once item has children and is in a window.");
7374 flags &= ~ItemIsFocusScope;
7375 }
else if (d->flags & ItemIsFocusScope) {
7376 qWarning(
"QQuickItem: Cannot unset FocusScope flag.");
7377 flags |= ItemIsFocusScope;
7381 if (
int(flags & ItemClipsChildrenToShape) !=
int(d->flags & ItemClipsChildrenToShape))
7382 d->dirty(QQuickItemPrivate::Clip);
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7403
7404
7405
7406
7408
7409
7410
7411
7412qreal QQuickItem::x()
const
7414 Q_D(
const QQuickItem);
7418qreal QQuickItem::y()
const
7420 Q_D(
const QQuickItem);
7425
7426
7427QPointF QQuickItem::position()
const
7429 Q_D(
const QQuickItem);
7430 return QPointF(d->x, d->y);
7433void QQuickItem::setX(qreal v)
7437
7438
7439
7440
7441
7442
7443
7444
7445 d->x.removeBindingUnlessInWrapper();
7449 const qreal oldx = d->x.valueBypassingBindings();
7453 d->x.setValueBypassingBindings(v);
7455 d->dirty(QQuickItemPrivate::Position);
7457 const qreal y = d->y.valueBypassingBindings();
7458 const qreal w = d->width.valueBypassingBindings();
7459 const qreal h = d->height.valueBypassingBindings();
7460 geometryChange(QRectF(v, y, w, h), QRectF(oldx, y, w, h));
7463void QQuickItem::setY(qreal v)
7466 d->y.removeBindingUnlessInWrapper();
7470 const qreal oldy = d->y.valueBypassingBindings();
7474 d->y.setValueBypassingBindings(v);
7476 d->dirty(QQuickItemPrivate::Position);
7480 const qreal x = d->x.valueBypassingBindings();
7481 const qreal w = d->width.valueBypassingBindings();
7482 const qreal h = d->height.valueBypassingBindings();
7483 geometryChange(QRectF(x, v, w, h), QRectF(x, oldy, w, h));
7487
7488
7489void QQuickItem::setPosition(
const QPointF &pos)
7493 const qreal oldx = d->x.valueBypassingBindings();
7494 const qreal oldy = d->y.valueBypassingBindings();
7496 if (QPointF(oldx, oldy) == pos)
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7512 d->x.setValueBypassingBindings(pos.x());
7513 d->y.setValueBypassingBindings(pos.y());
7515 d->dirty(QQuickItemPrivate::Position);
7517 const qreal w = d->width.valueBypassingBindings();
7518 const qreal h = d->height.valueBypassingBindings();
7519 geometryChange(QRectF(pos.x(), pos.y(), w, h), QRectF(oldx, oldy, w, h));
7523
7524
7525QBindable<qreal> QQuickItem::bindableX()
7527 return QBindable<qreal>(&d_func()->x);
7530QBindable<qreal> QQuickItem::bindableY()
7532 return QBindable<qreal>(&d_func()->y);
7536
7537
7538
7539
7540qreal QQuickItem::width()
const
7542 Q_D(
const QQuickItem);
7546void QQuickItem::setWidth(qreal w)
7549 d->width.removeBindingUnlessInWrapper();
7553 d->widthValidFlag =
true;
7554 const qreal oldWidth = d->width.valueBypassingBindings();
7558 d->width.setValueBypassingBindings(w);
7560 d->dirty(QQuickItemPrivate::Size);
7562 const qreal x = d->x.valueBypassingBindings();
7563 const qreal y = d->y.valueBypassingBindings();
7564 const qreal h = d->height.valueBypassingBindings();
7565 geometryChange(QRectF(x, y, w, h), QRectF(x, y, oldWidth, h));
7568void QQuickItem::resetWidth()
7571 d->width.takeBinding();
7572 d->widthValidFlag =
false;
7573 setImplicitWidth(implicitWidth());
7576void QQuickItemPrivate::implicitWidthChanged()
7579 notifyChangeListeners(QQuickItemPrivate::ImplicitWidth, &QQuickItemChangeListener::itemImplicitWidthChanged, q);
7580 emit q->implicitWidthChanged();
7583qreal QQuickItemPrivate::getImplicitWidth()
const
7585 return implicitWidth;
7588
7589
7590qreal QQuickItem::implicitWidth()
const
7592 Q_D(
const QQuickItem);
7593 return d->getImplicitWidth();
7596QBindable<qreal> QQuickItem::bindableWidth()
7598 return QBindable<qreal>(&d_func()->width);
7602
7603
7604
7605
7606
7607
7608
7609
7610
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
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683void QQuickItem::setImplicitWidth(qreal w)
7686 bool changed = w != d->implicitWidth;
7687 d->implicitWidth = w;
7689 if (d->width.valueBypassingBindings() == w || widthValid()) {
7691 d->implicitWidthChanged();
7692 if (d->width.valueBypassingBindings() == w || widthValid())
7697 const qreal oldWidth = d->width.valueBypassingBindings();
7698 Q_ASSERT(!d->width.hasBinding() || QQmlPropertyBinding::isUndefined(d->width.binding()));
7700 d->width.setValueBypassingBindings(w);
7702 d->dirty(QQuickItemPrivate::Size);
7704 const qreal x = d->x.valueBypassingBindings();
7705 const qreal y = d->y.valueBypassingBindings();
7706 const qreal width = w;
7707 const qreal height = d->height.valueBypassingBindings();
7708 geometryChange(QRectF(x, y, width, height), QRectF(x, y, oldWidth, height));
7711 d->implicitWidthChanged();
7715
7716
7717bool QQuickItem::widthValid()
const
7719 Q_D(
const QQuickItem);
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7737 return d->widthValid();
7741
7742
7743
7744
7745qreal QQuickItem::height()
const
7747 Q_D(
const QQuickItem);
7751void QQuickItem::setHeight(qreal h)
7757 d->height.removeBindingUnlessInWrapper();
7761 d->heightValidFlag =
true;
7762 const qreal oldHeight = d->height.valueBypassingBindings();
7766 d->height.setValueBypassingBindings(h);
7768 d->dirty(QQuickItemPrivate::Size);
7770 const qreal x = d->x.valueBypassingBindings();
7771 const qreal y = d->y.valueBypassingBindings();
7772 const qreal w = d->width.valueBypassingBindings();
7773 geometryChange(QRectF(x, y, w, h), QRectF(x, y, w, oldHeight));
7776void QQuickItem::resetHeight()
7782 d->height.takeBinding();
7783 d->heightValidFlag =
false;
7784 setImplicitHeight(implicitHeight());
7787void QQuickItemPrivate::implicitHeightChanged()
7790 notifyChangeListeners(QQuickItemPrivate::ImplicitHeight, &QQuickItemChangeListener::itemImplicitHeightChanged, q);
7791 emit q->implicitHeightChanged();
7794qreal QQuickItemPrivate::getImplicitHeight()
const
7796 return implicitHeight;
7799qreal QQuickItem::implicitHeight()
const
7801 Q_D(
const QQuickItem);
7802 return d->getImplicitHeight();
7805QBindable<qreal> QQuickItem::bindableHeight()
7807 return QBindable<qreal>(&d_func()->height);
7810void QQuickItem::setImplicitHeight(qreal h)
7813 bool changed = h != d->implicitHeight;
7814 d->implicitHeight = h;
7815 if (d->height.valueBypassingBindings() == h || heightValid()) {
7817 d->implicitHeightChanged();
7818 if (d->height.valueBypassingBindings() == h || heightValid())
7823 const qreal oldHeight = d->height.valueBypassingBindings();
7824 Q_ASSERT(!d->height.hasBinding() || QQmlPropertyBinding::isUndefined(d->height.binding()));
7826 d->height.setValueBypassingBindings(h);
7828 d->dirty(QQuickItemPrivate::Size);
7830 const qreal x = d->x.valueBypassingBindings();
7831 const qreal y = d->y.valueBypassingBindings();
7832 const qreal width = d->width.valueBypassingBindings();
7833 const qreal height = d->height.valueBypassingBindings();
7834 geometryChange(QRectF(x, y, width, height),
7835 QRectF(x, y, width, oldHeight));
7838 d->implicitHeightChanged();
7842
7843
7844void QQuickItem::setImplicitSize(qreal w, qreal h)
7847 bool wChanged = w != d->implicitWidth;
7848 bool hChanged = h != d->implicitHeight;
7850 d->implicitWidth = w;
7851 d->implicitHeight = h;
7855 qreal width = d->width.valueBypassingBindings();
7856 qreal height = d->height.valueBypassingBindings();
7857 if (width == w || widthValid()) {
7859 d->implicitWidthChanged();
7860 wDone = width == w || widthValid();
7863 if (height == h || heightValid()) {
7865 d->implicitHeightChanged();
7866 hDone = height == h || heightValid();
7872 const qreal oldWidth = width;
7873 const qreal oldHeight = height;
7876 d->width.setValueBypassingBindings(w);
7880 d->height.setValueBypassingBindings(h);
7883 d->dirty(QQuickItemPrivate::Size);
7885 const qreal x = d->x.valueBypassingBindings();
7886 const qreal y = d->y.valueBypassingBindings();
7887 geometryChange(QRectF(x, y, width, height),
7888 QRectF(x, y, oldWidth, oldHeight));
7890 if (!wDone && wChanged)
7891 d->implicitWidthChanged();
7892 if (!hDone && hChanged)
7893 d->implicitHeightChanged();
7897
7898
7899bool QQuickItem::heightValid()
const
7901 Q_D(
const QQuickItem);
7902 return d->heightValid();
7906
7907
7908
7909
7910
7911
7913QSizeF QQuickItem::size()
const
7915 Q_D(
const QQuickItem);
7916 return QSizeF(d->width, d->height);
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930void QQuickItem::setSize(
const QSizeF &size)
7933 d->heightValidFlag =
true;
7934 d->widthValidFlag =
true;
7936 const qreal oldHeight = d->height.valueBypassingBindings();
7937 const qreal oldWidth = d->width.valueBypassingBindings();
7939 if (oldWidth == size.width() && oldHeight == size.height())
7942 d->height.setValueBypassingBindings(size.height());
7943 d->width.setValueBypassingBindings(size.width());
7945 d->dirty(QQuickItemPrivate::Size);
7947 const qreal x = d->x.valueBypassingBindings();
7948 const qreal y = d->y.valueBypassingBindings();
7949 geometryChange(QRectF(x, y, size.width(), size.height()), QRectF(x, y, oldWidth, oldHeight));
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021bool QQuickItem::hasActiveFocus()
const
8023 Q_D(
const QQuickItem);
8024 return d->activeFocus;
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115bool QQuickItem::hasFocus()
const
8117 Q_D(
const QQuickItem);
8121void QQuickItem::setFocus(
bool focus)
8123 setFocus(focus, Qt::OtherFocusReason);
8126void QQuickItem::setFocus(
bool focus, Qt::FocusReason reason)
8130 QQuickItem *scope = parentItem();
8131 while (scope && !scope->isFocusScope() && scope->parentItem())
8132 scope = scope->parentItem();
8134 if (d->focus == focus && (!focus || !scope || QQuickItemPrivate::get(scope)->subFocusItem ==
this))
8137 bool notifyListeners =
false;
8138 if (d->window || d->parentItem) {
8140 auto da = d->deliveryAgentPrivate();
8143 da->setFocusInScope(scope,
this, reason);
8145 da->clearFocusInScope(scope,
this, reason);
8149 QVarLengthArray<QQuickItem *, 20> changed;
8150 QQuickItem *oldSubFocusItem = QQuickItemPrivate::get(scope)->subFocusItem;
8151 if (oldSubFocusItem) {
8152 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(scope,
false);
8153 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8154 changed << oldSubFocusItem;
8155 }
else if (!scope->isFocusScope() && scope->hasFocus()) {
8156 QQuickItemPrivate::get(scope)->focus =
false;
8159 d->updateSubFocusItem(scope, focus);
8163 notifyListeners =
true;
8164 emit focusChanged(focus);
8166 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8169 QVarLengthArray<QQuickItem *, 20> changed;
8170 QQuickItem *oldSubFocusItem = d->subFocusItem;
8171 if (!isFocusScope() && oldSubFocusItem) {
8172 QQuickItemPrivate::get(oldSubFocusItem)->updateSubFocusItem(
this,
false);
8173 QQuickItemPrivate::get(oldSubFocusItem)->focus =
false;
8174 changed << oldSubFocusItem;
8179 notifyListeners =
true;
8180 emit focusChanged(focus);
8182 QQuickDeliveryAgentPrivate::notifyFocusChangesRecur(changed.data(), changed.size() - 1, reason);
8184 if (notifyListeners)
8185 d->notifyChangeListeners(QQuickItemPrivate::Focus, &QQuickItemChangeListener::itemFocusChanged,
this, reason);
8189
8190
8191bool QQuickItem::isFocusScope()
const
8193 return flags() & ItemIsFocusScope;
8197
8198
8199
8200
8201
8202QQuickItem *QQuickItem::scopedFocusItem()
const
8204 Q_D(
const QQuickItem);
8205 if (!isFocusScope())
8208 return d->subFocusItem;
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8226
8227
8228
8229
8230
8231
8232Qt::FocusPolicy QQuickItem::focusPolicy()
const
8234 Q_D(
const QQuickItem);
8235 uint policy = d->focusPolicy;
8236 if (activeFocusOnTab())
8237 policy |= Qt::TabFocus;
8238 return static_cast<Qt::FocusPolicy>(policy);
8242
8243
8244
8245
8246void QQuickItem::setFocusPolicy(Qt::FocusPolicy policy)
8249 if (d->focusPolicy == policy)
8252 d->focusPolicy = policy;
8253 setActiveFocusOnTab(policy & Qt::TabFocus);
8254 emit focusPolicyChanged(policy);
8258
8259
8260
8261
8262
8263
8264
8265bool QQuickItem::isAncestorOf(
const QQuickItem *child)
const
8267 if (!child || child ==
this)
8269 const QQuickItem *ancestor = child;
8270 while ((ancestor = ancestor->parentItem())) {
8271 if (ancestor ==
this)
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288Qt::MouseButtons QQuickItem::acceptedMouseButtons()
const
8290 Q_D(
const QQuickItem);
8291 return d->acceptedMouseButtons();
8295
8296
8297
8298
8299
8300
8301
8302
8303void QQuickItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
8306 d->extra.setTag(d->extra.tag().setFlag(QQuickItemPrivate::LeftMouseButtonAccepted, buttons & Qt::LeftButton));
8308 buttons &= ~Qt::LeftButton;
8309 if (buttons || d->extra.isAllocated()) {
8310 d->extra.value().acceptedMouseButtonsWithoutHandlers = buttons;
8311 d->extra.value().acceptedMouseButtons = d->extra->pointerHandlers.isEmpty() ? buttons : Qt::AllButtons;
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326bool QQuickItem::filtersChildMouseEvents()
const
8328 Q_D(
const QQuickItem);
8329 return d->filtersChildMouseEvents;
8333
8334
8335
8336
8337
8338
8339
8340
8341void QQuickItem::setFiltersChildMouseEvents(
bool filter)
8344 d->filtersChildMouseEvents = filter;
8348
8349
8350bool QQuickItem::isUnderMouse()
const
8352 Q_D(
const QQuickItem);
8359 if (
const_cast<QQuickItemPrivate *>(d)->deliveryAgentPrivate()->lastMousePosition == QPointF())
8362 QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
8363 return contains(mapFromScene(d->window->mapFromGlobal(cursorPos)));
8367
8368
8369
8370
8371
8372
8373
8374bool QQuickItem::acceptHoverEvents()
const
8376 Q_D(
const QQuickItem);
8377 return d->hoverEnabled;
8381
8382
8383
8384
8385
8386void QQuickItem::setAcceptHoverEvents(
bool enabled)
8393 d->hoverEnabled = enabled;
8399 d->setHasHoverInChild(enabled);
8403 d->dirty(QQuickItemPrivate::Content);
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416bool QQuickItem::acceptTouchEvents()
const
8418 Q_D(
const QQuickItem);
8419 return d->touchEnabled;
8423
8424
8425
8426
8427
8428
8429
8430void QQuickItem::setAcceptTouchEvents(
bool enabled)
8433 d->touchEnabled = enabled;
8436void QQuickItemPrivate::setHasCursorInChild(
bool hc)
8438#if QT_CONFIG(cursor)
8443 if (!hc && subtreeCursorEnabled) {
8446 for (QQuickItem *otherChild : std::as_const(childItems)) {
8447 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8448 if (otherChildPrivate->subtreeCursorEnabled || otherChildPrivate->hasCursor)
8453 subtreeCursorEnabled = hc;
8454 QQuickItem *parent = q->parentItem();
8456 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8457 parentPrivate->setHasCursorInChild(hc);
8464void QQuickItemPrivate::setHasHoverInChild(
bool hasHover)
8470 if (!hasHover && subtreeHoverEnabled) {
8473 if (hasEnabledHoverHandlers())
8476 for (QQuickItem *otherChild : std::as_const(childItems)) {
8477 QQuickItemPrivate *otherChildPrivate = QQuickItemPrivate::get(otherChild);
8478 if (otherChildPrivate->subtreeHoverEnabled || otherChildPrivate->hoverEnabled)
8480 if (otherChildPrivate->hasEnabledHoverHandlers())
8485 qCDebug(lcHoverTrace) << q << subtreeHoverEnabled <<
"->" << hasHover;
8486 subtreeHoverEnabled = hasHover;
8487 QQuickItem *parent = q->parentItem();
8489 QQuickItemPrivate *parentPrivate = QQuickItemPrivate::get(parent);
8490 parentPrivate->setHasHoverInChild(hasHover);
8494#if QT_CONFIG(cursor)
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8510QCursor QQuickItem::cursor()
const
8512 Q_D(
const QQuickItem);
8513 return d->extra.isAllocated()
8519
8520
8521
8522
8524void QQuickItem::setCursor(
const QCursor &cursor)
8528 Qt::CursorShape oldShape = d->extra.isAllocated() ? d->extra->cursor.shape() : Qt::ArrowCursor;
8529 qCDebug(lcHoverTrace) << oldShape <<
"->" << cursor.shape();
8531 if (oldShape != cursor.shape() || oldShape >= Qt::LastCursor || cursor.shape() >= Qt::LastCursor) {
8532 d->extra.value().cursor = cursor;
8534 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8535 QWindow *window = renderWindow ? renderWindow : d->window;
8536 if (QQuickWindowPrivate::get(d->window)->cursorItem ==
this)
8537 window->setCursor(cursor);
8541 QPointF updateCursorPos;
8542 if (!d->hasCursor) {
8543 d->hasCursor =
true;
8545 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window);
8546 QWindow *window = renderWindow ? renderWindow : d->window;
8547 QPointF pos = window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8548 if (contains(mapFromScene(pos)))
8549 updateCursorPos = pos;
8552 d->setHasCursorInChild(d->hasCursor || d->hasCursorHandler);
8553 if (!updateCursorPos.isNull())
8554 QQuickWindowPrivate::get(d->window)->updateCursor(updateCursorPos);
8558
8559
8560
8561
8563void QQuickItem::unsetCursor()
8566 qCDebug(lcHoverTrace) <<
"clearing cursor";
8569 d->hasCursor =
false;
8570 d->setHasCursorInChild(d->hasCursorHandler);
8571 if (d->extra.isAllocated())
8572 d->extra->cursor = QCursor();
8575 QQuickWindowPrivate *windowPrivate = QQuickWindowPrivate::get(d->window);
8576 if (windowPrivate->cursorItem ==
this) {
8577 QPointF pos = d->window->mapFromGlobal(QGuiApplicationPrivate::lastCursorPosition);
8578 windowPrivate->updateCursor(pos);
8584
8585
8586
8587
8588
8589
8590QCursor QQuickItemPrivate::effectiveCursor(
const QQuickPointerHandler *handler)
const
8592 Q_Q(
const QQuickItem);
8595 bool hoverCursorSet =
false;
8596 QCursor hoverCursor;
8597 bool activeCursorSet =
false;
8598 QCursor activeCursor;
8599 if (
const QQuickHoverHandler *hoverHandler = qobject_cast<
const QQuickHoverHandler *>(handler)) {
8600 hoverCursorSet = hoverHandler->isCursorShapeExplicitlySet();
8601 hoverCursor = hoverHandler->cursorShape();
8602 }
else if (handler->active()) {
8603 activeCursorSet = handler->isCursorShapeExplicitlySet();
8604 activeCursor = handler->cursorShape();
8606 if (activeCursorSet)
8607 return activeCursor;
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633QQuickPointerHandler *QQuickItemPrivate::effectiveCursorHandler()
const
8635 if (!hasPointerHandlers())
8637 QQuickPointerHandler* activeHandler =
nullptr;
8638 QQuickPointerHandler* mouseHandler =
nullptr;
8639 QQuickPointerHandler* nonMouseHandler =
nullptr;
8640 for (QQuickPointerHandler *h : extra->pointerHandlers) {
8641 if (!h->isCursorShapeExplicitlySet())
8643 QQuickHoverHandler *hoverHandler = qmlobject_cast<QQuickHoverHandler *>(h);
8648 if (!activeHandler && hoverHandler && hoverHandler->isHovered()) {
8649 qCDebug(lcHoverTrace) << hoverHandler << hoverHandler->acceptedDevices() <<
"wants to set cursor" << hoverHandler->cursorShape();
8650 if (hoverHandler->acceptedDevices().testFlag(QPointingDevice::DeviceType::Mouse)) {
8652 if (mouseHandler && mouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8653 qCDebug(lcHoverTrace) <<
"mouse cursor conflict:" << mouseHandler <<
"wants" << mouseHandler->cursorShape()
8654 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8656 mouseHandler = hoverHandler;
8659 if (nonMouseHandler && nonMouseHandler->cursorShape() != hoverHandler->cursorShape()) {
8660 qCDebug(lcHoverTrace) <<
"non-mouse cursor conflict:" << nonMouseHandler <<
"wants" << nonMouseHandler->cursorShape()
8661 <<
"but" << hoverHandler <<
"wants" << hoverHandler->cursorShape();
8663 nonMouseHandler = hoverHandler;
8666 if (!hoverHandler && h->active())
8669 if (activeHandler) {
8670 qCDebug(lcHoverTrace) <<
"active handler choosing cursor" << activeHandler << activeHandler->cursorShape();
8671 return activeHandler;
8677 if (nonMouseHandler) {
8679 const bool beforeTimeout =
8680 QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime <
8681 QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime + kCursorOverrideTimeout;
8682 QQuickPointerHandler *winner = (beforeTimeout ? nonMouseHandler : mouseHandler);
8683 qCDebug(lcHoverTrace) <<
"non-mouse handler reacted last time:" << QQuickPointerHandlerPrivate::get(nonMouseHandler)->lastEventTime
8684 <<
"and mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime
8685 <<
"choosing cursor according to" << winner << winner->cursorShape();
8688 qCDebug(lcHoverTrace) <<
"non-mouse handler choosing cursor" << nonMouseHandler << nonMouseHandler->cursorShape();
8689 return nonMouseHandler;
8692 qCDebug(lcHoverTrace) <<
"mouse handler choosing cursor" << mouseHandler << mouseHandler->cursorShape();
8693 return mouseHandler;
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712void QQuickItem::grabMouse()
8717 auto da = d->deliveryAgentPrivate();
8719 auto eventInDelivery = da->eventInDelivery();
8720 if (!eventInDelivery) {
8721 qWarning() <<
"cannot grab mouse: no event is currently being delivered";
8724 auto epd = da->mousePointData();
8725 eventInDelivery->setExclusiveGrabber(epd->eventPoint,
this);
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739void QQuickItem::ungrabMouse()
8744 auto da = d->deliveryAgentPrivate();
8746 auto eventInDelivery = da->eventInDelivery();
8747 if (!eventInDelivery) {
8749 da->removeGrabber(
this);
8752 const auto &eventPoint = da->mousePointData()->eventPoint;
8753 if (eventInDelivery->exclusiveGrabber(eventPoint) ==
this)
8754 eventInDelivery->setExclusiveGrabber(eventPoint,
nullptr);
8758
8759
8760
8761
8762bool QQuickItem::keepMouseGrab()
const
8764 Q_D(
const QQuickItem);
8765 return d->keepMouse;
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784void QQuickItem::setKeepMouseGrab(
bool keep)
8787 d->keepMouse = keep;
8791
8792
8793
8794
8795
8796
8797
8798
8799void QQuickItem::grabTouchPoints(
const QList<
int> &ids)
8802 auto event = d->deliveryAgentPrivate()->eventInDelivery();
8803 if (Q_UNLIKELY(!event)) {
8804 qWarning() <<
"cannot grab: no event is currently being delivered";
8807 for (
auto pt : event->points()) {
8808 if (ids.contains(pt.id()))
8809 event->setExclusiveGrabber(pt,
this);
8814
8815
8816
8817void QQuickItem::ungrabTouchPoints()
8822 if (QQuickDeliveryAgentPrivate *da = d->deliveryAgentPrivate())
8823 da->removeGrabber(
this,
false,
true);
8827
8828
8829
8830
8831
8832bool QQuickItem::keepTouchGrab()
const
8834 Q_D(
const QQuickItem);
8835 return d->keepTouch;
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855void QQuickItem::setKeepTouchGrab(
bool keep)
8858 d->keepTouch = keep;
8862
8863
8864
8865
8866
8867
8868
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880bool QQuickItem::contains(
const QPointF &point)
const
8882 Q_D(
const QQuickItem);
8883 if (d->extra.isAllocated() && d->extra->mask) {
8884 if (
auto quickMask = qobject_cast<QQuickItem *>(d->extra->mask))
8885 return quickMask->contains(point - quickMask->position());
8888 QMetaMethod maskContains = d->extra->mask->metaObject()->method(d->extra->maskContainsIndex);
8889 maskContains.invoke(d->extra->mask,
8890 Qt::DirectConnection,
8891 Q_RETURN_ARG(
bool, res),
8892 Q_ARG(QPointF, point));
8896 qreal x = point.x();
8897 qreal y = point.y();
8898 return x >= 0 && y >= 0 && x < d->width && y < d->height;
8902
8903
8904
8905
8906
8907
8908
8909
8910
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
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964QObject *QQuickItem::containmentMask()
const
8966 Q_D(
const QQuickItem);
8967 if (!d->extra.isAllocated())
8969 return d->extra->mask.data();
8972void QQuickItem::setContainmentMask(QObject *mask)
8975 const bool extraDataExists = d->extra.isAllocated();
8977 if (mask ==
static_cast<QObject *>(
this))
8980 if (!extraDataExists && !mask)
8983 if (extraDataExists && d->extra->mask == mask)
8986 QQuickItem *quickMask = d->extra.isAllocated() ? qobject_cast<QQuickItem *>(d->extra->mask)
8989 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
8990 maskPrivate->registerAsContainmentMask(
this,
false);
8993 if (!extraDataExists)
8996 int methodIndex = mask->metaObject()->indexOfMethod(QByteArrayLiteral(
"contains(QPointF)"));
8997 if (methodIndex < 0) {
8998 qmlWarning(
this) << QStringLiteral(
"QQuickItem: Object set as mask does not have an invokable contains method, ignoring it.");
9001 d->extra->maskContainsIndex = methodIndex;
9003 d->extra->mask = mask;
9004 quickMask = qobject_cast<QQuickItem *>(mask);
9006 QQuickItemPrivate *maskPrivate = QQuickItemPrivate::get(quickMask);
9007 maskPrivate->registerAsContainmentMask(
this,
true);
9009 emit containmentMaskChanged();
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024QPointF QQuickItem::mapToItem(
const QQuickItem *item,
const QPointF &point)
const
9026 QPointF p = mapToScene(point);
9028 const auto *itemWindow = item->window();
9029 const auto *thisWindow = window();
9030 if (thisWindow && itemWindow && itemWindow != thisWindow)
9031 p = itemWindow->mapFromGlobal(thisWindow->mapToGlobal(p));
9033 p = item->mapFromScene(p);
9039
9040
9041
9042
9043
9044
9045
9046
9047QPointF QQuickItem::mapToScene(
const QPointF &point)
const
9049 Q_D(
const QQuickItem);
9050 return d->itemToWindowTransform().map(point);
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070QPointF QQuickItem::mapToGlobal(
const QPointF &point)
const
9072 Q_D(
const QQuickItem);
9074 if (Q_UNLIKELY(d->window ==
nullptr))
9075 return mapToScene(point);
9077 QPoint renderOffset;
9078 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9079 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9080 return effectiveWindow->mapToGlobal((mapToScene(point) + renderOffset));
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095QRectF QQuickItem::mapRectToItem(
const QQuickItem *item,
const QRectF &rect)
const
9097 Q_D(
const QQuickItem);
9098 QTransform t = d->itemToWindowTransform();
9100 t *= QQuickItemPrivate::get(item)->windowToItemTransform();
9101 return t.mapRect(rect);
9105
9106
9107
9108
9109
9110
9111
9112
9113QRectF QQuickItem::mapRectToScene(
const QRectF &rect)
const
9115 Q_D(
const QQuickItem);
9116 return d->itemToWindowTransform().mapRect(rect);
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131QPointF QQuickItem::mapFromItem(
const QQuickItem *item,
const QPointF &point)
const
9135 p = item->mapToScene(point);
9136 const auto *itemWindow = item->window();
9137 const auto *thisWindow = window();
9138 if (thisWindow && itemWindow && itemWindow != thisWindow)
9139 p = thisWindow->mapFromGlobal(itemWindow->mapToGlobal(p));
9141 return mapFromScene(p);
9145
9146
9147
9148
9149
9150
9151
9152
9153QPointF QQuickItem::mapFromScene(
const QPointF &point)
const
9155 Q_D(
const QQuickItem);
9156 return d->windowToItemTransform().map(point);
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182QPointF QQuickItem::mapFromGlobal(
const QPointF &point)
const
9184 Q_D(
const QQuickItem);
9187 if (Q_LIKELY(d->window)) {
9188 QPoint renderOffset;
9189 QWindow *renderWindow = QQuickRenderControl::renderWindowFor(d->window, &renderOffset);
9190 QWindow *effectiveWindow = renderWindow ? renderWindow : d->window;
9191 scenePoint = effectiveWindow->mapFromGlobal(point) - renderOffset;
9196 if (
auto da = QQuickDeliveryAgentPrivate::currentOrItemDeliveryAgent(
this)) {
9197 if (
auto sceneTransform = da->sceneTransform())
9198 scenePoint = sceneTransform->map(scenePoint);
9200 return mapFromScene(scenePoint);
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215QRectF QQuickItem::mapRectFromItem(
const QQuickItem *item,
const QRectF &rect)
const
9217 Q_D(
const QQuickItem);
9218 QTransform t = item?QQuickItemPrivate::get(item)->itemToWindowTransform():QTransform();
9219 t *= d->windowToItemTransform();
9220 return t.mapRect(rect);
9224
9225
9226
9227
9228
9229
9230
9231
9232QRectF QQuickItem::mapRectFromScene(
const QRectF &rect)
const
9234 Q_D(
const QQuickItem);
9235 return d->windowToItemTransform().mapRect(rect);
9239
9240
9241
9244
9245
9246
9249
9250
9251
9254
9255
9256
9259
9260
9261
9264
9265
9266
9269
9270
9271
9274
9275
9276
9279
9280
9281
9284
9285
9286
9289
9290
9291bool QQuickItem::event(QEvent *ev)
9295 switch (ev->type()) {
9297 case QEvent::InputMethodQuery: {
9298 QInputMethodQueryEvent *query =
static_cast<QInputMethodQueryEvent *>(ev);
9299 Qt::InputMethodQueries queries = query->queries();
9300 for (uint i = 0; i < 32; ++i) {
9301 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(
int)(queries & (1<<i));
9303 QVariant v = inputMethodQuery(q);
9304 query->setValue(q, v);
9310 case QEvent::InputMethod:
9311 inputMethodEvent(
static_cast<QInputMethodEvent *>(ev));
9314 case QEvent::TouchBegin:
9315 case QEvent::TouchUpdate:
9316 case QEvent::TouchEnd:
9317 case QEvent::TouchCancel:
9318 case QEvent::MouseButtonPress:
9319 case QEvent::MouseButtonRelease:
9320 case QEvent::MouseButtonDblClick:
9321#if QT_CONFIG(wheelevent)
9324 d->deliverPointerEvent(ev);
9326 case QEvent::StyleAnimationUpdate:
9332 case QEvent::HoverEnter:
9333 hoverEnterEvent(
static_cast<QHoverEvent*>(ev));
9335 case QEvent::HoverLeave:
9336 hoverLeaveEvent(
static_cast<QHoverEvent*>(ev));
9338 case QEvent::HoverMove:
9339 hoverMoveEvent(
static_cast<QHoverEvent*>(ev));
9341 case QEvent::KeyPress:
9342 case QEvent::KeyRelease:
9343 d->deliverKeyEvent(
static_cast<QKeyEvent*>(ev));
9345 case QEvent::ShortcutOverride:
9346 d->deliverShortcutOverrideEvent(
static_cast<QKeyEvent*>(ev));
9348 case QEvent::FocusIn:
9349 focusInEvent(
static_cast<QFocusEvent*>(ev));
9351 case QEvent::FocusOut:
9352 focusOutEvent(
static_cast<QFocusEvent*>(ev));
9354 case QEvent::MouseMove:
9355 mouseMoveEvent(
static_cast<QMouseEvent*>(ev));
9357#if QT_CONFIG(quick_draganddrop)
9358 case QEvent::DragEnter:
9359 dragEnterEvent(
static_cast<QDragEnterEvent*>(ev));
9361 case QEvent::DragLeave:
9362 dragLeaveEvent(
static_cast<QDragLeaveEvent*>(ev));
9364 case QEvent::DragMove:
9365 dragMoveEvent(
static_cast<QDragMoveEvent*>(ev));
9368 dropEvent(
static_cast<QDropEvent*>(ev));
9371#if QT_CONFIG(gestures)
9372 case QEvent::NativeGesture:
9376 case QEvent::LanguageChange:
9377 case QEvent::LocaleChange:
9378 for (QQuickItem *item : std::as_const(d->childItems))
9379 QCoreApplication::sendEvent(item, ev);
9381 case QEvent::WindowActivate:
9382 case QEvent::WindowDeactivate:
9383 if (d->providesPalette())
9384 d->setCurrentColorGroup();
9385 for (QQuickItem *item : std::as_const(d->childItems))
9386 QCoreApplication::sendEvent(item, ev);
9388 case QEvent::ApplicationPaletteChange:
9389 for (QQuickItem *item : std::as_const(d->childItems))
9390 QCoreApplication::sendEvent(item, ev);
9392 case QEvent::ContextMenu:
9394 d->handleContextMenuEvent(
static_cast<QContextMenuEvent*>(ev));
9397 return QObject::event(ev);
9403#ifndef QT_NO_DEBUG_STREAM
9405#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
9410 QDebugStateSaver saver(debug);
9413 debug <<
"QQuickItem(nullptr)";
9417 const QRectF rect(item->position(), QSizeF(item->width(), item->height()));
9419 debug << item->metaObject()->className() <<
'(' <<
static_cast<
void *>(item);
9423 if (item->isComponentComplete() && !QQmlData::wasDeleted(item)) {
9424 if (QQmlContext *context = qmlContext(item)) {
9425 const auto objectId = context->nameForObject(item);
9426 if (!objectId.isEmpty())
9427 debug <<
", id=" << objectId;
9430 if (!item->objectName().isEmpty())
9431 debug <<
", name=" << item->objectName();
9432 debug <<
", parent=" <<
static_cast<
void *>(item->parentItem())
9434 QtDebugUtils::formatQRect(debug, rect);
9435 if (
const qreal z = item->z())
9436 debug <<
", z=" << z;
9437 if (item->flags().testFlag(QQuickItem::ItemIsViewport))
9438 debug <<
" \U0001f5bc";
9439 if (item->flags().testFlag(QQuickItem::ItemObservesViewport))
9447
9448
9449
9450
9451
9452
9453
9455bool QQuickItem::isTextureProvider()
const
9457#if QT_CONFIG(quick_shadereffect)
9458 Q_D(
const QQuickItem);
9459 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9460 d->extra->layer->effectSource()->isTextureProvider() :
false;
9467
9468
9469
9470
9471
9472
9473
9475QSGTextureProvider *QQuickItem::textureProvider()
const
9477#if QT_CONFIG(quick_shadereffect)
9478 Q_D(
const QQuickItem);
9479 return d->extra.isAllocated() && d->extra->layer && d->extra->layer->effectSource() ?
9480 d->extra->layer->effectSource()->textureProvider() :
nullptr;
9487
9488
9489
9490
9491
9492
9493
9494
9495
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
9528#if QT_CONFIG(quick_shadereffect)
9530
9531
9532
9533QQuickItemLayer *QQuickItemPrivate::layer()
const
9535 if (!extra.isAllocated() || !extra->layer) {
9536 extra.value().layer =
new QQuickItemLayer(
const_cast<QQuickItem *>(q_func()));
9537 if (!componentComplete)
9538 extra->layer->classBegin();
9540 return extra->layer;
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561void QQuickItemPrivate::localizedTouchEvent(
const QTouchEvent *event,
bool isFiltering, QMutableTouchEvent *localized)
9564 QList<QEventPoint> touchPoints;
9565 QEventPoint::States eventStates;
9567 bool anyPressOrReleaseInside =
false;
9568 bool anyGrabber =
false;
9569 for (
auto &p : event->points()) {
9574 auto pointGrabber = event->exclusiveGrabber(p);
9575 bool isGrabber = (pointGrabber == q);
9576 if (!isGrabber && pointGrabber && isFiltering) {
9577 auto handlerGrabber = qmlobject_cast<QQuickPointerHandler *>(pointGrabber);
9578 if (handlerGrabber && handlerGrabber->parentItem() == q)
9585 const auto localPos = q->mapFromScene(p.scenePosition());
9586 bool isInside = q->contains(localPos);
9587 bool hasAnotherGrabber = pointGrabber && pointGrabber != q;
9589 if (isFiltering && !pointGrabber) {
9590 const auto pg = event->passiveGrabbers(p);
9591 if (!pg.isEmpty()) {
9595 auto handler = qmlobject_cast<QQuickPointerHandler *>(pg.constFirst());
9597 pointGrabber = handler->parentItem();
9602 bool grabberIsChild =
false;
9603 auto parent = qobject_cast<QQuickItem*>(pointGrabber);
9604 while (isFiltering && parent) {
9606 grabberIsChild =
true;
9609 parent = parent->parentItem();
9612 bool filterRelevant = isFiltering && grabberIsChild;
9613 if (!(isGrabber || (isInside && (!hasAnotherGrabber || isFiltering)) || filterRelevant))
9615 if ((p.state() == QEventPoint::State::Pressed || p.state() == QEventPoint::State::Released) && isInside)
9616 anyPressOrReleaseInside =
true;
9617 QEventPoint pCopy(p);
9618 eventStates |= p.state();
9619 if (p.state() == QEventPoint::State::Released)
9620 QMutableEventPoint::detach(pCopy);
9621 QMutableEventPoint::setPosition(pCopy, localPos);
9622 touchPoints.append(std::move(pCopy));
9627 if (touchPoints.isEmpty() || (!anyPressOrReleaseInside && !anyGrabber && !isFiltering)) {
9628 *localized = QMutableTouchEvent(QEvent::None);
9633 QEvent::Type eventType = event->type();
9634 switch (eventStates) {
9635 case QEventPoint::State::Pressed:
9636 eventType = QEvent::TouchBegin;
9638 case QEventPoint::State::Released:
9639 eventType = QEvent::TouchEnd;
9642 eventType = QEvent::TouchUpdate;
9646 QMutableTouchEvent ret(eventType, event->pointingDevice(), event->modifiers(), touchPoints);
9648 ret.setTimestamp(event->timestamp());
9653bool QQuickItemPrivate::hasPointerHandlers()
const
9655 return extra.isAllocated() && !extra->pointerHandlers.isEmpty();
9658bool QQuickItemPrivate::hasEnabledHoverHandlers()
const
9660 if (!hasPointerHandlers())
9662 for (QQuickPointerHandler *h : extra->pointerHandlers)
9663 if (
auto *hh = qmlobject_cast<QQuickHoverHandler *>(h); hh && hh->enabled())
9668void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
9674 extra.value().acceptedMouseButtons = Qt::AllButtons;
9675 auto &handlers = extra.value().pointerHandlers;
9676 if (!handlers.contains(h))
9677 handlers.prepend(h);
9678 auto &res = extra.value().resourcesList;
9679 if (!res.contains(h)) {
9681 QObject::connect(h, &QObject::destroyed, q, [
this](QObject *o) {
9682 _q_resourceObjectDeleted(o);
9687void QQuickItemPrivate::removePointerHandler(QQuickPointerHandler *h)
9691 auto &handlers = extra.value().pointerHandlers;
9692 handlers.removeOne(h);
9693 auto &res = extra.value().resourcesList;
9695 QObject::disconnect(h, &QObject::destroyed, q,
nullptr);
9696 if (handlers.isEmpty())
9697 extra.value().acceptedMouseButtons = extra.value().acceptedMouseButtonsWithoutHandlers;
9701
9702
9703
9704QObject *QQuickItemPrivate::setContextMenu(QObject *menu)
9706 QObject *ret = (extra.isAllocated() ? extra->contextMenu :
nullptr);
9707 extra.value().contextMenu = menu;
9711QtPrivate::QQuickAttachedPropertyPropagator *QQuickItemPrivate::attachedPropertyPropagator_parent(
9712 const QMetaObject *attachedType)
9715 qCDebug(lcAttachedPropertyPropagator).noquote() <<
"- attachedPropertyPropagator_parent called on"
9716 << q <<
"with attachedType" << attachedType->metaType().name();
9718 QQuickItem *parent = q->parentItem();
9719 if (
auto *attached = QtPrivate::QQuickAttachedPropertyPropagator::attachedObject(attachedType, parent)) {
9720 qCDebug(lcAttachedPropertyPropagator).noquote() <<
" - parent item has attached object"
9721 << attached <<
"- returning";
9728#if QT_CONFIG(quick_shadereffect)
9729QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
9735 , m_componentComplete(
true)
9736 , m_wrapMode(QQuickShaderEffectSource::ClampToEdge)
9737 , m_format(QQuickShaderEffectSource::RGBA8)
9739 , m_effectComponent(
nullptr)
9741 , m_effectSource(
nullptr)
9742 , m_textureMirroring(QQuickShaderEffectSource::MirrorVertically)
9747QQuickItemLayer::~QQuickItemLayer()
9749 delete m_effectSource;
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767void QQuickItemLayer::setEnabled(
bool e)
9772 if (m_componentComplete) {
9779 emit enabledChanged(e);
9782void QQuickItemLayer::classBegin()
9784 Q_ASSERT(!m_effectSource);
9785 Q_ASSERT(!m_effect);
9786 m_componentComplete =
false;
9789void QQuickItemLayer::componentComplete()
9791 Q_ASSERT(!m_componentComplete);
9792 m_componentComplete =
true;
9797void QQuickItemLayer::activate()
9799 Q_ASSERT(!m_effectSource);
9800 m_effectSource =
new QQuickShaderEffectSource();
9801 QQuickItemPrivate::get(m_effectSource)->setTransparentForPositioner(
true);
9803 QQuickItem *parentItem = m_item->parentItem();
9805 m_effectSource->setParentItem(parentItem);
9806 m_effectSource->stackAfter(m_item);
9809 m_effectSource->setSourceItem(m_item);
9810 m_effectSource->setHideSource(
true);
9811 m_effectSource->setSmooth(m_smooth);
9812 m_effectSource->setLive(m_live);
9813 m_effectSource->setTextureSize(m_size);
9814 m_effectSource->setSourceRect(m_sourceRect);
9815 m_effectSource->setMipmap(m_mipmap);
9816 m_effectSource->setWrapMode(m_wrapMode);
9817 m_effectSource->setFormat(m_format);
9818 m_effectSource->setTextureMirroring(m_textureMirroring);
9819 m_effectSource->setSamples(m_samples);
9821 if (m_effectComponent)
9824 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9831 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9832 id->addItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9835void QQuickItemLayer::deactivate()
9837 Q_ASSERT(m_effectSource);
9839 if (m_effectComponent)
9842 delete m_effectSource;
9843 m_effectSource =
nullptr;
9845 QQuickItemPrivate *id = QQuickItemPrivate::get(m_item);
9846 id->removeItemChangeListener(
this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Opacity | QQuickItemPrivate::Parent | QQuickItemPrivate::Visibility | QQuickItemPrivate::SiblingOrder);
9849void QQuickItemLayer::activateEffect()
9851 Q_ASSERT(m_effectSource);
9852 Q_ASSERT(m_effectComponent);
9853 Q_ASSERT(!m_effect);
9855 QObject *created = m_effectComponent->beginCreate(m_effectComponent->creationContext());
9856 m_effect = qobject_cast<QQuickItem *>(created);
9858 qWarning(
"Item: layer.effect is not a QML Item.");
9859 m_effectComponent->completeCreate();
9863 QQuickItem *parentItem = m_item->parentItem();
9865 m_effect->setParentItem(parentItem);
9866 m_effect->stackAfter(m_effectSource);
9868 m_effect->setVisible(m_item->isVisible());
9869 m_effect->setProperty(m_name, QVariant::fromValue<QObject *>(m_effectSource));
9870 QQuickItemPrivate::get(m_effect)->setTransparentForPositioner(
true);
9871 m_effectComponent->completeCreate();
9874void QQuickItemLayer::deactivateEffect()
9876 Q_ASSERT(m_effectSource);
9877 Q_ASSERT(m_effectComponent);
9885
9886
9887
9888
9889
9890
9891
9892
9893
9895void QQuickItemLayer::setEffect(QQmlComponent *component)
9897 if (component == m_effectComponent)
9900 bool updateNeeded =
false;
9901 if (m_effectSource && m_effectComponent) {
9903 updateNeeded =
true;
9906 m_effectComponent = component;
9908 if (m_effectSource && m_effectComponent) {
9910 updateNeeded =
true;
9918 m_effectSource->setVisible(m_item->isVisible() && !m_effect);
9921 emit effectChanged(component);
9926
9927
9928
9929
9930
9931
9932
9933
9934
9936void QQuickItemLayer::setMipmap(
bool mipmap)
9938 if (mipmap == m_mipmap)
9943 m_effectSource->setMipmap(m_mipmap);
9945 emit mipmapChanged(mipmap);
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9966void QQuickItemLayer::setFormat(QQuickShaderEffectSource::Format f)
9973 m_effectSource->setFormat(m_format);
9975 emit formatChanged(m_format);
9980
9981
9982
9983
9984
9985
9986
9987
9988
9990void QQuickItemLayer::setSourceRect(
const QRectF &sourceRect)
9992 if (sourceRect == m_sourceRect)
9994 m_sourceRect = sourceRect;
9997 m_effectSource->setSourceRect(m_sourceRect);
9999 emit sourceRectChanged(sourceRect);
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10014void QQuickItemLayer::setSmooth(
bool s)
10020 if (m_effectSource)
10021 m_effectSource->setSmooth(m_smooth);
10023 emit smoothChanged(s);
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10038void QQuickItemLayer::setLive(
bool live)
10040 if (m_live == live)
10044 if (m_effectSource)
10045 m_effectSource->setLive(m_live);
10047 emit liveChanged(live);
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10063void QQuickItemLayer::setSize(
const QSize &size)
10065 if (size == m_size)
10069 if (m_effectSource)
10070 m_effectSource->setTextureSize(size);
10072 emit sizeChanged(size);
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10093void QQuickItemLayer::setWrapMode(QQuickShaderEffectSource::WrapMode mode)
10095 if (mode == m_wrapMode)
10099 if (m_effectSource)
10100 m_effectSource->setWrapMode(m_wrapMode);
10102 emit wrapModeChanged(mode);
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10120void QQuickItemLayer::setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring)
10122 if (mirroring == m_textureMirroring)
10124 m_textureMirroring = mirroring;
10126 if (m_effectSource)
10127 m_effectSource->setTextureMirroring(m_textureMirroring);
10129 emit textureMirroringChanged(mirroring);
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10157void QQuickItemLayer::setSamples(
int count)
10159 if (m_samples == count)
10164 if (m_effectSource)
10165 m_effectSource->setSamples(m_samples);
10167 emit samplesChanged(count);
10171
10172
10173
10174
10175
10176
10177
10178
10179
10181void QQuickItemLayer::setName(
const QByteArray &name) {
10182 if (m_name == name)
10185 m_effect->setProperty(m_name, QVariant());
10186 m_effect->setProperty(name, QVariant::fromValue<QObject *>(m_effectSource));
10189 emit nameChanged(name);
10192void QQuickItemLayer::itemOpacityChanged(QQuickItem *item)
10198void QQuickItemLayer::itemGeometryChanged(QQuickItem *, QQuickGeometryChange,
const QRectF &)
10203void QQuickItemLayer::itemParentChanged(QQuickItem *item, QQuickItem *parent)
10206 Q_ASSERT(item == m_item);
10207 Q_ASSERT(parent != m_effectSource);
10208 Q_ASSERT(parent ==
nullptr || parent != m_effect);
10210 m_effectSource->setParentItem(parent);
10212 m_effectSource->stackAfter(m_item);
10215 m_effect->setParentItem(parent);
10217 m_effect->stackAfter(m_effectSource);
10221void QQuickItemLayer::itemSiblingOrderChanged(QQuickItem *)
10223 m_effectSource->stackAfter(m_item);
10225 m_effect->stackAfter(m_effectSource);
10228void QQuickItemLayer::itemVisibilityChanged(QQuickItem *)
10230 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10233 l->setVisible(m_item->isVisible());
10236void QQuickItemLayer::updateZ()
10238 if (!m_componentComplete || !m_enabled)
10240 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10243 l->setZ(m_item->z());
10246void QQuickItemLayer::updateOpacity()
10248 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10251 l->setOpacity(m_item->opacity());
10254void QQuickItemLayer::updateGeometry()
10256 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10261 QRectF bounds = m_item->QQuickItem::boundingRect();
10262 l->setSize(bounds.size());
10263 l->setPosition(bounds.topLeft() + m_item->position());
10266void QQuickItemLayer::updateMatrix()
10270 if (!m_componentComplete || !m_enabled)
10272 QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
10275 QQuickItemPrivate *ld = QQuickItemPrivate::get(l);
10276 l->setScale(m_item->scale());
10277 l->setRotation(m_item->rotation());
10278 ld->transforms = QQuickItemPrivate::get(m_item)->transforms;
10279 if (ld->origin() != QQuickItemPrivate::get(m_item)->origin())
10280 ld->extra.value().origin = QQuickItemPrivate::get(m_item)->origin();
10281 ld->dirty(QQuickItemPrivate::Transform);
10285QQuickItemPrivate::ExtraData::ExtraData()
10286: z(0), scale(1), rotation(0), opacity(1), biggestPointerHandlerMarginCache(-1),
10287 contents(
nullptr), screenAttached(
nullptr), layoutDirectionAttached(
nullptr),
10288 enterKeyAttached(
nullptr),
10289 keyHandler(
nullptr), contextMenu(
nullptr),
10290#if QT_CONFIG(quick_shadereffect)
10293 effectRefCount(0), hideRefCount(0),
10294 recursiveEffectRefCount(0),
10295 opacityNode(
nullptr), clipNode(
nullptr), rootNode(
nullptr),
10296 origin(QQuickItem::Center),
10297 transparentForPositioner(
false)
10299#ifdef QT_BUILD_INTERNAL
10300 ++QQuickItemPrivate::itemExtra_counter;
10305#if QT_CONFIG(accessibility)
10306QAccessible::Role QQuickItemPrivate::effectiveAccessibleRole()
const
10308 Q_Q(
const QQuickItem);
10309 auto *attached = qmlAttachedPropertiesObject<QQuickAccessibleAttached>(q,
false);
10310 auto role = QAccessible::NoRole;
10311 if (
auto *accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(attached))
10312 role = accessibleAttached->role();
10313 if (role == QAccessible::NoRole)
10314 role = accessibleRole();
10318QAccessible::Role QQuickItemPrivate::accessibleRole()
const
10320 return QAccessible::NoRole;
10329 static void markObjects(QV4::Heap::Base *that, QV4::MarkStack *markStack);
10342 QObjectWrapper *This =
static_cast<QObjectWrapper *>(that);
10343 if (QQuickItem *item =
static_cast<QQuickItem*>(This->object())) {
10344 for (QQuickItem *child : std::as_const(QQuickItemPrivate::get(item)->childItems))
10345 QV4::QObjectWrapper::markWrapper(child, markStack);
10347 QObjectWrapper::markObjects(that, markStack);
10350quint64 QQuickItemPrivate::_q_createJSWrapper(QQmlV4ExecutionEnginePtr engine)
10352 return (engine->memoryManager->allocate<QQuickItemWrapper>(q_func()))->asReturnedValue();
10357 QDebugStateSaver stateSaver(debug);
10358 debug.nospace() <<
"ChangeListener listener=" << listener.listener <<
" types=" << listener.types;
10363QPointF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y)
10364{
return mapFromItem(item, QPointF(x, y) ); }
10367QRectF QQuickItem::mapFromItem(
const QQuickItem *item,
const QRectF &rect)
const
10368{
return mapRectFromItem(item, rect); }
10371QRectF QQuickItem::mapFromItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10372{
return mapFromItem(item, QRectF(x, y, width, height)); }
10375QPointF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y)
10376{
return mapToItem(item, QPointF(x, y)); }
10379QRectF QQuickItem::mapToItem(
const QQuickItem *item,
const QRectF &rect)
const
10380{
return mapRectToItem(item, rect); }
10383QRectF QQuickItem::mapToItem(
const QQuickItem *item, qreal x, qreal y, qreal width, qreal height)
const
10384{
return mapToItem(item, QRectF(x, y, width, height)); }
10387QPointF QQuickItem::mapToGlobal(qreal x, qreal y)
const
10388{
return mapToGlobal(QPointF(x, y)); }
10391QPointF QQuickItem::mapFromGlobal(qreal x, qreal y)
const
10392{
return mapFromGlobal(QPointF(x, y)); }
10395QQuickItemChangeListener::~QQuickItemChangeListener() =
default;
10399#include <moc_qquickitem.cpp>
10401#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)