6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
255
256
257
258
259
260
263
264
265
266
267
268
271
272
273
274
275
276
279
280
281
282
283
284
287
288
289
290
291
292
295
296
297
298
299
300
303
304
305
306
307
308
311
312
313
314
315
316
319
320
321
322
323
324
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
727
728
729
730
731
732
733
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
767#include <QtCore/qbitarray.h>
768#include <QtCore/qpoint.h>
769#include <QtCore/qstack.h>
770#include <QtCore/qvariant.h>
771#include <QtCore/qvarlengtharray.h>
772#include <QtCore/qnumeric.h>
773#include <QtWidgets/qapplication.h>
774#include <QtGui/qbitmap.h>
775#include <QtGui/qpainter.h>
776#include <QtGui/qpainterpath.h>
777#include <QtGui/qpixmapcache.h>
778#include <QtWidgets/qstyleoption.h>
779#include <QtGui/qevent.h>
780#include <QtGui/qinputmethod.h>
781#if QT_CONFIG(graphicseffect)
782#include <QtWidgets/qgraphicseffect.h>
785#include <private/qgraphicsitem_p.h>
786#include <private/qgraphicswidget_p.h>
787#include <private/qwidgettextcontrol_p.h>
788#include <private/qtextdocumentlayout_p.h>
789#include <private/qtextengine_p.h>
790#include <private/qwidget_p.h>
791#include <private/qapplication_p.h>
792#include <private/qgesturemanager_p.h>
793#include <private/qdebug_p.h>
797QT_IMPL_METATYPE_EXTERN_TAGGED(QGraphicsItem*, QGraphicsItem_ptr)
799static inline void _q_adjustRect(QRect *rect)
803 rect->adjust(0, 0, 1, 0);
805 rect->adjust(0, 0, 0, 1);
809
810
819
820
821
822
823
828 const qreal penWidthZero = qreal(0.00000001);
830 if (path == QPainterPath() || pen == Qt::NoPen)
832 QPainterPathStroker ps;
833 ps.setCapStyle(pen.capStyle());
834 if (pen.widthF() <= 0.0)
835 ps.setWidth(penWidthZero);
837 ps.setWidth(pen.widthF());
838 ps.setJoinStyle(pen.joinStyle());
839 ps.setMiterLimit(pen.miterLimit());
840 QPainterPath p = ps.createStroke(path);
846
847
848QGraphicsItemPrivate::QGraphicsItemPrivate()
853 transformData(
nullptr),
854 graphicsEffect(
nullptr),
859 subFocusItem(
nullptr),
860 focusScopeItem(
nullptr),
861 imHints(Qt::ImhNone),
862 panelModality(QGraphicsItem::NonModal),
863 acceptedMouseButtons(0x1f),
865 explicitlyHidden(
false),
867 explicitlyDisabled(
false),
871 isMemberOfGroup(
false),
872 handlesChildEvents(
false),
873 itemDiscovered(
false),
877 hasBoundingRegionGranularity(
false),
880 dirtyChildren(
false),
881 localCollisionHack(
false),
882 inSetPosHelper(
false),
883 needSortChildren(
false),
884 allChildrenDirty(
false),
885 fullUpdatePending(
false),
887 paintedViewBoundingRectsNeedRepaint(
false),
888 dirtySceneTransform(
true),
889 geometryChanged(
true),
892 ignoreVisible(
false),
893 ignoreOpacity(
false),
894 acceptTouchEvents(
false),
895 acceptedTouchBeginEvent(
false),
896 filtersDescendantEvents(
false),
897 sceneTransformTranslateOnly(
false),
898 notifyBoundingRectChanged(
false),
899 notifyInvalidated(
false),
900 mouseSetsFocus(
true),
901 explicitActivate(
false),
903 holesInSiblingIndex(
false),
904 sequentialOrdering(
true),
905 updateDueToGraphicsEffect(
false),
906 scenePosDescendants(
false),
907 pendingPolish(
false),
908 mayHaveChildWithGraphicsEffect(
false),
909 sendParentChangeNotification(
false),
910 dirtyChildrenBoundingRect(
true),
911 globalStackingOrder(-1),
917
918
919QGraphicsItemPrivate::~QGraphicsItemPrivate()
924
925
926
927
928
929
930void QGraphicsItemPrivate::updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag,
931 AncestorFlag flag,
bool enabled,
bool root)
937 switch (
int(childFlag)) {
939 flag = AncestorFiltersChildEvents;
940 enabled = q->filtersChildEvents();
943 flag = AncestorHandlesChildEvents;
944 enabled = q->handlesChildEvents();
946 case QGraphicsItem::ItemClipsChildrenToShape:
947 flag = AncestorClipsChildren;
948 enabled = flags & QGraphicsItem::ItemClipsChildrenToShape;
950 case QGraphicsItem::ItemIgnoresTransformations:
951 flag = AncestorIgnoresTransformations;
952 enabled = flags & QGraphicsItem::ItemIgnoresTransformations;
954 case QGraphicsItem::ItemContainsChildrenInShape:
955 flag = AncestorContainsChildren;
956 enabled = flags & QGraphicsItem::ItemContainsChildrenInShape;
964 if ((parent->d_ptr->ancestorFlags & flag)
965 || (
int(parent->d_ptr->flags & childFlag) == childFlag)
966 || (
int(childFlag) == -1 && parent->d_ptr->handlesChildEvents)
967 || (
int(childFlag) == -2 && parent->d_ptr->filtersDescendantEvents)) {
969 ancestorFlags |= flag;
971 ancestorFlags &= ~flag;
980 if (((ancestorFlags & flag) && enabled) || (!(ancestorFlags & flag) && !enabled))
985 ancestorFlags |= flag;
987 ancestorFlags &= ~flag;
990 if ((
int(childFlag) != -1 &&
int(flags & childFlag) == childFlag)
991 || (
int(childFlag) == -1 && handlesChildEvents)
992 || (
int(childFlag) == -2 && filtersDescendantEvents))
996 for (
int i = 0; i < children.size(); ++i)
997 children.at(i)->d_ptr->updateAncestorFlag(childFlag, flag, enabled,
false);
1000void QGraphicsItemPrivate::updateAncestorFlags()
1005 QGraphicsItemPrivate *pd = parent->d_ptr.data();
1006 flags = pd->ancestorFlags;
1009 if (pd->filtersDescendantEvents)
1010 flags |= AncestorFiltersChildEvents;
1011 if (pd->handlesChildEvents)
1012 flags |= AncestorHandlesChildEvents;
1013 if (pd->flags & QGraphicsItem::ItemClipsChildrenToShape)
1014 flags |= AncestorClipsChildren;
1015 if (pd->flags & QGraphicsItem::ItemIgnoresTransformations)
1016 flags |= AncestorIgnoresTransformations;
1017 if (pd->flags & QGraphicsItem::ItemContainsChildrenInShape)
1018 flags |= AncestorContainsChildren;
1021 if (ancestorFlags == flags)
1023 ancestorFlags = flags;
1026 for (
int i = 0; i < children.size(); ++i)
1027 children.at(i)->d_ptr->updateAncestorFlags();
1031
1032
1033
1034
1035void QGraphicsItemPrivate::setIsMemberOfGroup(
bool enabled)
1038 isMemberOfGroup = enabled;
1039 if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {
1040 for (QGraphicsItem *child : std::as_const(children))
1041 child->d_func()->setIsMemberOfGroup(enabled);
1046
1047
1048
1049
1050void QGraphicsItemPrivate::remapItemPos(QEvent *event, QGraphicsItem *item)
1053 switch (event->type()) {
1054 case QEvent::GraphicsSceneMouseMove:
1055 case QEvent::GraphicsSceneMousePress:
1056 case QEvent::GraphicsSceneMouseRelease:
1057 case QEvent::GraphicsSceneMouseDoubleClick: {
1058 QGraphicsSceneMouseEvent *mouseEvent =
static_cast<QGraphicsSceneMouseEvent *>(event);
1059 mouseEvent->setPos(item->mapFromItem(q, mouseEvent->pos()));
1060 mouseEvent->setLastPos(item->mapFromItem(q, mouseEvent->pos()));
1061 for (
int i = 0x1; i <= 0x10; i <<= 1) {
1062 if (mouseEvent->buttons() & i) {
1063 Qt::MouseButton button = Qt::MouseButton(i);
1064 mouseEvent->setButtonDownPos(button, item->mapFromItem(q, mouseEvent->buttonDownPos(button)));
1069 case QEvent::GraphicsSceneWheel: {
1070 QGraphicsSceneWheelEvent *wheelEvent =
static_cast<QGraphicsSceneWheelEvent *>(event);
1071 wheelEvent->setPos(item->mapFromItem(q, wheelEvent->pos()));
1074 case QEvent::GraphicsSceneContextMenu: {
1075 QGraphicsSceneContextMenuEvent *contextEvent =
static_cast<QGraphicsSceneContextMenuEvent *>(event);
1076 contextEvent->setPos(item->mapFromItem(q, contextEvent->pos()));
1079 case QEvent::GraphicsSceneHoverMove: {
1080 QGraphicsSceneHoverEvent *hoverEvent =
static_cast<QGraphicsSceneHoverEvent *>(event);
1081 hoverEvent->setPos(item->mapFromItem(q, hoverEvent->pos()));
1090
1091
1092
1093
1094
1095
1097QTransform QGraphicsItemPrivate::genericMapFromSceneTransform(
const QWidget *viewport)
const
1099 Q_Q(
const QGraphicsItem);
1100 if (!itemIsUntransformable())
1101 return sceneTransform.inverted();
1102 const QGraphicsView *view = viewport
1103 ? qobject_cast<QGraphicsView *>(viewport->parentWidget())
1105 if (view ==
nullptr)
1106 return sceneTransform.inverted();
1108 const QTransform viewportTransform = view->viewportTransform();
1109 return viewportTransform * q->deviceTransform(viewportTransform).inverted();
1112QPointF QGraphicsItemPrivate::genericMapFromScene(
const QPointF &pos,
1113 const QWidget *viewport)
const
1115 return genericMapFromSceneTransform(viewport).map(pos);
1119
1120
1121
1122
1123
1124
1125
1126void QGraphicsItemPrivate::combineTransformToParent(QTransform *x,
const QTransform *viewTransform)
const
1129 if (viewTransform && itemIsUntransformable()) {
1130 *x = q_ptr->deviceTransform(*viewTransform);
1133 *x *= transformData->computedFullTransform();
1135 *x *= QTransform::fromTranslate(pos.x(), pos.y());
1140
1141
1142
1143
1144
1145
1146
1147
1148void QGraphicsItemPrivate::combineTransformFromParent(QTransform *x,
const QTransform *viewTransform)
const
1151 if (viewTransform && itemIsUntransformable()) {
1152 *x = q_ptr->deviceTransform(*viewTransform);
1154 x->translate(pos.x(), pos.y());
1156 *x = transformData->computedFullTransform(x);
1160void QGraphicsItemPrivate::updateSceneTransformFromParent()
1163 Q_ASSERT(!parent->d_ptr->dirtySceneTransform);
1164 if (parent->d_ptr->sceneTransformTranslateOnly) {
1165 sceneTransform = QTransform::fromTranslate(parent->d_ptr->sceneTransform.dx() + pos.x(),
1166 parent->d_ptr->sceneTransform.dy() + pos.y());
1168 sceneTransform = parent->d_ptr->sceneTransform;
1169 sceneTransform.translate(pos.x(), pos.y());
1171 if (transformData) {
1172 sceneTransform = transformData->computedFullTransform(&sceneTransform);
1173 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1175 sceneTransformTranslateOnly = parent->d_ptr->sceneTransformTranslateOnly;
1177 }
else if (!transformData) {
1178 sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());
1179 sceneTransformTranslateOnly = 1;
1180 }
else if (transformData->onlyTransform) {
1181 sceneTransform = transformData->transform;
1183 sceneTransform *= QTransform::fromTranslate(pos.x(), pos.y());
1184 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1185 }
else if (pos.isNull()) {
1186 sceneTransform = transformData->computedFullTransform();
1187 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1189 sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());
1190 sceneTransform = transformData->computedFullTransform(&sceneTransform);
1191 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1193 dirtySceneTransform = 0;
1197
1198
1199
1200
1201
1202
1203void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent,
const QVariant *newParentVariant,
1204 const QVariant *thisPointerVariant)
1207 if (newParent == parent)
1211 static_cast<QGraphicsWidgetPrivate *>(
this)->fixFocusChainBeforeReparenting((newParent &&
1212 newParent->isWidget()) ?
static_cast<QGraphicsWidget *>(newParent) :
nullptr,
1216 if (scene->d_func()->indexMethod != QGraphicsScene::NoIndex)
1217 scene->d_func()->index->itemChange(q, QGraphicsItem::ItemParentChange, newParent);
1220 if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges))
1221 scene->d_func()->setScenePosItemEnabled(q,
false);
1224 if (subFocusItem && parent) {
1226 subFocusItem->d_ptr->clearSubFocus(parent);
1233 q_ptr->prepareGeometryChange();
1237 parent->d_ptr->removeChild(q);
1238 if (thisPointerVariant)
1239 parent->itemChange(QGraphicsItem::ItemChildRemovedChange, *thisPointerVariant);
1244 if (scene && !inDestructor) {
1245 if (parent && !newParent) {
1246 scene->d_func()->registerTopLevelItem(q);
1247 }
else if (!parent && newParent) {
1248 scene->d_func()->unregisterTopLevelItem(q);
1254 QGraphicsItem *p = parent;
1255 QGraphicsItem *parentFocusScopeItem =
nullptr;
1257 if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) {
1260 QGraphicsItem *fsi = p->d_ptr->focusScopeItem;
1261 if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {
1262 parentFocusScopeItem = fsi;
1263 p->d_ptr->focusScopeItem =
nullptr;
1264 fsi->d_ptr->focusScopeItemChange(
false);
1268 p = p->d_ptr->parent;
1272 if (newParent && (graphicsEffect || mayHaveChildWithGraphicsEffect))
1273 newParent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();
1276 QGraphicsItem *newFocusScopeItem = subFocusItem ? subFocusItem : parentFocusScopeItem;
1277 if (newFocusScopeItem && newParent) {
1278 QGraphicsItem *p = newParent;
1280 if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) {
1281 if (subFocusItem && subFocusItem != q_ptr) {
1283 QGraphicsItem *ancestorScope =
nullptr;
1284 QGraphicsItem *p2 = subFocusItem->d_ptr->parent;
1285 while (p2 && p2 != p) {
1286 if (p2->d_ptr->flags & QGraphicsItem::ItemIsFocusScope)
1288 if (p2->d_ptr->flags & QGraphicsItem::ItemIsPanel)
1292 p2 = p2->d_ptr->parent;
1295 newFocusScopeItem = ancestorScope;
1298 p->d_ptr->focusScopeItem = newFocusScopeItem;
1299 newFocusScopeItem->d_ptr->focusScopeItemChange(
true);
1303 if (subFocusItem && !p->focusItem())
1304 subFocusItem->d_ptr->clearSubFocus();
1307 p = p->d_ptr->parent;
1312 invalidateDepthRecursively();
1314 if ((parent = newParent)) {
1315 if (parent->d_func()->scene && parent->d_func()->scene != scene) {
1317 parent->d_func()->scene->addItem(q);
1318 }
else if (!parent->d_func()->scene && scene) {
1320 scene->removeItem(q);
1323 parent->d_ptr->addChild(q);
1324 if (thisPointerVariant)
1325 parent->itemChange(QGraphicsItem::ItemChildAddedChange, *thisPointerVariant);
1328 if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges))
1329 scene->d_func()->setScenePosItemEnabled(q,
true);
1333 markParentDirty(
true);
1336 updateAncestorFlags();
1339 if (parent->d_ptr->visible != visible) {
1340 if (!parent->d_ptr->visible || !explicitlyHidden)
1341 setVisibleHelper(parent->d_ptr->visible,
false,
false);
1343 if (parent->isEnabled() != enabled) {
1344 if (!parent->d_ptr->enabled || !explicitlyDisabled)
1345 setEnabledHelper(parent->d_ptr->enabled,
false,
false);
1349 if (visible && parent->isActive())
1353 updateAncestorFlags();
1355 if (!inDestructor) {
1357 if (!visible && !explicitlyHidden)
1358 setVisibleHelper(
true,
false);
1359 if (!enabled && !explicitlyDisabled)
1360 setEnabledHelper(
true,
false);
1364 dirtySceneTransform = 1;
1365 if (!inDestructor && (transformData || (newParent && newParent->d_ptr->transformData)))
1370 subFocusItem->d_ptr->setSubFocus(newParent);
1371 if (parent && parent->isActive())
1372 subFocusItem->setFocus();
1376 if (newParentVariant)
1377 q->itemChange(QGraphicsItem::ItemParentHasChanged, *newParentVariant);
1380 emit
static_cast<QGraphicsObject *>(q)->parentChanged();
1384
1385
1386
1387
1388void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect, QGraphicsItem *topMostEffectItem)
1392 QRectF childrenRect;
1393 QRectF *result = rect;
1394 rect = &childrenRect;
1395 const bool setTopMostEffectItem = !topMostEffectItem;
1397 for (
int i = 0; i < children.size(); ++i) {
1398 QGraphicsItem *child = children.at(i);
1399 QGraphicsItemPrivate *childd = child->d_ptr.data();
1400 if (setTopMostEffectItem)
1401 topMostEffectItem = child;
1402 bool hasPos = !childd->pos.isNull();
1403 if (hasPos || childd->transformData) {
1405 QTransform matrix = childd->transformToParent();
1408 *rect |= matrix.mapRect(child->d_ptr->effectiveBoundingRect(topMostEffectItem));
1409 if (!childd->children.isEmpty())
1410 childd->childrenBoundingRectHelper(&matrix, rect, topMostEffectItem);
1413 *rect |= x->mapRect(child->d_ptr->effectiveBoundingRect(topMostEffectItem));
1415 *rect |= child->d_ptr->effectiveBoundingRect(topMostEffectItem);
1416 if (!childd->children.isEmpty())
1417 childd->childrenBoundingRectHelper(x, rect, topMostEffectItem);
1421 if (flags & QGraphicsItem::ItemClipsChildrenToShape){
1423 *rect &= x->mapRect(q->boundingRect());
1425 *rect &= q->boundingRect();
1431void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option,
const QTransform &worldTransform,
1432 const QRegion &exposedRegion,
bool allItems)
const
1435 Q_Q(
const QGraphicsItem);
1438 const QRectF brect = q->boundingRect();
1439 option->state = QStyle::State_None;
1440 option->rect = brect.toRect();
1441 option->exposedRect = brect;
1446 option->styleObject = q_ptr->toGraphicsObject();
1447 if (!option->styleObject)
1448 option->styleObject = scene;
1451 option->state |= QStyle::State_Selected;
1453 option->state |= QStyle::State_Enabled;
1455 option->state |= QStyle::State_HasFocus;
1457 if (scene->d_func()->hoverItems.contains(q_ptr))
1458 option->state |= QStyle::State_MouseOver;
1459 if (q == scene->mouseGrabberItem())
1460 option->state |= QStyle::State_Sunken;
1463 if (!(flags & QGraphicsItem::ItemUsesExtendedStyleOption))
1468 option->exposedRect = QRectF();
1469 const QTransform reverseMap = worldTransform.inverted();
1470 for (
const QRect &exposedRect : exposedRegion) {
1471 option->exposedRect |= reverseMap.mapRect(QRectF(exposedRect));
1472 if (option->exposedRect.contains(brect))
1475 option->exposedRect &= brect;
1480
1481
1482
1483
1486 QPixmapCache::remove(key);
1487 key = QPixmapCache::Key();
1488 const auto &constDeviceData = deviceData;
1489 for (
const auto &data : constDeviceData)
1490 QPixmapCache::remove(data.key);
1497
1498
1499
1500
1501
1502
1503
1504
1505QGraphicsItem::QGraphicsItem(QGraphicsItem *parent)
1506 : d_ptr(
new QGraphicsItemPrivate)
1508 d_ptr->q_ptr =
this;
1509 setParentItem(parent);
1513
1514
1515QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent)
1518 d_ptr->q_ptr =
this;
1519 setParentItem(parent);
1523
1524
1525
1526
1527
1528
1529
1530QGraphicsItem::~QGraphicsItem()
1532 if (d_ptr->isObject) {
1533 QGraphicsObject *o =
static_cast<QGraphicsObject *>(
this);
1534 QObjectPrivate *p = QObjectPrivate::get(o);
1535 p->wasDeleted =
true;
1536 if (p->declarativeData) {
1537 p->wasDeleted =
true;
1538 if (QAbstractDeclarativeData::destroyed)
1539 QAbstractDeclarativeData::destroyed(p->declarativeData, o);
1540 p->declarativeData =
nullptr;
1541 p->wasDeleted =
false;
1545 d_ptr->inDestructor = 1;
1546 d_ptr->removeExtraItemCache();
1548#ifndef QT_NO_GESTURES
1549 if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
1550 QGraphicsObject *o =
static_cast<QGraphicsObject *>(
this);
1551 if (QGestureManager *manager = QGestureManager::instance(QGestureManager::DontForceCreation)) {
1552 for (
auto it = d_ptr->gestureContext.constBegin(); it != d_ptr->gestureContext.constEnd(); ++it)
1553 manager->cleanupCachedGestures(o, it.key());
1559 setFocusProxy(
nullptr);
1562 QGraphicsItem *p = d_ptr->parent;
1564 if (p->flags() & ItemIsFocusScope) {
1565 if (p->d_ptr->focusScopeItem ==
this)
1566 p->d_ptr->focusScopeItem =
nullptr;
1569 p = p->d_ptr->parent;
1572 if (!d_ptr->children.isEmpty()) {
1573 while (!d_ptr->children.isEmpty())
1574 delete d_ptr->children.first();
1575 Q_ASSERT(d_ptr->children.isEmpty());
1579 d_ptr->scene->d_func()->removeItemHelper(
this);
1581 d_ptr->resetFocusProxy();
1582 setParentItem(
nullptr);
1585#if QT_CONFIG(graphicseffect)
1586 delete d_ptr->graphicsEffect;
1588 if (d_ptr->transformData) {
1589 for(
int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
1590 QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i);
1591 static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item =
nullptr;
1595 delete d_ptr->transformData;
1597 if (QGraphicsItemCustomDataStore *dataStore = qt_dataStore())
1598 dataStore->data.remove(
this);
1602
1603
1604
1605
1606
1607QGraphicsScene *QGraphicsItem::scene()
const
1609 return d_ptr->scene;
1613
1614
1615
1616
1617
1618QGraphicsItemGroup *QGraphicsItem::group()
const
1620 if (!d_ptr->isMemberOfGroup)
1622 QGraphicsItem *parent =
const_cast<QGraphicsItem *>(
this);
1623 while ((parent = parent->d_ptr->parent)) {
1624 if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent))
1633
1634
1635
1636
1637
1638
1639void QGraphicsItem::setGroup(QGraphicsItemGroup *group)
1642 if (QGraphicsItemGroup *group =
this->group())
1643 group->removeFromGroup(
this);
1645 group->addToGroup(
this);
1650
1651
1652
1653
1654
1655QGraphicsItem *QGraphicsItem::parentItem()
const
1657 return d_ptr->parent;
1661
1662
1663
1664
1665
1666
1667
1668QGraphicsItem *QGraphicsItem::topLevelItem()
const
1670 QGraphicsItem *parent =
const_cast<QGraphicsItem *>(
this);
1671 while (QGraphicsItem *grandPa = parent->parentItem())
1677
1678
1679
1680
1681
1682
1683
1684QGraphicsObject *QGraphicsItem::parentObject()
const
1686 QGraphicsItem *p = d_ptr->parent;
1687 return (p && p->d_ptr->isObject) ?
static_cast<QGraphicsObject *>(p) :
nullptr;
1691
1692
1693
1694
1695
1696
1697
1698QGraphicsWidget *QGraphicsItem::parentWidget()
const
1700 QGraphicsItem *p = parentItem();
1701 while (p && !p->isWidget())
1702 p = p->parentItem();
1703 return (p && p->isWidget()) ?
static_cast<QGraphicsWidget *>(p) :
nullptr;
1707
1708
1709
1710
1711
1712
1713
1714
1715QGraphicsWidget *QGraphicsItem::topLevelWidget()
const
1717 if (
const QGraphicsWidget *p = parentWidget())
1718 return p->topLevelWidget();
1719 return isWidget() ?
static_cast<QGraphicsWidget *>(
const_cast<QGraphicsItem *>(
this)) :
nullptr;
1723
1724
1725
1726
1727
1728
1729
1730
1731QGraphicsWidget *QGraphicsItem::window()
const
1733 QGraphicsItem *p = panel();
1734 if (p && p->isWindow())
1735 return static_cast<QGraphicsWidget *>(p);
1740
1741
1742
1743
1744
1745
1746
1747
1748QGraphicsItem *QGraphicsItem::panel()
const
1750 if (d_ptr->flags & ItemIsPanel)
1751 return const_cast<QGraphicsItem *>(
this);
1752 return d_ptr->parent ? d_ptr->parent->panel() :
nullptr;
1756
1757
1758
1759
1760
1761QGraphicsObject *QGraphicsItem::toGraphicsObject()
1763 return d_ptr->isObject ?
static_cast<QGraphicsObject *>(
this) :
nullptr;
1767
1768
1769
1770
1771
1772const QGraphicsObject *QGraphicsItem::toGraphicsObject()
const
1774 return d_ptr->isObject ?
static_cast<
const QGraphicsObject *>(
this) :
nullptr;
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791void QGraphicsItem::setParentItem(QGraphicsItem *newParent)
1793 if (newParent ==
this) {
1794 qWarning(
"QGraphicsItem::setParentItem: cannot assign %p as a parent of itself",
this);
1797 if (newParent == d_ptr->parent)
1800 const QVariant newParentVariant(itemChange(QGraphicsItem::ItemParentChange,
1801 QVariant::fromValue<QGraphicsItem *>(newParent)));
1802 newParent = qvariant_cast<QGraphicsItem *>(newParentVariant);
1803 if (newParent == d_ptr->parent)
1806 const QVariant thisPointerVariant(QVariant::fromValue<QGraphicsItem *>(
this));
1807 d_ptr->setParentItemHelper(newParent, &newParentVariant, &thisPointerVariant);
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820QList<QGraphicsItem *> QGraphicsItem::childItems()
const
1822 const_cast<QGraphicsItem *>(
this)->d_ptr->ensureSortedChildren();
1823 return d_ptr->children;
1827
1828
1829
1830
1831bool QGraphicsItem::isWidget()
const
1833 return d_ptr->isWidget;
1837
1838
1839
1840
1841
1842
1843bool QGraphicsItem::isWindow()
const
1845 return d_ptr->isWidget && (
static_cast<
const QGraphicsWidget *>(
this)->windowType() & Qt::Window);
1849
1850
1851
1852
1853
1854bool QGraphicsItem::isPanel()
const
1856 return d_ptr->flags & ItemIsPanel;
1860
1861
1862
1863
1864
1865
1866
1867
1868QGraphicsItem::GraphicsItemFlags QGraphicsItem::flags()
const
1870 return GraphicsItemFlags(d_ptr->flags);
1874
1875
1876
1877
1878
1879void QGraphicsItem::setFlag(GraphicsItemFlag flag,
bool enabled)
1882 setFlags(GraphicsItemFlags(d_ptr->flags) | flag);
1884 setFlags(GraphicsItemFlags(d_ptr->flags) & ~flag);
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902void QGraphicsItem::setFlags(GraphicsItemFlags flags)
1905 if (quint32(d_ptr->flags) == quint32(flags))
1907 flags = GraphicsItemFlags(itemChange(ItemFlagsChange, quint32(flags)).toUInt());
1908 if (quint32(d_ptr->flags) == quint32(flags))
1910 if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex)
1911 d_ptr->scene->d_func()->index->itemChange(
this, ItemFlagsChange, &flags);
1914 const quint32 geomChangeFlagsMask = (ItemClipsChildrenToShape | ItemClipsToShape | ItemIgnoresTransformations | ItemIsSelectable);
1915 bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask);
1917 d_ptr->updatePaintedViewBoundingRects(
true);
1920 GraphicsItemFlags oldFlags = GraphicsItemFlags(d_ptr->flags);
1923 d_ptr->flags = flags;
1925 if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) {
1931 if (!(d_ptr->flags & ItemIsSelectable) && isSelected()) {
1937 if ((flags & ItemClipsChildrenToShape) != (oldFlags & ItemClipsChildrenToShape)) {
1940 d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);
1943 d_ptr->dirtyChildrenBoundingRect = 1;
1944 d_ptr->markParentDirty(
true);
1947 if ((flags & ItemContainsChildrenInShape) != (oldFlags & ItemContainsChildrenInShape)) {
1949 d_ptr->updateAncestorFlag(ItemContainsChildrenInShape);
1952 if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) {
1955 d_ptr->updateAncestorFlag(ItemIgnoresTransformations);
1958 if ((flags & ItemNegativeZStacksBehindParent) != (oldFlags & ItemNegativeZStacksBehindParent)) {
1964 if (d_ptr->z < qreal(0.0))
1965 flags |= ItemStacksBehindParent;
1967 flags &= ~ItemStacksBehindParent;
1968 d_ptr->flags = flags;
1971 if ((flags & ItemStacksBehindParent) != (oldFlags & ItemStacksBehindParent)) {
1977 d_ptr->parent->d_ptr->needSortChildren = 1;
1978 else if (d_ptr->scene)
1979 d_ptr->scene->d_func()->needSortTopLevelItems = 1;
1982 if ((flags & ItemAcceptsInputMethod) != (oldFlags & ItemAcceptsInputMethod)) {
1985 d_ptr->scene->d_func()->updateInputMethodSensitivityInViews();
1988 if ((flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) {
1989 bool becomesPanel = (flags & ItemIsPanel);
1990 if ((d_ptr->panelModality != NonModal) && d_ptr->scene) {
1993 d_ptr->scene->d_func()->enterModal(
this);
1995 d_ptr->scene->d_func()->leaveModal(
this);
1997 if (d_ptr->isWidget && (becomesPanel || parentWidget())) {
1998 QGraphicsWidget *w =
static_cast<QGraphicsWidget *>(
this);
1999 QGraphicsWidget *focusFirst = w;
2000 QGraphicsWidget *focusLast = w;
2002 QGraphicsWidget *test = focusLast->d_func()->focusNext;
2003 if (!w->isAncestorOf(test) || test == w)
2010 QGraphicsWidget *beforeMe = w->d_func()->focusPrev;
2011 QGraphicsWidget *afterMe = focusLast->d_func()->focusNext;
2012 beforeMe->d_func()->focusNext = afterMe;
2013 afterMe->d_func()->focusPrev = beforeMe;
2014 focusFirst->d_func()->focusPrev = focusLast;
2015 focusLast->d_func()->focusNext = focusFirst;
2016 if (!isAncestorOf(focusFirst->d_func()->focusNext))
2017 focusFirst->d_func()->focusNext = w;
2018 }
else if (QGraphicsWidget *pw = parentWidget()) {
2020 QGraphicsWidget *beforeMe = pw;
2021 QGraphicsWidget *afterMe = pw->d_func()->focusNext;
2022 beforeMe->d_func()->focusNext = w;
2023 afterMe->d_func()->focusPrev = focusLast;
2024 w->d_func()->focusPrev = beforeMe;
2025 focusLast->d_func()->focusNext = afterMe;
2031 if ((flags & ItemSendsScenePositionChanges) != (oldFlags & ItemSendsScenePositionChanges)) {
2032 if (flags & ItemSendsScenePositionChanges)
2033 d_ptr->scene->d_func()->registerScenePosItem(
this);
2035 d_ptr->scene->d_func()->unregisterScenePosItem(
this);
2037 d_ptr->scene->d_func()->markDirty(
this, QRectF(),
true);
2041 itemChange(ItemFlagsHaveChanged, quint32(flags));
2045
2046
2047
2048
2049
2050
2051QGraphicsItem::CacheMode QGraphicsItem::cacheMode()
const
2053 return QGraphicsItem::CacheMode(d_ptr->cacheMode);
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093void QGraphicsItem::setCacheMode(CacheMode mode,
const QSize &logicalCacheSize)
2095 CacheMode lastMode = CacheMode(d_ptr->cacheMode);
2096 d_ptr->cacheMode = mode;
2097 bool noVisualChange = (mode == NoCache && lastMode == NoCache)
2098 || (mode == NoCache && lastMode == DeviceCoordinateCache)
2099 || (mode == DeviceCoordinateCache && lastMode == NoCache)
2100 || (mode == DeviceCoordinateCache && lastMode == DeviceCoordinateCache);
2101 if (mode == NoCache) {
2102 d_ptr->removeExtraItemCache();
2104 QGraphicsItemCache *cache = d_ptr->extraItemCache();
2109 if (mode == ItemCoordinateCache) {
2110 if (lastMode == mode && cache->fixedSize == logicalCacheSize)
2111 noVisualChange =
true;
2112 cache->fixedSize = logicalCacheSize;
2115 if (!noVisualChange)
2120
2121
2122
2123
2124QGraphicsItem::PanelModality QGraphicsItem::panelModality()
const
2126 return d_ptr->panelModality;
2130
2131
2132
2133
2134
2135
2136void QGraphicsItem::setPanelModality(PanelModality panelModality)
2138 if (d_ptr->panelModality == panelModality)
2141 PanelModality previousModality = d_ptr->panelModality;
2142 bool enterLeaveModal = (isPanel() && d_ptr->scene && isVisible());
2143 if (enterLeaveModal && panelModality == NonModal)
2144 d_ptr->scene->d_func()->leaveModal(
this);
2145 d_ptr->panelModality = panelModality;
2146 if (enterLeaveModal && d_ptr->panelModality != NonModal)
2147 d_ptr->scene->d_func()->enterModal(
this, previousModality);
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161bool QGraphicsItem::isBlockedByModalPanel(QGraphicsItem **blockingPanel)
const
2167 QGraphicsItem *dummy =
nullptr;
2169 blockingPanel = &dummy;
2171 const QGraphicsScenePrivate *scene_d = d_ptr->scene->d_func();
2172 if (scene_d->modalPanels.isEmpty())
2176 if (!scene_d->popupWidgets.isEmpty() && scene_d->popupWidgets.first() ==
this)
2179 for (
int i = 0; i < scene_d->modalPanels.size(); ++i) {
2180 QGraphicsItem *modalPanel = scene_d->modalPanels.at(i);
2181 if (modalPanel->panelModality() == QGraphicsItem::SceneModal) {
2183 if (modalPanel !=
this && !modalPanel->isAncestorOf(
this)) {
2184 *blockingPanel = modalPanel;
2189 if (modalPanel !=
this
2190 && !modalPanel->isAncestorOf(
this)
2191 && commonAncestorItem(modalPanel)) {
2192 *blockingPanel = modalPanel;
2200#if QT_CONFIG(tooltip)
2202
2203
2204
2205
2206
2207QString QGraphicsItem::toolTip()
const
2209 return d_ptr->extra(QGraphicsItemPrivate::ExtraToolTip).toString();
2213
2214
2215
2216
2217
2218void QGraphicsItem::setToolTip(
const QString &toolTip)
2220 const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip));
2221 d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString());
2222 itemChange(ItemToolTipHasChanged, toolTipVariant);
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242QCursor QGraphicsItem::cursor()
const
2244 return qvariant_cast<QCursor>(d_ptr->extra(QGraphicsItemPrivate::ExtraCursor));
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262void QGraphicsItem::setCursor(
const QCursor &cursor)
2264 const QVariant cursorVariant(itemChange(ItemCursorChange, QVariant::fromValue<QCursor>(cursor)));
2265 d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qvariant_cast<QCursor>(cursorVariant));
2266 d_ptr->hasCursor = 1;
2268 d_ptr->scene->d_func()->allItemsUseDefaultCursor =
false;
2269 const auto views = d_ptr->scene->views();
2270 for (QGraphicsView *view : views) {
2271 view->viewport()->setMouseTracking(
true);
2273 if (view->underMouse()) {
2274 const QPoint viewPoint = view->mapFromGlobal(QCursor::pos());
2275 const QPointF cursorPos = mapFromScene(view->mapToScene(viewPoint));
2277 if (boundingRect().contains(cursorPos)) {
2278 const auto itemsUnderCursor = view->items(viewPoint);
2279 for (QGraphicsItem *itemUnderCursor : itemsUnderCursor) {
2280 if (itemUnderCursor->hasCursor()) {
2281 QMetaObject::invokeMethod(view,
"_q_setViewportCursor",
2282 Q_ARG(QCursor, itemUnderCursor->cursor()));
2291 itemChange(ItemCursorHasChanged, cursorVariant);
2295
2296
2297
2298
2299
2300
2301
2302bool QGraphicsItem::hasCursor()
const
2304 return d_ptr->hasCursor;
2308
2309
2310
2311
2312void QGraphicsItem::unsetCursor()
2314 if (!d_ptr->hasCursor)
2316 d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraCursor);
2317 d_ptr->hasCursor = 0;
2319 const auto views = d_ptr->scene->views();
2320 for (QGraphicsView *view : views) {
2321 if (view->underMouse() && view->itemAt(view->mapFromGlobal(QCursor::pos())) ==
this) {
2322 QMetaObject::invokeMethod(view,
"_q_unsetViewportCursor");
2332
2333
2334
2335
2336
2337
2338
2339bool QGraphicsItem::isVisible()
const
2341 return d_ptr->visible;
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357bool QGraphicsItem::isVisibleTo(
const QGraphicsItem *parent)
const
2359 const QGraphicsItem *p =
this;
2360 if (d_ptr->explicitlyHidden)
2365 if (p->d_ptr->explicitlyHidden)
2367 }
while ((p = p->d_ptr->parent));
2368 return parent ==
nullptr;
2372
2373
2374
2375
2376
2377void QGraphicsItemPrivate::setVisibleHelper(
bool newVisible,
bool explicitly,
2378 bool update,
bool hiddenByPanel)
2384 explicitlyHidden = newVisible ? 0 : 1;
2387 if (visible == quint32(newVisible))
2391 if (parent && newVisible && !parent->d_ptr->visible)
2395 const QVariant newVisibleVariant(q_ptr->itemChange(QGraphicsItem::ItemVisibleChange,
2396 quint32(newVisible)));
2397 newVisible = newVisibleVariant.toBool();
2398 if (visible == quint32(newVisible))
2400 visible = newVisible;
2404 QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<
void *>(extra(ExtraCacheData));
2408#if QT_CONFIG(graphicseffect)
2409 invalidateParentGraphicsEffectsRecursively();
2411 scene->d_func()->markDirty(q_ptr, QRectF(),
false,
true);
2416 bool hasFocus = q_ptr->hasFocus();
2419 if (scene->d_func()->mouseGrabberItems.contains(q))
2421 if (scene->d_func()->keyboardGrabberItems.contains(q))
2422 q->ungrabKeyboard();
2423 if (q->isPanel() && panelModality != QGraphicsItem::NonModal)
2424 scene->d_func()->leaveModal(q_ptr);
2426 if (hasFocus && scene) {
2428 QGraphicsItem *focusItem = scene->focusItem();
2430 if (isWidget && !focusItem->isPanel()) {
2432 if (focusItem == q_ptr) {
2433 clear = !
static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(
true);
2436 }
while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
2439 clearFocusHelper(
false, hiddenByPanel);
2441 if (q_ptr->isSelected())
2442 q_ptr->setSelected(
false);
2444 geometryChanged = 1;
2445 paintedViewBoundingRectsNeedRepaint = 1;
2448 QGraphicsWidget *widget =
static_cast<QGraphicsWidget *>(q_ptr);
2449 if (widget->windowType() == Qt::Popup)
2450 scene->d_func()->addPopup(widget);
2452 if (q->isPanel() && panelModality != QGraphicsItem::NonModal) {
2453 scene->d_func()->enterModal(q_ptr);
2459 const bool updateChildren = update && !((flags & QGraphicsItem::ItemClipsChildrenToShape
2460 || flags & QGraphicsItem::ItemContainsChildrenInShape)
2461 && !(flags & QGraphicsItem::ItemHasNoContents));
2462 for (QGraphicsItem *child : std::as_const(children)) {
2463 if (!newVisible || !child->d_ptr->explicitlyHidden)
2464 child->d_ptr->setVisibleHelper(newVisible,
false, updateChildren, hiddenByPanel);
2468 if (scene && q->isPanel()) {
2470 if (parent && parent->isActive())
2474 scene->setActivePanel(parent);
2482 QGraphicsItem *p = parent;
2485 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
2486 QGraphicsItem *fsi = p->d_ptr->focusScopeItem;
2487 if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {
2489 while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible())
2490 fsi = fsi->d_ptr->focusScopeItem;
2491 fsi->d_ptr->setFocusHelper(Qt::OtherFocusReason,
true,
2496 p = p->d_ptr->parent;
2499 QGraphicsItem *fi = subFocusItem;
2500 if (fi && fi != scene->focusItem()) {
2501 scene->setFocusItem(fi);
2502 }
else if (flags & QGraphicsItem::ItemIsFocusScope &&
2503 !scene->focusItem() &&
2504 q->isAncestorOf(scene->d_func()->lastFocusItem)) {
2511 QGraphicsItem *p = parent;
2513 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
2514 if (p->d_ptr->visible) {
2515 p->d_ptr->setFocusHelper(Qt::OtherFocusReason,
true,
2520 p = p->d_ptr->parent;
2527 q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant);
2530 emit
static_cast<QGraphicsObject *>(q_ptr)->visibleChanged();
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565void QGraphicsItem::setVisible(
bool visible)
2567 d_ptr->setVisibleHelper(visible,
2574
2575
2576
2577
2578
2579
2580
2581
2584
2585
2586
2587
2588
2589
2590
2591
2594
2595
2596
2597
2598bool QGraphicsItem::isEnabled()
const
2600 return d_ptr->enabled;
2604
2605
2606
2607
2608
2609void QGraphicsItemPrivate::setEnabledHelper(
bool newEnabled,
bool explicitly,
bool update)
2613 explicitlyDisabled = newEnabled ? 0 : 1;
2616 if (enabled == quint32(newEnabled))
2622 if (scene->mouseGrabberItem() == q_ptr)
2623 q_ptr->ungrabMouse();
2624 if (q_ptr->hasFocus()) {
2627 QGraphicsItem *focusItem = scene->focusItem();
2629 if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {
2631 if (focusItem == q_ptr) {
2632 clear = !
static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(
true);
2635 }
while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
2638 q_ptr->clearFocus();
2641 if (q_ptr->isSelected())
2642 q_ptr->setSelected(
false);
2646 const QVariant newEnabledVariant(q_ptr->itemChange(QGraphicsItem::ItemEnabledChange,
2647 quint32(newEnabled)));
2648 enabled = newEnabledVariant.toBool();
2654 for (QGraphicsItem *child : std::as_const(children)) {
2655 if (!newEnabled || !child->d_ptr->explicitlyDisabled)
2656 child->d_ptr->setEnabledHelper(newEnabled,
false);
2660 q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant);
2663 emit
static_cast<QGraphicsObject *>(q_ptr)->enabledChanged();
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694void QGraphicsItem::setEnabled(
bool enabled)
2696 d_ptr->setEnabledHelper(enabled,
true);
2700
2701
2702
2703
2704
2705
2706
2707
2708bool QGraphicsItem::isSelected()
const
2710 if (QGraphicsItemGroup *group =
this->group())
2711 return group->isSelected();
2712 return d_ptr->selected;
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739void QGraphicsItem::setSelected(
bool selected)
2741 if (QGraphicsItemGroup *group =
this->group()) {
2742 group->setSelected(selected);
2746 if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible)
2748 if (d_ptr->selected == selected)
2750 const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected)));
2751 bool newSelected = newSelectedVariant.toBool();
2752 if (d_ptr->selected == newSelected)
2754 d_ptr->selected = newSelected;
2758 QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func();
2760 sceneD->selectedItems <<
this;
2765 if (!sceneD->selectionChanging)
2766 emit d_ptr->scene->selectionChanged();
2770 itemChange(QGraphicsItem::ItemSelectedHasChanged, newSelectedVariant);
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792qreal QGraphicsItem::opacity()
const
2794 return d_ptr->opacity;
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808qreal QGraphicsItem::effectiveOpacity()
const
2810 return d_ptr->effectiveOpacity();
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839void QGraphicsItem::setOpacity(qreal opacity)
2842 const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity));
2845 qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1));
2848 if (newOpacity == d_ptr->opacity)
2851 bool wasFullyTransparent = d_ptr->isOpacityNull();
2852 d_ptr->opacity = newOpacity;
2855 itemChange(ItemOpacityHasChanged, newOpacityVariant);
2859#if QT_CONFIG(graphicseffect)
2860 d_ptr->invalidateParentGraphicsEffectsRecursively();
2861 if (!(d_ptr->flags & ItemDoesntPropagateOpacityToChildren))
2862 d_ptr->invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::OpacityChanged);
2864 d_ptr->scene->d_func()->markDirty(
this, QRectF(),
2867 d_ptr->isOpacityNull());
2868 if (wasFullyTransparent)
2869 d_ptr->paintedViewBoundingRectsNeedRepaint = 1;
2872 if (d_ptr->isObject)
2873 emit
static_cast<QGraphicsObject *>(
this)->opacityChanged();
2877
2878
2879
2880
2881#if QT_CONFIG(graphicseffect)
2882QGraphicsEffect *QGraphicsItem::graphicsEffect()
const
2884 return d_ptr->graphicsEffect;
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect)
2904 if (d_ptr->graphicsEffect == effect)
2907 if (d_ptr->graphicsEffect) {
2908 delete d_ptr->graphicsEffect;
2909 d_ptr->graphicsEffect =
nullptr;
2910 }
else if (d_ptr->parent) {
2911 d_ptr->parent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();
2916 QGraphicsEffectSourcePrivate *sourced =
new QGraphicsItemEffectSourcePrivate(
this);
2917 QGraphicsEffectSource *source =
new QGraphicsEffectSource(*sourced);
2918 d_ptr->graphicsEffect = effect;
2919 effect->d_func()->setGraphicsEffectSource(source);
2920 prepareGeometryChange();
2925void QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively()
2927#if QT_CONFIG(graphicseffect)
2928 QGraphicsItemPrivate *itemPrivate =
this;
2931 if (itemPrivate->mayHaveChildWithGraphicsEffect)
2933 itemPrivate->mayHaveChildWithGraphicsEffect = 1;
2934 }
while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() :
nullptr));
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948QRectF QGraphicsItemPrivate::effectiveBoundingRect(
const QRectF &rect)
const
2950#if QT_CONFIG(graphicseffect)
2951 Q_Q(
const QGraphicsItem);
2952 QGraphicsEffect *effect = graphicsEffect;
2953 if (scene && effect && effect->isEnabled()) {
2954 if (scene->d_func()->views.isEmpty())
2955 return effect->boundingRectFor(rect);
2956 QRectF sceneRect = q->mapRectToScene(rect);
2957 QRectF sceneEffectRect;
2958 const auto views = scene->views();
2959 for (QGraphicsView *view : views) {
2960 QRectF deviceRect = view->d_func()->mapRectFromScene(sceneRect);
2961 QRect deviceEffectRect = effect->boundingRectFor(deviceRect).toAlignedRect();
2962 sceneEffectRect |= view->d_func()->mapRectToScene(deviceEffectRect);
2964 return q->mapRectFromScene(sceneEffectRect);
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980QRectF QGraphicsItemPrivate::effectiveBoundingRect(QGraphicsItem *topMostEffectItem)
const
2982#if QT_CONFIG(graphicseffect)
2983 Q_Q(
const QGraphicsItem);
2984 QRectF brect = effectiveBoundingRect(q_ptr->boundingRect());
2985 if (ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren
2986 || ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren
2987 || topMostEffectItem == q)
2990 const QGraphicsItem *effectParent = parent;
2991 while (effectParent) {
2992 QGraphicsEffect *effect = effectParent->d_ptr->graphicsEffect;
2993 if (scene && effect && effect->isEnabled()) {
2994 const QRectF brectInParentSpace = q->mapRectToItem(effectParent, brect);
2995 const QRectF effectRectInParentSpace = effectParent->d_ptr->effectiveBoundingRect(brectInParentSpace);
2996 brect = effectParent->mapRectToItem(q, effectRectInParentSpace);
2998 if (effectParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren
2999 || effectParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren
3000 || topMostEffectItem == effectParent) {
3003 effectParent = effectParent->d_ptr->parent;
3008 Q_UNUSED(topMostEffectItem);
3009 return q_ptr->boundingRect();
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025QRectF QGraphicsItemPrivate::sceneEffectiveBoundingRect()
const
3030 const QGraphicsItem *parentItem = q_ptr;
3031 const QGraphicsItemPrivate *itemd;
3033 itemd = parentItem->d_ptr.data();
3034 if (itemd->transformData)
3036 offset += itemd->pos;
3037 }
while ((parentItem = itemd->parent));
3039 QRectF br = effectiveBoundingRect();
3040 br.translate(offset);
3041 return !parentItem ? br : parentItem->sceneTransform().mapRect(br);
3045
3046
3047
3048
3049
3050
3051bool QGraphicsItem::acceptDrops()
const
3053 return d_ptr->acceptDrops;
3057
3058
3059
3060
3061
3062
3063void QGraphicsItem::setAcceptDrops(
bool on)
3065 d_ptr->acceptDrops = on;
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080Qt::MouseButtons QGraphicsItem::acceptedMouseButtons()
const
3082 return Qt::MouseButtons(d_ptr->acceptedMouseButtons);
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099void QGraphicsItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)
3101 if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) {
3102 if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() ==
this
3103 && d_ptr->scene->d_func()->lastMouseGrabberItemHasImplicitMouseGrab) {
3106 d_ptr->acceptedMouseButtons = quint32(buttons);
3111
3112
3113
3114
3115
3116
3117
3118
3119bool QGraphicsItem::acceptHoverEvents()
const
3121 return d_ptr->acceptsHover;
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156void QGraphicsItem::setAcceptHoverEvents(
bool enabled)
3158 if (d_ptr->acceptsHover == quint32(enabled))
3160 d_ptr->acceptsHover = quint32(enabled);
3161 if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) {
3162 d_ptr->scene->d_func()->allItemsIgnoreHoverEvents =
false;
3163 d_ptr->scene->d_func()->enableMouseTrackingOnViews();
3168
3169
3170
3171
3172
3173
3174bool QGraphicsItem::acceptTouchEvents()
const
3176 return d_ptr->acceptTouchEvents;
3180
3181
3182
3183
3184
3185
3186void QGraphicsItem::setAcceptTouchEvents(
bool enabled)
3188 if (d_ptr->acceptTouchEvents == quint32(enabled))
3190 d_ptr->acceptTouchEvents = quint32(enabled);
3191 if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) {
3192 d_ptr->scene->d_func()->allItemsIgnoreTouchEvents =
false;
3193 d_ptr->scene->d_func()->enableTouchEventsOnViews();
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208bool QGraphicsItem::filtersChildEvents()
const
3210 return d_ptr->filtersDescendantEvents;
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224void QGraphicsItem::setFiltersChildEvents(
bool enabled)
3226 if (d_ptr->filtersDescendantEvents == enabled)
3229 d_ptr->filtersDescendantEvents = enabled;
3230 d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-2));
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250bool QGraphicsItem::handlesChildEvents()
const
3252 return d_ptr->handlesChildEvents;
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275void QGraphicsItem::setHandlesChildEvents(
bool enabled)
3277 if (d_ptr->handlesChildEvents == enabled)
3280 d_ptr->handlesChildEvents = enabled;
3281 d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298bool QGraphicsItem::isActive()
const
3300 if (!d_ptr->scene || !d_ptr->scene->isActive())
3302 return panel() == d_ptr->scene->activePanel();
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319void QGraphicsItem::setActive(
bool active)
3321 d_ptr->explicitActivate = 1;
3322 d_ptr->wantsActive = active;
3326 d_ptr->scene->setActivePanel(
this);
3328 QGraphicsItem *activePanel = d_ptr->scene->activePanel();
3329 QGraphicsItem *thisPanel = panel();
3330 if (!activePanel || activePanel == thisPanel) {
3333 QGraphicsItem *nextToActivate =
nullptr;
3335 nextToActivate = d_ptr->parent->panel();
3336 if (!nextToActivate)
3337 nextToActivate = d_ptr->scene->d_func()->lastActivePanel;
3338 if (nextToActivate ==
this || isAncestorOf(nextToActivate))
3339 nextToActivate =
nullptr;
3340 d_ptr->scene->setActivePanel(nextToActivate);
3347
3348
3349
3350
3351
3352bool QGraphicsItem::hasFocus()
const
3354 if (!d_ptr->scene || !d_ptr->scene->isActive())
3357 if (d_ptr->focusProxy)
3358 return d_ptr->focusProxy->hasFocus();
3360 if (d_ptr->scene->d_func()->focusItem !=
this)
3363 return panel() == d_ptr->scene->d_func()->activePanel;
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386void QGraphicsItem::setFocus(Qt::FocusReason focusReason)
3388 d_ptr->setFocusHelper(focusReason,
true,
false);
3392
3393
3394void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason,
bool climb,
bool focusFromHide)
3397 if (!q_ptr->isEnabled() || !(flags & QGraphicsItem::ItemIsFocusable))
3401 QGraphicsItem *f = q_ptr;
3402 while (f->d_ptr->focusProxy)
3403 f = f->d_ptr->focusProxy;
3406 if (scene && scene->focusItem() == f)
3410 QGraphicsItem *p = parent;
3412 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
3413 QGraphicsItem *oldFocusScopeItem = p->d_ptr->focusScopeItem;
3414 p->d_ptr->focusScopeItem = q_ptr;
3415 if (oldFocusScopeItem)
3416 oldFocusScopeItem->d_ptr->focusScopeItemChange(
false);
3417 focusScopeItemChange(
true);
3418 if (!p->focusItem() && !focusFromHide) {
3427 p = p->d_ptr->parent;
3431 while (f->d_ptr->focusScopeItem && f->d_ptr->focusScopeItem->isVisible())
3432 f = f->d_ptr->focusScopeItem;
3436 QGraphicsItem *commonAncestor =
nullptr;
3437 if (scene && scene->focusItem() && scene->focusItem()->panel() == q_ptr->panel()) {
3438 commonAncestor = scene->focusItem()->commonAncestorItem(f);
3439 scene->focusItem()->d_ptr->clearSubFocus(scene->focusItem(), commonAncestor);
3442 f->d_ptr->setSubFocus(f, commonAncestor);
3446 QGraphicsItem *p = q_ptr->panel();
3447 if ((!p && scene->isActive()) || (p && p->isActive())) {
3449 scene->d_func()->setFocusItemHelper(f, focusReason);
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465void QGraphicsItem::clearFocus()
3467 d_ptr->clearFocusHelper(
true,
3472
3473
3474void QGraphicsItemPrivate::clearFocusHelper(
bool giveFocusToParent,
bool hiddenByParentPanel)
3476 QGraphicsItem *subFocusItem = q_ptr;
3477 if (flags & QGraphicsItem::ItemIsFocusScope) {
3478 while (subFocusItem->d_ptr->focusScopeItem)
3479 subFocusItem = subFocusItem->d_ptr->focusScopeItem;
3482 if (giveFocusToParent) {
3484 if (!inDestructor) {
3485 QGraphicsItem *p = parent;
3487 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {
3488 if (p->d_ptr->focusScopeItem == q_ptr) {
3489 p->d_ptr->focusScopeItem =
nullptr;
3490 if (!subFocusItem->hasFocus())
3491 focusScopeItemChange(
false);
3493 if (subFocusItem->hasFocus())
3494 p->d_ptr->setFocusHelper(Qt::OtherFocusReason,
false,
3498 p = p->d_ptr->parent;
3503 if (subFocusItem->hasFocus()) {
3505 if (!hiddenByParentPanel)
3506 clearSubFocus(q_ptr);
3509 scene->setFocusItem(
nullptr);
3514
3515
3516
3517
3518
3519
3520
3521QGraphicsItem *QGraphicsItem::focusProxy()
const
3523 return d_ptr->focusProxy;
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545void QGraphicsItem::setFocusProxy(QGraphicsItem *item)
3547 if (item == d_ptr->focusProxy)
3550 qWarning(
"QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
3554 if (item->d_ptr->scene != d_ptr->scene) {
3555 qWarning(
"QGraphicsItem::setFocusProxy: focus proxy must be in same scene");
3558 for (QGraphicsItem *f = item->focusProxy(); f !=
nullptr; f = f->focusProxy()) {
3560 qWarning(
"QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);
3566 QGraphicsItem *lastFocusProxy = d_ptr->focusProxy;
3568 lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&d_ptr->focusProxy);
3569 d_ptr->focusProxy = item;
3571 item->d_ptr->focusProxyRefs << &d_ptr->focusProxy;
3575
3576
3577
3578
3579
3580
3581
3582
3583QGraphicsItem *QGraphicsItem::focusItem()
const
3585 return d_ptr->subFocusItem;
3589
3590
3591
3592
3593QGraphicsItem *QGraphicsItem::focusScopeItem()
const
3595 return d_ptr->focusScopeItem;
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632void QGraphicsItem::grabMouse()
3634 if (!d_ptr->scene) {
3635 qWarning(
"QGraphicsItem::grabMouse: cannot grab mouse without scene");
3638 if (!d_ptr->visible) {
3639 qWarning(
"QGraphicsItem::grabMouse: cannot grab mouse while invisible");
3642 d_ptr->scene->d_func()->grabMouse(
this);
3646
3647
3648
3649
3650
3651void QGraphicsItem::ungrabMouse()
3653 if (!d_ptr->scene) {
3654 qWarning(
"QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene");
3657 d_ptr->scene->d_func()->ungrabMouse(
this);
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694void QGraphicsItem::grabKeyboard()
3696 if (!d_ptr->scene) {
3697 qWarning(
"QGraphicsItem::grabKeyboard: cannot grab keyboard without scene");
3700 if (!d_ptr->visible) {
3701 qWarning(
"QGraphicsItem::grabKeyboard: cannot grab keyboard while invisible");
3704 d_ptr->scene->d_func()->grabKeyboard(
this);
3708
3709
3710
3711
3712
3713void QGraphicsItem::ungrabKeyboard()
3715 if (!d_ptr->scene) {
3716 qWarning(
"QGraphicsItem::ungrabKeyboard: cannot ungrab keyboard without scene");
3719 d_ptr->scene->d_func()->ungrabKeyboard(
this);
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735QPointF QGraphicsItem::pos()
const
3741
3742
3743
3744
3745
3746
3749
3750
3751
3752
3753
3754
3755
3756void QGraphicsItem::setX(qreal x)
3758 if (d_ptr->inDestructor)
3764 setPos(QPointF(x, d_ptr->pos.y()));
3768
3769
3770
3771
3772
3773
3776
3777
3778
3779
3780
3781
3782
3783void QGraphicsItem::setY(qreal y)
3785 if (d_ptr->inDestructor)
3791 setPos(QPointF(d_ptr->pos.x(), y));
3795
3796
3797
3798
3799
3800QPointF QGraphicsItem::scenePos()
const
3802 return mapToScene(0, 0);
3806
3807
3808
3809
3810void QGraphicsItemPrivate::setPosHelper(
const QPointF &pos)
3815 q->prepareGeometryChange();
3816 QPointF oldPos =
this->pos;
3818 dirtySceneTransform = 1;
3821 if (pos.x() != oldPos.x())
3822 emit
static_cast<QGraphicsObject *>(q_ptr)->xChanged();
3823 if (pos.y() != oldPos.y())
3824 emit
static_cast<QGraphicsObject *>(q_ptr)->yChanged();
3829
3830
3831
3832
3833void QGraphicsItemPrivate::setTransformHelper(
const QTransform &transform)
3835 q_ptr->prepareGeometryChange();
3836 transformData->transform = transform;
3837 dirtySceneTransform = 1;
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851void QGraphicsItem::setPos(
const QPointF &pos)
3853 if (d_ptr->pos == pos)
3856 if (d_ptr->inDestructor)
3860 if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) {
3861 d_ptr->setPosHelper(pos);
3862 if (d_ptr->isWidget)
3863 static_cast<QGraphicsWidget *>(
this)->d_func()->setGeometryFromSetPos();
3864 if (d_ptr->scenePosDescendants)
3865 d_ptr->sendScenePosChange();
3870 const QVariant newPosVariant(itemChange(ItemPositionChange, QVariant::fromValue<QPointF>(pos)));
3871 QPointF newPos = newPosVariant.toPointF();
3872 if (newPos == d_ptr->pos)
3876 d_ptr->setPosHelper(newPos);
3879 itemChange(QGraphicsItem::ItemPositionHasChanged, newPosVariant);
3880 d_ptr->sendScenePosChange();
3884
3885
3886
3887
3888
3889
3892
3893
3894
3895
3896
3897
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913void QGraphicsItem::ensureVisible(
const QRectF &rect,
int xmargin,
int ymargin)
3918 sceneRect = sceneTransform().mapRect(rect);
3920 sceneRect = sceneBoundingRect();
3921 for (QGraphicsView *view : std::as_const(d_ptr->scene->d_func()->views))
3922 view->ensureVisible(sceneRect, xmargin, ymargin);
3927
3928
3929
3930
3931
3932
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946QTransform QGraphicsItem::transform()
const
3948 if (!d_ptr->transformData)
3949 return QTransform();
3950 return d_ptr->transformData->transform;
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964qreal QGraphicsItem::rotation()
const
3966 if (!d_ptr->transformData)
3968 return d_ptr->transformData->rotation;
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990void QGraphicsItem::setRotation(qreal angle)
3992 prepareGeometryChange();
3993 qreal newRotation = angle;
3995 if (d_ptr->flags & ItemSendsGeometryChanges) {
3997 const QVariant newRotationVariant(itemChange(ItemRotationChange, angle));
3998 newRotation = newRotationVariant.toReal();
4001 if (!d_ptr->transformData)
4002 d_ptr->transformData =
new QGraphicsItemPrivate::TransformData;
4004 if (d_ptr->transformData->rotation == newRotation)
4007 d_ptr->transformData->rotation = newRotation;
4008 d_ptr->transformData->onlyTransform =
false;
4009 d_ptr->dirtySceneTransform = 1;
4012 if (d_ptr->flags & ItemSendsGeometryChanges)
4013 itemChange(ItemRotationHasChanged, newRotation);
4015 if (d_ptr->isObject)
4016 emit
static_cast<QGraphicsObject *>(
this)->rotationChanged();
4018 d_ptr->transformChanged();
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032qreal QGraphicsItem::scale()
const
4034 if (!d_ptr->transformData)
4036 return d_ptr->transformData->scale;
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056void QGraphicsItem::setScale(qreal factor)
4058 prepareGeometryChange();
4059 qreal newScale = factor;
4061 if (d_ptr->flags & ItemSendsGeometryChanges) {
4063 const QVariant newScaleVariant(itemChange(ItemScaleChange, factor));
4064 newScale = newScaleVariant.toReal();
4067 if (!d_ptr->transformData)
4068 d_ptr->transformData =
new QGraphicsItemPrivate::TransformData;
4070 if (d_ptr->transformData->scale == newScale)
4073 d_ptr->transformData->scale = newScale;
4074 d_ptr->transformData->onlyTransform =
false;
4075 d_ptr->dirtySceneTransform = 1;
4078 if (d_ptr->flags & ItemSendsGeometryChanges)
4079 itemChange(ItemScaleHasChanged, newScale);
4081 if (d_ptr->isObject)
4082 emit
static_cast<QGraphicsObject *>(
this)->scaleChanged();
4084 d_ptr->transformChanged();
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103QList<QGraphicsTransform *> QGraphicsItem::transformations()
const
4105 if (!d_ptr->transformData)
4106 return QList<QGraphicsTransform *>();
4107 return d_ptr->transformData->graphicsTransforms;
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130void QGraphicsItem::setTransformations(
const QList<QGraphicsTransform *> &transformations)
4132 prepareGeometryChange();
4133 if (!d_ptr->transformData)
4134 d_ptr->transformData =
new QGraphicsItemPrivate::TransformData;
4135 d_ptr->transformData->graphicsTransforms = transformations;
4136 for (
int i = 0; i < transformations.size(); ++i)
4137 transformations.at(i)->d_func()->setItem(
this);
4138 d_ptr->transformData->onlyTransform =
false;
4139 d_ptr->dirtySceneTransform = 1;
4140 d_ptr->transformChanged();
4144
4145
4146void QGraphicsItemPrivate::prependGraphicsTransform(QGraphicsTransform *t)
4149 transformData =
new QGraphicsItemPrivate::TransformData;
4150 if (!transformData->graphicsTransforms.contains(t))
4151 transformData->graphicsTransforms.prepend(t);
4154 t->d_func()->setItem(q);
4155 transformData->onlyTransform =
false;
4156 dirtySceneTransform = 1;
4161
4162
4163void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t)
4166 transformData =
new QGraphicsItemPrivate::TransformData;
4167 if (!transformData->graphicsTransforms.contains(t))
4168 transformData->graphicsTransforms.append(t);
4171 t->d_func()->setItem(q);
4172 transformData->onlyTransform =
false;
4173 dirtySceneTransform = 1;
4178
4179
4180
4181
4182
4183
4184
4185
4186QPointF QGraphicsItem::transformOriginPoint()
const
4188 if (!d_ptr->transformData)
4189 return QPointF(0,0);
4190 return QPointF(d_ptr->transformData->xOrigin, d_ptr->transformData->yOrigin);
4194
4195
4196
4197
4198
4199
4200void QGraphicsItem::setTransformOriginPoint(
const QPointF &origin)
4202 prepareGeometryChange();
4203 QPointF newOrigin = origin;
4205 if (d_ptr->flags & ItemSendsGeometryChanges) {
4207 const QVariant newOriginVariant(itemChange(ItemTransformOriginPointChange,
4208 QVariant::fromValue<QPointF>(origin)));
4209 newOrigin = newOriginVariant.toPointF();
4212 if (!d_ptr->transformData)
4213 d_ptr->transformData =
new QGraphicsItemPrivate::TransformData;
4215 if (d_ptr->transformData->xOrigin == newOrigin.x()
4216 && d_ptr->transformData->yOrigin == newOrigin.y()) {
4220 d_ptr->transformData->xOrigin = newOrigin.x();
4221 d_ptr->transformData->yOrigin = newOrigin.y();
4222 d_ptr->transformData->onlyTransform =
false;
4223 d_ptr->dirtySceneTransform = 1;
4226 if (d_ptr->flags & ItemSendsGeometryChanges)
4227 itemChange(ItemTransformOriginPointHasChanged, QVariant::fromValue<QPointF>(newOrigin));
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260QTransform QGraphicsItem::sceneTransform()
const
4262 d_ptr->ensureSceneTransform();
4263 return d_ptr->sceneTransform;
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289QTransform QGraphicsItem::deviceTransform(
const QTransform &viewportTransform)
const
4292 if (!d_ptr->itemIsUntransformable()) {
4293 d_ptr->ensureSceneTransform();
4294 return d_ptr->sceneTransform * viewportTransform;
4298 const QGraphicsItem *untransformedAncestor =
this;
4299 QList<
const QGraphicsItem *> parents;
4300 while (untransformedAncestor && ((untransformedAncestor->d_ptr->ancestorFlags
4301 & QGraphicsItemPrivate::AncestorIgnoresTransformations))) {
4302 parents.prepend(untransformedAncestor);
4303 untransformedAncestor = untransformedAncestor->parentItem();
4306 if (!untransformedAncestor) {
4308 Q_ASSERT_X(untransformedAncestor,
"QGraphicsItem::deviceTransform",
4309 "Invalid object structure!");
4310 return QTransform();
4316 QGraphicsItem *parentOfUntransformedAncestor = untransformedAncestor->parentItem();
4317 QTransform inheritedMatrix;
4318 if (parentOfUntransformedAncestor)
4319 inheritedMatrix = parentOfUntransformedAncestor->sceneTransform();
4320 QPointF mappedPoint = (inheritedMatrix * viewportTransform).map(untransformedAncestor->pos());
4323 QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y());
4324 if (untransformedAncestor->d_ptr->transformData)
4325 matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix);
4328 for (
int i = 0; i < parents.size(); ++i) {
4329 const QGraphicsItem *parent = parents.at(i);
4330 parent->d_ptr->combineTransformFromParent(&matrix);
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353QTransform QGraphicsItem::itemTransform(
const QGraphicsItem *other,
bool *ok)
const
4356 if (other ==
nullptr) {
4357 qWarning(
"QGraphicsItem::itemTransform: null pointer passed");
4358 return QTransform();
4360 if (other ==
this) {
4363 return QTransform();
4366 QGraphicsItem *parent = d_ptr->parent;
4367 const QGraphicsItem *otherParent = other->d_ptr->parent;
4370 if (parent == other) {
4374 d_ptr->combineTransformFromParent(&x);
4379 if (otherParent ==
this) {
4380 const QPointF &otherPos = other->d_ptr->pos;
4381 if (other->d_ptr->transformData) {
4382 QTransform otherToParent;
4383 other->d_ptr->combineTransformFromParent(&otherToParent);
4384 return otherToParent.inverted(ok);
4388 return QTransform::fromTranslate(-otherPos.x(), -otherPos.y());
4392 if (parent == otherParent) {
4394 const QPointF &itemPos = d_ptr->pos;
4395 const QPointF &otherPos = other->d_ptr->pos;
4396 if (!d_ptr->transformData && !other->d_ptr->transformData) {
4397 QPointF delta = itemPos - otherPos;
4400 return QTransform::fromTranslate(delta.x(), delta.y());
4403 QTransform itemToParent;
4404 d_ptr->combineTransformFromParent(&itemToParent);
4405 QTransform otherToParent;
4406 other->d_ptr->combineTransformFromParent(&otherToParent);
4407 return itemToParent * otherToParent.inverted(ok);
4412 const QGraphicsItem *commonAncestor = commonAncestorItem(other);
4413 if (!commonAncestor) {
4414 d_ptr->ensureSceneTransform();
4415 other->d_ptr->ensureSceneTransform();
4416 return d_ptr->sceneTransform * other->d_ptr->sceneTransform.inverted(ok);
4421 bool cousins = other != commonAncestor &&
this != commonAncestor;
4424 QTransform thisToScene = itemTransform(commonAncestor, &good);
4425 QTransform otherToScene(Qt::Uninitialized);
4427 otherToScene = other->itemTransform(commonAncestor, &good);
4431 return QTransform();
4433 return thisToScene * otherToScene.inverted(ok);
4437 bool parentOfOther = isAncestorOf(other);
4438 const QGraphicsItem *child = parentOfOther ? other :
this;
4439 const QGraphicsItem *root = parentOfOther ?
this : other;
4442 const QGraphicsItem *p = child;
4444 p->d_ptr.data()->combineTransformToParent(&x);
4445 }
while ((p = p->d_ptr->parent) && p != root);
4447 return x.inverted(ok);
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474void QGraphicsItem::setTransform(
const QTransform &matrix,
bool combine)
4476 if (!d_ptr->transformData)
4477 d_ptr->transformData =
new QGraphicsItemPrivate::TransformData;
4479 QTransform newTransform(combine ? matrix * d_ptr->transformData->transform : matrix);
4480 if (d_ptr->transformData->transform == newTransform)
4484 if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) {
4485 d_ptr->setTransformHelper(newTransform);
4486 if (d_ptr->scenePosDescendants)
4487 d_ptr->sendScenePosChange();
4492 const QVariant newTransformVariant(itemChange(ItemTransformChange,
4493 QVariant::fromValue<QTransform>(newTransform)));
4494 newTransform = qvariant_cast<QTransform>(newTransformVariant);
4495 if (d_ptr->transformData->transform == newTransform)
4499 d_ptr->setTransformHelper(newTransform);
4502 itemChange(ItemTransformHasChanged, newTransformVariant);
4503 d_ptr->sendScenePosChange();
4507
4508
4509
4510
4511
4512
4513
4514
4515void QGraphicsItem::resetTransform()
4517 setTransform(QTransform(),
false);
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536void QGraphicsItem::advance(
int phase)
4542
4543
4544
4545
4546
4547
4548
4549qreal QGraphicsItem::zValue()
const
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568void QGraphicsItem::setZValue(qreal z)
4570 const QVariant newZVariant(itemChange(ItemZValueChange, z));
4571 qreal newZ = newZVariant.toReal();
4572 if (newZ == d_ptr->z)
4575 if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex) {
4577 d_ptr->scene->d_func()->index->itemChange(
this, ItemZValueChange, &newZ);
4582 d_ptr->parent->d_ptr->needSortChildren = 1;
4583 else if (d_ptr->scene)
4584 d_ptr->scene->d_func()->needSortTopLevelItems = 1;
4587 d_ptr->scene->d_func()->markDirty(
this, QRectF(),
true);
4589 itemChange(ItemZValueHasChanged, newZVariant);
4591 if (d_ptr->flags & ItemNegativeZStacksBehindParent)
4592 setFlag(QGraphicsItem::ItemStacksBehindParent, z < qreal(0.0));
4594 if (d_ptr->isObject)
4595 emit
static_cast<QGraphicsObject *>(
this)->zChanged();
4599
4600
4601
4602
4603
4604
4605
4606
4607void QGraphicsItemPrivate::ensureSequentialSiblingIndex()
4609 if (!sequentialOrdering) {
4610 std::sort(children.begin(), children.end(), insertionOrder);
4611 sequentialOrdering = 1;
4612 needSortChildren = 1;
4614 if (holesInSiblingIndex) {
4615 holesInSiblingIndex = 0;
4616 for (
int i = 0; i < children.size(); ++i)
4617 children[i]->d_ptr->siblingIndex = i;
4622
4623
4624inline void QGraphicsItemPrivate::sendScenePosChange()
4628 if (flags & QGraphicsItem::ItemSendsScenePositionChanges)
4629 q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos());
4630 if (scenePosDescendants) {
4631 for (QGraphicsItem *item : std::as_const(scene->d_func()->scenePosItems)) {
4632 if (q->isAncestorOf(item))
4633 item->itemChange(QGraphicsItem::ItemScenePositionHasChanged, item->scenePos());
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659void QGraphicsItem::stackBefore(
const QGraphicsItem *sibling)
4661 if (sibling ==
this)
4663 if (!sibling || d_ptr->parent != sibling->parentItem()) {
4664 qWarning(
"QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
4667 QList<QGraphicsItem *> *siblings = d_ptr->parent
4668 ? &d_ptr->parent->d_ptr->children
4669 : (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems :
nullptr);
4671 qWarning(
"QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
4678 d_ptr->parent->d_ptr->ensureSequentialSiblingIndex();
4680 d_ptr->scene->d_func()->ensureSequentialTopLevelSiblingIndexes();
4683 int siblingIndex = sibling->d_ptr->siblingIndex;
4684 int myIndex = d_ptr->siblingIndex;
4685 if (myIndex >= siblingIndex) {
4686 siblings->move(myIndex, siblingIndex);
4688 for (
int i = 0; i < siblings->size(); ++i) {
4689 int &index = siblings->at(i)->d_ptr->siblingIndex;
4690 if (i != siblingIndex && index >= siblingIndex && index <= myIndex)
4693 d_ptr->siblingIndex = siblingIndex;
4694 for (
int i = 0; i < siblings->size(); ++i) {
4695 int &index = siblings->at(i)->d_ptr->siblingIndex;
4696 if (i != siblingIndex && index >= siblingIndex && index <= myIndex)
4697 siblings->at(i)->d_ptr->siblingOrderChange();
4699 d_ptr->siblingOrderChange();
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720QRectF QGraphicsItem::childrenBoundingRect()
const
4722 if (!d_ptr->dirtyChildrenBoundingRect)
4723 return d_ptr->childrenBoundingRect;
4725 d_ptr->childrenBoundingRect = QRectF();
4726 d_ptr->childrenBoundingRectHelper(
nullptr, &d_ptr->childrenBoundingRect,
nullptr);
4727 d_ptr->dirtyChildrenBoundingRect = 0;
4728 return d_ptr->childrenBoundingRect;
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4765
4766
4767
4768
4769
4770QRectF QGraphicsItem::sceneBoundingRect()
const
4775 const QGraphicsItem *parentItem =
this;
4776 const QGraphicsItemPrivate *itemd;
4778 itemd = parentItem->d_ptr.data();
4779 if (itemd->transformData)
4781 offset += itemd->pos;
4782 }
while ((parentItem = itemd->parent));
4784 QRectF br = boundingRect();
4785 br.translate(offset);
4788 if (parentItem->d_ptr->hasTranslateOnlySceneTransform()) {
4789 br.translate(parentItem->d_ptr->sceneTransform.dx(), parentItem->d_ptr->sceneTransform.dy());
4792 return parentItem->d_ptr->sceneTransform.mapRect(br);
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817QPainterPath QGraphicsItem::shape()
const
4820 path.addRect(boundingRect());
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834bool QGraphicsItem::isClipped()
const
4836 Q_D(
const QGraphicsItem);
4837 return (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
4838 || (d->flags & QGraphicsItem::ItemClipsToShape);
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861QPainterPath QGraphicsItem::clipPath()
const
4863 Q_D(
const QGraphicsItem);
4865 return QPainterPath();
4867 const QRectF thisBoundingRect(boundingRect());
4868 if (thisBoundingRect.isEmpty())
4869 return QPainterPath();
4873 clip.addRect(thisBoundingRect);
4875 if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {
4876 const QGraphicsItem *parent =
this;
4877 const QGraphicsItem *lastParent =
this;
4880 while ((parent = parent->d_ptr->parent)) {
4881 if (parent->d_ptr->flags & ItemClipsChildrenToShape) {
4883 clip = lastParent->itemTransform(parent).map(clip);
4884 clip = clip.intersected(parent->shape());
4887 lastParent = parent;
4890 if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren))
4894 if (lastParent !=
this) {
4897 clip = lastParent->itemTransform(
this).map(clip);
4901 if (d->flags & ItemClipsToShape)
4902 clip = clip.intersected(shape());
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919bool QGraphicsItem::contains(
const QPointF &point)
const
4921 return isClipped() ? clipPath().contains(point) : shape().contains(point);
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953bool QGraphicsItem::collidesWithItem(
const QGraphicsItem *other, Qt::ItemSelectionMode mode)
const
4961 bool clips = (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);
4962 bool otherClips = (other->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);
4963 if (clips || otherClips) {
4964 const QGraphicsItem *closestClipper = isAncestorOf(other) ?
this : parentItem();
4965 while (closestClipper && !(closestClipper->flags() & ItemClipsChildrenToShape))
4966 closestClipper = closestClipper->parentItem();
4967 const QGraphicsItem *otherClosestClipper = other->isAncestorOf(
this) ? other : other->parentItem();
4968 while (otherClosestClipper && !(otherClosestClipper->flags() & ItemClipsChildrenToShape))
4969 otherClosestClipper = otherClosestClipper->parentItem();
4970 if (closestClipper == otherClosestClipper) {
4971 d_ptr->localCollisionHack = 1;
4972 bool res = collidesWithPath(mapFromItem(other, other->shape()), mode);
4973 d_ptr->localCollisionHack = 0;
4978 QPainterPath otherShape = other->isClipped() ? other->clipPath() : other->shape();
4979 return collidesWithPath(mapFromItem(other, otherShape), mode);
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996bool QGraphicsItem::collidesWithPath(
const QPainterPath &path, Qt::ItemSelectionMode mode)
const
4998 if (path.isEmpty()) {
5003 QRectF rectA(boundingRect());
5004 _q_adjustRect(&rectA);
5005 QRectF rectB(path.controlPointRect());
5006 _q_adjustRect(&rectB);
5007 if (!rectA.intersects(rectB)) {
5014 QPainterPath thisShape;
5015 if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape)
5016 thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape();
5018 thisShape.addRect(rectA);
5020 if (thisShape == QPainterPath()) {
5026 if (mode == Qt::IntersectsItemShape || mode == Qt::IntersectsItemBoundingRect)
5027 return path.intersects(thisShape);
5028 return path.contains(thisShape);
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041QList<QGraphicsItem *> QGraphicsItem::collidingItems(Qt::ItemSelectionMode mode)
const
5044 return d_ptr->scene->collidingItems(
this, mode);
5045 return QList<QGraphicsItem *>();
5049
5050
5051
5052
5053
5054
5055
5056
5057
5059 const QGraphicsItem *other,
5062 return other->mapToItem(item, other->opaqueArea()).contains(rect);
5066
5067
5068
5069
5070
5071
5072
5073
5074bool QGraphicsItem::isObscured(
const QRectF &rect)
const
5076 Q_D(
const QGraphicsItem);
5080 QRectF br = boundingRect();
5081 QRectF testRect = rect.isNull() ? br : rect;
5083 const auto items = d->scene->items(mapToScene(br), Qt::IntersectsItemBoundingRect);
5084 for (QGraphicsItem *item : items) {
5087 if (qt_QGraphicsItem_isObscured(
this, item, testRect))
5094
5095
5096
5097
5098
5099
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114bool QGraphicsItem::isObscuredBy(
const QGraphicsItem *item)
const
5118 return qt_closestItemFirst(item,
this)
5119 && qt_QGraphicsItem_isObscured(
this, item, boundingRect());
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135QPainterPath QGraphicsItem::opaqueArea()
const
5137 return QPainterPath();
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163QRegion QGraphicsItem::boundingRegion(
const QTransform &itemToDeviceTransform)
const
5173 qreal granularity = boundingRegionGranularity();
5174 QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect();
5175 _q_adjustRect(&deviceRect);
5176 if (granularity == 0.0)
5177 return QRegion(deviceRect);
5180 QSize bitmapSize(qMax(1,
int(deviceRect.width() * granularity) + pad * 2),
5181 qMax(1,
int(deviceRect.height() * granularity) + pad * 2));
5182 QImage mask(bitmapSize, QImage::Format_ARGB32_Premultiplied);
5185 p.setRenderHints(QPainter::Antialiasing);
5189 QPointF viewOrigo = itemToDeviceTransform.map(QPointF(0, 0));
5190 QPointF offset = viewOrigo - deviceRect.topLeft();
5191 p.scale(granularity, granularity);
5192 p.translate(offset);
5193 p.translate(pad, pad);
5194 p.setWorldTransform(itemToDeviceTransform,
true);
5195 p.translate(itemToDeviceTransform.inverted().map(QPointF(0, 0)));
5198 QStyleOptionGraphicsItem option;
5199 const_cast<QGraphicsItem *>(
this)->paint(&p, &option,
nullptr);
5203 QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);
5205 QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));
5206 for (
const QRect &rect : QRegion(colorMask)) {
5207 QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));
5208 r += xrect.adjusted(-1, -1, 1, 1) & deviceRect;
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226qreal QGraphicsItem::boundingRegionGranularity()
const
5228 return d_ptr->hasBoundingRegionGranularity
5229 ? qvariant_cast<qreal>(d_ptr->extra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity))
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252void QGraphicsItem::setBoundingRegionGranularity(qreal granularity)
5254 if (granularity < 0.0 || granularity > 1.0) {
5255 qWarning(
"QGraphicsItem::setBoundingRegionGranularity: invalid granularity %g", granularity);
5258 if (granularity == 0.0) {
5259 d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity);
5260 d_ptr->hasBoundingRegionGranularity = 0;
5263 d_ptr->hasBoundingRegionGranularity = 1;
5264 d_ptr->setExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity,
5265 QVariant::fromValue<qreal>(granularity));
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5313
5314
5315
5316bool QGraphicsItemPrivate::discardUpdateRequest(
bool ignoreVisibleBit,
bool ignoreDirtyBit,
5317 bool ignoreOpacity)
const
5322 || (!visible && !ignoreVisibleBit && !
this->ignoreVisible)
5323 || (!ignoreDirtyBit && fullUpdatePending)
5324 || (!ignoreOpacity && !
this->ignoreOpacity && childrenCombineOpacity() && isFullyTransparent());
5328
5329
5330int QGraphicsItemPrivate::depth()
const
5332 if (itemDepth == -1)
5333 const_cast<QGraphicsItemPrivate *>(
this)->resolveDepth();
5339
5340
5341#if QT_CONFIG(graphicseffect)
5342void QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively()
5344 QGraphicsItemPrivate *itemPrivate =
this;
5346 if (itemPrivate->graphicsEffect) {
5347 itemPrivate->notifyInvalidated = 1;
5349 if (!itemPrivate->updateDueToGraphicsEffect)
5350 static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
5352 }
while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() :
nullptr));
5355void QGraphicsItemPrivate::invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::InvalidateReason reason)
5357 if (!mayHaveChildWithGraphicsEffect)
5360 for (
int i = 0; i < children.size(); ++i) {
5361 QGraphicsItemPrivate *childPrivate = children.at(i)->d_ptr.data();
5362 if (reason == OpacityChanged && (childPrivate->flags & QGraphicsItem::ItemIgnoresParentOpacity))
5364 if (childPrivate->graphicsEffect) {
5365 childPrivate->notifyInvalidated = 1;
5366 static_cast<QGraphicsItemEffectSourcePrivate *>(childPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
5369 childPrivate->invalidateChildGraphicsEffectsRecursively(reason);
5375
5376
5377void QGraphicsItemPrivate::invalidateDepthRecursively()
5379 if (itemDepth == -1)
5383 for (
int i = 0; i < children.size(); ++i)
5384 children.at(i)->d_ptr->invalidateDepthRecursively();
5388
5389
5390
5391
5392void QGraphicsItemPrivate::resolveDepth()
5397 if (parent->d_ptr->itemDepth == -1)
5398 parent->d_ptr->resolveDepth();
5399 itemDepth = parent->d_ptr->itemDepth + 1;
5404
5405
5406
5407
5408
5409void QGraphicsItemPrivate::addChild(QGraphicsItem *child)
5413 ensureSequentialSiblingIndex();
5414 needSortChildren = 1;
5415 child->d_ptr->siblingIndex = children.size();
5416 children.append(child);
5418 emit
static_cast<QGraphicsObject *>(q_ptr)->childrenChanged();
5422
5423
5424
5425
5426
5427void QGraphicsItemPrivate::removeChild(QGraphicsItem *child)
5431 if (!holesInSiblingIndex)
5432 holesInSiblingIndex = child->d_ptr->siblingIndex != children.size() - 1;
5433 if (sequentialOrdering && !holesInSiblingIndex)
5434 children.removeAt(child->d_ptr->siblingIndex);
5436 children.removeOne(child);
5440 child->d_ptr->siblingIndex = -1;
5442 emit
static_cast<QGraphicsObject *>(q_ptr)->childrenChanged();
5446
5447
5448QGraphicsItemCache *QGraphicsItemPrivate::maybeExtraItemCache()
const
5450 return (QGraphicsItemCache *)qvariant_cast<
void *>(extra(ExtraCacheData));
5454
5455
5456QGraphicsItemCache *QGraphicsItemPrivate::extraItemCache()
const
5458 QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<
void *>(extra(ExtraCacheData));
5460 QGraphicsItemPrivate *that =
const_cast<QGraphicsItemPrivate *>(
this);
5461 c =
new QGraphicsItemCache;
5462 that->setExtra(ExtraCacheData, QVariant::fromValue<
void *>(c));
5468
5469
5470void QGraphicsItemPrivate::removeExtraItemCache()
5472 QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<
void *>(extra(ExtraCacheData));
5477 unsetExtra(ExtraCacheData);
5480void QGraphicsItemPrivate::updatePaintedViewBoundingRects(
bool updateChildren)
5485 for (
int i = 0; i < scene->d_func()->views.size(); ++i) {
5486 QGraphicsViewPrivate *viewPrivate = scene->d_func()->views.at(i)->d_func();
5487 QRect rect = paintedViewBoundingRects.value(viewPrivate->viewport);
5488 rect.translate(viewPrivate->dirtyScrollOffset);
5489 viewPrivate->updateRect(rect);
5492 if (updateChildren) {
5493 for (
int i = 0; i < children.size(); ++i)
5494 children.at(i)->d_ptr->updatePaintedViewBoundingRects(
true);
5503void QGraphicsItemPrivate::ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem)
5505 Q_ASSERT(topMostDirtyItem);
5507 if (dirtySceneTransform)
5508 *topMostDirtyItem = q_ptr;
5511 parent->d_ptr->ensureSceneTransformRecursive(topMostDirtyItem);
5513 if (*topMostDirtyItem == q_ptr) {
5514 if (!dirtySceneTransform)
5516 *topMostDirtyItem =
nullptr;
5517 }
else if (*topMostDirtyItem) {
5525 invalidateChildrenSceneTransform();
5528 updateSceneTransformFromParent();
5529 Q_ASSERT(!dirtySceneTransform);
5533
5534
5535void QGraphicsItemPrivate::setSubFocus(QGraphicsItem *rootItem, QGraphicsItem *stopItem)
5539 QGraphicsItem *parent = rootItem ? rootItem : q_ptr;
5540 if (parent->panel() != q_ptr->panel())
5545 if (parent != q_ptr && parent->d_ptr->subFocusItem) {
5546 if (parent->d_ptr->subFocusItem == q_ptr)
5548 parent->d_ptr->subFocusItem->d_ptr->clearSubFocus(
nullptr, stopItem);
5550 parent->d_ptr->subFocusItem = q_ptr;
5551 parent->d_ptr->subFocusItemChange();
5552 }
while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (visible || !parent->d_ptr->visible));
5554 if (scene && !scene->isActive()) {
5555 scene->d_func()->passiveFocusItem = subFocusItem;
5556 scene->d_func()->lastFocusItem = subFocusItem;
5561
5562
5563void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem, QGraphicsItem *stopItem)
5566 QGraphicsItem *parent = rootItem ? rootItem : q_ptr;
5568 if (parent->d_ptr->subFocusItem != q_ptr)
5570 parent->d_ptr->subFocusItem =
nullptr;
5571 if (parent != stopItem && !parent->isAncestorOf(stopItem))
5572 parent->d_ptr->subFocusItemChange();
5573 }
while (!parent->isPanel() && (parent = parent->d_ptr->parent));
5577
5578
5579
5580
5581
5582void QGraphicsItemPrivate::resetFocusProxy()
5584 for (
int i = 0; i < focusProxyRefs.size(); ++i)
5585 *focusProxyRefs.at(i) =
nullptr;
5586 focusProxyRefs.clear();
5590
5591
5592
5593
5594
5595void QGraphicsItemPrivate::subFocusItemChange()
5600
5601
5602
5603
5604
5605void QGraphicsItemPrivate::focusScopeItemChange(
bool isSubFocusItem)
5607 Q_UNUSED(isSubFocusItem);
5611
5612
5613
5614
5615
5616void QGraphicsItemPrivate::siblingOrderChange()
5621
5622
5623
5624
5625bool QGraphicsItemPrivate::isProxyWidget()
const
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648void QGraphicsItem::update(
const QRectF &rect)
5650 if (rect.isEmpty() && !rect.isNull())
5654#if QT_CONFIG(graphicseffect)
5655 d_ptr->invalidateParentGraphicsEffectsRecursively();
5658 if (CacheMode(d_ptr->cacheMode) != NoCache) {
5660 QGraphicsItemCache *cache = d_ptr->extraItemCache();
5661 if (!cache->allExposed) {
5662 if (rect.isNull()) {
5663 cache->allExposed =
true;
5664 cache->exposed.clear();
5666 cache->exposed.append(rect);
5670 if (d_ptr->fullUpdatePending)
5675 d_ptr->scene->d_func()->markDirty(
this, rect);
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705void QGraphicsItem::scroll(qreal dx, qreal dy,
const QRectF &rect)
5708 if (dx == 0.0 && dy == 0.0)
5726 if (d->cacheMode != QGraphicsItem::ItemCoordinateCache
5727 || !qFuzzyIsNull(dx -
int(dx)) || !qFuzzyIsNull(dy -
int(dy))) {
5732 QGraphicsItemCache *cache = d->extraItemCache();
5733 if (cache->allExposed || cache->fixedSize.isValid()) {
5740 QPixmap cachedPixmap;
5741 if (!QPixmapCache::find(cache->key, &cachedPixmap)) {
5746 QRect scrollRect = (rect.isNull() ? boundingRect() : rect).toAlignedRect();
5747 if (!scrollRect.intersects(cache->boundingRect))
5751 QPixmapCache::remove(cache->key);
5754 cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed);
5757 cache->key = QPixmapCache::insert(cachedPixmap);
5760 for (
int i = 0; i < cache->exposed.size(); ++i) {
5761 QRectF &e = cache->exposed[i];
5762 if (!rect.isNull() && !e.intersects(rect))
5764 e.translate(dx, dy);
5769 exposed.translate(cache->boundingRect.topLeft());
5770 for (
const QRect &exposedRect : exposed)
5771 cache->exposed += exposedRect;
5775 d->scene->d_func()->markDirty(
this, rect);
5779
5780
5781
5782
5783
5784
5787
5788
5789
5790
5791
5792
5793
5794
5795QPointF QGraphicsItem::mapToItem(
const QGraphicsItem *item,
const QPointF &point)
const
5798 return itemTransform(item).map(point);
5799 return mapToScene(point);
5803
5804
5805
5806
5807
5808
5811
5812
5813
5814
5815
5816
5817
5818QPointF QGraphicsItem::mapToParent(
const QPointF &point)
const
5821 if (!d_ptr->transformData)
5822 return point + d_ptr->pos;
5823 return d_ptr->transformToParent().map(point);
5827
5828
5829
5830
5831
5832
5835
5836
5837
5838
5839
5840
5841QPointF QGraphicsItem::mapToScene(
const QPointF &point)
const
5843 if (d_ptr->hasTranslateOnlySceneTransform())
5844 return QPointF(point.x() + d_ptr->sceneTransform.dx(), point.y() + d_ptr->sceneTransform.dy());
5845 return d_ptr->sceneTransform.map(point);
5849
5850
5851
5852
5853
5854
5857
5858
5859
5860
5861
5862
5863
5864
5865QPolygonF QGraphicsItem::mapToItem(
const QGraphicsItem *item,
const QRectF &rect)
const
5868 return itemTransform(item).map(rect);
5869 return mapToScene(rect);
5873
5874
5875
5876
5877
5880
5881
5882
5883
5884
5885
5886
5887
5888QPolygonF QGraphicsItem::mapToParent(
const QRectF &rect)
const
5891 if (!d_ptr->transformData)
5892 return rect.translated(d_ptr->pos);
5893 return d_ptr->transformToParent().map(rect);
5897
5898
5899
5900
5901
5904
5905
5906
5907
5908
5909
5910QPolygonF QGraphicsItem::mapToScene(
const QRectF &rect)
const
5912 if (d_ptr->hasTranslateOnlySceneTransform())
5913 return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
5914 return d_ptr->sceneTransform.map(rect);
5918
5919
5920
5921
5922
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936QRectF QGraphicsItem::mapRectToItem(
const QGraphicsItem *item,
const QRectF &rect)
const
5939 return itemTransform(item).mapRect(rect);
5940 return mapRectToScene(rect);
5944
5945
5946
5947
5948
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960QRectF QGraphicsItem::mapRectToParent(
const QRectF &rect)
const
5963 if (!d_ptr->transformData)
5964 return rect.translated(d_ptr->pos);
5965 return d_ptr->transformToParent().mapRect(rect);
5969
5970
5971
5972
5973
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985QRectF QGraphicsItem::mapRectToScene(
const QRectF &rect)
const
5987 if (d_ptr->hasTranslateOnlySceneTransform())
5988 return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
5989 return d_ptr->sceneTransform.mapRect(rect);
5993
5994
5995
5996
5997
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011QRectF QGraphicsItem::mapRectFromItem(
const QGraphicsItem *item,
const QRectF &rect)
const
6014 return item->itemTransform(
this).mapRect(rect);
6015 return mapRectFromScene(rect);
6019
6020
6021
6022
6023
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036QRectF QGraphicsItem::mapRectFromParent(
const QRectF &rect)
const
6039 if (!d_ptr->transformData)
6040 return rect.translated(-d_ptr->pos);
6041 return d_ptr->transformToParent().inverted().mapRect(rect);
6045
6046
6047
6048
6049
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061QRectF QGraphicsItem::mapRectFromScene(
const QRectF &rect)
const
6063 if (d_ptr->hasTranslateOnlySceneTransform())
6064 return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6065 return d_ptr->sceneTransform.inverted().mapRect(rect);
6069
6070
6071
6072
6073
6076
6077
6078
6079
6080
6081
6082
6083
6084QPolygonF QGraphicsItem::mapToItem(
const QGraphicsItem *item,
const QPolygonF &polygon)
const
6087 return itemTransform(item).map(polygon);
6088 return mapToScene(polygon);
6092
6093
6094
6095
6096
6097
6098
6099
6100QPolygonF QGraphicsItem::mapToParent(
const QPolygonF &polygon)
const
6103 if (!d_ptr->transformData)
6104 return polygon.translated(d_ptr->pos);
6105 return d_ptr->transformToParent().map(polygon);
6109
6110
6111
6112
6113
6114
6115QPolygonF QGraphicsItem::mapToScene(
const QPolygonF &polygon)
const
6117 if (d_ptr->hasTranslateOnlySceneTransform())
6118 return polygon.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6119 return d_ptr->sceneTransform.map(polygon);
6123
6124
6125
6126
6127
6128
6129
6130
6131QPainterPath QGraphicsItem::mapToItem(
const QGraphicsItem *item,
const QPainterPath &path)
const
6134 return itemTransform(item).map(path);
6135 return mapToScene(path);
6139
6140
6141
6142
6143
6144
6145
6146
6147QPainterPath QGraphicsItem::mapToParent(
const QPainterPath &path)
const
6150 if (!d_ptr->transformData)
6151 return path.translated(d_ptr->pos);
6152 return d_ptr->transformToParent().map(path);
6156
6157
6158
6159
6160
6161
6162QPainterPath QGraphicsItem::mapToScene(
const QPainterPath &path)
const
6164 if (d_ptr->hasTranslateOnlySceneTransform())
6165 return path.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6166 return d_ptr->sceneTransform.map(path);
6170
6171
6172
6173
6174
6175
6176
6177
6178QPointF QGraphicsItem::mapFromItem(
const QGraphicsItem *item,
const QPointF &point)
const
6181 return item->itemTransform(
this).map(point);
6182 return mapFromScene(point);
6186
6187
6188
6189
6190
6191
6194
6195
6196
6197
6198
6199
6200
6201QPointF QGraphicsItem::mapFromParent(
const QPointF &point)
const
6204 if (d_ptr->transformData)
6205 return d_ptr->transformToParent().inverted().map(point);
6206 return point - d_ptr->pos;
6210
6211
6212
6213
6214
6215
6218
6219
6220
6221
6222
6223
6224
6225QPointF QGraphicsItem::mapFromScene(
const QPointF &point)
const
6227 if (d_ptr->hasTranslateOnlySceneTransform())
6228 return QPointF(point.x() - d_ptr->sceneTransform.dx(), point.y() - d_ptr->sceneTransform.dy());
6229 return d_ptr->sceneTransform.inverted().map(point);
6233
6234
6235
6236
6237
6238
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250QPolygonF QGraphicsItem::mapFromItem(
const QGraphicsItem *item,
const QRectF &rect)
const
6253 return item->itemTransform(
this).map(rect);
6254 return mapFromScene(rect);
6258
6259
6260
6261
6262
6265
6266
6267
6268
6269
6270
6271
6272QPolygonF QGraphicsItem::mapFromParent(
const QRectF &rect)
const
6275 if (!d_ptr->transformData)
6276 return rect.translated(-d_ptr->pos);
6277 return d_ptr->transformToParent().inverted().map(rect);
6281
6282
6283
6284
6285
6288
6289
6290
6291
6292
6293
6294
6295QPolygonF QGraphicsItem::mapFromScene(
const QRectF &rect)
const
6297 if (d_ptr->hasTranslateOnlySceneTransform())
6298 return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6299 return d_ptr->sceneTransform.inverted().map(rect);
6303
6304
6305
6306
6307
6310
6311
6312
6313
6314
6315
6316
6317
6318QPolygonF QGraphicsItem::mapFromItem(
const QGraphicsItem *item,
const QPolygonF &polygon)
const
6321 return item->itemTransform(
this).map(polygon);
6322 return mapFromScene(polygon);
6326
6327
6328
6329
6330
6331
6332QPolygonF QGraphicsItem::mapFromParent(
const QPolygonF &polygon)
const
6335 if (!d_ptr->transformData)
6336 return polygon.translated(-d_ptr->pos);
6337 return d_ptr->transformToParent().inverted().map(polygon);
6341
6342
6343
6344
6345
6346
6347QPolygonF QGraphicsItem::mapFromScene(
const QPolygonF &polygon)
const
6349 if (d_ptr->hasTranslateOnlySceneTransform())
6350 return polygon.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6351 return d_ptr->sceneTransform.inverted().map(polygon);
6355
6356
6357
6358
6359
6360
6361
6362
6363QPainterPath QGraphicsItem::mapFromItem(
const QGraphicsItem *item,
const QPainterPath &path)
const
6366 return item->itemTransform(
this).map(path);
6367 return mapFromScene(path);
6371
6372
6373
6374
6375
6376
6377QPainterPath QGraphicsItem::mapFromParent(
const QPainterPath &path)
const
6380 if (!d_ptr->transformData)
6381 return path.translated(-d_ptr->pos);
6382 return d_ptr->transformToParent().inverted().map(path);
6386
6387
6388
6389
6390
6391
6392QPainterPath QGraphicsItem::mapFromScene(
const QPainterPath &path)
const
6394 if (d_ptr->hasTranslateOnlySceneTransform())
6395 return path.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6396 return d_ptr->sceneTransform.inverted().map(path);
6400
6401
6402
6403
6404
6405bool QGraphicsItem::isAncestorOf(
const QGraphicsItem *child)
const
6407 if (!child || child ==
this)
6409 if (child->d_ptr->depth() < d_ptr->depth())
6411 const QGraphicsItem *ancestor = child;
6412 while ((ancestor = ancestor->d_ptr->parent)) {
6413 if (ancestor ==
this)
6420
6421
6422
6423
6424
6425
6426
6427QGraphicsItem *QGraphicsItem::commonAncestorItem(
const QGraphicsItem *other)
const
6432 return const_cast<QGraphicsItem *>(
this);
6433 const QGraphicsItem *thisw =
this;
6434 const QGraphicsItem *otherw = other;
6435 int thisDepth = d_ptr->depth();
6436 int otherDepth = other->d_ptr->depth();
6437 while (thisDepth > otherDepth) {
6438 thisw = thisw->d_ptr->parent;
6441 while (otherDepth > thisDepth) {
6442 otherw = otherw->d_ptr->parent;
6445 while (thisw && thisw != otherw) {
6446 thisw = thisw->d_ptr->parent;
6447 otherw = otherw->d_ptr->parent;
6449 return const_cast<QGraphicsItem *>(thisw);
6453
6454
6455
6456
6457
6458
6459bool QGraphicsItem::isUnderMouse()
const
6461 Q_D(
const QGraphicsItem);
6465 QPoint cursorPos = QCursor::pos();
6466 const auto views = d->scene->views();
6467 for (QGraphicsView *view : views) {
6468 if (contains(mapFromScene(view->mapToScene(view->mapFromGlobal(cursorPos)))))
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487QVariant QGraphicsItem::data(
int key)
const
6489 QGraphicsItemCustomDataStore *store = qt_dataStore();
6490 if (!store->data.contains(
this))
6492 return store->data.value(
this).value(key);
6496
6497
6498
6499
6500
6501
6502
6503
6504void QGraphicsItem::setData(
int key,
const QVariant &value)
6506 qt_dataStore()->data[
this][key] = value;
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541int QGraphicsItem::type()
const
6543 return (
int)UserType;
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem)
6567 if (!d_ptr->scene) {
6568 qWarning(
"QGraphicsItem::installSceneEventFilter: event filters can only be installed"
6569 " on items in a scene.");
6572 if (d_ptr->scene != filterItem->scene()) {
6573 qWarning(
"QGraphicsItem::installSceneEventFilter: event filters can only be installed"
6574 " on items in the same scene.");
6577 d_ptr->scene->d_func()->installSceneEventFilter(
this, filterItem);
6581
6582
6583
6584
6585void QGraphicsItem::removeSceneEventFilter(QGraphicsItem *filterItem)
6587 if (!d_ptr->scene || d_ptr->scene != filterItem->scene())
6589 d_ptr->scene->d_func()->removeSceneEventFilter(
this, filterItem);
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608bool QGraphicsItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629bool QGraphicsItem::sceneEvent(QEvent *event)
6631 if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents) {
6632 if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave
6633 || event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) {
6639 QGraphicsItem *handler =
this;
6641 handler = handler->d_ptr->parent;
6643 }
while (handler->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents);
6647 d_ptr->remapItemPos(event, handler);
6648 handler->sceneEvent(event);
6652 if (event->type() == QEvent::FocusOut) {
6653 focusOutEvent(
static_cast<QFocusEvent *>(event));
6657 if (!d_ptr->visible) {
6662 switch (event->type()) {
6663 case QEvent::FocusIn:
6664 focusInEvent(
static_cast<QFocusEvent *>(event));
6666 case QEvent::GraphicsSceneContextMenu:
6667 contextMenuEvent(
static_cast<QGraphicsSceneContextMenuEvent *>(event));
6669 case QEvent::GraphicsSceneDragEnter:
6670 dragEnterEvent(
static_cast<QGraphicsSceneDragDropEvent *>(event));
6672 case QEvent::GraphicsSceneDragMove:
6673 dragMoveEvent(
static_cast<QGraphicsSceneDragDropEvent *>(event));
6675 case QEvent::GraphicsSceneDragLeave:
6676 dragLeaveEvent(
static_cast<QGraphicsSceneDragDropEvent *>(event));
6678 case QEvent::GraphicsSceneDrop:
6679 dropEvent(
static_cast<QGraphicsSceneDragDropEvent *>(event));
6681 case QEvent::GraphicsSceneHoverEnter:
6682 hoverEnterEvent(
static_cast<QGraphicsSceneHoverEvent *>(event));
6684 case QEvent::GraphicsSceneHoverMove:
6685 hoverMoveEvent(
static_cast<QGraphicsSceneHoverEvent *>(event));
6687 case QEvent::GraphicsSceneHoverLeave:
6688 hoverLeaveEvent(
static_cast<QGraphicsSceneHoverEvent *>(event));
6690 case QEvent::GraphicsSceneMouseMove:
6691 mouseMoveEvent(
static_cast<QGraphicsSceneMouseEvent *>(event));
6693 case QEvent::GraphicsSceneMousePress:
6694 mousePressEvent(
static_cast<QGraphicsSceneMouseEvent *>(event));
6696 case QEvent::GraphicsSceneMouseRelease:
6697 mouseReleaseEvent(
static_cast<QGraphicsSceneMouseEvent *>(event));
6699 case QEvent::GraphicsSceneMouseDoubleClick:
6700 mouseDoubleClickEvent(
static_cast<QGraphicsSceneMouseEvent *>(event));
6702 case QEvent::GraphicsSceneWheel:
6703 wheelEvent(
static_cast<QGraphicsSceneWheelEvent *>(event));
6705 case QEvent::KeyPress: {
6706 QKeyEvent *k =
static_cast<QKeyEvent *>(event);
6707 if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
6708 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
6710 if (k->key() == Qt::Key_Backtab
6711 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
6712 if (d_ptr->isWidget) {
6713 res =
static_cast<QGraphicsWidget *>(
this)->focusNextPrevChild(
false);
6714 }
else if (d_ptr->scene) {
6715 res = d_ptr->scene->focusNextPrevChild(
false);
6717 }
else if (k->key() == Qt::Key_Tab) {
6718 if (d_ptr->isWidget) {
6719 res =
static_cast<QGraphicsWidget *>(
this)->focusNextPrevChild(
true);
6720 }
else if (d_ptr->scene) {
6721 res = d_ptr->scene->focusNextPrevChild(
true);
6729 keyPressEvent(
static_cast<QKeyEvent *>(event));
6732 case QEvent::KeyRelease:
6733 keyReleaseEvent(
static_cast<QKeyEvent *>(event));
6735 case QEvent::InputMethod:
6736 inputMethodEvent(
static_cast<QInputMethodEvent *>(event));
6738 case QEvent::WindowActivate:
6739 case QEvent::WindowDeactivate:
6742 for (
int i = 0; i < d_ptr->children.size(); ++i) {
6743 QGraphicsItem *child = d_ptr->children.at(i);
6744 if (child->isVisible() && !child->isPanel()) {
6745 if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents))
6746 d_ptr->scene->sendEvent(child, event);
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776void QGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804void QGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
6808 if (d->isProxyWidget())
6809 static_cast<QGraphicsProxyWidget*>(
this)->dragEnterEvent(event);
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828void QGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
6832 if (d->isProxyWidget())
6833 static_cast<QGraphicsProxyWidget*>(
this)->dragLeaveEvent(event);
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855void QGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
6859 if (d->isProxyWidget())
6860 static_cast<QGraphicsProxyWidget*>(
this)->dragMoveEvent(event);
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877void QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event)
6881 if (d->isProxyWidget())
6882 static_cast<QGraphicsProxyWidget*>(
this)->dropEvent(event);
6886
6887
6888
6889
6890
6891
6892void QGraphicsItem::focusInEvent(QFocusEvent *event)
6899
6900
6901
6902
6903
6904void QGraphicsItem::focusOutEvent(QFocusEvent *event)
6911
6912
6913
6914
6915
6916
6917
6918
6919void QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
6926
6927
6928
6929
6930
6931
6932
6933void QGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
6939
6940
6941
6942
6943
6944
6945
6946
6947void QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965void QGraphicsItem::keyPressEvent(QKeyEvent *event)
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982void QGraphicsItem::keyReleaseEvent(QKeyEvent *event)
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
7022 if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
7023 bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
7025 if (!d_ptr->selected) {
7026 if (QGraphicsScene *scene = d_ptr->scene) {
7027 ++scene->d_func()->selectionChanging;
7028 scene->clearSelection();
7029 --scene->d_func()->selectionChanging;
7034 }
else if (!(flags() & ItemIsMovable)) {
7037 if (d_ptr->isWidget) {
7039 QGraphicsWidget *w =
static_cast<QGraphicsWidget *>(
this);
7040 if ((w->windowFlags() & Qt::Popup) == Qt::Popup) {
7042 if (!w->rect().contains(event->pos()))
7050 const QGraphicsItem *parent = item->parentItem();
7051 return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
7054bool QGraphicsItemPrivate::movableAncestorIsSelected(
const QGraphicsItem *item)
7056 const QGraphicsItem *parent = item->d_ptr->parent;
7057 return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
7083 if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {
7085 QList<QGraphicsItem *> selectedItems;
7086 QHash<QGraphicsItem *, QPointF> initialPositions;
7088 selectedItems = d_ptr->scene->selectedItems();
7089 initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;
7090 if (initialPositions.isEmpty()) {
7091 for (QGraphicsItem *item : std::as_const(selectedItems))
7092 initialPositions[item] = item->pos();
7093 initialPositions[
this] = pos();
7095 d_ptr->scene->d_func()->movingItemsInitialPositions = initialPositions;
7099 QGraphicsView *view =
nullptr;
7100 if (event->widget())
7101 view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget());
7105 bool movedMe =
false;
7106 while (i <= selectedItems.size()) {
7107 QGraphicsItem *item =
nullptr;
7108 if (i < selectedItems.size())
7109 item = selectedItems.at(i);
7122 if ((item->flags() & ItemIsMovable) && !QGraphicsItemPrivate::movableAncestorIsSelected(item)) {
7123 QPointF currentParentPos;
7124 QPointF buttonDownParentPos;
7125 if (view && (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorIgnoresTransformations)) {
7129 QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted();
7130 currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))));
7131 buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))));
7132 }
else if (view && (item->flags() & ItemIgnoresTransformations)) {
7137 QTransform itemTransform;
7138 if (item->d_ptr->transformData)
7139 itemTransform = item->d_ptr->transformData->computedFullTransform();
7140 itemTransform.translate(item->d_ptr->pos.x(), item->d_ptr->pos.y());
7141 QTransform viewToParentTransform = itemTransform
7142 * (item->sceneTransform() * view->viewportTransform()).inverted();
7143 currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos())));
7144 buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton))));
7147 currentParentPos = item->mapToParent(item->mapFromScene(event->scenePos()));
7148 buttonDownParentPos = item->mapToParent(item->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
7151 item->setPos(initialPositions.value(item) + currentParentPos - buttonDownParentPos);
7153 if (item->flags() & ItemIsSelectable)
7154 item->setSelected(
true);
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
7185 if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
7186 bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
7187 if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) {
7190 setSelected(!isSelected());
7192 bool selectionChanged =
false;
7193 if (QGraphicsScene *scene = d_ptr->scene) {
7194 ++scene->d_func()->selectionChanging;
7198 if (d_ptr->selected) {
7199 scene->d_func()->selectedItems.remove(
this);
7200 for (QGraphicsItem *item : std::as_const(scene->d_func()->selectedItems)) {
7201 if (item->isSelected()) {
7202 selectionChanged =
true;
7207 scene->clearSelection();
7208 if (d_ptr->selected)
7209 scene->d_func()->selectedItems.insert(
this);
7210 --scene->d_func()->selectionChanging;
7211 if (selectionChanged)
7212 emit d_ptr->scene->selectionChanged();
7218 if (d_ptr->scene && !event->buttons())
7219 d_ptr->scene->d_func()->movingItemsInitialPositions.clear();
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246void QGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
7248 mousePressEvent(event);
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265void QGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent *event)
7271
7272
7273
7274
7275
7276
7277void QGraphicsItem::inputMethodEvent(QInputMethodEvent *event)
7283
7284
7285
7286
7287
7288
7289
7290
7291QVariant QGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query)
const
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311Qt::InputMethodHints QGraphicsItem::inputMethodHints()
const
7313 Q_D(
const QGraphicsItem);
7318
7319
7320
7321
7322
7323
7324void QGraphicsItem::setInputMethodHints(Qt::InputMethodHints hints)
7330 d->scene->d_func()->updateInputMethodSensitivityInViews();
7331 QWidget *fw = QApplication::focusWidget();
7334 QGuiApplication::inputMethod()->update(Qt::ImHints);
7338
7339
7340
7341
7342
7343
7344void QGraphicsItem::updateMicroFocus()
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369QVariant QGraphicsItem::itemChange(GraphicsItemChange change,
const QVariant &value)
7376
7377
7378
7379
7380
7381bool QGraphicsItem::supportsExtension(Extension extension)
const
7383 Q_UNUSED(extension);
7388
7389
7390
7391
7392
7393void QGraphicsItem::setExtension(Extension extension,
const QVariant &variant)
7395 Q_UNUSED(extension);
7400
7401
7402
7403
7404
7405QVariant QGraphicsItem::extension(
const QVariant &variant)
const
7412
7413
7414
7415
7416
7417
7418void QGraphicsItem::addToIndex()
7420 if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren
7421 || d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren) {
7426 d_ptr->scene->d_func()->index->addItem(
this);
7430
7431
7432
7433
7434
7435
7436void QGraphicsItem::removeFromIndex()
7438 if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren
7439 || d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren) {
7444 d_ptr->scene->d_func()->index->removeItem(
this);
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460void QGraphicsItem::prepareGeometryChange()
7462 if (d_ptr->inDestructor)
7465 d_ptr->scene->d_func()->dirtyGrowingItemsBoundingRect =
true;
7466 d_ptr->geometryChanged = 1;
7467 d_ptr->paintedViewBoundingRectsNeedRepaint = 1;
7468 d_ptr->notifyBoundingRectChanged = !d_ptr->inSetPosHelper;
7470 QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func();
7471 scenePrivate->index->prepareBoundingRectChange(
this);
7472 scenePrivate->markDirty(
this, QRectF(),
true,
false,
7480 if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex)
7481 || scenePrivate->views.isEmpty()) {
7482 if (d_ptr->hasTranslateOnlySceneTransform()) {
7483 d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(),
7484 d_ptr->sceneTransform.dy()));
7486 d_ptr->scene->update(d_ptr->sceneTransform.mapRect(boundingRect()));
7491 d_ptr->markParentDirty(
true);
7495
7496
7497
7498
7499void Q_WIDGETS_EXPORT qt_graphicsItem_highlightSelected(
7500 QGraphicsItem *item, QPainter *painter,
const QStyleOptionGraphicsItem *option)
7502 const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
7503 if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
7506 const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
7507 if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))
7511 switch (item->type()) {
7512 case QGraphicsEllipseItem::Type:
7513 itemPenWidth =
static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();
7515 case QGraphicsPathItem::Type:
7516 itemPenWidth =
static_cast<QGraphicsPathItem *>(item)->pen().widthF();
7518 case QGraphicsPolygonItem::Type:
7519 itemPenWidth =
static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();
7521 case QGraphicsRectItem::Type:
7522 itemPenWidth =
static_cast<QGraphicsRectItem *>(item)->pen().widthF();
7524 case QGraphicsSimpleTextItem::Type:
7525 itemPenWidth =
static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();
7527 case QGraphicsLineItem::Type:
7528 itemPenWidth =
static_cast<QGraphicsLineItem *>(item)->pen().widthF();
7533 const qreal pad = itemPenWidth / 2;
7535 const qreal penWidth = 0;
7537 const QColor fgcolor = option->palette.windowText().color();
7538 const QColor bgcolor(
7539 fgcolor.red() > 127 ? 0 : 255,
7540 fgcolor.green() > 127 ? 0 : 255,
7541 fgcolor.blue() > 127 ? 0 : 255);
7543 painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));
7544 painter->setBrush(Qt::NoBrush);
7545 painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
7547 painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));
7548 painter->setBrush(Qt::NoBrush);
7549 painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7581
7582
7583QGraphicsObject::QGraphicsObject(QGraphicsItem *parent)
7584 : QGraphicsItem(parent)
7586 QGraphicsItem::d_ptr->isObject =
true;
7590
7591
7592QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent)
7593 : QGraphicsItem(dd, parent)
7595 QGraphicsItem::d_ptr->isObject =
true;
7599
7600
7601QGraphicsObject::~QGraphicsObject()
7606
7607
7608bool QGraphicsObject::event(QEvent *ev)
7610 if (ev->type() == QEvent::StyleAnimationUpdate) {
7617 return QObject::event(ev);
7620#ifndef QT_NO_GESTURES
7622
7623
7624
7625
7626void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
7628 bool contains = QGraphicsItem::d_ptr->gestureContext.contains(gesture);
7629 QGraphicsItem::d_ptr->gestureContext.insert(gesture, flags);
7630 if (!contains && QGraphicsItem::d_ptr->scene)
7631 QGraphicsItem::d_ptr->scene->d_func()->grabGesture(
this, gesture);
7635
7636
7637
7638
7639void QGraphicsObject::ungrabGesture(Qt::GestureType gesture)
7641 if (QGraphicsItem::d_ptr->gestureContext.remove(gesture) && QGraphicsItem::d_ptr->scene)
7642 QGraphicsItem::d_ptr->scene->d_func()->ungrabGesture(
this, gesture);
7647
7648
7649
7650
7651
7652
7653void QGraphicsObject::updateMicroFocus()
7655 QGraphicsItem::updateMicroFocus();
7659
7660
7661
7662
7663qreal QGraphicsItemPrivate::width()
const
7669
7670
7671
7672
7673void QGraphicsItemPrivate::setWidth(qreal w)
7679
7680
7681
7682
7683void QGraphicsItemPrivate::resetWidth()
7688
7689
7690
7691
7692qreal QGraphicsItemPrivate::height()
const
7698
7699
7700
7701
7702void QGraphicsItemPrivate::setHeight(qreal h)
7708
7709
7710
7711
7712void QGraphicsItemPrivate::resetHeight()
7717
7718
7719
7720
7723
7724
7725
7726
7729
7730
7731
7732
7735
7736
7737
7738
7739
7740
7741
7742
7745
7746
7747
7748
7749
7752
7753
7754
7755
7756
7757
7760
7761
7762
7763
7766
7767
7768
7769
7770
7771
7772
7775
7776
7777
7778
7779
7780
7781
7784
7785
7786
7787
7788
7789
7792
7793
7794
7795
7796
7797
7798
7801
7802
7803
7804
7805
7806
7809
7810
7811
7812
7813
7814
7815
7818
7819
7820
7821
7822
7823
7826
7827
7828
7829
7830
7831
7834
7835
7836
7837
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7855
7856
7857
7858
7862
7863
7864
7865
7866
7867
7868
7869
7870
7873
7874
7875
7876
7877
7878
7881
7882
7883
7884
7885
7886
7887
7888
7889
7892
7893
7894
7895
7896
7897
7900
7901
7902
7903
7904
7905
7906
7907
7910
7911
7912
7915
7916
7917
7920
7921
7922
7923
7924
7925
7928
7929
7930
7931
7932
7933
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7957 Q_DECLARE_PUBLIC(QAbstractGraphicsShapeItem)
7968
7969
7970
7971QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QGraphicsItem *parent)
7972 : QGraphicsItem(*
new QAbstractGraphicsShapeItemPrivate, parent)
7977
7978
7979QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QAbstractGraphicsShapeItemPrivate &dd, QGraphicsItem *parent)
7980 : QGraphicsItem(dd, parent)
7985
7986
7987QAbstractGraphicsShapeItem::~QAbstractGraphicsShapeItem()
7992
7993
7994
7995QPen QAbstractGraphicsShapeItem::pen()
const
7997 Q_D(
const QAbstractGraphicsShapeItem);
8002
8003
8004
8005
8006
8007
8008void QAbstractGraphicsShapeItem::setPen(
const QPen &pen)
8010 Q_D(QAbstractGraphicsShapeItem);
8013 prepareGeometryChange();
8015 d->boundingRect = QRectF();
8020
8021
8022
8023
8024QBrush QAbstractGraphicsShapeItem::brush()
const
8026 Q_D(
const QAbstractGraphicsShapeItem);
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040void QAbstractGraphicsShapeItem::setBrush(
const QBrush &brush)
8042 Q_D(QAbstractGraphicsShapeItem);
8043 if (d->brush == brush)
8050
8051
8052bool QAbstractGraphicsShapeItem::isObscuredBy(
const QGraphicsItem *item)
const
8054 return QGraphicsItem::isObscuredBy(item);
8058
8059
8060QPainterPath QAbstractGraphicsShapeItem::opaqueArea()
const
8062 Q_D(
const QAbstractGraphicsShapeItem);
8063 if (d->brush.isOpaque())
8064 return isClipped() ? clipPath() : shape();
8065 return QGraphicsItem::opaqueArea();
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8097 Q_DECLARE_PUBLIC(QGraphicsPathItem)
8103
8104
8105
8106
8107
8108QGraphicsPathItem::QGraphicsPathItem(
const QPainterPath &path,
8109 QGraphicsItem *parent)
8110 : QAbstractGraphicsShapeItem(*
new QGraphicsPathItemPrivate, parent)
8112 if (!path.isEmpty())
8117
8118
8119
8120
8121
8122QGraphicsPathItem::QGraphicsPathItem(QGraphicsItem *parent)
8123 : QAbstractGraphicsShapeItem(*
new QGraphicsPathItemPrivate, parent)
8128
8129
8130QGraphicsPathItem::~QGraphicsPathItem()
8135
8136
8137
8138
8139
8140QPainterPath QGraphicsPathItem::path()
const
8142 Q_D(
const QGraphicsPathItem);
8147
8148
8149
8150
8151void QGraphicsPathItem::setPath(
const QPainterPath &path)
8153 Q_D(QGraphicsPathItem);
8154 if (d->path == path)
8156 prepareGeometryChange();
8158 d->boundingRect = QRectF();
8163
8164
8165QRectF QGraphicsPathItem::boundingRect()
const
8167 Q_D(
const QGraphicsPathItem);
8168 if (d->boundingRect.isNull()) {
8169 qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF();
8171 d->boundingRect = d->path.controlPointRect();
8173 d->boundingRect = shape().controlPointRect();
8176 return d->boundingRect;
8180
8181
8182QPainterPath QGraphicsPathItem::shape()
const
8184 Q_D(
const QGraphicsPathItem);
8185 return qt_graphicsItem_shapeFromPath(d->path, d->pen);
8189
8190
8191bool QGraphicsPathItem::contains(
const QPointF &point)
const
8193 return QAbstractGraphicsShapeItem::contains(point);
8197
8198
8199void QGraphicsPathItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
8202 Q_D(QGraphicsPathItem);
8204 painter->setPen(d->pen);
8205 painter->setBrush(d->brush);
8206 painter->drawPath(d->path);
8208 if (option->state & QStyle::State_Selected)
8209 qt_graphicsItem_highlightSelected(
this, painter, option);
8213
8214
8215bool QGraphicsPathItem::isObscuredBy(
const QGraphicsItem *item)
const
8217 return QAbstractGraphicsShapeItem::isObscuredBy(item);
8221
8222
8223QPainterPath QGraphicsPathItem::opaqueArea()
const
8225 return QAbstractGraphicsShapeItem::opaqueArea();
8229
8230
8231int QGraphicsPathItem::type()
const
8237
8238
8239bool QGraphicsPathItem::supportsExtension(Extension extension)
const
8241 Q_UNUSED(extension);
8246
8247
8248void QGraphicsPathItem::setExtension(Extension extension,
const QVariant &variant)
8250 Q_UNUSED(extension);
8255
8256
8257QVariant QGraphicsPathItem::extension(
const QVariant &variant)
const
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8298 Q_DECLARE_PUBLIC(QGraphicsRectItem)
8304
8305
8306
8307
8308
8309QGraphicsRectItem::QGraphicsRectItem(
const QRectF &rect, QGraphicsItem *parent)
8310 : QAbstractGraphicsShapeItem(*
new QGraphicsRectItemPrivate, parent)
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h,
8327 QGraphicsItem *parent)
8328 : QAbstractGraphicsShapeItem(*
new QGraphicsRectItemPrivate, parent)
8330 setRect(QRectF(x, y, w, h));
8334
8335
8336
8337
8338
8339QGraphicsRectItem::QGraphicsRectItem(QGraphicsItem *parent)
8340 : QAbstractGraphicsShapeItem(*
new QGraphicsRectItemPrivate, parent)
8345
8346
8347QGraphicsRectItem::~QGraphicsRectItem()
8352
8353
8354
8355
8356QRectF QGraphicsRectItem::rect()
const
8358 Q_D(
const QGraphicsRectItem);
8363
8364
8365
8366
8367
8368
8369void QGraphicsRectItem::setRect(
const QRectF &rect)
8371 Q_D(QGraphicsRectItem);
8372 if (d->rect == rect)
8374 prepareGeometryChange();
8376 d->boundingRect = QRectF();
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8394
8395
8396QRectF QGraphicsRectItem::boundingRect()
const
8398 Q_D(
const QGraphicsRectItem);
8399 if (d->boundingRect.isNull()) {
8400 qreal halfpw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF() / 2;
8401 d->boundingRect = d->rect;
8403 d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw);
8405 return d->boundingRect;
8409
8410
8411QPainterPath QGraphicsRectItem::shape()
const
8413 Q_D(
const QGraphicsRectItem);
8415 path.addRect(d->rect);
8416 return qt_graphicsItem_shapeFromPath(path, d->pen);
8420
8421
8422bool QGraphicsRectItem::contains(
const QPointF &point)
const
8424 return QAbstractGraphicsShapeItem::contains(point);
8428
8429
8430void QGraphicsRectItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
8433 Q_D(QGraphicsRectItem);
8435 painter->setPen(d->pen);
8436 painter->setBrush(d->brush);
8437 painter->drawRect(d->rect);
8439 if (option->state & QStyle::State_Selected)
8440 qt_graphicsItem_highlightSelected(
this, painter, option);
8444
8445
8446bool QGraphicsRectItem::isObscuredBy(
const QGraphicsItem *item)
const
8448 return QAbstractGraphicsShapeItem::isObscuredBy(item);
8452
8453
8454QPainterPath QGraphicsRectItem::opaqueArea()
const
8456 return QAbstractGraphicsShapeItem::opaqueArea();
8460
8461
8462int QGraphicsRectItem::type()
const
8468
8469
8470bool QGraphicsRectItem::supportsExtension(Extension extension)
const
8472 Q_UNUSED(extension);
8477
8478
8479void QGraphicsRectItem::setExtension(Extension extension,
const QVariant &variant)
8481 Q_UNUSED(extension);
8486
8487
8488QVariant QGraphicsRectItem::extension(
const QVariant &variant)
const
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8530 Q_DECLARE_PUBLIC(QGraphicsEllipseItem)
8542
8543
8544
8545
8546
8547QGraphicsEllipseItem::QGraphicsEllipseItem(
const QRectF &rect, QGraphicsItem *parent)
8548 : QAbstractGraphicsShapeItem(*
new QGraphicsEllipseItemPrivate, parent)
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563QGraphicsEllipseItem::QGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h,
8564 QGraphicsItem *parent)
8565 : QAbstractGraphicsShapeItem(*
new QGraphicsEllipseItemPrivate, parent)
8573
8574
8575
8576
8577
8578QGraphicsEllipseItem::QGraphicsEllipseItem(QGraphicsItem *parent)
8579 : QAbstractGraphicsShapeItem(*
new QGraphicsEllipseItemPrivate, parent)
8584
8585
8586QGraphicsEllipseItem::~QGraphicsEllipseItem()
8591
8592
8593
8594
8595QRectF QGraphicsEllipseItem::rect()
const
8597 Q_D(
const QGraphicsEllipseItem);
8602
8603
8604
8605
8606
8607
8608
8609void QGraphicsEllipseItem::setRect(
const QRectF &rect)
8611 Q_D(QGraphicsEllipseItem);
8612 if (d->rect == rect)
8614 prepareGeometryChange();
8616 d->boundingRect = QRectF();
8621
8622
8623
8624
8625
8626
8627int QGraphicsEllipseItem::startAngle()
const
8629 Q_D(
const QGraphicsEllipseItem);
8630 return d->startAngle;
8634
8635
8636
8637
8638
8639
8640void QGraphicsEllipseItem::setStartAngle(
int angle)
8642 Q_D(QGraphicsEllipseItem);
8643 if (angle != d->startAngle) {
8644 prepareGeometryChange();
8645 d->boundingRect = QRectF();
8646 d->startAngle = angle;
8652
8653
8654
8655
8656
8657
8658
8659int QGraphicsEllipseItem::spanAngle()
const
8661 Q_D(
const QGraphicsEllipseItem);
8662 return d->spanAngle;
8666
8667
8668
8669
8670
8671
8672
8673void QGraphicsEllipseItem::setSpanAngle(
int angle)
8675 Q_D(QGraphicsEllipseItem);
8676 if (angle != d->spanAngle) {
8677 prepareGeometryChange();
8678 d->boundingRect = QRectF();
8679 d->spanAngle = angle;
8685
8686
8687QRectF QGraphicsEllipseItem::boundingRect()
const
8689 Q_D(
const QGraphicsEllipseItem);
8690 if (d->boundingRect.isNull()) {
8691 qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF();
8692 if (pw == 0.0 && d->spanAngle == 360 * 16)
8693 d->boundingRect = d->rect;
8695 d->boundingRect = shape().controlPointRect();
8697 return d->boundingRect;
8701
8702
8703QPainterPath QGraphicsEllipseItem::shape()
const
8705 Q_D(
const QGraphicsEllipseItem);
8707 if (d->rect.isNull())
8709 if (d->spanAngle != 360 * 16) {
8710 path.moveTo(d->rect.center());
8711 path.arcTo(d->rect, d->startAngle / 16.0, d->spanAngle / 16.0);
8713 path.addEllipse(d->rect);
8716 return qt_graphicsItem_shapeFromPath(path, d->pen);
8720
8721
8722bool QGraphicsEllipseItem::contains(
const QPointF &point)
const
8724 return QAbstractGraphicsShapeItem::contains(point);
8728
8729
8730void QGraphicsEllipseItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
8733 Q_D(QGraphicsEllipseItem);
8735 painter->setPen(d->pen);
8736 painter->setBrush(d->brush);
8737 if ((d->spanAngle != 0) && (qAbs(d->spanAngle) % (360 * 16) == 0))
8738 painter->drawEllipse(d->rect);
8740 painter->drawPie(d->rect, d->startAngle, d->spanAngle);
8742 if (option->state & QStyle::State_Selected)
8743 qt_graphicsItem_highlightSelected(
this, painter, option);
8747
8748
8749bool QGraphicsEllipseItem::isObscuredBy(
const QGraphicsItem *item)
const
8751 return QAbstractGraphicsShapeItem::isObscuredBy(item);
8755
8756
8757QPainterPath QGraphicsEllipseItem::opaqueArea()
const
8759 return QAbstractGraphicsShapeItem::opaqueArea();
8763
8764
8765int QGraphicsEllipseItem::type()
const
8772
8773
8774bool QGraphicsEllipseItem::supportsExtension(Extension extension)
const
8776 Q_UNUSED(extension);
8781
8782
8783void QGraphicsEllipseItem::setExtension(Extension extension,
const QVariant &variant)
8785 Q_UNUSED(extension);
8790
8791
8792QVariant QGraphicsEllipseItem::extension(
const QVariant &variant)
const
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8826 Q_DECLARE_PUBLIC(QGraphicsPolygonItem)
8837
8838
8839
8840
8841
8842QGraphicsPolygonItem::QGraphicsPolygonItem(
const QPolygonF &polygon, QGraphicsItem *parent)
8843 : QAbstractGraphicsShapeItem(*
new QGraphicsPolygonItemPrivate, parent)
8845 setPolygon(polygon);
8849
8850
8851
8852
8853
8854QGraphicsPolygonItem::QGraphicsPolygonItem(QGraphicsItem *parent)
8855 : QAbstractGraphicsShapeItem(*
new QGraphicsPolygonItemPrivate, parent)
8860
8861
8862QGraphicsPolygonItem::~QGraphicsPolygonItem()
8867
8868
8869
8870
8871
8872QPolygonF QGraphicsPolygonItem::polygon()
const
8874 Q_D(
const QGraphicsPolygonItem);
8879
8880
8881
8882
8883void QGraphicsPolygonItem::setPolygon(
const QPolygonF &polygon)
8885 Q_D(QGraphicsPolygonItem);
8886 if (d->polygon == polygon)
8888 prepareGeometryChange();
8889 d->polygon = polygon;
8890 d->boundingRect = QRectF();
8895
8896
8897
8898
8899
8900Qt::FillRule QGraphicsPolygonItem::fillRule()
const
8902 Q_D(
const QGraphicsPolygonItem);
8907
8908
8909
8910
8911
8912void QGraphicsPolygonItem::setFillRule(Qt::FillRule rule)
8914 Q_D(QGraphicsPolygonItem);
8915 if (rule != d->fillRule) {
8922
8923
8924QRectF QGraphicsPolygonItem::boundingRect()
const
8926 Q_D(
const QGraphicsPolygonItem);
8927 if (d->boundingRect.isNull()) {
8928 qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF();
8930 d->boundingRect = d->polygon.boundingRect();
8932 d->boundingRect = shape().controlPointRect();
8934 return d->boundingRect;
8938
8939
8940QPainterPath QGraphicsPolygonItem::shape()
const
8942 Q_D(
const QGraphicsPolygonItem);
8944 path.addPolygon(d->polygon);
8945 return qt_graphicsItem_shapeFromPath(path, d->pen);
8949
8950
8951bool QGraphicsPolygonItem::contains(
const QPointF &point)
const
8953 return QAbstractGraphicsShapeItem::contains(point);
8957
8958
8959void QGraphicsPolygonItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
8961 Q_D(QGraphicsPolygonItem);
8963 painter->setPen(d->pen);
8964 painter->setBrush(d->brush);
8965 painter->drawPolygon(d->polygon, d->fillRule);
8967 if (option->state & QStyle::State_Selected)
8968 qt_graphicsItem_highlightSelected(
this, painter, option);
8972
8973
8974bool QGraphicsPolygonItem::isObscuredBy(
const QGraphicsItem *item)
const
8976 return QAbstractGraphicsShapeItem::isObscuredBy(item);
8980
8981
8982QPainterPath QGraphicsPolygonItem::opaqueArea()
const
8984 return QAbstractGraphicsShapeItem::opaqueArea();
8988
8989
8990int QGraphicsPolygonItem::type()
const
8996
8997
8998bool QGraphicsPolygonItem::supportsExtension(Extension extension)
const
9000 Q_UNUSED(extension);
9005
9006
9007void QGraphicsPolygonItem::setExtension(Extension extension,
const QVariant &variant)
9009 Q_UNUSED(extension);
9014
9015
9016QVariant QGraphicsPolygonItem::extension(
const QVariant &variant)
const
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9049 Q_DECLARE_PUBLIC(QGraphicsLineItem)
9056
9057
9058
9059
9060
9061QGraphicsLineItem::QGraphicsLineItem(
const QLineF &line, QGraphicsItem *parent)
9062 : QGraphicsItem(*
new QGraphicsLineItemPrivate, parent)
9068
9069
9070
9071
9072
9073
9074QGraphicsLineItem::QGraphicsLineItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent)
9075 : QGraphicsItem(*
new QGraphicsLineItemPrivate, parent)
9077 setLine(x1, y1, x2, y2);
9083
9084
9085
9086
9087
9088QGraphicsLineItem::QGraphicsLineItem(QGraphicsItem *parent)
9089 : QGraphicsItem(*
new QGraphicsLineItemPrivate, parent)
9094
9095
9096QGraphicsLineItem::~QGraphicsLineItem()
9101
9102
9103
9104
9105
9106QPen QGraphicsLineItem::pen()
const
9108 Q_D(
const QGraphicsLineItem);
9113
9114
9115
9116
9117
9118void QGraphicsLineItem::setPen(
const QPen &pen)
9120 Q_D(QGraphicsLineItem);
9123 prepareGeometryChange();
9129
9130
9131
9132
9133QLineF QGraphicsLineItem::line()
const
9135 Q_D(
const QGraphicsLineItem);
9140
9141
9142
9143
9144void QGraphicsLineItem::setLine(
const QLineF &line)
9146 Q_D(QGraphicsLineItem);
9147 if (d->line == line)
9149 prepareGeometryChange();
9155
9156
9157
9158
9159
9160
9161
9162
9165
9166
9167QRectF QGraphicsLineItem::boundingRect()
const
9169 Q_D(
const QGraphicsLineItem);
9170 if (d->pen.widthF() == 0.0) {
9171 const qreal x1 = d->line.p1().x();
9172 const qreal x2 = d->line.p2().x();
9173 const qreal y1 = d->line.p1().y();
9174 const qreal y2 = d->line.p2().y();
9175 qreal lx = qMin(x1, x2);
9176 qreal rx = qMax(x1, x2);
9177 qreal ty = qMin(y1, y2);
9178 qreal by = qMax(y1, y2);
9179 return QRectF(lx, ty, rx - lx, by - ty);
9181 return shape().controlPointRect();
9185
9186
9187QPainterPath QGraphicsLineItem::shape()
const
9189 Q_D(
const QGraphicsLineItem);
9191 if (d->line == QLineF())
9194 path.moveTo(d->line.p1());
9195 path.lineTo(d->line.p2());
9196 return qt_graphicsItem_shapeFromPath(path, d->pen);
9200
9201
9202bool QGraphicsLineItem::contains(
const QPointF &point)
const
9204 return QGraphicsItem::contains(point);
9208
9209
9210void QGraphicsLineItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
9212 Q_D(QGraphicsLineItem);
9214 painter->setPen(d->pen);
9215 painter->drawLine(d->line);
9217 if (option->state & QStyle::State_Selected)
9218 qt_graphicsItem_highlightSelected(
this, painter, option);
9222
9223
9224bool QGraphicsLineItem::isObscuredBy(
const QGraphicsItem *item)
const
9226 return QGraphicsItem::isObscuredBy(item);
9230
9231
9232QPainterPath QGraphicsLineItem::opaqueArea()
const
9234 return QGraphicsItem::opaqueArea();
9238
9239
9240int QGraphicsLineItem::type()
const
9246
9247
9248bool QGraphicsLineItem::supportsExtension(Extension extension)
const
9250 Q_UNUSED(extension);
9255
9256
9257void QGraphicsLineItem::setExtension(Extension extension,
const QVariant &variant)
9259 Q_UNUSED(extension);
9264
9265
9266QVariant QGraphicsLineItem::extension(
const QVariant &variant)
const
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327Q_GUI_EXPORT
extern QPainterPath qt_regionToPath(
const QRegion ®ion);
9331 Q_DECLARE_PUBLIC(QGraphicsPixmapItem)
9348 shape = QPainterPath();
9349 switch (shapeMode) {
9350 case QGraphicsPixmapItem::MaskShape: {
9351 QBitmap mask = pixmap.mask();
9352 if (!mask.isNull()) {
9353 shape = qt_regionToPath(QRegion(mask).translated(offset.toPoint()));
9358 case QGraphicsPixmapItem::BoundingRectShape:
9359 shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));
9361 case QGraphicsPixmapItem::HeuristicMaskShape:
9362#ifndef QT_NO_IMAGE_HEURISTIC_MASK
9363 shape = qt_regionToPath(QRegion(pixmap.createHeuristicMask()).translated(offset.toPoint()));
9365 shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));
9373
9374
9375
9376
9377
9378QGraphicsPixmapItem::QGraphicsPixmapItem(
const QPixmap &pixmap, QGraphicsItem *parent)
9379 : QGraphicsItem(*
new QGraphicsPixmapItemPrivate, parent)
9385
9386
9387
9388
9389
9390QGraphicsPixmapItem::QGraphicsPixmapItem(QGraphicsItem *parent)
9391 : QGraphicsItem(*
new QGraphicsPixmapItemPrivate, parent)
9396
9397
9398QGraphicsPixmapItem::~QGraphicsPixmapItem()
9403
9404
9405
9406
9407void QGraphicsPixmapItem::setPixmap(
const QPixmap &pixmap)
9409 Q_D(QGraphicsPixmapItem);
9410 prepareGeometryChange();
9412 d->hasShape =
false;
9417
9418
9419
9420
9421
9422QPixmap QGraphicsPixmapItem::pixmap()
const
9424 Q_D(
const QGraphicsPixmapItem);
9429
9430
9431
9432
9433
9434
9435Qt::TransformationMode QGraphicsPixmapItem::transformationMode()
const
9437 Q_D(
const QGraphicsPixmapItem);
9438 return d->transformationMode;
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452void QGraphicsPixmapItem::setTransformationMode(Qt::TransformationMode mode)
9454 Q_D(QGraphicsPixmapItem);
9455 if (mode != d->transformationMode) {
9456 d->transformationMode = mode;
9462
9463
9464
9465
9466
9467QPointF QGraphicsPixmapItem::offset()
const
9469 Q_D(
const QGraphicsPixmapItem);
9474
9475
9476
9477
9478
9479void QGraphicsPixmapItem::setOffset(
const QPointF &offset)
9481 Q_D(QGraphicsPixmapItem);
9482 if (d->offset == offset)
9484 prepareGeometryChange();
9486 d->hasShape =
false;
9491
9492
9493
9494
9495
9498
9499
9500QRectF QGraphicsPixmapItem::boundingRect()
const
9502 Q_D(
const QGraphicsPixmapItem);
9503 if (d->pixmap.isNull())
9505 if (d->flags & ItemIsSelectable) {
9507 return QRectF(d->offset, d->pixmap.deviceIndependentSize()).adjusted(-pw/2, -pw/2, pw/2, pw/2);
9509 return QRectF(d->offset, d->pixmap.deviceIndependentSize());
9514
9515
9516QPainterPath QGraphicsPixmapItem::shape()
const
9518 Q_D(
const QGraphicsPixmapItem);
9520 QGraphicsPixmapItemPrivate *thatD =
const_cast<QGraphicsPixmapItemPrivate *>(d);
9521 thatD->updateShape();
9522 thatD->hasShape =
true;
9524 return d_func()->shape;
9528
9529
9530bool QGraphicsPixmapItem::contains(
const QPointF &point)
const
9532 return QGraphicsItem::contains(point);
9536
9537
9538void QGraphicsPixmapItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
9541 Q_D(QGraphicsPixmapItem);
9544 painter->setRenderHint(QPainter::SmoothPixmapTransform,
9545 (d->transformationMode == Qt::SmoothTransformation));
9547 painter->drawPixmap(d->offset, d->pixmap);
9549 if (option->state & QStyle::State_Selected)
9550 qt_graphicsItem_highlightSelected(
this, painter, option);
9554
9555
9556bool QGraphicsPixmapItem::isObscuredBy(
const QGraphicsItem *item)
const
9558 return QGraphicsItem::isObscuredBy(item);
9562
9563
9564QPainterPath QGraphicsPixmapItem::opaqueArea()
const
9570
9571
9572int QGraphicsPixmapItem::type()
const
9578
9579
9580
9581
9582
9583QGraphicsPixmapItem::ShapeMode QGraphicsPixmapItem::shapeMode()
const
9585 return d_func()->shapeMode;
9589
9590
9591
9592
9593
9594void QGraphicsPixmapItem::setShapeMode(ShapeMode mode)
9596 Q_D(QGraphicsPixmapItem);
9597 if (d->shapeMode == mode)
9599 d->shapeMode = mode;
9600 d->hasShape =
false;
9604
9605
9606bool QGraphicsPixmapItem::supportsExtension(Extension extension)
const
9608 Q_UNUSED(extension);
9613
9614
9615void QGraphicsPixmapItem::setExtension(Extension extension,
const QVariant &variant)
9617 Q_UNUSED(extension);
9622
9623
9624QVariant QGraphicsPixmapItem::extension(
const QVariant &variant)
const
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9679 {
return QPointF(0., pageNumber * control->document()->pageSize().height()); }
9681 {
if (control) control->processEvent(e, controlOffset()); }
9700
9701
9702
9703
9704
9705QGraphicsTextItem::QGraphicsTextItem(
const QString &text, QGraphicsItem *parent)
9706 : QGraphicsObject(*
new QGraphicsItemPrivate, parent),
9707 dd(
new QGraphicsTextItemPrivate)
9710 if (!text.isEmpty())
9712 setAcceptDrops(
true);
9713 setAcceptHoverEvents(
true);
9714 setFlags(ItemUsesExtendedStyleOption);
9718
9719
9720
9721
9722
9723QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent)
9724 : QGraphicsObject(*
new QGraphicsItemPrivate, parent),
9725 dd(
new QGraphicsTextItemPrivate)
9728 setAcceptDrops(
true);
9729 setAcceptHoverEvents(
true);
9730 setFlag(ItemUsesExtendedStyleOption);
9734
9735
9736QGraphicsTextItem::~QGraphicsTextItem()
9742
9743
9744
9745
9746QString QGraphicsTextItem::toHtml()
const
9748#ifndef QT_NO_TEXTHTMLPARSER
9750 return dd->control->toHtml();
9756
9757
9758
9759
9760
9761
9762void QGraphicsTextItem::setHtml(
const QString &text)
9764 dd->textControl()->setHtml(text);
9768
9769
9770
9771
9772QString QGraphicsTextItem::toPlainText()
const
9775 return dd->control->toPlainText();
9780
9781
9782
9783
9784
9785
9786void QGraphicsTextItem::setPlainText(
const QString &text)
9788 dd->textControl()->setPlainText(text);
9792
9793
9794
9795
9796QFont QGraphicsTextItem::font()
const
9800 return dd->control->document()->defaultFont();
9804
9805
9806
9807
9808void QGraphicsTextItem::setFont(
const QFont &font)
9810 dd->textControl()->document()->setDefaultFont(font);
9814
9815
9816void QGraphicsTextItem::setDefaultTextColor(
const QColor &col)
9818 QWidgetTextControl *c = dd->textControl();
9819 QPalette pal = c->palette();
9820 QColor old = pal.color(QPalette::Text);
9821 pal.setColor(QPalette::Text, col);
9828
9829
9830QColor QGraphicsTextItem::defaultTextColor()
const
9832 return dd->textControl()->palette().color(QPalette::Text);
9836
9837
9838QRectF QGraphicsTextItem::boundingRect()
const
9840 return dd->boundingRect;
9844
9845
9846QPainterPath QGraphicsTextItem::shape()
const
9849 return QPainterPath();
9851 path.addRect(dd->boundingRect);
9856
9857
9858bool QGraphicsTextItem::contains(
const QPointF &point)
const
9860 return dd->boundingRect.contains(point);
9864
9865
9866void QGraphicsTextItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
9872 QRectF r = option->exposedRect;
9873 painter->translate(-dd->controlOffset());
9874 r.translate(dd->controlOffset());
9876 QTextDocument *doc = dd->control->document();
9877 QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());
9882 layout->setViewport(dd->boundingRect);
9884 dd->control->drawContents(painter, r);
9887 layout->setViewport(QRect());
9892 if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))
9893 qt_graphicsItem_highlightSelected(
this, painter, option);
9897
9898
9899bool QGraphicsTextItem::isObscuredBy(
const QGraphicsItem *item)
const
9901 return QGraphicsItem::isObscuredBy(item);
9905
9906
9907QPainterPath QGraphicsTextItem::opaqueArea()
const
9909 return QGraphicsItem::opaqueArea();
9913
9914
9915int QGraphicsTextItem::type()
const
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936void QGraphicsTextItem::setTextWidth(qreal width)
9938 dd->textControl()->setTextWidth(width);
9942
9943
9944
9945
9946
9947
9948
9949qreal QGraphicsTextItem::textWidth()
const
9953 return dd->control->textWidth();
9957
9958
9959void QGraphicsTextItem::adjustSize()
9962 dd->control->adjustSize();
9966
9967
9968void QGraphicsTextItem::setDocument(QTextDocument *document)
9970 dd->textControl()->setDocument(document);
9971 dd->_q_updateBoundingRect(dd->control->size());
9975
9976
9977QTextDocument *QGraphicsTextItem::document()
const
9979 return dd->textControl()->document();
9983
9984
9985bool QGraphicsTextItem::sceneEvent(QEvent *event)
9987 QEvent::Type t = event->type();
9988 if (!dd->tabChangesFocus && (t == QEvent::KeyPress || t == QEvent::KeyRelease)) {
9989 int k = ((QKeyEvent *)event)->key();
9990 if (k == Qt::Key_Tab || k == Qt::Key_Backtab) {
9991 dd->sendControlEvent(event);
9995 bool result = QGraphicsItem::sceneEvent(event);
9998 switch (event->type()) {
9999 case QEvent::ContextMenu:
10000 case QEvent::FocusIn:
10001 case QEvent::FocusOut:
10002 case QEvent::GraphicsSceneDragEnter:
10003 case QEvent::GraphicsSceneDragLeave:
10004 case QEvent::GraphicsSceneDragMove:
10005 case QEvent::GraphicsSceneDrop:
10006 case QEvent::GraphicsSceneHoverEnter:
10007 case QEvent::GraphicsSceneHoverLeave:
10008 case QEvent::GraphicsSceneHoverMove:
10009 case QEvent::GraphicsSceneMouseDoubleClick:
10010 case QEvent::GraphicsSceneMousePress:
10011 case QEvent::GraphicsSceneMouseMove:
10012 case QEvent::GraphicsSceneMouseRelease:
10013 case QEvent::KeyPress:
10014 case QEvent::KeyRelease:
10015 case QEvent::InputMethod:
10018 if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) {
10019 QGuiApplication::inputMethod()->reset();
10021 QGuiApplication::inputMethod()->update(Qt::ImQueryInput);
10024 case QEvent::ShortcutOverride:
10025 dd->sendControlEvent(event);
10035
10036
10037void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
10039 if ((QGraphicsItem::d_ptr->flags & (ItemIsSelectable | ItemIsMovable))
10040 && (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) {
10043 dd->useDefaultImpl =
true;
10044 }
else if (event->buttons() == event->button()
10045 && dd->control->textInteractionFlags() == Qt::NoTextInteraction) {
10047 dd->useDefaultImpl =
true;
10049 if (dd->useDefaultImpl) {
10050 QGraphicsItem::mousePressEvent(event);
10051 if (!event->isAccepted())
10052 dd->useDefaultImpl =
false;
10056 dd->sendControlEvent(event);
10060
10061
10062void QGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
10064 if (dd->useDefaultImpl) {
10065 QGraphicsItem::mouseMoveEvent(event);
10069 dd->sendControlEvent(event);
10073
10074
10075void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
10077 if (dd->useDefaultImpl) {
10078 QGraphicsItem::mouseReleaseEvent(event);
10079 if (dd->control->textInteractionFlags() == Qt::NoTextInteraction
10080 && !event->buttons()) {
10082 dd->useDefaultImpl =
false;
10083 }
else if ((event->buttons() & Qt::LeftButton) == 0) {
10085 dd->useDefaultImpl =
false;
10090 QWidget *widget = event->widget();
10091 if (widget && (dd->control->textInteractionFlags() & Qt::TextEditable) && boundingRect().contains(event->pos())) {
10092 qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), dd->clickCausedFocus);
10094 dd->clickCausedFocus = 0;
10095 dd->sendControlEvent(event);
10099
10100
10101void QGraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
10103 if (dd->useDefaultImpl) {
10104 QGraphicsItem::mouseDoubleClickEvent(event);
10109 QGraphicsItem::mouseDoubleClickEvent(event);
10113 dd->sendControlEvent(event);
10117
10118
10119void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
10121 dd->sendControlEvent(event);
10125
10126
10127void QGraphicsTextItem::keyPressEvent(QKeyEvent *event)
10129 dd->sendControlEvent(event);
10133
10134
10135void QGraphicsTextItem::keyReleaseEvent(QKeyEvent *event)
10137 dd->sendControlEvent(event);
10141
10142
10143void QGraphicsTextItem::focusInEvent(QFocusEvent *event)
10145 dd->sendControlEvent(event);
10146 if (event->reason() == Qt::MouseFocusReason) {
10147 dd->clickCausedFocus = 1;
10153
10154
10155void QGraphicsTextItem::focusOutEvent(QFocusEvent *event)
10157 dd->sendControlEvent(event);
10162
10163
10164void QGraphicsTextItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
10166 dd->sendControlEvent(event);
10170
10171
10172void QGraphicsTextItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
10174 dd->sendControlEvent(event);
10178
10179
10180void QGraphicsTextItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
10182 dd->sendControlEvent(event);
10186
10187
10188void QGraphicsTextItem::dropEvent(QGraphicsSceneDragDropEvent *event)
10190 dd->sendControlEvent(event);
10194
10195
10196void QGraphicsTextItem::inputMethodEvent(QInputMethodEvent *event)
10198 dd->sendControlEvent(event);
10202
10203
10204void QGraphicsTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
10206 dd->sendControlEvent(event);
10210
10211
10212void QGraphicsTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
10214 dd->sendControlEvent(event);
10218
10219
10220void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
10222 dd->sendControlEvent(event);
10226
10227
10228QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query)
const
10231 if (query == Qt::ImEnabled)
10232 return isEnabled();
10233 else if (query == Qt::ImHints)
10234 v =
int(inputMethodHints());
10235 else if (dd->control)
10236 v = dd->control->inputMethodQuery(query, QVariant());
10238 if (v.userType() == QMetaType::QRectF)
10239 v = v.toRectF().translated(-dd->controlOffset());
10240 else if (v.userType() == QMetaType::QPointF)
10241 v = v.toPointF() - dd->controlOffset();
10242 else if (v.userType() == QMetaType::QRect)
10243 v = v.toRect().translated(-dd->controlOffset().toPoint());
10244 else if (v.userType() == QMetaType::QPoint)
10245 v = v.toPoint() - dd->controlOffset().toPoint();
10251
10252
10253bool QGraphicsTextItem::supportsExtension(Extension extension)
const
10255 Q_UNUSED(extension);
10260
10261
10262void QGraphicsTextItem::setExtension(Extension extension,
const QVariant &variant)
10264 Q_UNUSED(extension);
10269
10270
10271QVariant QGraphicsTextItem::extension(
const QVariant &variant)
const
10278
10279
10282 if (rect.isValid()) {
10283 rect.translate(-controlOffset());
10285 rect = boundingRect;
10287 if (rect.intersects(boundingRect))
10292
10293
10296 if (size != boundingRect.size()) {
10297 qq->prepareGeometryChange();
10298 boundingRect.setSize(size);
10304
10305
10308 if (
qq->hasFocus()) {
10309 rect.translate(-controlOffset());
10310 qq->ensureVisible(rect, 0, 0);
10317 QGraphicsTextItem *that =
const_cast<QGraphicsTextItem *>(
qq);
10318 control =
new QWidgetTextControl(that);
10319 control->setTextInteractionFlags(Qt::NoTextInteraction);
10321 QObject::connect(control, &QWidgetTextControl::updateRequest, qq,
10322 [dd = that->dd](
const QRectF &rect) { dd->_q_update(rect); });
10323 QObject::connect(control, &QWidgetTextControl::documentSizeChanged, qq,
10324 [dd = that->dd](QSizeF size) { dd->_q_updateBoundingRect(size); });
10325 QObject::connect(control, &QWidgetTextControl::visibilityRequest, qq,
10326 [dd = that->dd](
const QRectF &rect) { dd->_q_ensureVisible(rect); });
10327 QObject::connect(control, &QWidgetTextControl::linkActivated, qq,
10328 &QGraphicsTextItem::linkActivated);
10329 QObject::connect(control, &QWidgetTextControl::linkHovered, qq,
10330 &QGraphicsTextItem::linkHovered);
10332 const QSizeF pgSize = control->document()->pageSize();
10333 if (pgSize.height() != -1) {
10334 qq->prepareGeometryChange();
10335 that->dd->boundingRect.setSize(pgSize);
10338 that->dd->_q_updateBoundingRect(control->size());
10345
10346
10350 path.addRect(
qq->boundingRect());
10352 QPainterPath docPath;
10353 const QTextFrameFormat format = control->document()->rootFrame()->frameFormat();
10355 qq->boundingRect().adjusted(
10356 format.leftMargin(),
10357 format.topMargin(),
10358 -format.rightMargin(),
10359 -format.bottomMargin()));
10361 return path.subtracted(docPath).contains(event->pos());
10365
10366
10367
10368
10369
10370
10371
10372
10375
10376
10377
10378
10379
10380
10381
10382
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395void QGraphicsTextItem::setTextInteractionFlags(Qt::TextInteractionFlags flags)
10397 if (flags == Qt::NoTextInteraction)
10398 setFlags(
this->flags() & ~(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod));
10400 setFlags(
this->flags() | QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod);
10402 dd->textControl()->setTextInteractionFlags(flags);
10406
10407
10408
10409
10410Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags()
const
10413 return Qt::NoTextInteraction;
10414 return dd->control->textInteractionFlags();
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429void QGraphicsTextItem::setTabChangesFocus(
bool b)
10431 dd->tabChangesFocus = b;
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444bool QGraphicsTextItem::tabChangesFocus()
const
10446 return dd->tabChangesFocus;
10450
10451
10452
10453
10454
10455
10456
10457
10458void QGraphicsTextItem::setOpenExternalLinks(
bool open)
10460 dd->textControl()->setOpenExternalLinks(open);
10463bool QGraphicsTextItem::openExternalLinks()
const
10467 return dd->control->openExternalLinks();
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480void QGraphicsTextItem::setTextCursor(
const QTextCursor &cursor)
10482 dd->textControl()->setTextCursor(cursor);
10485QTextCursor QGraphicsTextItem::textCursor()
const
10488 return QTextCursor();
10489 return dd->control->textCursor();
10494 Q_DECLARE_PUBLIC(QGraphicsSimpleTextItem)
10509 layout->setCacheEnabled(
true);
10510 layout->beginLayout();
10511 while (layout->createLine().isValid())
10513 layout->endLayout();
10514 qreal maxWidth = 0;
10516 for (
int i = 0; i < layout->lineCount(); ++i) {
10517 QTextLine line = layout->lineAt(i);
10518 maxWidth = qMax(maxWidth, line.naturalTextWidth());
10519 line.setPosition(
QPointF(0, y));
10520 y += line.height();
10522 return QRectF(0, 0, maxWidth, y);
10527 Q_Q(QGraphicsSimpleTextItem);
10529 if (text.isEmpty()) {
10532 QString tmp = text;
10533 tmp.replace(u'\n', QChar::LineSeparator);
10534 Q_DECL_UNINITIALIZED QStackTextEngine engine(tmp, font);
10535 QTextLayout layout(&engine);
10536 br = setupTextLayout(&layout);
10538 if (br != boundingRect) {
10539 q->prepareGeometryChange();
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10580
10581
10582
10583
10584
10585
10586QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(QGraphicsItem *parent)
10587 : QAbstractGraphicsShapeItem(*
new QGraphicsSimpleTextItemPrivate, parent)
10592
10593
10594
10595
10596
10597
10598QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(
const QString &text, QGraphicsItem *parent)
10599 : QAbstractGraphicsShapeItem(*
new QGraphicsSimpleTextItemPrivate, parent)
10605
10606
10607QGraphicsSimpleTextItem::~QGraphicsSimpleTextItem()
10612
10613
10614
10615
10616
10617void QGraphicsSimpleTextItem::setText(
const QString &text)
10619 Q_D(QGraphicsSimpleTextItem);
10620 if (d->text == text)
10623 d->updateBoundingRect();
10628
10629
10630QString QGraphicsSimpleTextItem::text()
const
10632 Q_D(
const QGraphicsSimpleTextItem);
10637
10638
10639void QGraphicsSimpleTextItem::setFont(
const QFont &font)
10641 Q_D(QGraphicsSimpleTextItem);
10643 d->updateBoundingRect();
10647
10648
10649QFont QGraphicsSimpleTextItem::font()
const
10651 Q_D(
const QGraphicsSimpleTextItem);
10656
10657
10658QRectF QGraphicsSimpleTextItem::boundingRect()
const
10660 Q_D(
const QGraphicsSimpleTextItem);
10661 return d->boundingRect;
10665
10666
10667QPainterPath QGraphicsSimpleTextItem::shape()
const
10669 Q_D(
const QGraphicsSimpleTextItem);
10671 path.addRect(d->boundingRect);
10676
10677
10678bool QGraphicsSimpleTextItem::contains(
const QPointF &point)
const
10680 Q_D(
const QGraphicsSimpleTextItem);
10681 return d->boundingRect.contains(point);
10685
10686
10687void QGraphicsSimpleTextItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
10690 Q_D(QGraphicsSimpleTextItem);
10692 painter->setFont(d->font);
10694 QString tmp = d->text;
10695 tmp.replace(u'\n', QChar::LineSeparator);
10696 Q_DECL_UNINITIALIZED QStackTextEngine engine(tmp, d->font);
10697 QTextLayout layout(&engine);
10700 p.setBrush(d->brush);
10701 painter->setPen(p);
10702 if (d->pen.style() == Qt::NoPen && d->brush.style() == Qt::SolidPattern) {
10703 painter->setBrush(Qt::NoBrush);
10705 QTextLayout::FormatRange range;
10707 range.length = layout.text().size();
10708 range.format.setTextOutline(d->pen);
10709 layout.setFormats(QList<QTextLayout::FormatRange>(1, range));
10712 setupTextLayout(&layout);
10713 layout.draw(painter, QPointF(0, 0));
10715 if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))
10716 qt_graphicsItem_highlightSelected(
this, painter, option);
10720
10721
10722bool QGraphicsSimpleTextItem::isObscuredBy(
const QGraphicsItem *item)
const
10724 return QAbstractGraphicsShapeItem::isObscuredBy(item);
10728
10729
10730QPainterPath QGraphicsSimpleTextItem::opaqueArea()
const
10732 return QAbstractGraphicsShapeItem::opaqueArea();
10736
10737
10738int QGraphicsSimpleTextItem::type()
const
10744
10745
10746bool QGraphicsSimpleTextItem::supportsExtension(Extension extension)
const
10748 Q_UNUSED(extension);
10753
10754
10755void QGraphicsSimpleTextItem::setExtension(Extension extension,
const QVariant &variant)
10757 Q_UNUSED(extension);
10762
10763
10764QVariant QGraphicsSimpleTextItem::extension(
const QVariant &variant)
const
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10836
10837
10838
10839
10840
10841QGraphicsItemGroup::QGraphicsItemGroup(QGraphicsItem *parent)
10842 : QGraphicsItem(*
new QGraphicsItemGroupPrivate, parent)
10844 setHandlesChildEvents(
true);
10848
10849
10850QGraphicsItemGroup::~QGraphicsItemGroup()
10855
10856
10857
10858
10859
10860
10861void QGraphicsItemGroup::addToGroup(QGraphicsItem *item)
10863 Q_D(QGraphicsItemGroup);
10865 qWarning(
"QGraphicsItemGroup::addToGroup: cannot add null item");
10868 if (item ==
this) {
10869 qWarning(
"QGraphicsItemGroup::addToGroup: cannot add a group to itself");
10875 QTransform itemTransform = item->itemTransform(
this, &ok);
10878 qWarning(
"QGraphicsItemGroup::addToGroup: could not find a valid transformation from item to group coordinates");
10882 QTransform newItemTransform(itemTransform);
10883 item->setPos(mapFromItem(item, 0, 0));
10884 item->setParentItem(
this);
10887 if (!item->pos().isNull())
10888 newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
10891 QPointF origin = item->transformOriginPoint();
10893 QList<QGraphicsTransform*> transformList = item->transformations();
10894 for (
int i = 0; i < transformList.size(); ++i)
10895 transformList.at(i)->applyTo(&m);
10896 newItemTransform *= m.toTransform().inverted();
10897 newItemTransform.translate(origin.x(), origin.y());
10898 newItemTransform.rotate(-item->rotation());
10899 newItemTransform.scale(1/item->scale(), 1/item->scale());
10900 newItemTransform.translate(-origin.x(), -origin.y());
10904 item->setTransform(newItemTransform);
10905 item->d_func()->setIsMemberOfGroup(
true);
10906 prepareGeometryChange();
10907 d->itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect());
10912
10913
10914
10915
10916
10917
10918
10919void QGraphicsItemGroup::removeFromGroup(QGraphicsItem *item)
10921 Q_D(QGraphicsItemGroup);
10923 qWarning(
"QGraphicsItemGroup::removeFromGroup: cannot remove null item");
10927 QGraphicsItem *newParent = d_ptr->parent;
10931 QTransform itemTransform;
10933 itemTransform = item->itemTransform(newParent, &ok);
10935 itemTransform = item->sceneTransform();
10937 QPointF oldPos = item->mapToItem(newParent, 0, 0);
10938 item->setParentItem(newParent);
10939 item->setPos(oldPos);
10942 if (!item->pos().isNull())
10943 itemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
10947 QPointF origin = item->transformOriginPoint();
10949 QList<QGraphicsTransform*> transformList = item->transformations();
10950 for (
int i = 0; i < transformList.size(); ++i)
10951 transformList.at(i)->applyTo(&m);
10952 itemTransform *= m.toTransform().inverted();
10953 itemTransform.translate(origin.x(), origin.y());
10954 itemTransform.rotate(-item->rotation());
10955 itemTransform.scale(1 / item->scale(), 1 / item->scale());
10956 itemTransform.translate(-origin.x(), -origin.y());
10960 item->setTransform(itemTransform);
10961 item->d_func()->setIsMemberOfGroup(item->group() !=
nullptr);
10964 prepareGeometryChange();
10965 d->itemsBoundingRect = childrenBoundingRect();
10969
10970
10971
10972
10973QRectF QGraphicsItemGroup::boundingRect()
const
10975 Q_D(
const QGraphicsItemGroup);
10976 return d->itemsBoundingRect;
10980
10981
10982void QGraphicsItemGroup::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
10986 if (option->state & QStyle::State_Selected) {
10987 Q_D(QGraphicsItemGroup);
10988 painter->setBrush(Qt::NoBrush);
10989 painter->drawRect(d->itemsBoundingRect);
10994
10995
10996bool QGraphicsItemGroup::isObscuredBy(
const QGraphicsItem *item)
const
10998 return QGraphicsItem::isObscuredBy(item);
11002
11003
11004QPainterPath QGraphicsItemGroup::opaqueArea()
const
11006 return QGraphicsItem::opaqueArea();
11010
11011
11012int QGraphicsItemGroup::type()
const
11017#if QT_CONFIG(graphicseffect)
11018QRectF QGraphicsItemEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system)
const
11020 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
11021 if (!info && deviceCoordinates) {
11023 qWarning(
"QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
11027 QRectF rect = item->boundingRect();
11028 if (!item->d_ptr->children.isEmpty())
11029 rect |= item->childrenBoundingRect();
11031 if (deviceCoordinates) {
11032 Q_ASSERT(info->painter);
11033 rect = info->painter->worldTransform().mapRect(rect);
11039void QGraphicsItemEffectSourcePrivate::draw(QPainter *painter)
11042 qWarning(
"QGraphicsEffectSource::draw: Can only begin as a result of QGraphicsEffect::draw");
11046 Q_ASSERT(item->d_ptr->scene);
11047 QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
11048 if (painter == info->painter) {
11049 scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
11050 info->widget, info->opacity, info->effectTransform, info->wasDirtySceneTransform,
11053 QTransform effectTransform = info->painter->worldTransform().inverted();
11054 effectTransform *= painter->worldTransform();
11055 scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
11056 info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
11062QRectF QGraphicsItemEffectSourcePrivate::paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode,
const QRectF &sourceRect,
bool *unpadded)
const
11064 QRectF effectRectF;
11069 if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) {
11071 QRectF deviceRect = system == Qt::DeviceCoordinates ? sourceRect : info->painter->worldTransform().mapRect(sourceRect);
11072 effectRectF = item->graphicsEffect()->boundingRectFor(deviceRect);
11074 *unpadded = (effectRectF.size() == sourceRect.size());
11075 if (info && system == Qt::LogicalCoordinates)
11076 effectRectF = info->painter->worldTransform().inverted().mapRect(effectRectF);
11079 effectRectF = item->graphicsEffect()->boundingRectFor(sourceRect);
11081 }
else if (mode == QGraphicsEffect::PadToTransparentBorder) {
11083 effectRectF = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5);
11085 effectRectF = sourceRect;
11090 return effectRectF;
11093QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
11094 QGraphicsEffect::PixmapPadMode mode)
const
11096 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
11097 if (!info && deviceCoordinates) {
11099 qWarning(
"QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
11102 if (!item->d_ptr->scene)
11104 QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
11107 const QRectF sourceRect = boundingRect(system);
11108 QRectF effectRectF = paddedEffectRect(system, mode, sourceRect, &unpadded);
11109 QRect effectRect = effectRectF.toAlignedRect();
11112 *offset = effectRect.topLeft();
11114 bool untransformed = !deviceCoordinates
11115 || info->painter->worldTransform().type() <= QTransform::TxTranslate;
11116 if (untransformed && unpadded && isPixmap()) {
11118 *offset = boundingRect(system).topLeft().toPoint();
11119 return static_cast<QGraphicsPixmapItem *>(item)->pixmap();
11122 if (effectRect.isEmpty())
11125 const auto dpr = info ? info->painter->device()->devicePixelRatio() : 1.0;
11126 QPixmap pixmap(QRectF(effectRectF.topLeft(), effectRectF.size() * dpr).toAlignedRect().size());
11127 pixmap.setDevicePixelRatio(dpr);
11128 pixmap.fill(Qt::transparent);
11129 QPainter pixmapPainter(&pixmap);
11130 pixmapPainter.setRenderHints(info ? info->painter->renderHints() : QPainter::TextAntialiasing);
11132 QTransform effectTransform = QTransform::fromTranslate(-effectRect.x(), -effectRect.y());
11133 if (deviceCoordinates && info->effectTransform)
11134 effectTransform *= *info->effectTransform;
11138 QTransform sceneTransform = item->sceneTransform();
11139 QTransform newEffectTransform = sceneTransform.inverted();
11140 newEffectTransform *= effectTransform;
11141 scened->draw(item, &pixmapPainter,
nullptr, &sceneTransform,
nullptr,
nullptr, qreal(1.0),
11142 &newEffectTransform,
false,
true);
11143 }
else if (deviceCoordinates) {
11145 scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr,
nullptr,
11146 info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
11150 QTransform newEffectTransform = info->transformPtr->inverted();
11151 newEffectTransform *= effectTransform;
11152 scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr,
nullptr,
11153 info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform,
11157 pixmapPainter.end();
11163#ifndef QT_NO_DEBUG_STREAM
11166 if (
const QGraphicsItem *parent = item->parentItem())
11167 debug <<
", parent=" <<
static_cast<
const void *>(parent);
11169 QtDebugUtils::formatQPoint(debug, item->pos());
11170 if (
const qreal z = item->zValue())
11171 debug <<
", z=" << z;
11173 debug <<
", flags=" << item->flags();
11178 QDebugStateSaver saver(debug);
11182 return debug <<
"QGraphicsItem(0x0)";
11184 if (
const QGraphicsObject *o = item->toGraphicsObject())
11185 debug << o->metaObject()->className();
11187 debug <<
"QGraphicsItem";
11188 debug <<
'(' <<
static_cast<
const void *>(item);
11189 if (
const QGraphicsProxyWidget *pw = qgraphicsitem_cast<
const QGraphicsProxyWidget *>(item)) {
11190 debug <<
", widget=";
11191 if (
const QWidget *w = pw->widget()) {
11192 debug << w->metaObject()->className() <<
'(' <<
static_cast<
const void *>(w);
11193 if (!w->objectName().isEmpty())
11194 debug <<
", name=" << w->objectName();
11197 debug <<
"QWidget(0x0)";
11200 formatGraphicsItemHelper(debug, item);
11207 QDebugStateSaver saver(debug);
11211 return debug <<
"QGraphicsObject(0x0)";
11213 debug << item->metaObject()->className() <<
'(' <<
static_cast<
const void *>(item);
11214 if (!item->objectName().isEmpty())
11215 debug <<
", name=" << item->objectName();
11216 formatGraphicsItemHelper(debug, item);
11223 const char *str =
"UnknownChange";
11225 case QGraphicsItem::ItemChildAddedChange:
11226 str =
"ItemChildAddedChange";
11228 case QGraphicsItem::ItemChildRemovedChange:
11229 str =
"ItemChildRemovedChange";
11231 case QGraphicsItem::ItemCursorChange:
11232 str =
"ItemCursorChange";
11234 case QGraphicsItem::ItemCursorHasChanged:
11235 str =
"ItemCursorHasChanged";
11237 case QGraphicsItem::ItemEnabledChange:
11238 str =
"ItemEnabledChange";
11240 case QGraphicsItem::ItemEnabledHasChanged:
11241 str =
"ItemEnabledHasChanged";
11243 case QGraphicsItem::ItemFlagsChange:
11244 str =
"ItemFlagsChange";
11246 case QGraphicsItem::ItemFlagsHaveChanged:
11247 str =
"ItemFlagsHaveChanged";
11249 case QGraphicsItem::ItemParentChange:
11250 str =
"ItemParentChange";
11252 case QGraphicsItem::ItemParentHasChanged:
11253 str =
"ItemParentHasChanged";
11255 case QGraphicsItem::ItemPositionChange:
11256 str =
"ItemPositionChange";
11258 case QGraphicsItem::ItemPositionHasChanged:
11259 str =
"ItemPositionHasChanged";
11261 case QGraphicsItem::ItemSceneChange:
11262 str =
"ItemSceneChange";
11264 case QGraphicsItem::ItemSceneHasChanged:
11265 str =
"ItemSceneHasChanged";
11267 case QGraphicsItem::ItemSelectedChange:
11268 str =
"ItemSelectedChange";
11270 case QGraphicsItem::ItemSelectedHasChanged:
11271 str =
"ItemSelectedHasChanged";
11273 case QGraphicsItem::ItemToolTipChange:
11274 str =
"ItemToolTipChange";
11276 case QGraphicsItem::ItemToolTipHasChanged:
11277 str =
"ItemToolTipHasChanged";
11279 case QGraphicsItem::ItemTransformChange:
11280 str =
"ItemTransformChange";
11282 case QGraphicsItem::ItemTransformHasChanged:
11283 str =
"ItemTransformHasChanged";
11285 case QGraphicsItem::ItemVisibleChange:
11286 str =
"ItemVisibleChange";
11288 case QGraphicsItem::ItemVisibleHasChanged:
11289 str =
"ItemVisibleHasChanged";
11291 case QGraphicsItem::ItemZValueChange:
11292 str =
"ItemZValueChange";
11294 case QGraphicsItem::ItemZValueHasChanged:
11295 str =
"ItemZValueHasChanged";
11297 case QGraphicsItem::ItemOpacityChange:
11298 str =
"ItemOpacityChange";
11300 case QGraphicsItem::ItemOpacityHasChanged:
11301 str =
"ItemOpacityHasChanged";
11303 case QGraphicsItem::ItemScenePositionHasChanged:
11304 str =
"ItemScenePositionHasChanged";
11306 case QGraphicsItem::ItemRotationChange:
11307 str =
"ItemRotationChange";
11309 case QGraphicsItem::ItemRotationHasChanged:
11310 str =
"ItemRotationHasChanged";
11312 case QGraphicsItem::ItemScaleChange:
11313 str =
"ItemScaleChange";
11315 case QGraphicsItem::ItemScaleHasChanged:
11316 str =
"ItemScaleHasChanged";
11318 case QGraphicsItem::ItemTransformOriginPointChange:
11319 str =
"ItemTransformOriginPointChange";
11321 case QGraphicsItem::ItemTransformOriginPointHasChanged:
11322 str =
"ItemTransformOriginPointHasChanged";
11331 const char *str =
"UnknownFlag";
11333 case QGraphicsItem::ItemIsMovable:
11334 str =
"ItemIsMovable";
11336 case QGraphicsItem::ItemIsSelectable:
11337 str =
"ItemIsSelectable";
11339 case QGraphicsItem::ItemIsFocusable:
11340 str =
"ItemIsFocusable";
11342 case QGraphicsItem::ItemClipsToShape:
11343 str =
"ItemClipsToShape";
11345 case QGraphicsItem::ItemClipsChildrenToShape:
11346 str =
"ItemClipsChildrenToShape";
11348 case QGraphicsItem::ItemIgnoresTransformations:
11349 str =
"ItemIgnoresTransformations";
11351 case QGraphicsItem::ItemIgnoresParentOpacity:
11352 str =
"ItemIgnoresParentOpacity";
11354 case QGraphicsItem::ItemDoesntPropagateOpacityToChildren:
11355 str =
"ItemDoesntPropagateOpacityToChildren";
11357 case QGraphicsItem::ItemStacksBehindParent:
11358 str =
"ItemStacksBehindParent";
11360 case QGraphicsItem::ItemUsesExtendedStyleOption:
11361 str =
"ItemUsesExtendedStyleOption";
11363 case QGraphicsItem::ItemHasNoContents:
11364 str =
"ItemHasNoContents";
11366 case QGraphicsItem::ItemSendsGeometryChanges:
11367 str =
"ItemSendsGeometryChanges";
11369 case QGraphicsItem::ItemAcceptsInputMethod:
11370 str =
"ItemAcceptsInputMethod";
11372 case QGraphicsItem::ItemNegativeZStacksBehindParent:
11373 str =
"ItemNegativeZStacksBehindParent";
11375 case QGraphicsItem::ItemIsPanel:
11376 str =
"ItemIsPanel";
11378 case QGraphicsItem::ItemIsFocusScope:
11379 str =
"ItemIsFocusScope";
11381 case QGraphicsItem::ItemSendsScenePositionChanges:
11382 str =
"ItemSendsScenePositionChanges";
11384 case QGraphicsItem::ItemStopsClickFocusPropagation:
11385 str =
"ItemStopsClickFocusPropagation";
11387 case QGraphicsItem::ItemStopsFocusHandling:
11388 str =
"ItemStopsFocusHandling";
11390 case QGraphicsItem::ItemContainsChildrenInShape:
11391 str =
"ItemContainsChildrenInShape";
11402 for (
int i = 0; i < 17; ++i) {
11403 if (flags & (1 << i)) {
11407 debug << QGraphicsItem::GraphicsItemFlag(
int(flags & (1 << i)));
11418#include "moc_qgraphicsitem.cpp"
QHash< const QGraphicsItem *, QMap< int, QVariant > > data
QGraphicsPixmapItem::ShapeMode shapeMode
Qt::TransformationMode transformationMode
void updateBoundingRect()
void _q_updateBoundingRect(const QSizeF &)
void _q_ensureVisible(QRectF)
QPointF controlOffset() const
QGraphicsTextItemPrivate()
bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *)
QWidgetTextControl * control
QWidgetTextControl * textControl() const
void sendControlEvent(QEvent *e)
\inmodule QtCore\reentrant
static void formatGraphicsItemHelper(QDebug debug, const QGraphicsItem *item)
bool _qt_movableAncestorIsSelected(const QGraphicsItem *item)
static QRectF setupTextLayout(QTextLayout *layout)
QDebug operator<<(QDebug debug, const QGraphicsObject *item)
static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen)
QDebug operator<<(QDebug debug, const QGraphicsItem *item)
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item, const QGraphicsItem *other, const QRectF &rect)
QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)