qgraphicsitem.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsitem.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10static inline void _q_adjustRect(QRect *rect)-
11{-
12 ((!(rect)) ? qt_assert("rect",__FILE__,769775) : qt_noop());-
13 if (!rect->width())-
14 rect->adjust(0, 0, 1, 0);-
15 if (!rect->height())-
16 rect->adjust(0, 0, 0, 1);-
17}-
18-
19-
20-
21-
22class QGraphicsItemCustomDataStore-
23{-
24public:-
25 QHash<const QGraphicsItem *, QMap<int, QVariant> > data;-
26};-
27namespace { namespace Q_QGS_qt_dataStore { typedef QGraphicsItemCustomDataStore Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QGraphicsItemCustomDataStore, Q_QGS_qt_dataStore::innerFunction, Q_QGS_qt_dataStore::guard> qt_dataStore;-
28-
29-
30-
31-
32-
33-
34-
35static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen)-
36{-
37-
38-
39 const qreal penWidthZero = qreal(0.00000001);-
40-
41 if (path == QPainterPath() || pen == Qt::NoPen)-
42 return path;-
43 QPainterPathStroker ps;-
44 ps.setCapStyle(pen.capStyle());-
45 if (pen.widthF() <= 0.0)-
46 ps.setWidth(penWidthZero);-
47 else-
48 ps.setWidth(pen.widthF());-
49 ps.setJoinStyle(pen.joinStyle());-
50 ps.setMiterLimit(pen.miterLimit());-
51 QPainterPath p = ps.createStroke(path);-
52 p.addPath(path);-
53 return p;-
54}-
55-
56-
57-
58-
59QGraphicsItemPrivate::QGraphicsItemPrivate()-
60 : z(0),-
61 opacity(1.),-
62 scene(nullptr),-
63 parent(nullptr),-
64 transformData(nullptr),-
65 graphicsEffect(nullptr),-
66 index(-1),-
67 siblingIndex(-1),-
68 itemDepth(-1),-
69 focusProxy(nullptr),-
70 subFocusItem(nullptr),-
71 focusScopeItem(nullptr),-
72 imHints(Qt::ImhNone),-
73 panelModality(QGraphicsItem::NonModal),-
74 acceptedMouseButtons(0x1f),-
75 visible(true),-
76 explicitlyHidden(false),-
77 enabled(true),-
78 explicitlyDisabled(false),-
79 selected(false),-
80 acceptsHover(false),-
81 acceptDrops(false),-
82 isMemberOfGroup(false),-
83 handlesChildEvents(false),-
84 itemDiscovered(false),-
85 hasCursor(false),-
86 ancestorFlags(0),-
87 cacheMode(0),-
88 hasBoundingRegionGranularity(false),-
89 isWidget(false),-
90 dirty(false),-
91 dirtyChildren(false),-
92 localCollisionHack(false),-
93 inSetPosHelper(false),-
94 needSortChildren(false),-
95 allChildrenDirty(false),-
96 fullUpdatePending(false),-
97 flags(0),-
98 paintedViewBoundingRectsNeedRepaint(false),-
99 dirtySceneTransform(true),-
100 geometryChanged(true),-
101 inDestructor(false),-
102 isObject(false),-
103 ignoreVisible(false),-
104 ignoreOpacity(false),-
105 acceptTouchEvents(false),-
106 acceptedTouchBeginEvent(false),-
107 filtersDescendantEvents(false),-
108 sceneTransformTranslateOnly(false),-
109 notifyBoundingRectChanged(false),-
110 notifyInvalidated(false),-
111 mouseSetsFocus(true),-
112 explicitActivate(false),-
113 wantsActive(false),-
114 holesInSiblingIndex(false),-
115 sequentialOrdering(true),-
116 updateDueToGraphicsEffect(false),-
117 scenePosDescendants(false),-
118 pendingPolish(false),-
119 mayHaveChildWithGraphicsEffect(false),-
120 isDeclarativeItem(false),-
121 sendParentChangeNotification(false),-
122 dirtyChildrenBoundingRect(true),-
123 globalStackingOrder(-1),-
124 q_ptr(nullptr)-
125{-
126}
never executed: end of block
0
127-
128-
129-
130-
131QGraphicsItemPrivate::~QGraphicsItemPrivate()-
132{-
133}-
134void QGraphicsItemPrivate::updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag,-
135 AncestorFlag flag, bool enabled, bool root)-
136{-
137 QGraphicsItem * const q = q_func();-
138 if (root) {-
139-
140-
141 switch (int(childFlag)) {-
142 case -2:-
143 flag = AncestorFiltersChildEvents;-
144 enabled = q->filtersChildEvents();-
145 break;-
146 case -1:-
147 flag = AncestorHandlesChildEvents;-
148 enabled = q->handlesChildEvents();-
149 break;-
150 case QGraphicsItem::ItemClipsChildrenToShape:-
151 flag = AncestorClipsChildren;-
152 enabled = flags & QGraphicsItem::ItemClipsChildrenToShape;-
153 break;-
154 case QGraphicsItem::ItemIgnoresTransformations:-
155 flag = AncestorIgnoresTransformations;-
156 enabled = flags & QGraphicsItem::ItemIgnoresTransformations;-
157 break;-
158 case QGraphicsItem::ItemContainsChildrenInShape:-
159 flag = AncestorContainsChildren;-
160 enabled = flags & QGraphicsItem::ItemContainsChildrenInShape;-
161 break;-
162 default:-
163 return;-
164 }-
165-
166 if (parent) {-
167-
168 if ((parent->d_ptr->ancestorFlags & flag)-
169 || (int(parent->d_ptr->flags & childFlag) == childFlag)-
170 || (int(childFlag) == -1 && parent->d_ptr->handlesChildEvents)-
171 || (int(childFlag) == -2 && parent->d_ptr->filtersDescendantEvents)) {-
172 enabled = true;-
173 ancestorFlags |= flag;-
174 } else {-
175 ancestorFlags &= ~flag;-
176 }-
177 } else {-
178-
179-
180 ancestorFlags = 0;-
181 }-
182 } else {-
183-
184 if (((ancestorFlags & flag) && enabled) || (!(ancestorFlags & flag) && !enabled))-
185 return;-
186-
187-
188 if (enabled)-
189 ancestorFlags |= flag;-
190 else-
191 ancestorFlags &= ~flag;-
192-
193-
194 if ((int(childFlag) != -1 && int(flags & childFlag) == childFlag)-
195 || (int(childFlag) == -1 && handlesChildEvents)-
196 || (int(childFlag) == -2 && filtersDescendantEvents))-
197 return;-
198 }-
199-
200 for (int i = 0; i < children.size(); ++i)-
201 children.at(i)->d_ptr->updateAncestorFlag(childFlag, flag, enabled, false);-
202}-
203-
204void QGraphicsItemPrivate::updateAncestorFlags()-
205{-
206 int flags = 0;-
207 if (parent) {-
208-
209 QGraphicsItemPrivate *pd = parent->d_ptr.data();-
210 flags = pd->ancestorFlags;-
211-
212-
213 if (pd->filtersDescendantEvents)-
214 flags |= AncestorFiltersChildEvents;-
215 if (pd->handlesChildEvents)-
216 flags |= AncestorHandlesChildEvents;-
217 if (pd->flags & QGraphicsItem::ItemClipsChildrenToShape)-
218 flags |= AncestorClipsChildren;-
219 if (pd->flags & QGraphicsItem::ItemIgnoresTransformations)-
220 flags |= AncestorIgnoresTransformations;-
221 if (pd->flags & QGraphicsItem::ItemContainsChildrenInShape)-
222 flags |= AncestorContainsChildren;-
223 }-
224-
225 if (ancestorFlags == flags)-
226 return;-
227 ancestorFlags = flags;-
228-
229-
230 for (int i = 0; i < children.size(); ++i)-
231 children.at(i)->d_ptr->updateAncestorFlags();-
232}-
233-
234-
235-
236-
237-
238-
239void QGraphicsItemPrivate::setIsMemberOfGroup(bool enabled)-
240{-
241 QGraphicsItem * const q = q_func();-
242 isMemberOfGroup = enabled;-
243 if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {-
244 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(children)>::type> _container_((children)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *child = *_container_.i; _container_.control; _container_.control = 0)-
245 child->d_func()->setIsMemberOfGroup(enabled);-
246 }-
247}-
248-
249-
250-
251-
252-
253-
254void QGraphicsItemPrivate::remapItemPos(QEvent *event, QGraphicsItem *item)-
255{-
256 QGraphicsItem * const q = q_func();-
257 switch (event->type()) {-
258 case QEvent::GraphicsSceneMouseMove:-
259 case QEvent::GraphicsSceneMousePress:-
260 case QEvent::GraphicsSceneMouseRelease:-
261 case QEvent::GraphicsSceneMouseDoubleClick: {-
262 QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);-
263 mouseEvent->setPos(item->mapFromItem(q, mouseEvent->pos()));-
264 mouseEvent->setLastPos(item->mapFromItem(q, mouseEvent->pos()));-
265 for (int i = 0x1; i <= 0x10; i <<= 1) {-
266 if (mouseEvent->buttons() & i) {-
267 Qt::MouseButton button = Qt::MouseButton(i);-
268 mouseEvent->setButtonDownPos(button, item->mapFromItem(q, mouseEvent->buttonDownPos(button)));-
269 }-
270 }-
271 break;-
272 }-
273 case QEvent::GraphicsSceneWheel: {-
274 QGraphicsSceneWheelEvent *wheelEvent = static_cast<QGraphicsSceneWheelEvent *>(event);-
275 wheelEvent->setPos(item->mapFromItem(q, wheelEvent->pos()));-
276 break;-
277 }-
278 case QEvent::GraphicsSceneContextMenu: {-
279 QGraphicsSceneContextMenuEvent *contextEvent = static_cast<QGraphicsSceneContextMenuEvent *>(event);-
280 contextEvent->setPos(item->mapFromItem(q, contextEvent->pos()));-
281 break;-
282 }-
283 case QEvent::GraphicsSceneHoverMove: {-
284 QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event);-
285 hoverEvent->setPos(item->mapFromItem(q, hoverEvent->pos()));-
286 break;-
287 }-
288 default:-
289 break;-
290 }-
291}-
292QPointF QGraphicsItemPrivate::genericMapFromScene(const QPointF &pos,-
293 const QWidget *viewport) const-
294{-
295 const QGraphicsItem * const q = q_func();-
296 if (!itemIsUntransformable())-
297 return q->mapFromScene(pos);-
298 QGraphicsView *view = 0;-
299 if (viewport)-
300 view = qobject_cast<QGraphicsView *>(viewport->parentWidget());-
301 if (!view)-
302 return q->mapFromScene(pos);-
303-
304 return q->deviceTransform(view->viewportTransform()).inverted().map(view->mapFromScene(pos));-
305}-
306void QGraphicsItemPrivate::combineTransformToParent(QTransform *x, const QTransform *viewTransform) const-
307{-
308-
309 if (viewTransform && itemIsUntransformable()) {-
310 *x = q_ptr->deviceTransform(*viewTransform);-
311 } else {-
312 if (transformData)-
313 *x *= transformData->computedFullTransform();-
314 if (!pos.isNull())-
315 *x *= QTransform::fromTranslate(pos.x(), pos.y());-
316 }-
317}-
318void QGraphicsItemPrivate::combineTransformFromParent(QTransform *x, const QTransform *viewTransform) const-
319{-
320-
321 if (viewTransform && itemIsUntransformable()) {-
322 *x = q_ptr->deviceTransform(*viewTransform);-
323 } else {-
324 x->translate(pos.x(), pos.y());-
325 if (transformData)-
326 *x = transformData->computedFullTransform(x);-
327 }-
328}-
329-
330void QGraphicsItemPrivate::updateSceneTransformFromParent()-
331{-
332 if (parent) {-
333 ((!(!parent->d_ptr->dirtySceneTransform)) ? qt_assert("!parent->d_ptr->dirtySceneTransform",__FILE__,10461131) : qt_noop());-
334 if (parent->d_ptr->sceneTransformTranslateOnly) {-
335 sceneTransform = QTransform::fromTranslate(parent->d_ptr->sceneTransform.dx() + pos.x(),-
336 parent->d_ptr->sceneTransform.dy() + pos.y());-
337 } else {-
338 sceneTransform = parent->d_ptr->sceneTransform;-
339 sceneTransform.translate(pos.x(), pos.y());-
340 }-
341 if (transformData) {-
342 sceneTransform = transformData->computedFullTransform(&sceneTransform);-
343 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);-
344 } else {-
345 sceneTransformTranslateOnly = parent->d_ptr->sceneTransformTranslateOnly;-
346 }-
347 } else if (!transformData) {-
348 sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());-
349 sceneTransformTranslateOnly = 1;-
350 } else if (transformData->onlyTransform) {-
351 sceneTransform = transformData->transform;-
352 if (!pos.isNull())-
353 sceneTransform *= QTransform::fromTranslate(pos.x(), pos.y());-
354 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);-
355 } else if (pos.isNull()) {-
356 sceneTransform = transformData->computedFullTransform();-
357 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);-
358 } else {-
359 sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());-
360 sceneTransform = transformData->computedFullTransform(&sceneTransform);-
361 sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);-
362 }-
363 dirtySceneTransform = 0;-
364}-
365void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const QVariant *newParentVariant,-
366 const QVariant *thisPointerVariant)-
367{-
368 QGraphicsItem * const q = q_func();-
369 if (newParent == parent)-
370 return;-
371-
372 if (isWidget)-
373 static_cast<QGraphicsWidgetPrivate *>(this)->fixFocusChainBeforeReparenting((newParent &&-
374 newParent->isWidget()) ? static_cast<QGraphicsWidget *>(newParent) : 0,-
375 scene);-
376 if (scene) {-
377-
378 if (scene->d_func()->indexMethod != QGraphicsScene::NoIndex)-
379 scene->d_func()->index->itemChange(q, QGraphicsItem::ItemParentChange, newParent);-
380-
381-
382 if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges))-
383 scene->d_func()->setScenePosItemEnabled(q, false);-
384 }-
385-
386 if (subFocusItem && parent) {-
387-
388 subFocusItem->d_ptr->clearSubFocus(parent);-
389 }-
390-
391-
392-
393-
394 if (!inDestructor)-
395 q_ptr->prepareGeometryChange();-
396-
397 if (parent) {-
398-
399 parent->d_ptr->removeChild(q);-
400 if (thisPointerVariant)-
401 parent->itemChange(QGraphicsItem::ItemChildRemovedChange, *thisPointerVariant);-
402 }-
403-
404-
405-
406 if (scene && !inDestructor) {-
407 if (parent && !newParent) {-
408 scene->d_func()->registerTopLevelItem(q);-
409 } else if (!parent && newParent) {-
410 scene->d_func()->unregisterTopLevelItem(q);-
411 }-
412 }-
413-
414-
415-
416 QGraphicsItem *p = parent;-
417 QGraphicsItem *parentFocusScopeItem = 0;-
418 while (p) {-
419 if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) {-
420-
421-
422 QGraphicsItem *fsi = p->d_ptr->focusScopeItem;-
423 if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {-
424 parentFocusScopeItem = fsi;-
425 p->d_ptr->focusScopeItem = 0;-
426 fsi->d_ptr->focusScopeItemChange(false);-
427 }-
428 break;-
429 }-
430 p = p->d_ptr->parent;-
431 }-
432-
433-
434 if (newParent && (graphicsEffect || mayHaveChildWithGraphicsEffect))-
435 newParent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();-
436-
437-
438 QGraphicsItem *newFocusScopeItem = subFocusItem ? subFocusItem : parentFocusScopeItem;-
439 if (newFocusScopeItem && newParent) {-
440 QGraphicsItem *p = newParent;-
441 while (p) {-
442 if (p->d_ptr->flags & QGraphicsItem::ItemIsFocusScope) {-
443 if (subFocusItem && subFocusItem != q_ptr) {-
444-
445 QGraphicsItem *ancestorScope = 0;-
446 QGraphicsItem *p2 = subFocusItem->d_ptr->parent;-
447 while (p2 && p2 != p) {-
448 if (p2->d_ptr->flags & QGraphicsItem::ItemIsFocusScope)-
449 ancestorScope = p2;-
450 if (p2->d_ptr->flags & QGraphicsItem::ItemIsPanel)-
451 break;-
452 if (p2 == q_ptr)-
453 break;-
454 p2 = p2->d_ptr->parent;-
455 }-
456 if (ancestorScope)-
457 newFocusScopeItem = ancestorScope;-
458 }-
459-
460 p->d_ptr->focusScopeItem = newFocusScopeItem;-
461 newFocusScopeItem->d_ptr->focusScopeItemChange(true);-
462-
463-
464-
465 if (subFocusItem && !p->focusItem())-
466 subFocusItem->d_ptr->clearSubFocus();-
467 break;-
468 }-
469 p = p->d_ptr->parent;-
470 }-
471 }-
472-
473-
474 invalidateDepthRecursively();-
475-
476 if ((parent = newParent)) {-
477 if (parent->d_func()->scene && parent->d_func()->scene != scene) {-
478-
479 parent->d_func()->scene->addItem(q);-
480 } else if (!parent->d_func()->scene && scene) {-
481-
482 scene->removeItem(q);-
483 }-
484-
485 parent->d_ptr->addChild(q);-
486 if (thisPointerVariant)-
487 parent->itemChange(QGraphicsItem::ItemChildAddedChange, *thisPointerVariant);-
488 if (scene) {-
489-
490 if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges))-
491 scene->d_func()->setScenePosItemEnabled(q, true);-
492 }-
493-
494-
495 markParentDirty( true);-
496-
497-
498 updateAncestorFlags();-
499-
500-
501 if (parent->d_ptr->visible != visible) {-
502 if (!parent->d_ptr->visible || !explicitlyHidden)-
503 setVisibleHelper(parent->d_ptr->visible, false, false);-
504 }-
505 if (parent->isEnabled() != enabled) {-
506 if (!parent->d_ptr->enabled || !explicitlyDisabled)-
507 setEnabledHelper(parent->d_ptr->enabled, false, false);-
508 }-
509-
510-
511 if (visible && parent->isActive())-
512 q->setActive(true);-
513 } else {-
514-
515 updateAncestorFlags();-
516-
517 if (!inDestructor) {-
518-
519 if (!visible && !explicitlyHidden)-
520 setVisibleHelper(true, false);-
521 if (!enabled && !explicitlyDisabled)-
522 setEnabledHelper(true, false);-
523 }-
524 }-
525-
526 dirtySceneTransform = 1;-
527 if (!inDestructor && (transformData || (newParent && newParent->d_ptr->transformData)))-
528 transformChanged();-
529-
530-
531 if (subFocusItem) {-
532 subFocusItem->d_ptr->setSubFocus(newParent);-
533 if (parent && parent->isActive())-
534 subFocusItem->setFocus();-
535 }-
536-
537-
538 if (newParentVariant)-
539 q->itemChange(QGraphicsItem::ItemParentHasChanged, *newParentVariant);-
540-
541 if (isObject)-
542 static_cast<QGraphicsObject *>(q)->parentChanged();-
543}-
544-
545-
546-
547-
548-
549-
550void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect, QGraphicsItem *topMostEffectItem)-
551{-
552 QGraphicsItem * const q = q_func();-
553-
554 QRectF childrenRect;-
555 QRectF *result = rect;-
556 rect = &childrenRect;-
557 const bool setTopMostEffectItem = !topMostEffectItem;-
558-
559 for (int i = 0; i < children.size(); ++i) {-
560 QGraphicsItem *child = children.at(i);-
561 QGraphicsItemPrivate *childd = child->d_ptr.data();-
562 if (setTopMostEffectItem)-
563 topMostEffectItem = child;-
564 bool hasPos = !childd->pos.isNull();-
565 if (hasPos || childd->transformData) {-
566-
567 QTransform matrix = childd->transformToParent();-
568 if (x)-
569 matrix *= *x;-
570 *rect |= matrix.mapRect(child->d_ptr->effectiveBoundingRect(topMostEffectItem));-
571 if (!childd->children.isEmpty())-
572 childd->childrenBoundingRectHelper(&matrix, rect, topMostEffectItem);-
573 } else {-
574 if (x)-
575 *rect |= x->mapRect(child->d_ptr->effectiveBoundingRect(topMostEffectItem));-
576 else-
577 *rect |= child->d_ptr->effectiveBoundingRect(topMostEffectItem);-
578 if (!childd->children.isEmpty())-
579 childd->childrenBoundingRectHelper(x, rect, topMostEffectItem);-
580 }-
581 }-
582-
583 if (flags & QGraphicsItem::ItemClipsChildrenToShape){-
584 if (x)-
585 *rect &= x->mapRect(q->boundingRect());-
586 else-
587 *rect &= q->boundingRect();-
588 }-
589-
590 *result |= *rect;-
591}-
592-
593void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform,-
594 const QRegion &exposedRegion, bool allItems) const-
595{-
596 ((!(option)) ? qt_assert("option",__FILE__,13171402) : qt_noop());-
597 const QGraphicsItem * const q = q_func();-
598-
599-
600 const QRectF brect = q->boundingRect();-
601 option->state = QStyle::State_None;-
602 option->rect = brect.toRect();-
603 option->levelOfDetail = 1;-
604 option->exposedRect = brect;-
605-
606-
607-
608-
609 option->styleObject = q_ptr->toGraphicsObject();-
610 if (!option->styleObject)-
611 option->styleObject = scene;-
612-
613 if (selected)-
614 option->state |= QStyle::State_Selected;-
615 if (enabled)-
616 option->state |= QStyle::State_Enabled;-
617 if (q->hasFocus())-
618 option->state |= QStyle::State_HasFocus;-
619 if (scene) {-
620 if (scene->d_func()->hoverItems.contains(q_ptr))-
621 option->state |= QStyle::State_MouseOver;-
622 if (q == scene->mouseGrabberItem())-
623 option->state |= QStyle::State_Sunken;-
624 }-
625-
626 if (!(flags & QGraphicsItem::ItemUsesExtendedStyleOption))-
627 return;-
628-
629-
630 option->matrix = worldTransform.toAffine();-
631-
632 if (!allItems) {-
633-
634 option->exposedRect = QRectF();-
635 const QTransform reverseMap = worldTransform.inverted();-
636 const QVector<QRect> exposedRects(exposedRegion.rects());-
637 for (int i = 0; i < exposedRects.size(); ++i) {-
638 option->exposedRect |= reverseMap.mapRect(QRectF(exposedRects.at(i)));-
639 if (option->exposedRect.contains(brect))-
640 break;-
641 }-
642 option->exposedRect &= brect;-
643 }-
644}-
645-
646-
647-
648-
649-
650-
651void QGraphicsItemCache::purge()-
652{-
653 QPixmapCache::remove(key);-
654 key = QPixmapCache::Key();-
655 QMutableHashIterator<QPaintDevice *, DeviceData> it(const auto &constDeviceData = deviceData);-
while;
656 for (it.hasNext()) {-
DeviceDataconst auto &data = it.next().value();: constDeviceData)
657 QPixmapCache::remove(data.key);
never executed: QPixmapCache::remove(data.key);
0
658 data.cacheIndent = QPoint();-
}deviceData.clear();
659 allExposed = true;-
660 exposed.clear();-
661}
never executed: end of block
0
662QGraphicsItem::QGraphicsItem(QGraphicsItem *parent)-
663 : d_ptr(new QGraphicsItemPrivate)-
664{-
665 d_ptr->q_ptr = this;-
666 setParentItem(parent);-
667}-
668-
669-
670-
671-
672QGraphicsItem::QGraphicsItem(QGraphicsItemPrivate &dd, QGraphicsItem *parent)-
673 : d_ptr(&dd)-
674{-
675 d_ptr->q_ptr = this;-
676 setParentItem(parent);-
677}-
678QGraphicsItem::~QGraphicsItem()-
679{-
680 if (d_ptr->isObject
d_ptr->isObjectDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
681 QGraphicsObject *o = static_cast<QGraphicsObject *>(this);-
682 QObjectPrivate *p = QObjectPrivate::get(o);-
683 p->wasDeleted = true;-
684 if (p->declarativeData
p->declarativeDataDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
685 if (static_cast<
static_cast<QA...)->ownedByQml1Description
TRUEnever evaluated
FALSEnever evaluated
QAbstractDeclarativeDataImpl*>(p->declarativeData)->ownedByQml1
static_cast<QA...)->ownedByQml1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
686 if (QAbstractDeclarativeData::destroyed_qml1
QAbstractDecla...destroyed_qml1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
687 QAbstractDeclarativeData::destroyed_qml1(p->declarativeData, o);
never executed: QAbstractDeclarativeData::destroyed_qml1(p->declarativeData, o);
0
688 }
never executed: end of block
else {
0
689 if (QAbstractDeclarativeData::destroyed
QAbstractDecla...ata::destroyedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
690 QAbstractDeclarativeData::destroyed(p->declarativeData, o);
never executed: QAbstractDeclarativeData::destroyed(p->declarativeData, o);
0
691 }
never executed: end of block
0
692 p->declarativeData = 0;-
693 }
never executed: end of block
0
694 }
never executed: end of block
0
695-
696 d_ptr->inDestructor = 1;-
697 d_ptr->removeExtraItemCache();-
698-
699-
700 if (d_ptr->isObject
d_ptr->isObjectDescription
TRUEnever evaluated
FALSEnever evaluated
&& !d_ptr->gestureContext.isEmpty()
!d_ptr->gestur...text.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
701 QGraphicsObject *o = static_cast<QGraphicsObject *>(this);-
702 if (QGestureManager *manager = QGestureManager::instance()
QGestureManage...er::instance()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
703 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d_ptr->gestureContext.keys())>::type> _container_((const auto types = d_ptr->gestureContext.keys())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)();-
704 for (Qt::GestureType type = *_container_.i; _container_.control; _container_.control = 0: types)-
705 manager->cleanupCachedGestures(o, type);
never executed: manager->cleanupCachedGestures(o, type);
0
706 }
never executed: end of block
0
707 }
never executed: end of block
0
708-
709-
710 clearFocus();-
711 setFocusProxy(0);-
712-
713-
714 QGraphicsItem *p = d_ptr->parent;-
715 while (p
pDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
716 if (p->flags() & ItemIsFocusScope
p->flags() & ItemIsFocusScopeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
717 if (p->d_ptr->focusScopeItem == this
p->d_ptr->focu...peItem == thisDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
718 p->d_ptr->focusScopeItem = 0;
never executed: p->d_ptr->focusScopeItem = 0;
0
719 break;
never executed: break;
0
720 }-
721 p = p->d_ptr->parent;-
722 }
never executed: end of block
0
723-
724 if (!d_ptr->children.isEmpty()
!d_ptr->children.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
725 while (!d_ptr->children.isEmpty()
!d_ptr->children.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
726 delete d_ptr->children.first();
never executed: delete d_ptr->children.first();
0
727 ((!(d_ptr->children.isEmpty())) ? qt_assert("d_ptr->children.isEmpty()",__FILE__,14691552) : qt_noop());-
728 }
never executed: end of block
0
729-
730 if (d_ptr->scene
d_ptr->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
731 d_ptr->scene->d_func()->removeItemHelper(this);-
732 }
never executed: end of block
else {
0
733 d_ptr->resetFocusProxy();-
734 setParentItem(0);-
735 }
never executed: end of block
0
736-
737-
738 delete d_ptr->graphicsEffect;-
739-
740 if (d_ptr->transformData
d_ptr->transformDataDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
741 for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size()
i < d_ptr->tra...nsforms.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
742 QGraphicsTransform *t = d_ptr->transformData->graphicsTransforms.at(i);-
743 static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0;-
744 delete t;-
745 }
never executed: end of block
0
746 }
never executed: end of block
0
747 delete d_ptr->transformData;-
748-
749 if (QGraphicsItemCustomDataStore *dataStore = qt_dataStore()
QGraphicsItemC...qt_dataStore()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
750 dataStore->data.remove(this);
never executed: dataStore->data.remove(this);
0
751}
never executed: end of block
0
752-
753-
754-
755-
756-
757-
758-
759QGraphicsScene *QGraphicsItem::scene() const-
760{-
761 return d_ptr->scene;-
762}-
763-
764-
765-
766-
767-
768-
769-
770QGraphicsItemGroup *QGraphicsItem::group() const-
771{-
772 if (!d_ptr->isMemberOfGroup)-
773 return 0;-
774 QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);-
775 while ((parent = parent->d_ptr->parent)) {-
776 if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent))-
777 return group;-
778 }-
779-
780-
781 return 0;-
782}-
783void QGraphicsItem::setGroup(QGraphicsItemGroup *group)-
784{-
785 if (!group) {-
786 if (QGraphicsItemGroup *group = this->group())-
787 group->removeFromGroup(this);-
788 } else {-
789 group->addToGroup(this);-
790 }-
791}-
792-
793-
794-
795-
796-
797-
798-
799QGraphicsItem *QGraphicsItem::parentItem() const-
800{-
801 return d_ptr->parent;-
802}-
803QGraphicsItem *QGraphicsItem::topLevelItem() const-
804{-
805 QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);-
806 while (QGraphicsItem *grandPa = parent->parentItem())-
807 parent = grandPa;-
808 return parent;-
809}-
810QGraphicsObject *QGraphicsItem::parentObject() const-
811{-
812 QGraphicsItem *p = d_ptr->parent;-
813 return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : 0;-
814}-
815QGraphicsWidget *QGraphicsItem::parentWidget() const-
816{-
817 QGraphicsItem *p = parentItem();-
818 while (p && !p->isWidget())-
819 p = p->parentItem();-
820 return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : 0;-
821}-
822QGraphicsWidget *QGraphicsItem::topLevelWidget() const-
823{-
824 if (const QGraphicsWidget *p = parentWidget())-
825 return p->topLevelWidget();-
826 return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : 0;-
827}-
828QGraphicsWidget *QGraphicsItem::window() const-
829{-
830 QGraphicsItem *p = panel();-
831 if (p && p->isWindow())-
832 return static_cast<QGraphicsWidget *>(p);-
833 return 0;-
834}-
835QGraphicsItem *QGraphicsItem::panel() const-
836{-
837 if (d_ptr->flags & ItemIsPanel)-
838 return const_cast<QGraphicsItem *>(this);-
839 return d_ptr->parent ? d_ptr->parent->panel() : 0;-
840}-
841-
842-
843-
844-
845-
846-
847-
848QGraphicsObject *QGraphicsItem::toGraphicsObject()-
849{-
850 return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : 0;-
851}-
852-
853-
854-
855-
856-
857-
858-
859const QGraphicsObject *QGraphicsItem::toGraphicsObject() const-
860{-
861 return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0;-
862}-
863void QGraphicsItem::setParentItem(QGraphicsItem *newParent)-
864{-
865 if (newParent == this) {-
866 QMessageLogger(__FILE__, 16861769, __PRETTY_FUNCTION__).warning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this);-
867 return;-
868 }-
869 if (newParent == d_ptr->parent)-
870 return;-
871-
872 const QVariant newParentVariant(itemChange(QGraphicsItem::ItemParentChange,-
873 QVariant::fromValue<QGraphicsItem *>(newParent)));-
874 newParent = qvariant_cast<QGraphicsItem *>(newParentVariant);-
875 if (newParent == d_ptr->parent)-
876 return;-
877-
878 const QVariant thisPointerVariant(QVariant::fromValue<QGraphicsItem *>(this));-
879 d_ptr->setParentItemHelper(newParent, &newParentVariant, &thisPointerVariant);-
880}-
881QList<QGraphicsItem *> QGraphicsItem::childItems() const-
882{-
883 const_cast<QGraphicsItem *>(this)->d_ptr->ensureSortedChildren();-
884 return d_ptr->children;-
885}-
886-
887-
888-
889-
890-
891-
892bool QGraphicsItem::isWidget() const-
893{-
894 return d_ptr->isWidget;-
895}-
896bool QGraphicsItem::isWindow() const-
897{-
898 return d_ptr->isWidget && (static_cast<const QGraphicsWidget *>(this)->windowType() & Qt::Window);-
899}-
900-
901-
902-
903-
904-
905-
906-
907bool QGraphicsItem::isPanel() const-
908{-
909 return d_ptr->flags & ItemIsPanel;-
910}-
911QGraphicsItem::GraphicsItemFlags QGraphicsItem::flags() const-
912{-
913 return GraphicsItemFlags(d_ptr->flags);-
914}-
915-
916-
917-
918-
919-
920-
921-
922void QGraphicsItem::setFlag(GraphicsItemFlag flag, bool enabled)-
923{-
924 if (enabled)-
925 setFlags(GraphicsItemFlags(d_ptr->flags) | flag);-
926 else-
927 setFlags(GraphicsItemFlags(d_ptr->flags) & ~flag);-
928}-
929void QGraphicsItem::setFlags(GraphicsItemFlags flags)-
930{-
931-
932 if (quint32(d_ptr->flags) == quint32(flags))-
933 return;-
934 flags = GraphicsItemFlags(itemChange(ItemFlagsChange, quint32(flags)).toUInt());-
935 if (quint32(d_ptr->flags) == quint32(flags))-
936 return;-
937 if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex)-
938 d_ptr->scene->d_func()->index->itemChange(this, ItemFlagsChange, &flags);-
939-
940-
941 const quint32 geomChangeFlagsMask = (ItemClipsChildrenToShape | ItemClipsToShape | ItemIgnoresTransformations | ItemIsSelectable);-
942 bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask);-
943 if (fullUpdate)-
944 d_ptr->updatePaintedViewBoundingRects( true);-
945-
946-
947 GraphicsItemFlags oldFlags = GraphicsItemFlags(d_ptr->flags);-
948-
949-
950 d_ptr->flags = flags;-
951-
952 if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) {-
953-
954-
955 clearFocus();-
956 }-
957-
958 if (!(d_ptr->flags & ItemIsSelectable) && isSelected()) {-
959-
960-
961 setSelected(false);-
962 }-
963-
964 if ((flags & ItemClipsChildrenToShape) != (oldFlags & ItemClipsChildrenToShape)) {-
965-
966-
967 d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);-
968-
969-
970 d_ptr->dirtyChildrenBoundingRect = 1;-
971 d_ptr->markParentDirty(true);-
972 }-
973-
974 if ((flags & ItemContainsChildrenInShape) != (oldFlags & ItemContainsChildrenInShape)) {-
975-
976 d_ptr->updateAncestorFlag(ItemContainsChildrenInShape);-
977 }-
978-
979 if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) {-
980-
981-
982 d_ptr->updateAncestorFlag(ItemIgnoresTransformations);-
983 }-
984-
985 if ((flags & ItemNegativeZStacksBehindParent) != (oldFlags & ItemNegativeZStacksBehindParent)) {-
986-
987-
988-
989-
990-
991 if (d_ptr->z < qreal(0.0))-
992 flags |= ItemStacksBehindParent;-
993 else-
994 flags &= ~ItemStacksBehindParent;-
995 d_ptr->flags = flags;-
996 }-
997-
998 if ((flags & ItemStacksBehindParent) != (oldFlags & ItemStacksBehindParent)) {-
999-
1000-
1001-
1002-
1003 if (d_ptr->parent)-
1004 d_ptr->parent->d_ptr->needSortChildren = 1;-
1005 else if (d_ptr->scene)-
1006 d_ptr->scene->d_func()->needSortTopLevelItems = 1;-
1007 }-
1008-
1009 if ((flags & ItemAcceptsInputMethod) != (oldFlags & ItemAcceptsInputMethod)) {-
1010-
1011 if (d_ptr->scene)-
1012 d_ptr->scene->d_func()->updateInputMethodSensitivityInViews();-
1013 }-
1014-
1015 if ((flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) {-
1016 bool becomesPanel = (flags & ItemIsPanel);-
1017 if ((d_ptr->panelModality != NonModal) && d_ptr->scene) {-
1018-
1019 if (becomesPanel)-
1020 d_ptr->scene->d_func()->enterModal(this);-
1021 else-
1022 d_ptr->scene->d_func()->leaveModal(this);-
1023 }-
1024 if (d_ptr->isWidget && (becomesPanel || parentWidget())) {-
1025 QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this);-
1026 QGraphicsWidget *focusFirst = w;-
1027 QGraphicsWidget *focusLast = w;-
1028 for (;;) {-
1029 QGraphicsWidget *test = focusLast->d_func()->focusNext;-
1030 if (!w->isAncestorOf(test) || test == w)-
1031 break;-
1032 focusLast = test;-
1033 }-
1034-
1035 if (becomesPanel) {-
1036-
1037 QGraphicsWidget *beforeMe = w->d_func()->focusPrev;-
1038 QGraphicsWidget *afterMe = focusLast->d_func()->focusNext;-
1039 beforeMe->d_func()->focusNext = afterMe;-
1040 afterMe->d_func()->focusPrev = beforeMe;-
1041 focusFirst->d_func()->focusPrev = focusLast;-
1042 focusLast->d_func()->focusNext = focusFirst;-
1043 if (!isAncestorOf(focusFirst->d_func()->focusNext))-
1044 focusFirst->d_func()->focusNext = w;-
1045 } else if (QGraphicsWidget *pw = parentWidget()) {-
1046-
1047 QGraphicsWidget *beforeMe = pw;-
1048 QGraphicsWidget *afterMe = pw->d_func()->focusNext;-
1049 beforeMe->d_func()->focusNext = w;-
1050 afterMe->d_func()->focusPrev = focusLast;-
1051 w->d_func()->focusPrev = beforeMe;-
1052 focusLast->d_func()->focusNext = afterMe;-
1053 }-
1054 }-
1055 }-
1056-
1057 if (d_ptr->scene) {-
1058 if ((flags & ItemSendsScenePositionChanges) != (oldFlags & ItemSendsScenePositionChanges)) {-
1059 if (flags & ItemSendsScenePositionChanges)-
1060 d_ptr->scene->d_func()->registerScenePosItem(this);-
1061 else-
1062 d_ptr->scene->d_func()->unregisterScenePosItem(this);-
1063 }-
1064 d_ptr->scene->d_func()->markDirty(this, QRectF(), true);-
1065 }-
1066-
1067-
1068 itemChange(ItemFlagsHaveChanged, quint32(flags));-
1069}-
1070QGraphicsItem::CacheMode QGraphicsItem::cacheMode() const-
1071{-
1072 return QGraphicsItem::CacheMode(d_ptr->cacheMode);-
1073}-
1074void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize)-
1075{-
1076 CacheMode lastMode = CacheMode(d_ptr->cacheMode);-
1077 d_ptr->cacheMode = mode;-
1078 bool noVisualChange = (mode == NoCache && lastMode == NoCache)-
1079 || (mode == NoCache && lastMode == DeviceCoordinateCache)-
1080 || (mode == DeviceCoordinateCache && lastMode == NoCache)-
1081 || (mode == DeviceCoordinateCache && lastMode == DeviceCoordinateCache);-
1082 if (mode == NoCache) {-
1083 d_ptr->removeExtraItemCache();-
1084 } else {-
1085 QGraphicsItemCache *cache = d_ptr->extraItemCache();-
1086-
1087-
1088 cache->purge();-
1089-
1090 if (mode == ItemCoordinateCache) {-
1091 if (lastMode == mode && cache->fixedSize == logicalCacheSize)-
1092 noVisualChange = true;-
1093 cache->fixedSize = logicalCacheSize;-
1094 }-
1095 }-
1096 if (!noVisualChange)-
1097 update();-
1098}-
1099-
1100-
1101-
1102-
1103-
1104-
1105QGraphicsItem::PanelModality QGraphicsItem::panelModality() const-
1106{-
1107 return d_ptr->panelModality;-
1108}-
1109void QGraphicsItem::setPanelModality(PanelModality panelModality)-
1110{-
1111 if (d_ptr->panelModality == panelModality)-
1112 return;-
1113-
1114 PanelModality previousModality = d_ptr->panelModality;-
1115 bool enterLeaveModal = (isPanel() && d_ptr->scene && isVisible());-
1116 if (enterLeaveModal && panelModality == NonModal)-
1117 d_ptr->scene->d_func()->leaveModal(this);-
1118 d_ptr->panelModality = panelModality;-
1119 if (enterLeaveModal && d_ptr->panelModality != NonModal)-
1120 d_ptr->scene->d_func()->enterModal(this, previousModality);-
1121}-
1122bool QGraphicsItem::isBlockedByModalPanel(QGraphicsItem **blockingPanel) const-
1123{-
1124 if (!d_ptr->scene
!d_ptr->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1125 return
never executed: return false;
false;
never executed: return false;
0
1126-
1127-
1128 QGraphicsItem *dummy = 0;-
1129 if (!blockingPanel
!blockingPanelDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1130 blockingPanel = &dummy;
never executed: blockingPanel = &dummy;
0
1131-
1132 const QGraphicsScenePrivate *scene_d = d_ptr->scene->d_func();-
1133 if (scene_d->modalPanels.isEmpty()
scene_d->modalPanels.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1134 return
never executed: return false;
false;
never executed: return false;
0
1135-
1136-
1137 if (!scene_d->popupWidgets.isEmpty()
!scene_d->popu...gets.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& scene_d->popupWidgets.first() == this
scene_d->popup...irst() == thisDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1138 return
never executed: return false;
false;
never executed: return false;
0
1139-
1140 for (int i = 0; i < scene_d->modalPanels.count()
i < scene_d->m...Panels.count()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1141 QGraphicsItem *modalPanel = scene_d->modalPanels.at(i);-
1142 if (modalPanel->panelModality() == QGraphicsItem::SceneModal
modalPanel->pa...em::SceneModalDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1143-
1144 if (modalPanel != this
modalPanel != thisDescription
TRUEnever evaluated
FALSEnever evaluated
&& !modalPanel->isAncestorOf(this)
!modalPanel->i...cestorOf(this)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1145 *blockingPanel = modalPanel;-
1146 return
never executed: return true;
true;
never executed: return true;
0
1147 }-
1148 }
never executed: end of block
else {
0
1149-
1150 if (modalPanel != this
modalPanel != thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
1151 && !modalPanel->isAncestorOf(this)
!modalPanel->i...cestorOf(this)Description
TRUEnever evaluated
FALSEnever evaluated
0
1152 && commonAncestorItem(modalPanel)
commonAncestorItem(modalPanel)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1153 *blockingPanel = modalPanel;-
1154 return
never executed: return true;
true;
never executed: return true;
0
1155 }-
1156 }
never executed: end of block
0
1157 }-
1158 return
never executed: return false;
false;
never executed: return false;
0
1159}-
1160QString QGraphicsItem::toolTip() const-
1161{-
1162 return d_ptr->extra(QGraphicsItemPrivate::ExtraToolTip).toString();-
1163}-
1164-
1165-
1166-
1167-
1168-
1169-
1170-
1171void QGraphicsItem::setToolTip(const QString &toolTip)-
1172{-
1173 const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip));-
1174 d_ptr->setExtra(QGraphicsItemPrivate::ExtraToolTip, toolTipVariant.toString());-
1175 itemChange(ItemToolTipHasChanged, toolTipVariant);-
1176}-
1177QCursor QGraphicsItem::cursor() const-
1178{-
1179 return qvariant_cast<QCursor>(d_ptr->extra(QGraphicsItemPrivate::ExtraCursor));-
1180}-
1181void QGraphicsItem::setCursor(const QCursor &cursor)-
1182{-
1183 const QVariant cursorVariant(itemChange(ItemCursorChange, QVariant::fromValue<QCursor>(cursor)));-
1184 d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qvariant_cast<QCursor>(cursorVariant));-
1185 d_ptr->hasCursor = 1;-
1186 if (d_ptr->scene
d_ptr->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1187 d_ptr->scene->d_func()->allItemsUseDefaultCursor = false;-
1188 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d_ptr->scene->const auto views ())>::type> _container_((= d_ptr->scene->views())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)();-
1189 for (QGraphicsView *view = *_container_.i; _container_.control; _container_.control = 0: views) {-
1190 view->viewport()->setMouseTracking(true);-
1191-
1192 if (view->underMouse()
view->underMouse()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1193 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(view->items(view->mapFromGlobal(QCursor::pos())))>::type> _container_((const auto itemsUnderCursor = view->items(view->mapFromGlobal(QCursor::pos())))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)()));-
1194 for (QGraphicsItem *itemUnderCursor = *_container_.i; _container_.control; _container_.control = 0: itemsUnderCursor) {-
1195 if (itemUnderCursor->hasCursor()
itemUnderCursor->hasCursor()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1196 QMetaObject::invokeMethod(view, "_q_setViewportCursor",-
1197 QArgument<QCursor >("QCursor", itemUnderCursor->cursor()));-
1198 break;
never executed: break;
0
1199 }-
1200 }
never executed: end of block
0
1201 break;
never executed: break;
0
1202 }-
1203 }
never executed: end of block
0
1204 }
never executed: end of block
0
1205 itemChange(ItemCursorHasChanged, cursorVariant);-
1206}
never executed: end of block
0
1207bool QGraphicsItem::hasCursor() const-
1208{-
1209 return d_ptr->hasCursor;-
1210}-
1211-
1212-
1213-
1214-
1215-
1216-
1217void QGraphicsItem::unsetCursor()-
1218{-
1219 if (!d_ptr->hasCursor
!d_ptr->hasCursorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1220 return;
never executed: return;
0
1221 d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraCursor);-
1222 d_ptr->hasCursor = 0;-
1223 if (d_ptr->scene
d_ptr->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1224 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d_ptr->scene->const auto views ())>::type> _container_((= d_ptr->scene->views())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)();-
1225 for (QGraphicsView *view = *_container_.i; _container_.control; _container_.control = 0: views) {-
1226 if (view->underMouse()
view->underMouse()Description
TRUEnever evaluated
FALSEnever evaluated
&& view->itemAt(view->mapFromGlobal(QCursor::pos())) == this
view->itemAt(v...os())) == thisDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1227 QMetaObject::invokeMethod(view, "_q_unsetViewportCursor");-
1228 break;
never executed: break;
0
1229 }-
1230 }
never executed: end of block
0
1231 }
never executed: end of block
0
1232}
never executed: end of block
0
1233bool QGraphicsItem::isVisible() const-
1234{-
1235 return d_ptr->visible;-
1236}-
1237bool QGraphicsItem::isVisibleTo(const QGraphicsItem *parent) const-
1238{-
1239 const QGraphicsItem *p = this;-
1240 if (d_ptr->explicitlyHidden)-
1241 return false;-
1242 do {-
1243 if (p == parent)-
1244 return true;-
1245 if (p->d_ptr->explicitlyHidden)-
1246 return false;-
1247 } while ((p = p->d_ptr->parent));-
1248 return parent == 0;-
1249}-
1250-
1251-
1252-
1253-
1254-
1255-
1256-
1257void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly,-
1258 bool update, bool hiddenByPanel)-
1259{-
1260 QGraphicsItem * const q = q_func();-
1261-
1262-
1263 if (explicitly)-
1264 explicitlyHidden = newVisible ? 0 : 1;-
1265-
1266-
1267 if (visible == quint32(newVisible))-
1268 return;-
1269-
1270-
1271 if (parent && newVisible && !parent->d_ptr->visible)-
1272 return;-
1273-
1274-
1275 const QVariant newVisibleVariant(q_ptr->itemChange(QGraphicsItem::ItemVisibleChange,-
1276 quint32(newVisible)));-
1277 newVisible = newVisibleVariant.toBool();-
1278 if (visible == quint32(newVisible))-
1279 return;-
1280 visible = newVisible;-
1281-
1282-
1283 if (update) {-
1284 QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));-
1285 if (c)-
1286 c->purge();-
1287 if (scene) {-
1288-
1289 invalidateParentGraphicsEffectsRecursively();-
1290-
1291 scene->d_func()->markDirty(q_ptr, QRectF(), false, true);-
1292 }-
1293 }-
1294-
1295-
1296 bool hasFocus = q_ptr->hasFocus();-
1297 if (!newVisible) {-
1298 if (scene) {-
1299 if (scene->d_func()->mouseGrabberItems.contains(q))-
1300 q->ungrabMouse();-
1301 if (scene->d_func()->keyboardGrabberItems.contains(q))-
1302 q->ungrabKeyboard();-
1303 if (q->isPanel() && panelModality != QGraphicsItem::NonModal)-
1304 scene->d_func()->leaveModal(q_ptr);-
1305 }-
1306 if (hasFocus && scene) {-
1307-
1308 QGraphicsItem *focusItem = scene->focusItem();-
1309 bool clear = true;-
1310 if (isWidget && !focusItem->isPanel()) {-
1311 do {-
1312 if (focusItem == q_ptr) {-
1313 clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);-
1314 break;-
1315 }-
1316 } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());-
1317 }-
1318 if (clear)-
1319 clearFocusHelper( false, hiddenByPanel);-
1320 }-
1321 if (q_ptr->isSelected())-
1322 q_ptr->setSelected(false);-
1323 } else {-
1324 geometryChanged = 1;-
1325 paintedViewBoundingRectsNeedRepaint = 1;-
1326 if (scene) {-
1327 if (isWidget) {-
1328 QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);-
1329 if (widget->windowType() == Qt::Popup)-
1330 scene->d_func()->addPopup(widget);-
1331 }-
1332 if (q->isPanel() && panelModality != QGraphicsItem::NonModal) {-
1333 scene->d_func()->enterModal(q_ptr);-
1334 }-
1335 }-
1336 }-
1337-
1338-
1339 const bool updateChildren = update && !((flags & QGraphicsItem::ItemClipsChildrenToShape-
1340 || flags & QGraphicsItem::ItemContainsChildrenInShape)-
1341 && !(flags & QGraphicsItem::ItemHasNoContents));-
1342 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(children)>::type> _container_((children)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *child = *_container_.i; _container_.control; _container_.control = 0) {-
1343 if (!newVisible || !child->d_ptr->explicitlyHidden)-
1344 child->d_ptr->setVisibleHelper(newVisible, false, updateChildren, hiddenByPanel);-
1345 }-
1346-
1347-
1348 if (scene && q->isPanel()) {-
1349 if (newVisible) {-
1350 if (parent && parent->isActive())-
1351 q->setActive(true);-
1352 } else {-
1353 if (q->isActive())-
1354 scene->setActivePanel(parent);-
1355 }-
1356 }-
1357-
1358-
1359 if (scene) {-
1360 if (newVisible) {-
1361-
1362 QGraphicsItem *p = parent;-
1363 bool done = false;-
1364 while (p) {-
1365 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {-
1366 QGraphicsItem *fsi = p->d_ptr->focusScopeItem;-
1367 if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {-
1368 done = true;-
1369 while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible())-
1370 fsi = fsi->d_ptr->focusScopeItem;-
1371 fsi->d_ptr->setFocusHelper(Qt::OtherFocusReason, true,-
1372 false);-
1373 }-
1374 break;-
1375 }-
1376 p = p->d_ptr->parent;-
1377 }-
1378 if (!done) {-
1379 QGraphicsItem *fi = subFocusItem;-
1380 if (fi && fi != scene->focusItem()) {-
1381 scene->setFocusItem(fi);-
1382 } else if (flags & QGraphicsItem::ItemIsFocusScope &&-
1383 !scene->focusItem() &&-
1384 q->isAncestorOf(scene->d_func()->lastFocusItem)) {-
1385 q_ptr->setFocus();-
1386 }-
1387 }-
1388 } else {-
1389-
1390 if (hasFocus) {-
1391 QGraphicsItem *p = parent;-
1392 while (p) {-
1393 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {-
1394 if (p->d_ptr->visible) {-
1395 p->d_ptr->setFocusHelper(Qt::OtherFocusReason, true,-
1396 true);-
1397 }-
1398 break;-
1399 }-
1400 p = p->d_ptr->parent;-
1401 }-
1402 }-
1403 }-
1404 }-
1405-
1406-
1407 q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant);-
1408-
1409 if (isObject)-
1410 static_cast<QGraphicsObject *>(q_ptr)->visibleChanged();-
1411}-
1412void QGraphicsItem::setVisible(bool visible)-
1413{-
1414 d_ptr->setVisibleHelper(visible,-
1415 true,-
1416 true,-
1417 isPanel());-
1418}-
1419bool QGraphicsItem::isEnabled() const-
1420{-
1421 return d_ptr->enabled;-
1422}-
1423-
1424-
1425-
1426-
1427-
1428-
1429-
1430void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bool update)-
1431{-
1432-
1433 if (explicitly)-
1434 explicitlyDisabled = newEnabled ? 0 : 1;-
1435-
1436-
1437 if (enabled == quint32(newEnabled))-
1438 return;-
1439-
1440-
1441 if (!newEnabled) {-
1442 if (scene && scene->mouseGrabberItem() == q_ptr)-
1443 q_ptr->ungrabMouse();-
1444 if (q_ptr->hasFocus()) {-
1445-
1446-
1447 QGraphicsItem *focusItem = scene->focusItem();-
1448 bool clear = true;-
1449 if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {-
1450 do {-
1451 if (focusItem == q_ptr) {-
1452 clear = !static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);-
1453 break;-
1454 }-
1455 } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());-
1456 }-
1457 if (clear)-
1458 q_ptr->clearFocus();-
1459 }-
1460 if (q_ptr->isSelected())-
1461 q_ptr->setSelected(false);-
1462 }-
1463-
1464-
1465 const QVariant newEnabledVariant(q_ptr->itemChange(QGraphicsItem::ItemEnabledChange,-
1466 quint32(newEnabled)));-
1467 enabled = newEnabledVariant.toBool();-
1468-
1469-
1470 if (update)-
1471 q_ptr->update();-
1472-
1473 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(children)>::type> _container_((children)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *child = *_container_.i; _container_.control; _container_.control = 0) {-
1474 if (!newEnabled || !child->d_ptr->explicitlyDisabled)-
1475 child->d_ptr->setEnabledHelper(newEnabled, false);-
1476 }-
1477-
1478-
1479 q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant);-
1480-
1481 if (isObject)-
1482 static_cast<QGraphicsObject *>(q_ptr)->enabledChanged();-
1483}-
1484void QGraphicsItem::setEnabled(bool enabled)-
1485{-
1486 d_ptr->setEnabledHelper(enabled, true);-
1487}-
1488bool QGraphicsItem::isSelected() const-
1489{-
1490 if (QGraphicsItemGroup *group = this->group())-
1491 return group->isSelected();-
1492 return d_ptr->selected;-
1493}-
1494void QGraphicsItem::setSelected(bool selected)-
1495{-
1496 if (QGraphicsItemGroup *group = this->group()) {-
1497 group->setSelected(selected);-
1498 return;-
1499 }-
1500-
1501 if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible)-
1502 selected = false;-
1503 if (d_ptr->selected == selected)-
1504 return;-
1505 const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected)));-
1506 bool newSelected = newSelectedVariant.toBool();-
1507 if (d_ptr->selected == newSelected)-
1508 return;-
1509 d_ptr->selected = newSelected;-
1510-
1511 update();-
1512 if (d_ptr->scene) {-
1513 QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func();-
1514 if (selected) {-
1515 sceneD->selectedItems << this;-
1516 } else {-
1517-
1518-
1519 }-
1520 if (!sceneD->selectionChanging)-
1521 d_ptr->scene->selectionChanged();-
1522 }-
1523-
1524-
1525 itemChange(QGraphicsItem::ItemSelectedHasChanged, newSelectedVariant);-
1526}-
1527qreal QGraphicsItem::opacity() const-
1528{-
1529 return d_ptr->opacity;-
1530}-
1531qreal QGraphicsItem::effectiveOpacity() const-
1532{-
1533 return d_ptr->effectiveOpacity();-
1534}-
1535void QGraphicsItem::setOpacity(qreal opacity)-
1536{-
1537-
1538 const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity));-
1539-
1540-
1541 qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1));-
1542-
1543-
1544 if (newOpacity == d_ptr->opacity)-
1545 return;-
1546-
1547 bool wasFullyTransparent = d_ptr->isOpacityNull();-
1548 d_ptr->opacity = newOpacity;-
1549-
1550-
1551 itemChange(ItemOpacityHasChanged, newOpacityVariant);-
1552-
1553-
1554 if (d_ptr->scene) {-
1555-
1556 d_ptr->invalidateParentGraphicsEffectsRecursively();-
1557 if (!(d_ptr->flags & ItemDoesntPropagateOpacityToChildren))-
1558 d_ptr->invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::OpacityChanged);-
1559-
1560 d_ptr->scene->d_func()->markDirty(this, QRectF(),-
1561 true,-
1562 false,-
1563 d_ptr->isOpacityNull());-
1564 if (wasFullyTransparent)-
1565 d_ptr->paintedViewBoundingRectsNeedRepaint = 1;-
1566 }-
1567-
1568 if (d_ptr->isObject)-
1569 static_cast<QGraphicsObject *>(this)->opacityChanged();-
1570}-
1571-
1572-
1573-
1574-
1575-
1576-
1577-
1578QGraphicsEffect *QGraphicsItem::graphicsEffect() const-
1579{-
1580 return d_ptr->graphicsEffect;-
1581}-
1582void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect)-
1583{-
1584 if (d_ptr->graphicsEffect == effect)-
1585 return;-
1586-
1587 if (d_ptr->graphicsEffect) {-
1588 delete d_ptr->graphicsEffect;-
1589 d_ptr->graphicsEffect = 0;-
1590 } else if (d_ptr->parent) {-
1591 d_ptr->parent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();-
1592 }-
1593-
1594 if (effect) {-
1595-
1596 QGraphicsEffectSourcePrivate *sourced = new QGraphicsItemEffectSourcePrivate(this);-
1597 QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);-
1598 d_ptr->graphicsEffect = effect;-
1599 effect->d_func()->setGraphicsEffectSource(source);-
1600 prepareGeometryChange();-
1601 }-
1602}-
1603-
1604-
1605void QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively()-
1606{-
1607-
1608 QGraphicsItemPrivate *itemPrivate = this;-
1609 do {-
1610-
1611 if (itemPrivate->mayHaveChildWithGraphicsEffect)-
1612 return;-
1613 itemPrivate->mayHaveChildWithGraphicsEffect = 1;-
1614 } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));-
1615-
1616}-
1617QRectF QGraphicsItemPrivate::effectiveBoundingRect(const QRectF &rect) const-
1618{-
1619-
1620 const QGraphicsItem * const q = q_func();-
1621 QGraphicsEffect *effect = graphicsEffect;-
1622 if (scene
sceneDescription
TRUEnever evaluated
FALSEnever evaluated
&& effect
effectDescription
TRUEnever evaluated
FALSEnever evaluated
&& effect->isEnabled()
effect->isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1623 if (scene->d_func()->views.isEmpty()
scene->d_func(...iews.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1624 return
never executed: return effect->boundingRectFor(rect);
effect->boundingRectFor(rect);
never executed: return effect->boundingRectFor(rect);
0
1625 QRectF sceneRect = q->mapRectToScene(rect);-
1626 QRectF sceneEffectRect;-
1627 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(scene->const auto views ())>::type> _container_((= scene->views())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)();-
1628 for (QGraphicsView *view = *_container_.i; _container_.control; _container_.control = 0: views) {-
1629 QRectF deviceRect = view->d_func()->mapRectFromScene(sceneRect);-
1630 QRect deviceEffectRect = effect->boundingRectFor(deviceRect).toAlignedRect();-
1631 sceneEffectRect |= view->d_func()->mapRectToScene(deviceEffectRect);-
1632 }
never executed: end of block
0
1633 return
never executed: return q->mapRectFromScene(sceneEffectRect);
q->mapRectFromScene(sceneEffectRect);
never executed: return q->mapRectFromScene(sceneEffectRect);
0
1634 }-
1635-
1636 return
never executed: return rect;
rect;
never executed: return rect;
0
1637}-
1638QRectF QGraphicsItemPrivate::effectiveBoundingRect(QGraphicsItem *topMostEffectItem) const-
1639{-
1640-
1641 const QGraphicsItem * const q = q_func();-
1642 QRectF brect = effectiveBoundingRect(q_ptr->boundingRect());-
1643 if (ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren-
1644 || ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren-
1645 || topMostEffectItem == q)-
1646 return brect;-
1647-
1648 const QGraphicsItem *effectParent = parent;-
1649 while (effectParent) {-
1650 QGraphicsEffect *effect = effectParent->d_ptr->graphicsEffect;-
1651 if (scene && effect && effect->isEnabled()) {-
1652 const QRectF brectInParentSpace = q->mapRectToItem(effectParent, brect);-
1653 const QRectF effectRectInParentSpace = effectParent->d_ptr->effectiveBoundingRect(brectInParentSpace);-
1654 brect = effectParent->mapRectToItem(q, effectRectInParentSpace);-
1655 }-
1656 if (effectParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren-
1657 || effectParent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren-
1658 || topMostEffectItem == effectParent) {-
1659 return brect;-
1660 }-
1661 effectParent = effectParent->d_ptr->parent;-
1662 }-
1663-
1664 return brect;-
1665-
1666-
1667-
1668-
1669}-
1670QRectF QGraphicsItemPrivate::sceneEffectiveBoundingRect() const-
1671{-
1672-
1673-
1674 QPointF offset;-
1675 const QGraphicsItem *parentItem = q_ptr;-
1676 const QGraphicsItemPrivate *itemd;-
1677 do {-
1678 itemd = parentItem->d_ptr.data();-
1679 if (itemd->transformData)-
1680 break;-
1681 offset += itemd->pos;-
1682 } while ((parentItem = itemd->parent));-
1683-
1684 QRectF br = effectiveBoundingRect();-
1685 br.translate(offset);-
1686 return !parentItem ? br : parentItem->sceneTransform().mapRect(br);-
1687}-
1688bool QGraphicsItem::acceptDrops() const-
1689{-
1690 return d_ptr->acceptDrops;-
1691}-
1692void QGraphicsItem::setAcceptDrops(bool on)-
1693{-
1694 d_ptr->acceptDrops = on;-
1695}-
1696Qt::MouseButtons QGraphicsItem::acceptedMouseButtons() const-
1697{-
1698 return Qt::MouseButtons(d_ptr->acceptedMouseButtons);-
1699}-
1700void QGraphicsItem::setAcceptedMouseButtons(Qt::MouseButtons buttons)-
1701{-
1702 if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) {-
1703 if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() == this-
1704 && d_ptr->scene->d_func()->lastMouseGrabberItemHasImplicitMouseGrab) {-
1705 ungrabMouse();-
1706 }-
1707 d_ptr->acceptedMouseButtons = quint32(buttons);-
1708 }-
1709}-
1710bool QGraphicsItem::acceptHoverEvents() const-
1711{-
1712 return d_ptr->acceptsHover;-
1713}-
1714void QGraphicsItem::setAcceptHoverEvents(bool enabled)-
1715{-
1716 if (d_ptr->acceptsHover == quint32(enabled))-
1717 return;-
1718 d_ptr->acceptsHover = quint32(enabled);-
1719 if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) {-
1720 d_ptr->scene->d_func()->allItemsIgnoreHoverEvents = false;-
1721 d_ptr->scene->d_func()->enableMouseTrackingOnViews();-
1722 }-
1723}-
1724bool QGraphicsItem::acceptTouchEvents() const-
1725{-
1726 return d_ptr->acceptTouchEvents;-
1727}-
1728void QGraphicsItem::setAcceptTouchEvents(bool enabled)-
1729{-
1730 if (d_ptr->acceptTouchEvents == quint32(enabled))-
1731 return;-
1732 d_ptr->acceptTouchEvents = quint32(enabled);-
1733 if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) {-
1734 d_ptr->scene->d_func()->allItemsIgnoreTouchEvents = false;-
1735 d_ptr->scene->d_func()->enableTouchEventsOnViews();-
1736 }-
1737}-
1738bool QGraphicsItem::filtersChildEvents() const-
1739{-
1740 return d_ptr->filtersDescendantEvents;-
1741}-
1742void QGraphicsItem::setFiltersChildEvents(bool enabled)-
1743{-
1744 if (d_ptr->filtersDescendantEvents == enabled)-
1745 return;-
1746-
1747 d_ptr->filtersDescendantEvents = enabled;-
1748 d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-2));-
1749}-
1750bool QGraphicsItem::handlesChildEvents() const-
1751{-
1752 return d_ptr->handlesChildEvents;-
1753}-
1754void QGraphicsItem::setHandlesChildEvents(bool enabled)-
1755{-
1756 if (d_ptr->handlesChildEvents == enabled)-
1757 return;-
1758-
1759 d_ptr->handlesChildEvents = enabled;-
1760 d_ptr->updateAncestorFlag(QGraphicsItem::GraphicsItemFlag(-1));-
1761}-
1762bool QGraphicsItem::isActive() const-
1763{-
1764 if (!d_ptr->scene || !d_ptr->scene->isActive())-
1765 return false;-
1766 return panel() == d_ptr->scene->activePanel();-
1767}-
1768void QGraphicsItem::setActive(bool active)-
1769{-
1770 d_ptr->explicitActivate = 1;-
1771 d_ptr->wantsActive = active;-
1772 if (d_ptr->scene) {-
1773 if (active) {-
1774-
1775 d_ptr->scene->setActivePanel(this);-
1776 } else {-
1777 QGraphicsItem *activePanel = d_ptr->scene->activePanel();-
1778 QGraphicsItem *thisPanel = panel();-
1779 if (!activePanel || activePanel == thisPanel) {-
1780-
1781-
1782 QGraphicsItem *nextToActivate = 0;-
1783 if (d_ptr->parent)-
1784 nextToActivate = d_ptr->parent->panel();-
1785 if (!nextToActivate)-
1786 nextToActivate = d_ptr->scene->d_func()->lastActivePanel;-
1787 if (nextToActivate == this || isAncestorOf(nextToActivate))-
1788 nextToActivate = 0;-
1789 d_ptr->scene->setActivePanel(nextToActivate);-
1790 }-
1791 }-
1792 }-
1793}-
1794-
1795-
1796-
1797-
1798-
1799-
1800-
1801bool QGraphicsItem::hasFocus() const-
1802{-
1803 if (!d_ptr->scene || !d_ptr->scene->isActive())-
1804 return false;-
1805-
1806 if (d_ptr->focusProxy)-
1807 return d_ptr->focusProxy->hasFocus();-
1808-
1809 if (d_ptr->scene->d_func()->focusItem != this)-
1810 return false;-
1811-
1812 return panel() == d_ptr->scene->d_func()->activePanel;-
1813}-
1814void QGraphicsItem::setFocus(Qt::FocusReason focusReason)-
1815{-
1816 d_ptr->setFocusHelper(focusReason, true, false);-
1817}-
1818-
1819-
1820-
1821-
1822void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide)-
1823{-
1824-
1825 if (!q_ptr->isEnabled() || !(flags & QGraphicsItem::ItemIsFocusable))-
1826 return;-
1827-
1828-
1829 QGraphicsItem *f = q_ptr;-
1830 while (f->d_ptr->focusProxy)-
1831 f = f->d_ptr->focusProxy;-
1832-
1833-
1834 if (scene && scene->focusItem() == f)-
1835 return;-
1836-
1837-
1838 QGraphicsItem *p = parent;-
1839 while (p) {-
1840 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {-
1841 QGraphicsItem *oldFocusScopeItem = p->d_ptr->focusScopeItem;-
1842 p->d_ptr->focusScopeItem = q_ptr;-
1843 if (oldFocusScopeItem)-
1844 oldFocusScopeItem->d_ptr->focusScopeItemChange(false);-
1845 focusScopeItemChange(true);-
1846 if (!p->focusItem() && !focusFromHide) {-
1847-
1848-
1849-
1850-
1851 return;-
1852 }-
1853 break;-
1854 }-
1855 p = p->d_ptr->parent;-
1856 }-
1857-
1858 if (climb) {-
1859 while (f->d_ptr->focusScopeItem && f->d_ptr->focusScopeItem->isVisible())-
1860 f = f->d_ptr->focusScopeItem;-
1861 }-
1862-
1863-
1864 QGraphicsItem *commonAncestor = 0;-
1865 if (scene && scene->focusItem() && scene->focusItem()->panel() == q_ptr->panel()) {-
1866 commonAncestor = scene->focusItem()->commonAncestorItem(f);-
1867 scene->focusItem()->d_ptr->clearSubFocus(scene->focusItem(), commonAncestor);-
1868 }-
1869-
1870 f->d_ptr->setSubFocus(f, commonAncestor);-
1871-
1872-
1873 if (scene) {-
1874 QGraphicsItem *p = q_ptr->panel();-
1875 if ((!p && scene->isActive()) || (p && p->isActive())) {-
1876-
1877 scene->d_func()->setFocusItemHelper(f, focusReason);-
1878 }-
1879 }-
1880}-
1881void QGraphicsItem::clearFocus()-
1882{-
1883 d_ptr->clearFocusHelper( true,-
1884 false);-
1885}-
1886-
1887-
1888-
1889-
1890void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenByParentPanel)-
1891{-
1892 QGraphicsItem *subFocusItem = q_ptr;-
1893 if (flags & QGraphicsItem::ItemIsFocusScope) {-
1894 while (subFocusItem->d_ptr->focusScopeItem)-
1895 subFocusItem = subFocusItem->d_ptr->focusScopeItem;-
1896 }-
1897-
1898 if (giveFocusToParent) {-
1899-
1900 if (!inDestructor) {-
1901 QGraphicsItem *p = parent;-
1902 while (p) {-
1903 if (p->flags() & QGraphicsItem::ItemIsFocusScope) {-
1904 if (p->d_ptr->focusScopeItem == q_ptr) {-
1905 p->d_ptr->focusScopeItem = 0;-
1906 if (!subFocusItem->hasFocus())-
1907 focusScopeItemChange(false);-
1908 }-
1909 if (subFocusItem->hasFocus())-
1910 p->d_ptr->setFocusHelper(Qt::OtherFocusReason, false,-
1911 false);-
1912 return;-
1913 }-
1914 p = p->d_ptr->parent;-
1915 }-
1916 }-
1917 }-
1918-
1919 if (subFocusItem->hasFocus()) {-
1920-
1921 if (!hiddenByParentPanel)-
1922 clearSubFocus(q_ptr);-
1923-
1924-
1925 scene->setFocusItem(0);-
1926 }-
1927}-
1928QGraphicsItem *QGraphicsItem::focusProxy() const-
1929{-
1930 return d_ptr->focusProxy;-
1931}-
1932void QGraphicsItem::setFocusProxy(QGraphicsItem *item)-
1933{-
1934 if (item == d_ptr->focusProxy)-
1935 return;-
1936 if (item == this) {-
1937 QMessageLogger(__FILE__, 34523539, __PRETTY_FUNCTION__).warning("QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");-
1938 return;-
1939 }-
1940 if (item) {-
1941 if (item->d_ptr->scene != d_ptr->scene) {-
1942 QMessageLogger(__FILE__, 34573544, __PRETTY_FUNCTION__).warning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene");-
1943 return;-
1944 }-
1945 for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) {-
1946 if (f == this) {-
1947 QMessageLogger(__FILE__, 34623549, __PRETTY_FUNCTION__).warning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);-
1948 return;-
1949 }-
1950 }-
1951 }-
1952-
1953 QGraphicsItem *lastFocusProxy = d_ptr->focusProxy;-
1954 if (lastFocusProxy)-
1955 lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&d_ptr->focusProxy);-
1956 d_ptr->focusProxy = item;-
1957 if (item)-
1958 item->d_ptr->focusProxyRefs << &d_ptr->focusProxy;-
1959}-
1960QGraphicsItem *QGraphicsItem::focusItem() const-
1961{-
1962 return d_ptr->subFocusItem;-
1963}-
1964-
1965-
1966-
1967-
1968-
1969-
1970QGraphicsItem *QGraphicsItem::focusScopeItem() const-
1971{-
1972 return d_ptr->focusScopeItem;-
1973}-
1974void QGraphicsItem::grabMouse()-
1975{-
1976 if (!d_ptr->scene) {-
1977 QMessageLogger(__FILE__, 35373624, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabMouse: cannot grab mouse without scene");-
1978 return;-
1979 }-
1980 if (!d_ptr->visible) {-
1981 QMessageLogger(__FILE__, 35413628, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabMouse: cannot grab mouse while invisible");-
1982 return;-
1983 }-
1984 d_ptr->scene->d_func()->grabMouse(this);-
1985}-
1986-
1987-
1988-
1989-
1990-
1991-
1992-
1993void QGraphicsItem::ungrabMouse()-
1994{-
1995 if (!d_ptr->scene) {-
1996 QMessageLogger(__FILE__, 35563643, __PRETTY_FUNCTION__).warning("QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene");-
1997 return;-
1998 }-
1999 d_ptr->scene->d_func()->ungrabMouse(this);-
2000}-
2001void QGraphicsItem::grabKeyboard()-
2002{-
2003 if (!d_ptr->scene) {-
2004 QMessageLogger(__FILE__, 35993686, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: cannot grab keyboard without scene");-
2005 return;-
2006 }-
2007 if (!d_ptr->visible) {-
2008 QMessageLogger(__FILE__, 36033690, __PRETTY_FUNCTION__).warning("QGraphicsItem::grabKeyboard: cannot grab keyboard while invisible");-
2009 return;-
2010 }-
2011 d_ptr->scene->d_func()->grabKeyboard(this);-
2012}-
2013-
2014-
2015-
2016-
2017-
2018-
2019-
2020void QGraphicsItem::ungrabKeyboard()-
2021{-
2022 if (!d_ptr->scene) {-
2023 QMessageLogger(__FILE__, 36183705, __PRETTY_FUNCTION__).warning("QGraphicsItem::ungrabKeyboard: cannot ungrab keyboard without scene");-
2024 return;-
2025 }-
2026 d_ptr->scene->d_func()->ungrabKeyboard(this);-
2027}-
2028QPointF QGraphicsItem::pos() const-
2029{-
2030 return d_ptr->pos;-
2031}-
2032void QGraphicsItem::setX(qreal x)-
2033{-
2034 if (d_ptr->inDestructor)-
2035 return;-
2036-
2037 if (qIsNaN(x))-
2038 return;-
2039-
2040 setPos(QPointF(x, d_ptr->pos.y()));-
2041}-
2042void QGraphicsItem::setY(qreal y)-
2043{-
2044 if (d_ptr->inDestructor)-
2045 return;-
2046-
2047 if (qIsNaN(y))-
2048 return;-
2049-
2050 setPos(QPointF(d_ptr->pos.x(), y));-
2051}-
2052-
2053-
2054-
2055-
2056-
2057-
2058-
2059QPointF QGraphicsItem::scenePos() const-
2060{-
2061 return mapToScene(0, 0);-
2062}-
2063-
2064-
2065-
2066-
2067-
2068-
2069void QGraphicsItemPrivate::setPosHelper(const QPointF &pos)-
2070{-
2071 QGraphicsItem * const q = q_func();-
2072 inSetPosHelper = 1;-
2073 if (scene)-
2074 q->prepareGeometryChange();-
2075 QPointF oldPos = this->pos;-
2076 this->pos = pos;-
2077 dirtySceneTransform = 1;-
2078 inSetPosHelper = 0;-
2079 if (isObject) {-
2080 if (pos.x() != oldPos.x())-
2081 static_cast<QGraphicsObject *>(q_ptr)->xChanged();-
2082 if (pos.y() != oldPos.y())-
2083 static_cast<QGraphicsObject *>(q_ptr)->yChanged();-
2084 }-
2085}-
2086-
2087-
2088-
2089-
2090-
2091-
2092void QGraphicsItemPrivate::setTransformHelper(const QTransform &transform)-
2093{-
2094 q_ptr->prepareGeometryChange();-
2095 transformData->transform = transform;-
2096 dirtySceneTransform = 1;-
2097 transformChanged();-
2098}-
2099void QGraphicsItem::setPos(const QPointF &pos)-
2100{-
2101 if (d_ptr->pos == pos)-
2102 return;-
2103-
2104 if (d_ptr->inDestructor)-
2105 return;-
2106-
2107-
2108 if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) {-
2109 d_ptr->setPosHelper(pos);-
2110 if (d_ptr->isWidget)-
2111 static_cast<QGraphicsWidget *>(this)->d_func()->setGeometryFromSetPos();-
2112 if (d_ptr->scenePosDescendants)-
2113 d_ptr->sendScenePosChange();-
2114 return;-
2115 }-
2116-
2117-
2118 const QVariant newPosVariant(itemChange(ItemPositionChange, QVariant::fromValue<QPointF>(pos)));-
2119 QPointF newPos = newPosVariant.toPointF();-
2120 if (newPos == d_ptr->pos)-
2121 return;-
2122-
2123-
2124 d_ptr->setPosHelper(newPos);-
2125-
2126-
2127 itemChange(QGraphicsItem::ItemPositionHasChanged, newPosVariant);-
2128 d_ptr->sendScenePosChange();-
2129}-
2130void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)-
2131{-
2132 if (d_ptr->scene) {-
2133 QRectF sceneRect;-
2134 if (!rect.isNull())-
2135 sceneRect = sceneTransform().mapRect(rect);-
2136 else-
2137 sceneRect = sceneBoundingRect();-
2138 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d_ptr->scene->d_func()->views)>::type> _container_((d_ptr->scene->d_func()->views)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsView *view = *_container_.i; _container_.control; _container_.control = 0)-
2139 view->ensureVisible(sceneRect, xmargin, ymargin);-
2140 }-
2141}-
2142QMatrix QGraphicsItem::matrix() const-
2143{-
2144 return transform().toAffine();-
2145}-
2146QTransform QGraphicsItem::transform() const-
2147{-
2148 if (!d_ptr->transformData)-
2149 return QTransform();-
2150 return d_ptr->transformData->transform;-
2151}-
2152qreal QGraphicsItem::rotation() const-
2153{-
2154 if (!d_ptr->transformData)-
2155 return 0;-
2156 return d_ptr->transformData->rotation;-
2157}-
2158void QGraphicsItem::setRotation(qreal angle)-
2159{-
2160 prepareGeometryChange();-
2161 qreal newRotation = angle;-
2162-
2163 if (d_ptr->flags & ItemSendsGeometryChanges) {-
2164-
2165 const QVariant newRotationVariant(itemChange(ItemRotationChange, angle));-
2166 newRotation = newRotationVariant.toReal();-
2167 }-
2168-
2169 if (!d_ptr->transformData)-
2170 d_ptr->transformData = new QGraphicsItemPrivate::TransformData;-
2171-
2172 if (d_ptr->transformData->rotation == newRotation)-
2173 return;-
2174-
2175 d_ptr->transformData->rotation = newRotation;-
2176 d_ptr->transformData->onlyTransform = false;-
2177 d_ptr->dirtySceneTransform = 1;-
2178-
2179-
2180 if (d_ptr->flags & ItemSendsGeometryChanges)-
2181 itemChange(ItemRotationHasChanged, newRotation);-
2182-
2183 if (d_ptr->isObject)-
2184 static_cast<QGraphicsObject *>(this)->rotationChanged();-
2185-
2186 d_ptr->transformChanged();-
2187}-
2188qreal QGraphicsItem::scale() const-
2189{-
2190 if (!d_ptr->transformData)-
2191 return 1.;-
2192 return d_ptr->transformData->scale;-
2193}-
2194void QGraphicsItem::setScale(qreal factor)-
2195{-
2196 prepareGeometryChange();-
2197 qreal newScale = factor;-
2198-
2199 if (d_ptr->flags & ItemSendsGeometryChanges) {-
2200-
2201 const QVariant newScaleVariant(itemChange(ItemScaleChange, factor));-
2202 newScale = newScaleVariant.toReal();-
2203 }-
2204-
2205 if (!d_ptr->transformData)-
2206 d_ptr->transformData = new QGraphicsItemPrivate::TransformData;-
2207-
2208 if (d_ptr->transformData->scale == newScale)-
2209 return;-
2210-
2211 d_ptr->transformData->scale = newScale;-
2212 d_ptr->transformData->onlyTransform = false;-
2213 d_ptr->dirtySceneTransform = 1;-
2214-
2215-
2216 if (d_ptr->flags & ItemSendsGeometryChanges)-
2217 itemChange(ItemScaleHasChanged, newScale);-
2218-
2219 if (d_ptr->isObject)-
2220 static_cast<QGraphicsObject *>(this)->scaleChanged();-
2221-
2222 d_ptr->transformChanged();-
2223}-
2224QList<QGraphicsTransform *> QGraphicsItem::transformations() const-
2225{-
2226 if (!d_ptr->transformData)-
2227 return QList<QGraphicsTransform *>();-
2228 return d_ptr->transformData->graphicsTransforms;-
2229}-
2230void QGraphicsItem::setTransformations(const QList<QGraphicsTransform *> &transformations)-
2231{-
2232 prepareGeometryChange();-
2233 if (!d_ptr->transformData)-
2234 d_ptr->transformData = new QGraphicsItemPrivate::TransformData;-
2235 d_ptr->transformData->graphicsTransforms = transformations;-
2236 for (int i = 0; i < transformations.size(); ++i)-
2237 transformations.at(i)->d_func()->setItem(this);-
2238 d_ptr->transformData->onlyTransform = false;-
2239 d_ptr->dirtySceneTransform = 1;-
2240 d_ptr->transformChanged();-
2241}-
2242-
2243-
2244-
2245-
2246void QGraphicsItemPrivate::prependGraphicsTransform(QGraphicsTransform *t)-
2247{-
2248 if (!transformData)-
2249 transformData = new QGraphicsItemPrivate::TransformData;-
2250 if (!transformData->graphicsTransforms.contains(t))-
2251 transformData->graphicsTransforms.prepend(t);-
2252-
2253 QGraphicsItem * const q = q_func();-
2254 t->d_func()->setItem(q);-
2255 transformData->onlyTransform = false;-
2256 dirtySceneTransform = 1;-
2257 transformChanged();-
2258}-
2259-
2260-
2261-
2262-
2263void QGraphicsItemPrivate::appendGraphicsTransform(QGraphicsTransform *t)-
2264{-
2265 if (!transformData)-
2266 transformData = new QGraphicsItemPrivate::TransformData;-
2267 if (!transformData->graphicsTransforms.contains(t))-
2268 transformData->graphicsTransforms.append(t);-
2269-
2270 QGraphicsItem * const q = q_func();-
2271 t->d_func()->setItem(q);-
2272 transformData->onlyTransform = false;-
2273 dirtySceneTransform = 1;-
2274 transformChanged();-
2275}-
2276QPointF QGraphicsItem::transformOriginPoint() const-
2277{-
2278 if (!d_ptr->transformData)-
2279 return QPointF(0,0);-
2280 return QPointF(d_ptr->transformData->xOrigin, d_ptr->transformData->yOrigin);-
2281}-
2282void QGraphicsItem::setTransformOriginPoint(const QPointF &origin)-
2283{-
2284 prepareGeometryChange();-
2285 QPointF newOrigin = origin;-
2286-
2287 if (d_ptr->flags & ItemSendsGeometryChanges) {-
2288-
2289 const QVariant newOriginVariant(itemChange(ItemTransformOriginPointChange,-
2290 QVariant::fromValue<QPointF>(origin)));-
2291 newOrigin = newOriginVariant.toPointF();-
2292 }-
2293-
2294 if (!d_ptr->transformData)-
2295 d_ptr->transformData = new QGraphicsItemPrivate::TransformData;-
2296-
2297 if (d_ptr->transformData->xOrigin == newOrigin.x()-
2298 && d_ptr->transformData->yOrigin == newOrigin.y()) {-
2299 return;-
2300 }-
2301-
2302 d_ptr->transformData->xOrigin = newOrigin.x();-
2303 d_ptr->transformData->yOrigin = newOrigin.y();-
2304 d_ptr->transformData->onlyTransform = false;-
2305 d_ptr->dirtySceneTransform = 1;-
2306-
2307-
2308 if (d_ptr->flags & ItemSendsGeometryChanges)-
2309 itemChange(ItemTransformOriginPointHasChanged, QVariant::fromValue<QPointF>(newOrigin));-
2310}-
2311QMatrix QGraphicsItem::sceneMatrix() const-
2312{-
2313 d_ptr->ensureSceneTransform();-
2314 return d_ptr->sceneTransform.toAffine();-
2315}-
2316QTransform QGraphicsItem::sceneTransform() const-
2317{-
2318 d_ptr->ensureSceneTransform();-
2319 return d_ptr->sceneTransform;-
2320}-
2321QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) const-
2322{-
2323-
2324 if (!d_ptr->itemIsUntransformable()) {-
2325 d_ptr->ensureSceneTransform();-
2326 return d_ptr->sceneTransform * viewportTransform;-
2327 }-
2328-
2329-
2330 const QGraphicsItem *untransformedAncestor = this;-
2331 QList<const QGraphicsItem *> parents;-
2332 while (untransformedAncestor && ((untransformedAncestor->d_ptr->ancestorFlags-
2333 & QGraphicsItemPrivate::AncestorIgnoresTransformations))) {-
2334 parents.prepend(untransformedAncestor);-
2335 untransformedAncestor = untransformedAncestor->parentItem();-
2336 }-
2337-
2338 if (!untransformedAncestor) {-
2339-
2340 ((!(untransformedAncestor)) ? qt_assert_x("QGraphicsItem::deviceTransform", "Invalid object structure!",-
2341 __FILE__-
2342 ,-
2343 42414328-
2344 ) : qt_noop())-
2345 ;-
2346 return QTransform();-
2347 }-
2348-
2349-
2350-
2351-
2352 QGraphicsItem *parentOfUntransformedAncestor = untransformedAncestor->parentItem();-
2353 QTransform inheritedMatrix;-
2354 if (parentOfUntransformedAncestor)-
2355 inheritedMatrix = parentOfUntransformedAncestor->sceneTransform();-
2356 QPointF mappedPoint = (inheritedMatrix * viewportTransform).map(untransformedAncestor->pos());-
2357-
2358-
2359 QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y());-
2360 if (untransformedAncestor->d_ptr->transformData)-
2361 matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix);-
2362-
2363-
2364 for (int i = 0; i < parents.size(); ++i) {-
2365 const QGraphicsItem *parent = parents.at(i);-
2366 parent->d_ptr->combineTransformFromParent(&matrix);-
2367 }-
2368-
2369 return matrix;-
2370}-
2371QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) const-
2372{-
2373-
2374 if (other == 0) {-
2375 QMessageLogger(__FILE__, 42894376, __PRETTY_FUNCTION__).warning("QGraphicsItem::itemTransform: null pointer passed");-
2376 return QTransform();-
2377 }-
2378 if (other == this) {-
2379 if (ok)-
2380 *ok = true;-
2381 return QTransform();-
2382 }-
2383-
2384 QGraphicsItem *parent = d_ptr->parent;-
2385 const QGraphicsItem *otherParent = other->d_ptr->parent;-
2386-
2387-
2388 if (parent == other) {-
2389 if (ok)-
2390 *ok = true;-
2391 QTransform x;-
2392 d_ptr->combineTransformFromParent(&x);-
2393 return x;-
2394 }-
2395-
2396-
2397 if (otherParent == this) {-
2398 const QPointF &otherPos = other->d_ptr->pos;-
2399 if (other->d_ptr->transformData) {-
2400 QTransform otherToParent;-
2401 other->d_ptr->combineTransformFromParent(&otherToParent);-
2402 return otherToParent.inverted(ok);-
2403 }-
2404 if (ok)-
2405 *ok = true;-
2406 return QTransform::fromTranslate(-otherPos.x(), -otherPos.y());-
2407 }-
2408-
2409-
2410 if (parent == otherParent) {-
2411-
2412 const QPointF &itemPos = d_ptr->pos;-
2413 const QPointF &otherPos = other->d_ptr->pos;-
2414 if (!d_ptr->transformData && !other->d_ptr->transformData) {-
2415 QPointF delta = itemPos - otherPos;-
2416 if (ok)-
2417 *ok = true;-
2418 return QTransform::fromTranslate(delta.x(), delta.y());-
2419 }-
2420-
2421 QTransform itemToParent;-
2422 d_ptr->combineTransformFromParent(&itemToParent);-
2423 QTransform otherToParent;-
2424 other->d_ptr->combineTransformFromParent(&otherToParent);-
2425 return itemToParent * otherToParent.inverted(ok);-
2426 }-
2427-
2428-
2429-
2430 const QGraphicsItem *commonAncestor = commonAncestorItem(other);-
2431 if (!commonAncestor) {-
2432 d_ptr->ensureSceneTransform();-
2433 other->d_ptr->ensureSceneTransform();-
2434 return d_ptr->sceneTransform * other->d_ptr->sceneTransform.inverted(ok);-
2435 }-
2436-
2437-
2438-
2439 bool cousins = other != commonAncestor && this != commonAncestor;-
2440 if (cousins) {-
2441 bool good = false;-
2442 QTransform thisToScene = itemTransform(commonAncestor, &good);-
2443 QTransform otherToScene(Qt::Uninitialized);-
2444 if (good)-
2445 otherToScene = other->itemTransform(commonAncestor, &good);-
2446 if (!good) {-
2447 if (ok)-
2448 *ok = false;-
2449 return QTransform();-
2450 }-
2451 return thisToScene * otherToScene.inverted(ok);-
2452 }-
2453-
2454-
2455 bool parentOfOther = isAncestorOf(other);-
2456 const QGraphicsItem *child = parentOfOther ? other : this;-
2457 const QGraphicsItem *root = parentOfOther ? this : other;-
2458-
2459 QTransform x;-
2460 const QGraphicsItem *p = child;-
2461 do {-
2462 p->d_ptr.data()->combineTransformToParent(&x);-
2463 } while ((p = p->d_ptr->parent) && p != root);-
2464 if (parentOfOther)-
2465 return x.inverted(ok);-
2466 if (ok)-
2467 *ok = true;-
2468 return x;-
2469}-
2470void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)-
2471{-
2472 if (!d_ptr->transformData)-
2473 d_ptr->transformData = new QGraphicsItemPrivate::TransformData;-
2474-
2475 QTransform newTransform(combine ? QTransform(matrix) * d_ptr->transformData->transform : QTransform(matrix));-
2476 if (d_ptr->transformData->transform == newTransform)-
2477 return;-
2478-
2479-
2480 if (!(d_ptr->flags & ItemSendsGeometryChanges)) {-
2481 d_ptr->setTransformHelper(newTransform);-
2482 return;-
2483 }-
2484-
2485-
2486 const QVariant newMatrixVariant = QVariant::fromValue<QMatrix>(newTransform.toAffine());-
2487 newTransform = QTransform(qvariant_cast<QMatrix>(itemChange(ItemMatrixChange, newMatrixVariant)));-
2488 if (d_ptr->transformData->transform == newTransform)-
2489 return;-
2490-
2491-
2492 d_ptr->setTransformHelper(newTransform);-
2493-
2494-
2495 itemChange(ItemTransformHasChanged, QVariant::fromValue<QTransform>(newTransform));-
2496}-
2497void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)-
2498{-
2499 if (!d_ptr->transformData)-
2500 d_ptr->transformData = new QGraphicsItemPrivate::TransformData;-
2501-
2502 QTransform newTransform(combine ? matrix * d_ptr->transformData->transform : matrix);-
2503 if (d_ptr->transformData->transform == newTransform)-
2504 return;-
2505-
2506-
2507 if (!(d_ptr->flags & (ItemSendsGeometryChanges | ItemSendsScenePositionChanges))) {-
2508 d_ptr->setTransformHelper(newTransform);-
2509 if (d_ptr->scenePosDescendants)-
2510 d_ptr->sendScenePosChange();-
2511 return;-
2512 }-
2513-
2514-
2515 const QVariant newTransformVariant(itemChange(ItemTransformChange,-
2516 QVariant::fromValue<QTransform>(newTransform)));-
2517 newTransform = qvariant_cast<QTransform>(newTransformVariant);-
2518 if (d_ptr->transformData->transform == newTransform)-
2519 return;-
2520-
2521-
2522 d_ptr->setTransformHelper(newTransform);-
2523-
2524-
2525 itemChange(ItemTransformHasChanged, newTransformVariant);-
2526 d_ptr->sendScenePosChange();-
2527}-
2528-
2529-
2530-
2531-
2532-
2533-
2534void QGraphicsItem::resetMatrix()-
2535{-
2536 resetTransform();-
2537}-
2538void QGraphicsItem::resetTransform()-
2539{-
2540 setTransform(QTransform(), false);-
2541}-
2542void QGraphicsItem::advance(int phase)-
2543{-
2544 (void)phase;;-
2545}-
2546qreal QGraphicsItem::zValue() const-
2547{-
2548 return d_ptr->z;-
2549}-
2550void QGraphicsItem::setZValue(qreal z)-
2551{-
2552 const QVariant newZVariant(itemChange(ItemZValueChange, z));-
2553 qreal newZ = newZVariant.toReal();-
2554 if (newZ == d_ptr->z)-
2555 return;-
2556-
2557 if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex) {-
2558-
2559 d_ptr->scene->d_func()->index->itemChange(this, ItemZValueChange, &newZ);-
2560 }-
2561-
2562 d_ptr->z = newZ;-
2563 if (d_ptr->parent)-
2564 d_ptr->parent->d_ptr->needSortChildren = 1;-
2565 else if (d_ptr->scene)-
2566 d_ptr->scene->d_func()->needSortTopLevelItems = 1;-
2567-
2568 if (d_ptr->scene)-
2569 d_ptr->scene->d_func()->markDirty(this, QRectF(), true);-
2570-
2571 itemChange(ItemZValueHasChanged, newZVariant);-
2572-
2573 if (d_ptr->flags & ItemNegativeZStacksBehindParent)-
2574 setFlag(QGraphicsItem::ItemStacksBehindParent, z < qreal(0.0));-
2575-
2576 if (d_ptr->isObject)-
2577 static_cast<QGraphicsObject *>(this)->zChanged();-
2578}-
2579void QGraphicsItemPrivate::ensureSequentialSiblingIndex()-
2580{-
2581 if (!sequentialOrdering) {-
2582 std::sort(children.begin(), children.end(), insertionOrder);-
2583 sequentialOrdering = 1;-
2584 needSortChildren = 1;-
2585 }-
2586 if (holesInSiblingIndex) {-
2587 holesInSiblingIndex = 0;-
2588 for (int i = 0; i < children.size(); ++i)-
2589 children[i]->d_ptr->siblingIndex = i;-
2590 }-
2591}-
2592-
2593-
2594-
2595-
2596inline void QGraphicsItemPrivate::sendScenePosChange()-
2597{-
2598 QGraphicsItem * const q = q_func();-
2599 if (scene) {-
2600 if (flags & QGraphicsItem::ItemSendsScenePositionChanges)-
2601 q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos());-
2602 if (scenePosDescendants) {-
2603 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(scene->d_func()->scenePosItems)>::type> _container_((scene->d_func()->scenePosItems)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *item = *_container_.i; _container_.control; _container_.control = 0) {-
2604 if (q->isAncestorOf(item))-
2605 item->itemChange(QGraphicsItem::ItemScenePositionHasChanged, item->scenePos());-
2606 }-
2607 }-
2608 }-
2609}-
2610void QGraphicsItem::stackBefore(const QGraphicsItem *sibling)-
2611{-
2612 if (sibling == this)-
2613 return;-
2614 if (!sibling || d_ptr->parent != sibling->parentItem()) {-
2615 QMessageLogger(__FILE__, 47244811, __PRETTY_FUNCTION__).warning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);-
2616 return;-
2617 }-
2618 QList<QGraphicsItem *> *siblings = d_ptr->parent-
2619 ? &d_ptr->parent->d_ptr->children-
2620 : (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems : 0);-
2621 if (!siblings) {-
2622 QMessageLogger(__FILE__, 47314818, __PRETTY_FUNCTION__).warning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);-
2623 return;-
2624 }-
2625-
2626-
2627-
2628 if (d_ptr->parent)-
2629 d_ptr->parent->d_ptr->ensureSequentialSiblingIndex();-
2630 else-
2631 d_ptr->scene->d_func()->ensureSequentialTopLevelSiblingIndexes();-
2632-
2633-
2634 int siblingIndex = sibling->d_ptr->siblingIndex;-
2635 int myIndex = d_ptr->siblingIndex;-
2636 if (myIndex >= siblingIndex) {-
2637 siblings->move(myIndex, siblingIndex);-
2638-
2639 for (int i = 0; i < siblings->size(); ++i) {-
2640 int &index = siblings->at(i)->d_ptr->siblingIndex;-
2641 if (i != siblingIndex && index >= siblingIndex && index <= myIndex)-
2642 ++index;-
2643 }-
2644 d_ptr->siblingIndex = siblingIndex;-
2645 for (int i = 0; i < siblings->size(); ++i) {-
2646 int &index = siblings->at(i)->d_ptr->siblingIndex;-
2647 if (i != siblingIndex && index >= siblingIndex && index <= myIndex)-
2648 siblings->at(i)->d_ptr->siblingOrderChange();-
2649 }-
2650 d_ptr->siblingOrderChange();-
2651 }-
2652}-
2653QRectF QGraphicsItem::childrenBoundingRect() const-
2654{-
2655 if (!d_ptr->dirtyChildrenBoundingRect)-
2656 return d_ptr->childrenBoundingRect;-
2657-
2658 d_ptr->childrenBoundingRect = QRectF();-
2659 d_ptr->childrenBoundingRectHelper(0, &d_ptr->childrenBoundingRect, 0);-
2660 d_ptr->dirtyChildrenBoundingRect = 0;-
2661 return d_ptr->childrenBoundingRect;-
2662}-
2663QRectF QGraphicsItem::sceneBoundingRect() const-
2664{-
2665-
2666-
2667 QPointF offset;-
2668 const QGraphicsItem *parentItem = this;-
2669 const QGraphicsItemPrivate *itemd;-
2670 do {-
2671 itemd = parentItem->d_ptr.data();-
2672 if (itemd->transformData)-
2673 break;-
2674 offset += itemd->pos;-
2675 } while ((parentItem = itemd->parent));-
2676-
2677 QRectF br = boundingRect();-
2678 br.translate(offset);-
2679 if (!parentItem)-
2680 return br;-
2681 if (parentItem->d_ptr->hasTranslateOnlySceneTransform()) {-
2682 br.translate(parentItem->d_ptr->sceneTransform.dx(), parentItem->d_ptr->sceneTransform.dy());-
2683 return br;-
2684 }-
2685 return parentItem->d_ptr->sceneTransform.mapRect(br);-
2686}-
2687QPainterPath QGraphicsItem::shape() const-
2688{-
2689 QPainterPath path;-
2690 path.addRect(boundingRect());-
2691 return path;-
2692}-
2693bool QGraphicsItem::isClipped() const-
2694{-
2695 const QGraphicsItemPrivate * const d = d_func();-
2696 return (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)-
2697 || (d->flags & QGraphicsItem::ItemClipsToShape);-
2698}-
2699QPainterPath QGraphicsItem::clipPath() const-
2700{-
2701 const QGraphicsItemPrivate * const d = d_func();-
2702 if (!isClipped())-
2703 return QPainterPath();-
2704-
2705 const QRectF thisBoundingRect(boundingRect());-
2706 if (thisBoundingRect.isEmpty())-
2707 return QPainterPath();-
2708-
2709 QPainterPath clip;-
2710-
2711 clip.addRect(thisBoundingRect);-
2712-
2713 if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {-
2714 const QGraphicsItem *parent = this;-
2715 const QGraphicsItem *lastParent = this;-
2716-
2717-
2718 while ((parent = parent->d_ptr->parent)) {-
2719 if (parent->d_ptr->flags & ItemClipsChildrenToShape) {-
2720-
2721 clip = lastParent->itemTransform(parent).map(clip);-
2722 clip = clip.intersected(parent->shape());-
2723 if (clip.isEmpty())-
2724 return clip;-
2725 lastParent = parent;-
2726 }-
2727-
2728 if (!(parent->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren))-
2729 break;-
2730 }-
2731-
2732 if (lastParent != this) {-
2733-
2734-
2735 clip = lastParent->itemTransform(this).map(clip);-
2736 }-
2737 }-
2738-
2739 if (d->flags & ItemClipsToShape)-
2740 clip = clip.intersected(shape());-
2741-
2742 return clip;-
2743}-
2744bool QGraphicsItem::contains(const QPointF &point) const-
2745{-
2746 return isClipped() ? clipPath().contains(point) : shape().contains(point);-
2747}-
2748bool QGraphicsItem::collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode) const-
2749{-
2750 if (other == this)-
2751 return true;-
2752 if (!other)-
2753 return false;-
2754-
2755-
2756 bool clips = (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);-
2757 bool otherClips = (other->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);-
2758 if (clips || otherClips) {-
2759 const QGraphicsItem *closestClipper = isAncestorOf(other) ? this : parentItem();-
2760 while (closestClipper && !(closestClipper->flags() & ItemClipsChildrenToShape))-
2761 closestClipper = closestClipper->parentItem();-
2762 const QGraphicsItem *otherClosestClipper = other->isAncestorOf(this) ? other : other->parentItem();-
2763 while (otherClosestClipper && !(otherClosestClipper->flags() & ItemClipsChildrenToShape))-
2764 otherClosestClipper = otherClosestClipper->parentItem();-
2765 if (closestClipper == otherClosestClipper) {-
2766 d_ptr->localCollisionHack = 1;-
2767 bool res = collidesWithPath(mapFromItem(other, other->shape()), mode);-
2768 d_ptr->localCollisionHack = 0;-
2769 return res;-
2770 }-
2771 }-
2772-
2773 QPainterPath otherShape = other->isClipped() ? other->clipPath() : other->shape();-
2774 return collidesWithPath(mapFromItem(other, otherShape), mode);-
2775}-
2776bool QGraphicsItem::collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode) const-
2777{-
2778 if (path.isEmpty()) {-
2779-
2780 return false;-
2781 }-
2782-
2783 QRectF rectA(boundingRect());-
2784 _q_adjustRect(&rectA);-
2785 QRectF rectB(path.controlPointRect());-
2786 _q_adjustRect(&rectB);-
2787 if (!rectA.intersects(rectB)) {-
2788-
2789-
2790 return false;-
2791 }-
2792-
2793-
2794 QPainterPath thisShape;-
2795 if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape)-
2796 thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape();-
2797 else-
2798 thisShape.addRect(rectA);-
2799-
2800 if (thisShape == QPainterPath()) {-
2801-
2802 return false;-
2803 }-
2804-
2805-
2806 if (mode == Qt::IntersectsItemShape || mode == Qt::IntersectsItemBoundingRect)-
2807 return path.intersects(thisShape);-
2808 return path.contains(thisShape);-
2809}-
2810QList<QGraphicsItem *> QGraphicsItem::collidingItems(Qt::ItemSelectionMode mode) const-
2811{-
2812 if (d_ptr->scene)-
2813 return d_ptr->scene->collidingItems(this, mode);-
2814 return QList<QGraphicsItem *>();-
2815}-
2816static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item,-
2817 const QGraphicsItem *other,-
2818 const QRectF &rect)-
2819{-
2820 return other->mapToItem(item, other->opaqueArea()).contains(rect);-
2821}-
2822bool QGraphicsItem::isObscured(const QRectF &rect) const-
2823{-
2824 const QGraphicsItemPrivate * const d = d_func();-
2825 if (!d->scene
!d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2826 return
never executed: return false;
false;
never executed: return false;
0
2827-
2828 QRectF br = boundingRect();-
2829 QRectF testRect = rect.isNull()
rect.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
? br : rect;
0
2830-
2831 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d->scene->const auto items (mapToScene(br), Qt::IntersectsItemBoundingRect))>::type> _container_((= d->scene->items(mapToScene(br), Qt::IntersectsItemBoundingRect))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1));-
2832 for (QGraphicsItem *item = *_container_.i; _container_.control; _container_.control = 0: items) {-
2833 if (item == this
item == thisDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
2834 break;
never executed: break;
0
2835 if (qt_QGraphicsItem_isObscured(this, item, testRect)
qt_QGraphicsIt...tem, testRect)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2836 return
never executed: return true;
true;
never executed: return true;
0
2837 }
never executed: end of block
0
2838 return
never executed: return false;
false;
never executed: return false;
0
2839}-
2840bool QGraphicsItem::isObscuredBy(const QGraphicsItem *item) const-
2841{-
2842 if (!item)-
2843 return false;-
2844 return qt_closestItemFirst(item, this)-
2845 && qt_QGraphicsItem_isObscured(this, item, boundingRect());-
2846}-
2847QPainterPath QGraphicsItem::opaqueArea() const-
2848{-
2849 return QPainterPath();-
2850}-
2851QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) const-
2852{-
2853 qreal granularity = boundingRegionGranularity();-
2854 QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect();-
2855 _q_adjustRect(&deviceRect);-
2856 if (granularity == 0.0
granularity == 0.0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
2857 return
never executed: return QRegion(deviceRect);
QRegion(deviceRect);
never executed: return QRegion(deviceRect);
0
2858-
2859 int pad = 1;-
2860 QSize bitmapSize(qMax(1, int(deviceRect.width() * granularity) + pad * 2),-
2861 qMax(1, int(deviceRect.height() * granularity) + pad * 2));-
2862 QImage mask(bitmapSize, QImage::Format_ARGB32_Premultiplied);-
2863 mask.fill(0);-
2864 QPainter p(&mask);-
2865 p.setRenderHints(QPainter::Antialiasing);-
2866-
2867-
2868-
2869 QPointF viewOrigo = itemToDeviceTransform.map(QPointF(0, 0));-
2870 QPointF offset = viewOrigo - deviceRect.topLeft();-
2871 p.scale(granularity, granularity);-
2872 p.translate(offset);-
2873 p.translate(pad, pad);-
2874 p.setWorldTransform(itemToDeviceTransform, true);-
2875 p.translate(itemToDeviceTransform.inverted().map(QPointF(0, 0)));-
2876-
2877-
2878 QStyleOptionGraphicsItem option;-
2879 const_cast<QGraphicsItem *>(this)->paint(&p, &option, 0);-
2880 p.end();-
2881-
2882-
2883 QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);-
2884 QRegion r;-
2885 QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));-
2886 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(QRegion( colorMask ).const auto rects ())>::type> _container_((= QRegion(colorMask).rects())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)();-
2887 for (const QRect &rect = *_container_.i; _container_.control; _container_.control = 0: rects) {-
2888 QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));-
2889 r += xrect.adjusted(-1, -1, 1, 1) & deviceRect;-
2890 }
never executed: end of block
0
2891 return
never executed: return r;
r;
never executed: return r;
0
2892}-
2893qreal QGraphicsItem::boundingRegionGranularity() const-
2894{-
2895 return d_ptr->hasBoundingRegionGranularity-
2896 ? qvariant_cast<qreal>(d_ptr->extra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity))-
2897 : 0;-
2898}-
2899void QGraphicsItem::setBoundingRegionGranularity(qreal granularity)-
2900{-
2901 if (granularity < 0.0 || granularity > 1.0) {-
2902 QMessageLogger(__FILE__, 53145403, __PRETTY_FUNCTION__).warning("QGraphicsItem::setBoundingRegionGranularity: invalid granularity %g", granularity);-
2903 return;-
2904 }-
2905 if (granularity == 0.0) {-
2906 d_ptr->unsetExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity);-
2907 d_ptr->hasBoundingRegionGranularity = 0;-
2908 return;-
2909 }-
2910 d_ptr->hasBoundingRegionGranularity = 1;-
2911 d_ptr->setExtra(QGraphicsItemPrivate::ExtraBoundingRegionGranularity,-
2912 QVariant::fromValue<qreal>(granularity));-
2913}-
2914bool QGraphicsItemPrivate::discardUpdateRequest(bool ignoreVisibleBit, bool ignoreDirtyBit,-
2915 bool ignoreOpacity) const-
2916{-
2917-
2918-
2919 return !scene-
2920 || (!visible && !ignoreVisibleBit && !this->ignoreVisible)-
2921 || (!ignoreDirtyBit && fullUpdatePending)-
2922 || (!ignoreOpacity && !this->ignoreOpacity && childrenCombineOpacity() && isFullyTransparent());-
2923}-
2924-
2925-
2926-
2927-
2928int QGraphicsItemPrivate::depth() const-
2929{-
2930 if (itemDepth == -1)-
2931 const_cast<QGraphicsItemPrivate *>(this)->resolveDepth();-
2932-
2933 return itemDepth;-
2934}-
2935-
2936-
2937-
2938-
2939-
2940void QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively()-
2941{-
2942 QGraphicsItemPrivate *itemPrivate = this;-
2943 do {-
2944 if (itemPrivate->graphicsEffect) {-
2945 itemPrivate->notifyInvalidated = 1;-
2946-
2947 if (!itemPrivate->updateDueToGraphicsEffect)-
2948 static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();-
2949 }-
2950 } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));-
2951}-
2952-
2953void QGraphicsItemPrivate::invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::InvalidateReason reason)-
2954{-
2955 if (!mayHaveChildWithGraphicsEffect)-
2956 return;-
2957-
2958 for (int i = 0; i < children.size(); ++i) {-
2959 QGraphicsItemPrivate *childPrivate = children.at(i)->d_ptr.data();-
2960 if (reason == OpacityChanged && (childPrivate->flags & QGraphicsItem::ItemIgnoresParentOpacity))-
2961 continue;-
2962 if (childPrivate->graphicsEffect) {-
2963 childPrivate->notifyInvalidated = 1;-
2964 static_cast<QGraphicsItemEffectSourcePrivate *>(childPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();-
2965 }-
2966-
2967 childPrivate->invalidateChildGraphicsEffectsRecursively(reason);-
2968 }-
2969}-
2970-
2971-
2972-
2973-
2974-
2975void QGraphicsItemPrivate::invalidateDepthRecursively()-
2976{-
2977 if (itemDepth == -1)-
2978 return;-
2979-
2980 itemDepth = -1;-
2981 for (int i = 0; i < children.size(); ++i)-
2982 children.at(i)->d_ptr->invalidateDepthRecursively();-
2983}-
2984-
2985-
2986-
2987-
2988-
2989-
2990void QGraphicsItemPrivate::resolveDepth()-
2991{-
2992 if (!parent)-
2993 itemDepth = 0;-
2994 else {-
2995 if (parent->d_ptr->itemDepth == -1)-
2996 parent->d_ptr->resolveDepth();-
2997 itemDepth = parent->d_ptr->itemDepth + 1;-
2998 }-
2999}-
3000-
3001-
3002-
3003-
3004-
3005-
3006-
3007void QGraphicsItemPrivate::addChild(QGraphicsItem *child)-
3008{-
3009-
3010-
3011 ensureSequentialSiblingIndex();-
3012 needSortChildren = 1;-
3013 child->d_ptr->siblingIndex = children.size();-
3014 children.append(child);-
3015 if (isObject)-
3016 static_cast<QGraphicsObject *>(q_ptr)->childrenChanged();-
3017}-
3018-
3019-
3020-
3021-
3022-
3023-
3024-
3025void QGraphicsItemPrivate::removeChild(QGraphicsItem *child)-
3026{-
3027-
3028-
3029 if (!holesInSiblingIndex)-
3030 holesInSiblingIndex = child->d_ptr->siblingIndex != children.size() - 1;-
3031 if (sequentialOrdering && !holesInSiblingIndex)-
3032 children.removeAt(child->d_ptr->siblingIndex);-
3033 else-
3034 children.removeOne(child);-
3035-
3036-
3037-
3038 child->d_ptr->siblingIndex = -1;-
3039 if (isObject)-
3040 static_cast<QGraphicsObject *>(q_ptr)->childrenChanged();-
3041}-
3042-
3043-
3044-
3045-
3046QGraphicsItemCache *QGraphicsItemPrivate::maybeExtraItemCache() const-
3047{-
3048 return (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));-
3049}-
3050-
3051-
3052-
3053-
3054QGraphicsItemCache *QGraphicsItemPrivate::extraItemCache() const-
3055{-
3056 QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));-
3057 if (!c) {-
3058 QGraphicsItemPrivate *that = const_cast<QGraphicsItemPrivate *>(this);-
3059 c = new QGraphicsItemCache;-
3060 that->setExtra(ExtraCacheData, QVariant::fromValue<void *>(c));-
3061 }-
3062 return c;-
3063}-
3064-
3065-
3066-
3067-
3068void QGraphicsItemPrivate::removeExtraItemCache()-
3069{-
3070 QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));-
3071 if (c) {-
3072 c->purge();-
3073 delete c;-
3074 }-
3075 unsetExtra(ExtraCacheData);-
3076}-
3077-
3078void QGraphicsItemPrivate::updatePaintedViewBoundingRects(bool updateChildren)-
3079{-
3080 if (!scene)-
3081 return;-
3082-
3083 for (int i = 0; i < scene->d_func()->views.size(); ++i) {-
3084 QGraphicsViewPrivate *viewPrivate = scene->d_func()->views.at(i)->d_func();-
3085 QRect rect = paintedViewBoundingRects.value(viewPrivate->viewport);-
3086 rect.translate(viewPrivate->dirtyScrollOffset);-
3087 viewPrivate->updateRect(rect);-
3088 }-
3089-
3090 if (updateChildren) {-
3091 for (int i = 0; i < children.size(); ++i)-
3092 children.at(i)->d_ptr->updatePaintedViewBoundingRects(true);-
3093 }-
3094}-
3095-
3096-
3097-
3098-
3099-
3100-
3101void QGraphicsItemPrivate::ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem)-
3102{-
3103 ((!(topMostDirtyItem)) ? qt_assert("topMostDirtyItem",__FILE__,55645653) : qt_noop());-
3104-
3105 if (dirtySceneTransform)-
3106 *topMostDirtyItem = q_ptr;-
3107-
3108 if (parent)-
3109 parent->d_ptr->ensureSceneTransformRecursive(topMostDirtyItem);-
3110-
3111 if (*topMostDirtyItem == q_ptr) {-
3112 if (!dirtySceneTransform)-
3113 return;-
3114 *topMostDirtyItem = 0;-
3115 } else if (*topMostDirtyItem) {-
3116 return;-
3117 }-
3118-
3119-
3120-
3121-
3122-
3123 invalidateChildrenSceneTransform();-
3124-
3125-
3126 updateSceneTransformFromParent();-
3127 ((!(!dirtySceneTransform)) ? qt_assert("!dirtySceneTransform",__FILE__,55885677) : qt_noop());-
3128}-
3129-
3130-
3131-
3132-
3133void QGraphicsItemPrivate::setSubFocus(QGraphicsItem *rootItem, QGraphicsItem *stopItem)-
3134{-
3135-
3136-
3137 QGraphicsItem *parent = rootItem ? rootItem : q_ptr;-
3138 if (parent->panel() != q_ptr->panel())-
3139 return;-
3140-
3141 do {-
3142-
3143 if (parent != q_ptr && parent->d_ptr->subFocusItem) {-
3144 if (parent->d_ptr->subFocusItem == q_ptr)-
3145 break;-
3146 parent->d_ptr->subFocusItem->d_ptr->clearSubFocus(0, stopItem);-
3147 }-
3148 parent->d_ptr->subFocusItem = q_ptr;-
3149 parent->d_ptr->subFocusItemChange();-
3150 } while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (visible || !parent->d_ptr->visible));-
3151-
3152 if (scene && !scene->isActive()) {-
3153 scene->d_func()->passiveFocusItem = subFocusItem;-
3154 scene->d_func()->lastFocusItem = subFocusItem;-
3155 }-
3156}-
3157-
3158-
3159-
3160-
3161void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem, QGraphicsItem *stopItem)-
3162{-
3163-
3164 QGraphicsItem *parent = rootItem ? rootItem : q_ptr;-
3165 do {-
3166 if (parent->d_ptr->subFocusItem != q_ptr)-
3167 break;-
3168 parent->d_ptr->subFocusItem = 0;-
3169 if (parent != stopItem && !parent->isAncestorOf(stopItem))-
3170 parent->d_ptr->subFocusItemChange();-
3171 } while (!parent->isPanel() && (parent = parent->d_ptr->parent));-
3172}-
3173-
3174-
3175-
3176-
3177-
3178-
3179-
3180void QGraphicsItemPrivate::resetFocusProxy()-
3181{-
3182 for (int i = 0; i < focusProxyRefs.size(); ++i)-
3183 *focusProxyRefs.at(i) = 0;-
3184 focusProxyRefs.clear();-
3185}-
3186-
3187-
3188-
3189-
3190-
3191-
3192-
3193void QGraphicsItemPrivate::subFocusItemChange()-
3194{-
3195}-
3196-
3197-
3198-
3199-
3200-
3201-
3202-
3203void QGraphicsItemPrivate::focusScopeItemChange(bool isSubFocusItem)-
3204{-
3205 (void)isSubFocusItem;;-
3206}-
3207-
3208-
3209-
3210-
3211-
3212-
3213-
3214void QGraphicsItemPrivate::siblingOrderChange()-
3215{-
3216}-
3217-
3218-
3219-
3220-
3221-
3222-
3223bool QGraphicsItemPrivate::isProxyWidget() const-
3224{-
3225 return false;-
3226}-
3227void QGraphicsItem::update(const QRectF &rect)-
3228{-
3229 if (rect.isEmpty() && !rect.isNull())-
3230 return;-
3231-
3232-
3233-
3234 d_ptr->invalidateParentGraphicsEffectsRecursively();-
3235-
3236-
3237 if (CacheMode(d_ptr->cacheMode) != NoCache) {-
3238-
3239 QGraphicsItemCache *cache = d_ptr->extraItemCache();-
3240 if (!cache->allExposed) {-
3241 if (rect.isNull()) {-
3242 cache->allExposed = true;-
3243 cache->exposed.clear();-
3244 } else {-
3245 cache->exposed.append(rect);-
3246 }-
3247 }-
3248-
3249 if (d_ptr->fullUpdatePending)-
3250 return;-
3251 }-
3252-
3253 if (d_ptr->scene)-
3254 d_ptr->scene->d_func()->markDirty(this, rect);-
3255}-
3256void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)-
3257{-
3258 QGraphicsItemPrivate * const d = d_func();-
3259 if (dx == 0.0 && dy == 0.0)-
3260 return;-
3261 if (!d->scene)-
3262 return;-
3263 if (d->cacheMode != QGraphicsItem::ItemCoordinateCache-
3264 || !qFuzzyIsNull(dx - int(dx)) || !qFuzzyIsNull(dy - int(dy))) {-
3265 update(rect);-
3266 return;-
3267 }-
3268-
3269 QGraphicsItemCache *cache = d->extraItemCache();-
3270 if (cache->allExposed || cache->fixedSize.isValid()) {-
3271-
3272 update(rect);-
3273 return;-
3274 }-
3275-
3276-
3277 QPixmap cachedPixmap;-
3278 if (!QPixmapCache::find(cache->key, &cachedPixmap)) {-
3279 update(rect);-
3280 return;-
3281 }-
3282-
3283 QRect scrollRect = (rect.isNull() ? boundingRect() : rect).toAlignedRect();-
3284 if (!scrollRect.intersects(cache->boundingRect))-
3285 return;-
3286-
3287-
3288 QPixmapCache::remove(cache->key);-
3289-
3290 QRegion exposed;-
3291 cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed);-
3292-
3293-
3294 cache->key = QPixmapCache::insert(cachedPixmap);-
3295-
3296-
3297 for (int i = 0; i < cache->exposed.size(); ++i) {-
3298 QRectF &e = cache->exposed[i];-
3299 if (!rect.isNull() && !e.intersects(rect))-
3300 continue;-
3301 e.translate(dx, dy);-
3302 }-
3303-
3304-
3305-
3306 exposed.translate(cache->boundingRect.topLeft());-
3307 const QVector<QRect> exposedRects = exposed.rects();-
3308 for (int i = 0; i < exposedRects.size(); ++i)-
3309 cache->exposed += exposedRects.at(i);-
3310-
3311-
3312-
3313 d->scene->d_func()->markDirty(this, rect);-
3314}-
3315QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPointF &point) const-
3316{-
3317 if (item)-
3318 return itemTransform(item).map(point);-
3319 return mapToScene(point);-
3320}-
3321QPointF QGraphicsItem::mapToParent(const QPointF &point) const-
3322{-
3323-
3324 if (!d_ptr->transformData)-
3325 return point + d_ptr->pos;-
3326 return d_ptr->transformToParent().map(point);-
3327}-
3328QPointF QGraphicsItem::mapToScene(const QPointF &point) const-
3329{-
3330 if (d_ptr->hasTranslateOnlySceneTransform())-
3331 return QPointF(point.x() + d_ptr->sceneTransform.dx(), point.y() + d_ptr->sceneTransform.dy());-
3332 return d_ptr->sceneTransform.map(point);-
3333}-
3334QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QRectF &rect) const-
3335{-
3336 if (item)-
3337 return itemTransform(item).map(rect);-
3338 return mapToScene(rect);-
3339}-
3340QPolygonF QGraphicsItem::mapToParent(const QRectF &rect) const-
3341{-
3342-
3343 if (!d_ptr->transformData)-
3344 return rect.translated(d_ptr->pos);-
3345 return d_ptr->transformToParent().map(rect);-
3346}-
3347QPolygonF QGraphicsItem::mapToScene(const QRectF &rect) const-
3348{-
3349 if (d_ptr->hasTranslateOnlySceneTransform())-
3350 return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());-
3351 return d_ptr->sceneTransform.map(rect);-
3352}-
3353QRectF QGraphicsItem::mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const-
3354{-
3355 if (item)-
3356 return itemTransform(item).mapRect(rect);-
3357 return mapRectToScene(rect);-
3358}-
3359QRectF QGraphicsItem::mapRectToParent(const QRectF &rect) const-
3360{-
3361-
3362 if (!d_ptr->transformData)-
3363 return rect.translated(d_ptr->pos);-
3364 return d_ptr->transformToParent().mapRect(rect);-
3365}-
3366QRectF QGraphicsItem::mapRectToScene(const QRectF &rect) const-
3367{-
3368 if (d_ptr->hasTranslateOnlySceneTransform())-
3369 return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());-
3370 return d_ptr->sceneTransform.mapRect(rect);-
3371}-
3372QRectF QGraphicsItem::mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const-
3373{-
3374 if (item)-
3375 return item->itemTransform(this).mapRect(rect);-
3376 return mapRectFromScene(rect);-
3377}-
3378QRectF QGraphicsItem::mapRectFromParent(const QRectF &rect) const-
3379{-
3380-
3381 if (!d_ptr->transformData)-
3382 return rect.translated(-d_ptr->pos);-
3383 return d_ptr->transformToParent().inverted().mapRect(rect);-
3384}-
3385QRectF QGraphicsItem::mapRectFromScene(const QRectF &rect) const-
3386{-
3387 if (d_ptr->hasTranslateOnlySceneTransform())-
3388 return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());-
3389 return d_ptr->sceneTransform.inverted().mapRect(rect);-
3390}-
3391QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPolygonF &polygon) const-
3392{-
3393 if (item)-
3394 return itemTransform(item).map(polygon);-
3395 return mapToScene(polygon);-
3396}-
3397QPolygonF QGraphicsItem::mapToParent(const QPolygonF &polygon) const-
3398{-
3399-
3400 if (!d_ptr->transformData)-
3401 return polygon.translated(d_ptr->pos);-
3402 return d_ptr->transformToParent().map(polygon);-
3403}-
3404QPolygonF QGraphicsItem::mapToScene(const QPolygonF &polygon) const-
3405{-
3406 if (d_ptr->hasTranslateOnlySceneTransform())-
3407 return polygon.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());-
3408 return d_ptr->sceneTransform.map(polygon);-
3409}-
3410QPainterPath QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPainterPath &path) const-
3411{-
3412 if (item)-
3413 return itemTransform(item).map(path);-
3414 return mapToScene(path);-
3415}-
3416QPainterPath QGraphicsItem::mapToParent(const QPainterPath &path) const-
3417{-
3418-
3419 if (!d_ptr->transformData)-
3420 return path.translated(d_ptr->pos);-
3421 return d_ptr->transformToParent().map(path);-
3422}-
3423QPainterPath QGraphicsItem::mapToScene(const QPainterPath &path) const-
3424{-
3425 if (d_ptr->hasTranslateOnlySceneTransform())-
3426 return path.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());-
3427 return d_ptr->sceneTransform.map(path);-
3428}-
3429QPointF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPointF &point) const-
3430{-
3431 if (item)-
3432 return item->itemTransform(this).map(point);-
3433 return mapFromScene(point);-
3434}-
3435QPointF QGraphicsItem::mapFromParent(const QPointF &point) const-
3436{-
3437-
3438 if (d_ptr->transformData)-
3439 return d_ptr->transformToParent().inverted().map(point);-
3440 return point - d_ptr->pos;-
3441}-
3442QPointF QGraphicsItem::mapFromScene(const QPointF &point) const-
3443{-
3444 if (d_ptr->hasTranslateOnlySceneTransform())-
3445 return QPointF(point.x() - d_ptr->sceneTransform.dx(), point.y() - d_ptr->sceneTransform.dy());-
3446 return d_ptr->sceneTransform.inverted().map(point);-
3447}-
3448QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QRectF &rect) const-
3449{-
3450 if (item)-
3451 return item->itemTransform(this).map(rect);-
3452 return mapFromScene(rect);-
3453}-
3454QPolygonF QGraphicsItem::mapFromParent(const QRectF &rect) const-
3455{-
3456-
3457 if (!d_ptr->transformData)-
3458 return rect.translated(-d_ptr->pos);-
3459 return d_ptr->transformToParent().inverted().map(rect);-
3460}-
3461QPolygonF QGraphicsItem::mapFromScene(const QRectF &rect) const-
3462{-
3463 if (d_ptr->hasTranslateOnlySceneTransform())-
3464 return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());-
3465 return d_ptr->sceneTransform.inverted().map(rect);-
3466}-
3467QPolygonF QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPolygonF &polygon) const-
3468{-
3469 if (item)-
3470 return item->itemTransform(this).map(polygon);-
3471 return mapFromScene(polygon);-
3472}-
3473QPolygonF QGraphicsItem::mapFromParent(const QPolygonF &polygon) const-
3474{-
3475-
3476 if (!d_ptr->transformData)-
3477 return polygon.translated(-d_ptr->pos);-
3478 return d_ptr->transformToParent().inverted().map(polygon);-
3479}-
3480QPolygonF QGraphicsItem::mapFromScene(const QPolygonF &polygon) const-
3481{-
3482 if (d_ptr->hasTranslateOnlySceneTransform())-
3483 return polygon.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());-
3484 return d_ptr->sceneTransform.inverted().map(polygon);-
3485}-
3486QPainterPath QGraphicsItem::mapFromItem(const QGraphicsItem *item, const QPainterPath &path) const-
3487{-
3488 if (item)-
3489 return item->itemTransform(this).map(path);-
3490 return mapFromScene(path);-
3491}-
3492QPainterPath QGraphicsItem::mapFromParent(const QPainterPath &path) const-
3493{-
3494-
3495 if (!d_ptr->transformData)-
3496 return path.translated(-d_ptr->pos);-
3497 return d_ptr->transformToParent().inverted().map(path);-
3498}-
3499QPainterPath QGraphicsItem::mapFromScene(const QPainterPath &path) const-
3500{-
3501 if (d_ptr->hasTranslateOnlySceneTransform())-
3502 return path.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());-
3503 return d_ptr->sceneTransform.inverted().map(path);-
3504}-
3505-
3506-
3507-
3508-
3509-
3510-
3511-
3512bool QGraphicsItem::isAncestorOf(const QGraphicsItem *child) const-
3513{-
3514 if (!child || child == this)-
3515 return false;-
3516 if (child->d_ptr->depth() < d_ptr->depth())-
3517 return false;-
3518 const QGraphicsItem *ancestor = child;-
3519 while ((ancestor = ancestor->d_ptr->parent)) {-
3520 if (ancestor == this)-
3521 return true;-
3522 }-
3523 return false;-
3524}-
3525QGraphicsItem *QGraphicsItem::commonAncestorItem(const QGraphicsItem *other) const-
3526{-
3527 if (!other)-
3528 return 0;-
3529 if (other == this)-
3530 return const_cast<QGraphicsItem *>(this);-
3531 const QGraphicsItem *thisw = this;-
3532 const QGraphicsItem *otherw = other;-
3533 int thisDepth = d_ptr->depth();-
3534 int otherDepth = other->d_ptr->depth();-
3535 while (thisDepth > otherDepth) {-
3536 thisw = thisw->d_ptr->parent;-
3537 --thisDepth;-
3538 }-
3539 while (otherDepth > thisDepth) {-
3540 otherw = otherw->d_ptr->parent;-
3541 --otherDepth;-
3542 }-
3543 while (thisw && thisw != otherw) {-
3544 thisw = thisw->d_ptr->parent;-
3545 otherw = otherw->d_ptr->parent;-
3546 }-
3547 return const_cast<QGraphicsItem *>(thisw);-
3548}-
3549bool QGraphicsItem::isUnderMouse() const-
3550{-
3551 const QGraphicsItemPrivate * const d = d_func();-
3552 if (!d->scene
!d->sceneDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
3553 return
never executed: return false;
false;
never executed: return false;
0
3554-
3555 QPoint cursorPos = QCursor::pos();-
3556 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(d->scene->const auto views ())>::type> _container_((= d->scene->views())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)();-
3557 for (QGraphicsView *view = *_container_.i; _container_.control; _container_.control = 0: views) {-
3558 if (contains(mapFromScene(view->mapToScene(view->mapFromGlobal(cursorPos))))
contains(mapFr...(cursorPos))))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
3559 return
never executed: return true;
true;
never executed: return true;
0
3560 }
never executed: end of block
0
3561 return
never executed: return false;
false;
never executed: return false;
0
3562}-
3563QVariant QGraphicsItem::data(int key) const-
3564{-
3565 QGraphicsItemCustomDataStore *store = qt_dataStore();-
3566 if (!store->data.contains(this))-
3567 return QVariant();-
3568 return store->data.value(this).value(key);-
3569}-
3570void QGraphicsItem::setData(int key, const QVariant &value)-
3571{-
3572 qt_dataStore()->data[this][key] = value;-
3573}-
3574int QGraphicsItem::type() const-
3575{-
3576 return (int)UserType;-
3577}-
3578void QGraphicsItem::installSceneEventFilter(QGraphicsItem *filterItem)-
3579{-
3580 if (!d_ptr->scene) {-
3581 QMessageLogger(__FILE__, 66276717, __PRETTY_FUNCTION__).warning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"-
3582 " on items in a scene.");-
3583 return;-
3584 }-
3585 if (d_ptr->scene != filterItem->scene()) {-
3586 QMessageLogger(__FILE__, 66326722, __PRETTY_FUNCTION__).warning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"-
3587 " on items in the same scene.");-
3588 return;-
3589 }-
3590 d_ptr->scene->d_func()->installSceneEventFilter(this, filterItem);-
3591}-
3592-
3593-
3594-
3595-
3596-
3597-
3598void QGraphicsItem::removeSceneEventFilter(QGraphicsItem *filterItem)-
3599{-
3600 if (!d_ptr->scene || d_ptr->scene != filterItem->scene())-
3601 return;-
3602 d_ptr->scene->d_func()->removeSceneEventFilter(this, filterItem);-
3603}-
3604bool QGraphicsItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event)-
3605{-
3606 (void)watched;;-
3607 (void)event;;-
3608 return false;-
3609}-
3610bool QGraphicsItem::sceneEvent(QEvent *event)-
3611{-
3612 if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents) {-
3613 if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave-
3614 || event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) {-
3615-
3616-
3617 return true;-
3618 }-
3619-
3620 QGraphicsItem *handler = this;-
3621 do {-
3622 handler = handler->d_ptr->parent;-
3623 ((!(handler)) ? qt_assert("handler",__FILE__,67016791) : qt_noop());-
3624 } while (handler->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents);-
3625-
3626-
3627-
3628 d_ptr->remapItemPos(event, handler);-
3629 handler->sceneEvent(event);-
3630 return true;-
3631 }-
3632-
3633 if (event->type() == QEvent::FocusOut) {-
3634 focusOutEvent(static_cast<QFocusEvent *>(event));-
3635 return true;-
3636 }-
3637-
3638 if (!d_ptr->visible) {-
3639-
3640 return true;-
3641 }-
3642-
3643 switch (event->type()) {-
3644 case QEvent::FocusIn:-
3645 focusInEvent(static_cast<QFocusEvent *>(event));-
3646 break;-
3647 case QEvent::GraphicsSceneContextMenu:-
3648 contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event));-
3649 break;-
3650 case QEvent::GraphicsSceneDragEnter:-
3651 dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));-
3652 break;-
3653 case QEvent::GraphicsSceneDragMove:-
3654 dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));-
3655 break;-
3656 case QEvent::GraphicsSceneDragLeave:-
3657 dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));-
3658 break;-
3659 case QEvent::GraphicsSceneDrop:-
3660 dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));-
3661 break;-
3662 case QEvent::GraphicsSceneHoverEnter:-
3663 hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event));-
3664 break;-
3665 case QEvent::GraphicsSceneHoverMove:-
3666 hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));-
3667 break;-
3668 case QEvent::GraphicsSceneHoverLeave:-
3669 hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));-
3670 break;-
3671 case QEvent::GraphicsSceneMouseMove:-
3672 mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));-
3673 break;-
3674 case QEvent::GraphicsSceneMousePress:-
3675 mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));-
3676 break;-
3677 case QEvent::GraphicsSceneMouseRelease:-
3678 mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));-
3679 break;-
3680 case QEvent::GraphicsSceneMouseDoubleClick:-
3681 mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event));-
3682 break;-
3683 case QEvent::GraphicsSceneWheel:-
3684 wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event));-
3685 break;-
3686 case QEvent::KeyPress: {-
3687 QKeyEvent *k = static_cast<QKeyEvent *>(event);-
3688 if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {-
3689 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {-
3690 bool res = false;-
3691 if (k->key() == Qt::Key_Backtab-
3692 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {-
3693 if (d_ptr->isWidget) {-
3694 res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(false);-
3695 } else if (d_ptr->scene) {-
3696 res = d_ptr->scene->focusNextPrevChild(false);-
3697 }-
3698 } else if (k->key() == Qt::Key_Tab) {-
3699 if (d_ptr->isWidget) {-
3700 res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(true);-
3701 } else if (d_ptr->scene) {-
3702 res = d_ptr->scene->focusNextPrevChild(true);-
3703 }-
3704 }-
3705 if (!res)-
3706 event->ignore();-
3707 return true;-
3708 }-
3709 }-
3710 keyPressEvent(static_cast<QKeyEvent *>(event));-
3711 break;-
3712 }-
3713 case QEvent::KeyRelease:-
3714 keyReleaseEvent(static_cast<QKeyEvent *>(event));-
3715 break;-
3716 case QEvent::InputMethod:-
3717 inputMethodEvent(static_cast<QInputMethodEvent *>(event));-
3718 break;-
3719 case QEvent::WindowActivate:-
3720 case QEvent::WindowDeactivate:-
3721-
3722 if (d_ptr->scene) {-
3723 for (int i = 0; i < d_ptr->children.size(); ++i) {-
3724 QGraphicsItem *child = d_ptr->children.at(i);-
3725 if (child->isVisible() && !child->isPanel()) {-
3726 if (!(child->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorHandlesChildEvents))-
3727 d_ptr->scene->sendEvent(child, event);-
3728 }-
3729 }-
3730 }-
3731 break;-
3732 default:-
3733 return false;-
3734 }-
3735-
3736 return true;-
3737}-
3738void QGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)-
3739{-
3740 event->ignore();-
3741}-
3742void QGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)-
3743{-
3744 QGraphicsItemPrivate * const d = d_func();-
3745-
3746 if (d->isProxyWidget())-
3747 static_cast<QGraphicsProxyWidget*>(this)->dragEnterEvent(event);-
3748}-
3749void QGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)-
3750{-
3751 QGraphicsItemPrivate * const d = d_func();-
3752-
3753 if (d->isProxyWidget())-
3754 static_cast<QGraphicsProxyWidget*>(this)->dragLeaveEvent(event);-
3755}-
3756void QGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)-
3757{-
3758 QGraphicsItemPrivate * const d = d_func();-
3759-
3760 if (d->isProxyWidget())-
3761 static_cast<QGraphicsProxyWidget*>(this)->dragMoveEvent(event);-
3762}-
3763void QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event)-
3764{-
3765 QGraphicsItemPrivate * const d = d_func();-
3766-
3767 if (d->isProxyWidget())-
3768 static_cast<QGraphicsProxyWidget*>(this)->dropEvent(event);-
3769}-
3770void QGraphicsItem::focusInEvent(QFocusEvent *event)-
3771{-
3772 (void)event;;-
3773 update();-
3774}-
3775-
3776-
3777-
3778-
3779-
3780-
3781-
3782void QGraphicsItem::focusOutEvent(QFocusEvent *event)-
3783{-
3784 (void)event;;-
3785 update();-
3786}-
3787void QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)-
3788{-
3789 (void)event;;-
3790 update();-
3791}-
3792void QGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)-
3793{-
3794 (void)event;;-
3795}-
3796void QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)-
3797{-
3798 (void)event;;-
3799 update();-
3800}-
3801void QGraphicsItem::keyPressEvent(QKeyEvent *event)-
3802{-
3803 event->ignore();-
3804}-
3805void QGraphicsItem::keyReleaseEvent(QKeyEvent *event)-
3806{-
3807 event->ignore();-
3808}-
3809void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)-
3810{-
3811 if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {-
3812 bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;-
3813 if (!multiSelect) {-
3814 if (!d_ptr->selected) {-
3815 if (QGraphicsScene *scene = d_ptr->scene) {-
3816 ++scene->d_func()->selectionChanging;-
3817 scene->clearSelection();-
3818 --scene->d_func()->selectionChanging;-
3819 }-
3820 setSelected(true);-
3821 }-
3822 }-
3823 } else if (!(flags() & ItemIsMovable)) {-
3824 event->ignore();-
3825 }-
3826 if (d_ptr->isWidget) {-
3827-
3828 QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this);-
3829 if ((w->windowFlags() & Qt::Popup) == Qt::Popup) {-
3830 event->accept();-
3831 if (!w->rect().contains(event->pos()))-
3832 w->close();-
3833 }-
3834 }-
3835}-
3836-
3837-
3838-
3839-
3840bool _qt_movableAncestorIsSelected(const QGraphicsItem *item)-
3841{-
3842 const QGraphicsItem *parent = item->parentItem();-
3843 return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));-
3844}-
3845-
3846bool QGraphicsItemPrivate::movableAncestorIsSelected(const QGraphicsItem *item)-
3847{-
3848 const QGraphicsItem *parent = item->d_ptr->parent;-
3849 return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));-
3850}-
3851void QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)-
3852{-
3853 if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {-
3854-
3855 QList<QGraphicsItem *> selectedItems;-
3856 QHash<QGraphicsItem *, QPointF> initialPositions;-
3857 if (d_ptr->scene) {-
3858 selectedItems = d_ptr->scene->selectedItems();-
3859 initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;-
3860 if (initialPositions.isEmpty()) {-
3861 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(selectedItems)>::type> _container_((selectedItems)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *item = *_container_.i; _container_.control; _container_.control = 0)-
3862 initialPositions[item] = item->pos();-
3863 initialPositions[this] = pos();-
3864 }-
3865 d_ptr->scene->d_func()->movingItemsInitialPositions = initialPositions;-
3866 }-
3867-
3868-
3869 QGraphicsView *view = 0;-
3870 if (event->widget())-
3871 view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget());-
3872-
3873-
3874 int i = 0;-
3875 bool movedMe = false;-
3876 while (i <= selectedItems.size()) {-
3877 QGraphicsItem *item = 0;-
3878 if (i < selectedItems.size())-
3879 item = selectedItems.at(i);-
3880 else-
3881 item = this;-
3882 if (item == this) {-
3883-
3884-
3885-
3886-
3887 if (movedMe)-
3888 break;-
3889 movedMe = true;-
3890 }-
3891-
3892 if ((item->flags() & ItemIsMovable) && !QGraphicsItemPrivate::movableAncestorIsSelected(item)) {-
3893 QPointF currentParentPos;-
3894 QPointF buttonDownParentPos;-
3895 if (item->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorIgnoresTransformations) {-
3896-
3897-
3898-
3899 QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted();-
3900 currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))));-
3901 buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))));-
3902 } else if (item->flags() & ItemIgnoresTransformations) {-
3903-
3904-
3905-
3906-
3907 QTransform itemTransform;-
3908 if (item->d_ptr->transformData)-
3909 itemTransform = item->d_ptr->transformData->computedFullTransform();-
3910 itemTransform.translate(item->d_ptr->pos.x(), item->d_ptr->pos.y());-
3911 QTransform viewToParentTransform = itemTransform-
3912 * (item->sceneTransform() * view->viewportTransform()).inverted();-
3913 currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos())));-
3914 buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton))));-
3915 } else {-
3916-
3917 currentParentPos = item->mapToParent(item->mapFromScene(event->scenePos()));-
3918 buttonDownParentPos = item->mapToParent(item->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));-
3919 }-
3920-
3921 item->setPos(initialPositions.value(item) + currentParentPos - buttonDownParentPos);-
3922-
3923 if (item->flags() & ItemIsSelectable)-
3924 item->setSelected(true);-
3925 }-
3926 ++i;-
3927 }-
3928-
3929 } else {-
3930 event->ignore();-
3931 }-
3932}-
3933void QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)-
3934{-
3935 if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {-
3936 bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;-
3937 if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) {-
3938-
3939 if (multiSelect) {-
3940 setSelected(!isSelected());-
3941 } else {-
3942 bool selectionChanged = false;-
3943 if (QGraphicsScene *scene = d_ptr->scene) {-
3944 ++scene->d_func()->selectionChanging;-
3945-
3946-
3947-
3948 if (d_ptr->selected) {-
3949 scene->d_func()->selectedItems.remove(this);-
3950 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(scene->d_func()->selectedItems)>::type> _container_((scene->d_func()->selectedItems)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsItem *item = *_container_.i; _container_.control; _container_.control = 0) {-
3951 if (item->isSelected()) {-
3952 selectionChanged = true;-
3953 break;-
3954 }-
3955 }-
3956 }-
3957 scene->clearSelection();-
3958 if (d_ptr->selected)-
3959 scene->d_func()->selectedItems.insert(this);-
3960 --scene->d_func()->selectionChanging;-
3961 if (selectionChanged)-
3962 d_ptr->scene->selectionChanged();-
3963 }-
3964 setSelected(true);-
3965 }-
3966 }-
3967 }-
3968 if (d_ptr->scene && !event->buttons())-
3969 d_ptr->scene->d_func()->movingItemsInitialPositions.clear();-
3970}-
3971void QGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)-
3972{-
3973 mousePressEvent(event);-
3974}-
3975void QGraphicsItem::wheelEvent(QGraphicsSceneWheelEvent *event)-
3976{-
3977 event->ignore();-
3978}-
3979void QGraphicsItem::inputMethodEvent(QInputMethodEvent *event)-
3980{-
3981 event->ignore();-
3982}-
3983QVariant QGraphicsItem::inputMethodQuery(Qt::InputMethodQuery query) const-
3984{-
3985 (void)query;;-
3986 return QVariant();-
3987}-
3988Qt::InputMethodHints QGraphicsItem::inputMethodHints() const-
3989{-
3990 const QGraphicsItemPrivate * const d = d_func();-
3991 return d->imHints;-
3992}-
3993void QGraphicsItem::setInputMethodHints(Qt::InputMethodHints hints)-
3994{-
3995 QGraphicsItemPrivate * const d = d_func();-
3996 d->imHints = hints;-
3997 if (!hasFocus())-
3998 return;-
3999 d->scene->d_func()->updateInputMethodSensitivityInViews();-
4000 QWidget *fw = QApplication::focusWidget();-
4001 if (!fw)-
4002 return;-
4003 QGuiApplication::inputMethod()->update(Qt::ImHints);-
4004}-
4005void QGraphicsItem::updateMicroFocus()-
4006{-
4007}-
4008QVariant QGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value)-
4009{-
4010 (void)change;;-
4011 return value;-
4012}-
4013-
4014-
4015-
4016-
4017-
4018-
4019-
4020bool QGraphicsItem::supportsExtension(Extension extension) const-
4021{-
4022 (void)extension;;-
4023 return false;-
4024}-
4025-
4026-
4027-
4028-
4029-
4030-
4031-
4032void QGraphicsItem::setExtension(Extension extension, const QVariant &variant)-
4033{-
4034 (void)extension;;-
4035 (void)variant;;-
4036}-
4037-
4038-
4039-
4040-
4041-
4042-
4043-
4044QVariant QGraphicsItem::extension(const QVariant &variant) const-
4045{-
4046 (void)variant;;-
4047 return QVariant();-
4048}-
4049void QGraphicsItem::addToIndex()-
4050{-
4051 if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren-
4052 || d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren) {-
4053-
4054 return;-
4055 }-
4056 if (d_ptr->scene)-
4057 d_ptr->scene->d_func()->index->addItem(this);-
4058}-
4059void QGraphicsItem::removeFromIndex()-
4060{-
4061 if (d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren-
4062 || d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorContainsChildren) {-
4063-
4064 return;-
4065 }-
4066 if (d_ptr->scene)-
4067 d_ptr->scene->d_func()->index->removeItem(this);-
4068}-
4069void QGraphicsItem::prepareGeometryChange()-
4070{-
4071 if (d_ptr->inDestructor)-
4072 return;-
4073 if (d_ptr->scene) {-
4074 d_ptr->scene->d_func()->dirtyGrowingItemsBoundingRect = true;-
4075 d_ptr->geometryChanged = 1;-
4076 d_ptr->paintedViewBoundingRectsNeedRepaint = 1;-
4077 d_ptr->notifyBoundingRectChanged = !d_ptr->inSetPosHelper;-
4078-
4079 QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func();-
4080 scenePrivate->index->prepareBoundingRectChange(this);-
4081 scenePrivate->markDirty(this, QRectF(), true, false,-
4082 false, false,-
4083 true);-
4084-
4085-
4086-
4087-
4088-
4089 if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex)-
4090 || scenePrivate->views.isEmpty()) {-
4091 if (d_ptr->hasTranslateOnlySceneTransform()) {-
4092 d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(),-
4093 d_ptr->sceneTransform.dy()));-
4094 } else {-
4095 d_ptr->scene->update(d_ptr->sceneTransform.mapRect(boundingRect()));-
4096 }-
4097 }-
4098 }-
4099-
4100 d_ptr->markParentDirty( true);-
4101}-
4102static void qt_graphicsItem_highlightSelected(-
4103 QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)-
4104{-
4105 const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));-
4106 if (qFuzzyIsNull(qMax(murect.width(), murect.height())))-
4107 return;-
4108-
4109 const QRectF mbrect = painter->transform().mapRect(item->boundingRect());-
4110 if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))-
4111 return;-
4112-
4113 qreal itemPenWidth;-
4114 switch (item->type()) {-
4115 case QGraphicsEllipseItem::Type:-
4116 itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();-
4117 break;-
4118 case QGraphicsPathItem::Type:-
4119 itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF();-
4120 break;-
4121 case QGraphicsPolygonItem::Type:-
4122 itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();-
4123 break;-
4124 case QGraphicsRectItem::Type:-
4125 itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF();-
4126 break;-
4127 case QGraphicsSimpleTextItem::Type:-
4128 itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();-
4129 break;-
4130 case QGraphicsLineItem::Type:-
4131 itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF();-
4132 break;-
4133 default:-
4134 itemPenWidth = 1.0;-
4135 }-
4136 const qreal pad = itemPenWidth / 2;-
4137-
4138 const qreal penWidth = 0;-
4139-
4140 const QColor fgcolor = option->palette.windowText().color();-
4141 const QColor bgcolor(-
4142 fgcolor.red() > 127 ? 0 : 255,-
4143 fgcolor.green() > 127 ? 0 : 255,-
4144 fgcolor.blue() > 127 ? 0 : 255);-
4145-
4146 painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));-
4147 painter->setBrush(Qt::NoBrush);-
4148 painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));-
4149-
4150 painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));-
4151 painter->setBrush(Qt::NoBrush);-
4152 painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));-
4153}-
4154QGraphicsObject::QGraphicsObject(QGraphicsItem *parent)-
4155 : QGraphicsItem(parent)-
4156{-
4157 QGraphicsItem::d_ptr->isObject = true;-
4158}-
4159-
4160-
4161-
4162-
4163QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent)-
4164 : QGraphicsItem(dd, parent)-
4165{-
4166 QGraphicsItem::d_ptr->isObject = true;-
4167}-
4168-
4169-
4170-
4171-
4172QGraphicsObject::~QGraphicsObject()-
4173{-
4174}-
4175-
4176-
4177-
4178-
4179bool QGraphicsObject::event(QEvent *ev)-
4180{-
4181 if (ev->type() == QEvent::StyleAnimationUpdate) {-
4182 if (isVisible()) {-
4183 ev->accept();-
4184 update();-
4185 }-
4186 return true;-
4187 }-
4188 return QObject::event(ev);-
4189}-
4190-
4191-
4192-
4193-
4194-
4195-
4196-
4197void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)-
4198{-
4199 bool contains = QGraphicsItem::d_ptr->gestureContext.contains(gesture);-
4200 QGraphicsItem::d_ptr->gestureContext.insert(gesture, flags);-
4201 if (!contains && QGraphicsItem::d_ptr->scene)-
4202 QGraphicsItem::d_ptr->scene->d_func()->grabGesture(this, gesture);-
4203}-
4204-
4205-
4206-
4207-
4208-
4209-
4210void QGraphicsObject::ungrabGesture(Qt::GestureType gesture)-
4211{-
4212 if (QGraphicsItem::d_ptr->gestureContext.remove(gesture) && QGraphicsItem::d_ptr->scene)-
4213 QGraphicsItem::d_ptr->scene->d_func()->ungrabGesture(this, gesture);-
4214}-
4215void QGraphicsObject::updateMicroFocus()-
4216{-
4217 QGraphicsItem::updateMicroFocus();-
4218}-
4219-
4220void QGraphicsItemPrivate::children_append(QDeclarativeListProperty<QGraphicsObject> *list, QGraphicsObject *item)-
4221{-
4222 if (item) {-
4223 QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(list->object);-
4224 if (QGraphicsItemPrivate::get(graphicsObject)->sendParentChangeNotification) {-
4225 item->setParentItem(graphicsObject);-
4226 } else {-
4227 QGraphicsItemPrivate::get(item)->setParentItemHelper(graphicsObject, 0, 0);-
4228 }-
4229 }-
4230}-
4231-
4232int QGraphicsItemPrivate::children_count(QDeclarativeListProperty<QGraphicsObject> *list)-
4233{-
4234 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));-
4235 return d->children.count();-
4236}-
4237-
4238QGraphicsObject *QGraphicsItemPrivate::children_at(QDeclarativeListProperty<QGraphicsObject> *list, int index)-
4239{-
4240 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));-
4241 if (index >= 0 && index < d->children.count())-
4242 return d->children.at(index)->toGraphicsObject();-
4243 else-
4244 return 0;-
4245}-
4246-
4247void QGraphicsItemPrivate::children_clear(QDeclarativeListProperty<QGraphicsObject> *list)-
4248{-
4249 QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));-
4250 int childCount = d->children.count();-
4251 if (d->sendParentChangeNotification) {-
4252 for (int index = 0; index < childCount; index++)-
4253 d->children.at(0)->setParentItem(0);-
4254 } else {-
4255 for (int index = 0; index < childCount; index++)-
4256 QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, 0, 0);-
4257 }-
4258}-
4259QDeclarativeListProperty<QGraphicsObject> QGraphicsItemPrivate::childrenList()-
4260{-
4261 QGraphicsItem * const q = q_func();-
4262 if (isObject) {-
4263 QGraphicsObject *that = static_cast<QGraphicsObject *>(q);-
4264 return QDeclarativeListProperty<QGraphicsObject>(that, &children, children_append,-
4265 children_count, children_at, children_clear);-
4266 } else {-
4267-
4268 return QDeclarativeListProperty<QGraphicsObject>();-
4269 }-
4270}-
4271-
4272-
4273-
4274-
4275-
4276-
4277qreal QGraphicsItemPrivate::width() const-
4278{-
4279 return 0;-
4280}-
4281-
4282-
4283-
4284-
4285-
4286-
4287void QGraphicsItemPrivate::setWidth(qreal w)-
4288{-
4289 (void)w;;-
4290}-
4291-
4292-
4293-
4294-
4295-
4296-
4297void QGraphicsItemPrivate::resetWidth()-
4298{-
4299}-
4300-
4301-
4302-
4303-
4304-
4305-
4306qreal QGraphicsItemPrivate::height() const-
4307{-
4308 return 0;-
4309}-
4310-
4311-
4312-
4313-
4314-
4315-
4316void QGraphicsItemPrivate::setHeight(qreal h)-
4317{-
4318 (void)h;;-
4319}-
4320-
4321-
4322-
4323-
4324-
4325-
4326void QGraphicsItemPrivate::resetHeight()-
4327{-
4328}-
4329class QAbstractGraphicsShapeItemPrivate : public QGraphicsItemPrivate-
4330{-
4331 inline QAbstractGraphicsShapeItem* q_func() { return static_cast<QAbstractGraphicsShapeItem *>(q_ptr); } inline const QAbstractGraphicsShapeItem* q_func() const { return static_cast<const QAbstractGraphicsShapeItem *>(q_ptr); } friend class QAbstractGraphicsShapeItem;-
4332public:-
4333-
4334 QBrush brush;-
4335 QPen pen;-
4336-
4337-
4338 mutable QRectF boundingRect;-
4339};-
4340-
4341-
4342-
4343-
4344-
4345QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QGraphicsItem *parent)-
4346 : QGraphicsItem(*new QAbstractGraphicsShapeItemPrivate, parent)-
4347{-
4348}-
4349-
4350-
4351-
4352-
4353QAbstractGraphicsShapeItem::QAbstractGraphicsShapeItem(QAbstractGraphicsShapeItemPrivate &dd, QGraphicsItem *parent)-
4354 : QGraphicsItem(dd, parent)-
4355{-
4356}-
4357-
4358-
4359-
4360-
4361QAbstractGraphicsShapeItem::~QAbstractGraphicsShapeItem()-
4362{-
4363}-
4364-
4365-
4366-
4367-
4368-
4369QPen QAbstractGraphicsShapeItem::pen() const-
4370{-
4371 const QAbstractGraphicsShapeItemPrivate * const d = d_func();-
4372 return d->pen;-
4373}-
4374void QAbstractGraphicsShapeItem::setPen(const QPen &pen)-
4375{-
4376 QAbstractGraphicsShapeItemPrivate * const d = d_func();-
4377 if (d->pen == pen)-
4378 return;-
4379 prepareGeometryChange();-
4380 d->pen = pen;-
4381 d->boundingRect = QRectF();-
4382 update();-
4383}-
4384-
4385-
4386-
4387-
4388-
4389-
4390QBrush QAbstractGraphicsShapeItem::brush() const-
4391{-
4392 const QAbstractGraphicsShapeItemPrivate * const d = d_func();-
4393 return d->brush;-
4394}-
4395void QAbstractGraphicsShapeItem::setBrush(const QBrush &brush)-
4396{-
4397 QAbstractGraphicsShapeItemPrivate * const d = d_func();-
4398 if (d->brush == brush)-
4399 return;-
4400 d->brush = brush;-
4401 update();-
4402}-
4403-
4404-
4405-
4406-
4407bool QAbstractGraphicsShapeItem::isObscuredBy(const QGraphicsItem *item) const-
4408{-
4409 return QGraphicsItem::isObscuredBy(item);-
4410}-
4411-
4412-
4413-
4414-
4415QPainterPath QAbstractGraphicsShapeItem::opaqueArea() const-
4416{-
4417 const QAbstractGraphicsShapeItemPrivate * const d = d_func();-
4418 if (d->brush.isOpaque())-
4419 return isClipped() ? clipPath() : shape();-
4420 return QGraphicsItem::opaqueArea();-
4421}-
4422class QGraphicsPathItemPrivate : public QAbstractGraphicsShapeItemPrivate-
4423{-
4424 inline QGraphicsPathItem* q_func() { return static_cast<QGraphicsPathItem *>(q_ptr); } inline const QGraphicsPathItem* q_func() const { return static_cast<const QGraphicsPathItem *>(q_ptr); } friend class QGraphicsPathItem;-
4425public:-
4426 QPainterPath path;-
4427};-
4428-
4429-
4430-
4431-
4432-
4433-
4434-
4435QGraphicsPathItem::QGraphicsPathItem(const QPainterPath &path,-
4436 QGraphicsItem *parent)-
4437 : QAbstractGraphicsShapeItem(*new QGraphicsPathItemPrivate, parent)-
4438{-
4439 if (!path.isEmpty())-
4440 setPath(path);-
4441}-
4442-
4443-
4444-
4445-
4446-
4447-
4448-
4449QGraphicsPathItem::QGraphicsPathItem(QGraphicsItem *parent)-
4450 : QAbstractGraphicsShapeItem(*new QGraphicsPathItemPrivate, parent)-
4451{-
4452}-
4453-
4454-
4455-
4456-
4457QGraphicsPathItem::~QGraphicsPathItem()-
4458{-
4459}-
4460-
4461-
4462-
4463-
4464-
4465-
4466-
4467QPainterPath QGraphicsPathItem::path() const-
4468{-
4469 const QGraphicsPathItemPrivate * const d = d_func();-
4470 return d->path;-
4471}-
4472-
4473-
4474-
4475-
4476-
4477-
4478void QGraphicsPathItem::setPath(const QPainterPath &path)-
4479{-
4480 QGraphicsPathItemPrivate * const d = d_func();-
4481 if (d->path == path)-
4482 return;-
4483 prepareGeometryChange();-
4484 d->path = path;-
4485 d->boundingRect = QRectF();-
4486 update();-
4487}-
4488-
4489-
4490-
4491-
4492QRectF QGraphicsPathItem::boundingRect() const-
4493{-
4494 const QGraphicsPathItemPrivate * const d = d_func();-
4495 if (d->boundingRect.isNull()) {-
4496 qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF();-
4497 if (pw == 0.0)-
4498 d->boundingRect = d->path.controlPointRect();-
4499 else {-
4500 d->boundingRect = shape().controlPointRect();-
4501 }-
4502 }-
4503 return d->boundingRect;-
4504}-
4505-
4506-
4507-
4508-
4509QPainterPath QGraphicsPathItem::shape() const-
4510{-
4511 const QGraphicsPathItemPrivate * const d = d_func();-
4512 return qt_graphicsItem_shapeFromPath(d->path, d->pen);-
4513}-
4514-
4515-
4516-
4517-
4518bool QGraphicsPathItem::contains(const QPointF &point) const-
4519{-
4520 return QAbstractGraphicsShapeItem::contains(point);-
4521}-
4522-
4523-
4524-
4525-
4526void QGraphicsPathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,-
4527 QWidget *widget)-
4528{-
4529 QGraphicsPathItemPrivate * const d = d_func();-
4530 (void)widget;;-
4531 painter->setPen(d->pen);-
4532 painter->setBrush(d->brush);-
4533 painter->drawPath(d->path);-
4534-
4535 if (option->state & QStyle::State_Selected)-
4536 qt_graphicsItem_highlightSelected(this, painter, option);-
4537}-
4538-
4539-
4540-
4541-
4542bool QGraphicsPathItem::isObscuredBy(const QGraphicsItem *item) const-
4543{-
4544 return QAbstractGraphicsShapeItem::isObscuredBy(item);-
4545}-
4546-
4547-
4548-
4549-
4550QPainterPath QGraphicsPathItem::opaqueArea() const-
4551{-
4552 return QAbstractGraphicsShapeItem::opaqueArea();-
4553}-
4554-
4555-
4556-
4557-
4558int QGraphicsPathItem::type() const-
4559{-
4560 return Type;-
4561}-
4562-
4563-
4564-
4565-
4566bool QGraphicsPathItem::supportsExtension(Extension extension) const-
4567{-
4568 (void)extension;;-
4569 return false;-
4570}-
4571-
4572-
4573-
4574-
4575void QGraphicsPathItem::setExtension(Extension extension, const QVariant &variant)-
4576{-
4577 (void)extension;;-
4578 (void)variant;;-
4579}-
4580-
4581-
4582-
4583-
4584QVariant QGraphicsPathItem::extension(const QVariant &variant) const-
4585{-
4586 (void)variant;;-
4587 return QVariant();-
4588}-
4589class QGraphicsRectItemPrivate : public QAbstractGraphicsShapeItemPrivate-
4590{-
4591 inline QGraphicsRectItem* q_func() { return static_cast<QGraphicsRectItem *>(q_ptr); } inline const QGraphicsRectItem* q_func() const { return static_cast<const QGraphicsRectItem *>(q_ptr); } friend class QGraphicsRectItem;-
4592public:-
4593 QRectF rect;-
4594};-
4595-
4596-
4597-
4598-
4599-
4600-
4601-
4602QGraphicsRectItem::QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent)-
4603 : QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent)-
4604{-
4605 setRect(rect);-
4606}-
4607QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal w, qreal h,-
4608 QGraphicsItem *parent)-
4609 : QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent)-
4610{-
4611 setRect(QRectF(x, y, w, h));-
4612}-
4613-
4614-
4615-
4616-
4617-
4618-
4619-
4620QGraphicsRectItem::QGraphicsRectItem(QGraphicsItem *parent)-
4621 : QAbstractGraphicsShapeItem(*new QGraphicsRectItemPrivate, parent)-
4622{-
4623}-
4624-
4625-
4626-
4627-
4628QGraphicsRectItem::~QGraphicsRectItem()-
4629{-
4630}-
4631-
4632-
4633-
4634-
4635-
4636-
4637QRectF QGraphicsRectItem::rect() const-
4638{-
4639 const QGraphicsRectItemPrivate * const d = d_func();-
4640 return d->rect;-
4641}-
4642void QGraphicsRectItem::setRect(const QRectF &rect)-
4643{-
4644 QGraphicsRectItemPrivate * const d = d_func();-
4645 if (d->rect == rect)-
4646 return;-
4647 prepareGeometryChange();-
4648 d->rect = rect;-
4649 d->boundingRect = QRectF();-
4650 update();-
4651}-
4652QRectF QGraphicsRectItem::boundingRect() const-
4653{-
4654 const QGraphicsRectItemPrivate * const d = d_func();-
4655 if (d->boundingRect.isNull()) {-
4656 qreal halfpw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF() / 2;-
4657 d->boundingRect = d->rect;-
4658 if (halfpw > 0.0)-
4659 d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw);-
4660 }-
4661 return d->boundingRect;-
4662}-
4663-
4664-
4665-
4666-
4667QPainterPath QGraphicsRectItem::shape() const-
4668{-
4669 const QGraphicsRectItemPrivate * const d = d_func();-
4670 QPainterPath path;-
4671 path.addRect(d->rect);-
4672 return qt_graphicsItem_shapeFromPath(path, d->pen);-
4673}-
4674-
4675-
4676-
4677-
4678bool QGraphicsRectItem::contains(const QPointF &point) const-
4679{-
4680 return QAbstractGraphicsShapeItem::contains(point);-
4681}-
4682-
4683-
4684-
4685-
4686void QGraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,-
4687 QWidget *widget)-
4688{-
4689 QGraphicsRectItemPrivate * const d = d_func();-
4690 (void)widget;;-
4691 painter->setPen(d->pen);-
4692 painter->setBrush(d->brush);-
4693 painter->drawRect(d->rect);-
4694-
4695 if (option->state & QStyle::State_Selected)-
4696 qt_graphicsItem_highlightSelected(this, painter, option);-
4697}-
4698-
4699-
4700-
4701-
4702bool QGraphicsRectItem::isObscuredBy(const QGraphicsItem *item) const-
4703{-
4704 return QAbstractGraphicsShapeItem::isObscuredBy(item);-
4705}-
4706-
4707-
4708-
4709-
4710QPainterPath QGraphicsRectItem::opaqueArea() const-
4711{-
4712 return QAbstractGraphicsShapeItem::opaqueArea();-
4713}-
4714-
4715-
4716-
4717-
4718int QGraphicsRectItem::type() const-
4719{-
4720 return Type;-
4721}-
4722-
4723-
4724-
4725-
4726bool QGraphicsRectItem::supportsExtension(Extension extension) const-
4727{-
4728 (void)extension;;-
4729 return false;-
4730}-
4731-
4732-
4733-
4734-
4735void QGraphicsRectItem::setExtension(Extension extension, const QVariant &variant)-
4736{-
4737 (void)extension;;-
4738 (void)variant;;-
4739}-
4740-
4741-
4742-
4743-
4744QVariant QGraphicsRectItem::extension(const QVariant &variant) const-
4745{-
4746 (void)variant;;-
4747 return QVariant();-
4748}-
4749class QGraphicsEllipseItemPrivate : public QAbstractGraphicsShapeItemPrivate-
4750{-
4751 inline QGraphicsEllipseItem* q_func() { return static_cast<QGraphicsEllipseItem *>(q_ptr); } inline const QGraphicsEllipseItem* q_func() const { return static_cast<const QGraphicsEllipseItem *>(q_ptr); } friend class QGraphicsEllipseItem;-
4752public:-
4753 inline QGraphicsEllipseItemPrivate()-
4754 : startAngle(0), spanAngle(360 * 16)-
4755 { }-
4756-
4757 QRectF rect;-
4758 int startAngle;-
4759 int spanAngle;-
4760};-
4761-
4762-
4763-
4764-
4765-
4766-
4767-
4768QGraphicsEllipseItem::QGraphicsEllipseItem(const QRectF &rect, QGraphicsItem *parent)-
4769 : QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent)-
4770{-
4771 setRect(rect);-
4772}-
4773QGraphicsEllipseItem::QGraphicsEllipseItem(qreal x, qreal y, qreal w, qreal h,-
4774 QGraphicsItem *parent)-
4775 : QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent)-
4776{-
4777 setRect(x,y,w,h);-
4778}-
4779QGraphicsEllipseItem::QGraphicsEllipseItem(QGraphicsItem *parent)-
4780 : QAbstractGraphicsShapeItem(*new QGraphicsEllipseItemPrivate, parent)-
4781{-
4782}-
4783-
4784-
4785-
4786-
4787QGraphicsEllipseItem::~QGraphicsEllipseItem()-
4788{-
4789}-
4790-
4791-
4792-
4793-
4794-
4795-
4796QRectF QGraphicsEllipseItem::rect() const-
4797{-
4798 const QGraphicsEllipseItemPrivate * const d = d_func();-
4799 return d->rect;-
4800}-
4801void QGraphicsEllipseItem::setRect(const QRectF &rect)-
4802{-
4803 QGraphicsEllipseItemPrivate * const d = d_func();-
4804 if (d->rect == rect)-
4805 return;-
4806 prepareGeometryChange();-
4807 d->rect = rect;-
4808 d->boundingRect = QRectF();-
4809 update();-
4810}-
4811int QGraphicsEllipseItem::startAngle() const-
4812{-
4813 const QGraphicsEllipseItemPrivate * const d = d_func();-
4814 return d->startAngle;-
4815}-
4816void QGraphicsEllipseItem::setStartAngle(int angle)-
4817{-
4818 QGraphicsEllipseItemPrivate * const d = d_func();-
4819 if (angle != d->startAngle) {-
4820 prepareGeometryChange();-
4821 d->boundingRect = QRectF();-
4822 d->startAngle = angle;-
4823 update();-
4824 }-
4825}-
4826int QGraphicsEllipseItem::spanAngle() const-
4827{-
4828 const QGraphicsEllipseItemPrivate * const d = d_func();-
4829 return d->spanAngle;-
4830}-
4831void QGraphicsEllipseItem::setSpanAngle(int angle)-
4832{-
4833 QGraphicsEllipseItemPrivate * const d = d_func();-
4834 if (angle != d->spanAngle) {-
4835 prepareGeometryChange();-
4836 d->boundingRect = QRectF();-
4837 d->spanAngle = angle;-
4838 update();-
4839 }-
4840}-
4841-
4842-
4843-
4844-
4845QRectF QGraphicsEllipseItem::boundingRect() const-
4846{-
4847 const QGraphicsEllipseItemPrivate * const d = d_func();-
4848 if (d->boundingRect.isNull()) {-
4849 qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF();-
4850 if (pw == 0.0 && d->spanAngle == 360 * 16)-
4851 d->boundingRect = d->rect;-
4852 else-
4853 d->boundingRect = shape().controlPointRect();-
4854 }-
4855 return d->boundingRect;-
4856}-
4857-
4858-
4859-
4860-
4861QPainterPath QGraphicsEllipseItem::shape() const-
4862{-
4863 const QGraphicsEllipseItemPrivate * const d = d_func();-
4864 QPainterPath path;-
4865 if (d->rect.isNull())-
4866 return path;-
4867 if (d->spanAngle != 360 * 16) {-
4868 path.moveTo(d->rect.center());-
4869 path.arcTo(d->rect, d->startAngle / 16.0, d->spanAngle / 16.0);-
4870 } else {-
4871 path.addEllipse(d->rect);-
4872 }-
4873-
4874 return qt_graphicsItem_shapeFromPath(path, d->pen);-
4875}-
4876-
4877-
4878-
4879-
4880bool QGraphicsEllipseItem::contains(const QPointF &point) const-
4881{-
4882 return QAbstractGraphicsShapeItem::contains(point);-
4883}-
4884-
4885-
4886-
4887-
4888void QGraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,-
4889 QWidget *widget)-
4890{-
4891 QGraphicsEllipseItemPrivate * const d = d_func();-
4892 (void)widget;;-
4893 painter->setPen(d->pen);-
4894 painter->setBrush(d->brush);-
4895 if ((d->spanAngle != 0) && (qAbs(d->spanAngle) % (360 * 16) == 0))-
4896 painter->drawEllipse(d->rect);-
4897 else-
4898 painter->drawPie(d->rect, d->startAngle, d->spanAngle);-
4899-
4900 if (option->state & QStyle::State_Selected)-
4901 qt_graphicsItem_highlightSelected(this, painter, option);-
4902}-
4903-
4904-
4905-
4906-
4907bool QGraphicsEllipseItem::isObscuredBy(const QGraphicsItem *item) const-
4908{-
4909 return QAbstractGraphicsShapeItem::isObscuredBy(item);-
4910}-
4911-
4912-
4913-
4914-
4915QPainterPath QGraphicsEllipseItem::opaqueArea() const-
4916{-
4917 return QAbstractGraphicsShapeItem::opaqueArea();-
4918}-
4919-
4920-
4921-
4922-
4923int QGraphicsEllipseItem::type() const-
4924{-
4925 return Type;-
4926}-
4927-
4928-
4929-
4930-
4931-
4932bool QGraphicsEllipseItem::supportsExtension(Extension extension) const-
4933{-
4934 (void)extension;;-
4935 return false;-
4936}-
4937-
4938-
4939-
4940-
4941void QGraphicsEllipseItem::setExtension(Extension extension, const QVariant &variant)-
4942{-
4943 (void)extension;;-
4944 (void)variant;;-
4945}-
4946-
4947-
4948-
4949-
4950QVariant QGraphicsEllipseItem::extension(const QVariant &variant) const-
4951{-
4952 (void)variant;;-
4953 return QVariant();-
4954}-
4955class QGraphicsPolygonItemPrivate : public QAbstractGraphicsShapeItemPrivate-
4956{-
4957 inline QGraphicsPolygonItem* q_func() { return static_cast<QGraphicsPolygonItem *>(q_ptr); } inline const QGraphicsPolygonItem* q_func() const { return static_cast<const QGraphicsPolygonItem *>(q_ptr); } friend class QGraphicsPolygonItem;-
4958public:-
4959 inline QGraphicsPolygonItemPrivate()-
4960 : fillRule(Qt::OddEvenFill)-
4961 { }-
4962-
4963 QPolygonF polygon;-
4964 Qt::FillRule fillRule;-
4965};-
4966-
4967-
4968-
4969-
4970-
4971-
4972-
4973QGraphicsPolygonItem::QGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent)-
4974 : QAbstractGraphicsShapeItem(*new QGraphicsPolygonItemPrivate, parent)-
4975{-
4976 setPolygon(polygon);-
4977}-
4978-
4979-
4980-
4981-
4982-
4983-
4984-
4985QGraphicsPolygonItem::QGraphicsPolygonItem(QGraphicsItem *parent)-
4986 : QAbstractGraphicsShapeItem(*new QGraphicsPolygonItemPrivate, parent)-
4987{-
4988}-
4989-
4990-
4991-
4992-
4993QGraphicsPolygonItem::~QGraphicsPolygonItem()-
4994{-
4995}-
4996-
4997-
4998-
4999-
5000-
5001-
5002-
5003QPolygonF QGraphicsPolygonItem::polygon() const-
5004{-
5005 const QGraphicsPolygonItemPrivate * const d = d_func();-
5006 return d->polygon;-
5007}-
5008-
5009-
5010-
5011-
5012-
5013-
5014void QGraphicsPolygonItem::setPolygon(const QPolygonF &polygon)-
5015{-
5016 QGraphicsPolygonItemPrivate * const d = d_func();-
5017 if (d->polygon == polygon)-
5018 return;-
5019 prepareGeometryChange();-
5020 d->polygon = polygon;-
5021 d->boundingRect = QRectF();-
5022 update();-
5023}-
5024-
5025-
5026-
5027-
5028-
5029-
5030-
5031Qt::FillRule QGraphicsPolygonItem::fillRule() const-
5032{-
5033 const QGraphicsPolygonItemPrivate * const d = d_func();-
5034 return d->fillRule;-
5035}-
5036-
5037-
5038-
5039-
5040-
5041-
5042-
5043void QGraphicsPolygonItem::setFillRule(Qt::FillRule rule)-
5044{-
5045 QGraphicsPolygonItemPrivate * const d = d_func();-
5046 if (rule != d->fillRule) {-
5047 d->fillRule = rule;-
5048 update();-
5049 }-
5050}-
5051-
5052-
5053-
5054-
5055QRectF QGraphicsPolygonItem::boundingRect() const-
5056{-
5057 const QGraphicsPolygonItemPrivate * const d = d_func();-
5058 if (d->boundingRect.isNull()) {-
5059 qreal pw = pen().style() == Qt::NoPen ? qreal(0) : pen().widthF();-
5060 if (pw == 0.0)-
5061 d->boundingRect = d->polygon.boundingRect();-
5062 else-
5063 d->boundingRect = shape().controlPointRect();-
5064 }-
5065 return d->boundingRect;-
5066}-
5067-
5068-
5069-
5070-
5071QPainterPath QGraphicsPolygonItem::shape() const-
5072{-
5073 const QGraphicsPolygonItemPrivate * const d = d_func();-
5074 QPainterPath path;-
5075 path.addPolygon(d->polygon);-
5076 return qt_graphicsItem_shapeFromPath(path, d->pen);-
5077}-
5078-
5079-
5080-
5081-
5082bool QGraphicsPolygonItem::contains(const QPointF &point) const-
5083{-
5084 return QAbstractGraphicsShapeItem::contains(point);-
5085}-
5086-
5087-
5088-
5089-
5090void QGraphicsPolygonItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)-
5091{-
5092 QGraphicsPolygonItemPrivate * const d = d_func();-
5093 (void)widget;;-
5094 painter->setPen(d->pen);-
5095 painter->setBrush(d->brush);-
5096 painter->drawPolygon(d->polygon, d->fillRule);-
5097-
5098 if (option->state & QStyle::State_Selected)-
5099 qt_graphicsItem_highlightSelected(this, painter, option);-
5100}-
5101-
5102-
5103-
5104-
5105bool QGraphicsPolygonItem::isObscuredBy(const QGraphicsItem *item) const-
5106{-
5107 return QAbstractGraphicsShapeItem::isObscuredBy(item);-
5108}-
5109-
5110-
5111-
5112-
5113QPainterPath QGraphicsPolygonItem::opaqueArea() const-
5114{-
5115 return QAbstractGraphicsShapeItem::opaqueArea();-
5116}-
5117-
5118-
5119-
5120-
5121int QGraphicsPolygonItem::type() const-
5122{-
5123 return Type;-
5124}-
5125-
5126-
5127-
5128-
5129bool QGraphicsPolygonItem::supportsExtension(Extension extension) const-
5130{-
5131 (void)extension;;-
5132 return false;-
5133}-
5134-
5135-
5136-
5137-
5138void QGraphicsPolygonItem::setExtension(Extension extension, const QVariant &variant)-
5139{-
5140 (void)extension;;-
5141 (void)variant;;-
5142}-
5143-
5144-
5145-
5146-
5147QVariant QGraphicsPolygonItem::extension(const QVariant &variant) const-
5148{-
5149 (void)variant;;-
5150 return QVariant();-
5151}-
5152class QGraphicsLineItemPrivate : public QGraphicsItemPrivate-
5153{-
5154 inline QGraphicsLineItem* q_func() { return static_cast<QGraphicsLineItem *>(q_ptr); } inline const QGraphicsLineItem* q_func() const { return static_cast<const QGraphicsLineItem *>(q_ptr); } friend class QGraphicsLineItem;-
5155public:-
5156 QLineF line;-
5157 QPen pen;-
5158};-
5159-
5160-
5161-
5162-
5163-
5164-
5165-
5166QGraphicsLineItem::QGraphicsLineItem(const QLineF &line, QGraphicsItem *parent)-
5167 : QGraphicsItem(*new QGraphicsLineItemPrivate, parent)-
5168{-
5169 setLine(line);-
5170}-
5171QGraphicsLineItem::QGraphicsLineItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent)-
5172 : QGraphicsItem(*new QGraphicsLineItemPrivate, parent)-
5173{-
5174 setLine(x1, y1, x2, y2);-
5175}-
5176QGraphicsLineItem::QGraphicsLineItem(QGraphicsItem *parent)-
5177 : QGraphicsItem(*new QGraphicsLineItemPrivate, parent)-
5178{-
5179}-
5180-
5181-
5182-
5183-
5184QGraphicsLineItem::~QGraphicsLineItem()-
5185{-
5186}-
5187-
5188-
5189-
5190-
5191-
5192-
5193-
5194QPen QGraphicsLineItem::pen() const-
5195{-
5196 const QGraphicsLineItemPrivate * const d = d_func();-
5197 return d->pen;-
5198}-
5199-
5200-
5201-
5202-
5203-
5204-
5205-
5206void QGraphicsLineItem::setPen(const QPen &pen)-
5207{-
5208 QGraphicsLineItemPrivate * const d = d_func();-
5209 if (d->pen == pen)-
5210 return;-
5211 prepareGeometryChange();-
5212 d->pen = pen;-
5213 update();-
5214}-
5215-
5216-
5217-
5218-
5219-
5220-
5221QLineF QGraphicsLineItem::line() const-
5222{-
5223 const QGraphicsLineItemPrivate * const d = d_func();-
5224 return d->line;-
5225}-
5226-
5227-
5228-
5229-
5230-
5231-
5232void QGraphicsLineItem::setLine(const QLineF &line)-
5233{-
5234 QGraphicsLineItemPrivate * const d = d_func();-
5235 if (d->line == line)-
5236 return;-
5237 prepareGeometryChange();-
5238 d->line = line;-
5239 update();-
5240}-
5241QRectF QGraphicsLineItem::boundingRect() const-
5242{-
5243 const QGraphicsLineItemPrivate * const d = d_func();-
5244 if (d->pen.widthF() == 0.0) {-
5245 const qreal x1 = d->line.p1().x();-
5246 const qreal x2 = d->line.p2().x();-
5247 const qreal y1 = d->line.p1().y();-
5248 const qreal y2 = d->line.p2().y();-
5249 qreal lx = qMin(x1, x2);-
5250 qreal rx = qMax(x1, x2);-
5251 qreal ty = qMin(y1, y2);-
5252 qreal by = qMax(y1, y2);-
5253 return QRectF(lx, ty, rx - lx, by - ty);-
5254 }-
5255 return shape().controlPointRect();-
5256}-
5257-
5258-
5259-
5260-
5261QPainterPath QGraphicsLineItem::shape() const-
5262{-
5263 const QGraphicsLineItemPrivate * const d = d_func();-
5264 QPainterPath path;-
5265 if (d->line == QLineF())-
5266 return path;-
5267-
5268 path.moveTo(d->line.p1());-
5269 path.lineTo(d->line.p2());-
5270 return qt_graphicsItem_shapeFromPath(path, d->pen);-
5271}-
5272-
5273-
5274-
5275-
5276bool QGraphicsLineItem::contains(const QPointF &point) const-
5277{-
5278 return QGraphicsItem::contains(point);-
5279}-
5280-
5281-
5282-
5283-
5284void QGraphicsLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)-
5285{-
5286 QGraphicsLineItemPrivate * const d = d_func();-
5287 (void)widget;;-
5288 painter->setPen(d->pen);-
5289 painter->drawLine(d->line);-
5290-
5291 if (option->state & QStyle::State_Selected)-
5292 qt_graphicsItem_highlightSelected(this, painter, option);-
5293}-
5294-
5295-
5296-
5297-
5298bool QGraphicsLineItem::isObscuredBy(const QGraphicsItem *item) const-
5299{-
5300 return QGraphicsItem::isObscuredBy(item);-
5301}-
5302-
5303-
5304-
5305-
5306QPainterPath QGraphicsLineItem::opaqueArea() const-
5307{-
5308 return QGraphicsItem::opaqueArea();-
5309}-
5310-
5311-
5312-
5313-
5314int QGraphicsLineItem::type() const-
5315{-
5316 return Type;-
5317}-
5318-
5319-
5320-
5321-
5322bool QGraphicsLineItem::supportsExtension(Extension extension) const-
5323{-
5324 (void)extension;;-
5325 return false;-
5326}-
5327-
5328-
5329-
5330-
5331void QGraphicsLineItem::setExtension(Extension extension, const QVariant &variant)-
5332{-
5333 (void)extension;;-
5334 (void)variant;;-
5335}-
5336-
5337-
5338-
5339-
5340QVariant QGraphicsLineItem::extension(const QVariant &variant) const-
5341{-
5342 (void)variant;;-
5343 return QVariant();-
5344}-
5345extern QPainterPath qt_regionToPath(const QRegion &region);-
5346-
5347class QGraphicsPixmapItemPrivate : public QGraphicsItemPrivate-
5348{-
5349 inline QGraphicsPixmapItem* q_func() { return static_cast<QGraphicsPixmapItem *>(q_ptr); } inline const QGraphicsPixmapItem* q_func() const { return static_cast<const QGraphicsPixmapItem *>(q_ptr); } friend class QGraphicsPixmapItem;-
5350public:-
5351 QGraphicsPixmapItemPrivate()-
5352 : transformationMode(Qt::FastTransformation),-
5353 shapeMode(QGraphicsPixmapItem::MaskShape),-
5354 hasShape(false)-
5355 {}-
5356-
5357 QPixmap pixmap;-
5358 Qt::TransformationMode transformationMode;-
5359 QPointF offset;-
5360 QGraphicsPixmapItem::ShapeMode shapeMode;-
5361 QPainterPath shape;-
5362 bool hasShape;-
5363-
5364 void updateShape()-
5365 {-
5366 shape = QPainterPath();-
5367 switch (shapeMode) {-
5368 case QGraphicsPixmapItem::MaskShape: {-
5369 QBitmap mask = pixmap.mask();-
5370 if (!mask.isNull()) {-
5371 shape = qt_regionToPath(QRegion(mask).translated(offset.toPoint()));-
5372 break;-
5373 }-
5374-
5375 }-
5376 case QGraphicsPixmapItem::BoundingRectShape:-
5377 shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));-
5378 break;-
5379 case QGraphicsPixmapItem::HeuristicMaskShape:-
5380-
5381 shape = qt_regionToPath(QRegion(pixmap.createHeuristicMask()).translated(offset.toPoint()));-
5382-
5383-
5384-
5385 break;-
5386 }-
5387 }-
5388};-
5389-
5390-
5391-
5392-
5393-
5394-
5395-
5396QGraphicsPixmapItem::QGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent)-
5397 : QGraphicsItem(*new QGraphicsPixmapItemPrivate, parent)-
5398{-
5399 setPixmap(pixmap);-
5400}-
5401-
5402-
5403-
5404-
5405-
5406-
5407-
5408QGraphicsPixmapItem::QGraphicsPixmapItem(QGraphicsItem *parent)-
5409 : QGraphicsItem(*new QGraphicsPixmapItemPrivate, parent)-
5410{-
5411}-
5412-
5413-
5414-
5415-
5416QGraphicsPixmapItem::~QGraphicsPixmapItem()-
5417{-
5418}-
5419-
5420-
5421-
5422-
5423-
5424-
5425void QGraphicsPixmapItem::setPixmap(const QPixmap &pixmap)-
5426{-
5427 QGraphicsPixmapItemPrivate * const d = d_func();-
5428 prepareGeometryChange();-
5429 d->pixmap = pixmap;-
5430 d->hasShape = false;-
5431 update();-
5432}-
5433-
5434-
5435-
5436-
5437-
5438-
5439-
5440QPixmap QGraphicsPixmapItem::pixmap() const-
5441{-
5442 const QGraphicsPixmapItemPrivate * const d = d_func();-
5443 return d->pixmap;-
5444}-
5445Qt::TransformationMode QGraphicsPixmapItem::transformationMode() const-
5446{-
5447 const QGraphicsPixmapItemPrivate * const d = d_func();-
5448 return d->transformationMode;-
5449}-
5450void QGraphicsPixmapItem::setTransformationMode(Qt::TransformationMode mode)-
5451{-
5452 QGraphicsPixmapItemPrivate * const d = d_func();-
5453 if (mode != d->transformationMode) {-
5454 d->transformationMode = mode;-
5455 update();-
5456 }-
5457}-
5458-
5459-
5460-
5461-
5462-
5463-
5464-
5465QPointF QGraphicsPixmapItem::offset() const-
5466{-
5467 const QGraphicsPixmapItemPrivate * const d = d_func();-
5468 return d->offset;-
5469}-
5470-
5471-
5472-
5473-
5474-
5475-
5476-
5477void QGraphicsPixmapItem::setOffset(const QPointF &offset)-
5478{-
5479 QGraphicsPixmapItemPrivate * const d = d_func();-
5480 if (d->offset == offset)-
5481 return;-
5482 prepareGeometryChange();-
5483 d->offset = offset;-
5484 d->hasShape = false;-
5485 update();-
5486}-
5487QRectF QGraphicsPixmapItem::boundingRect() const-
5488{-
5489 const QGraphicsPixmapItemPrivate * const d = d_func();-
5490 if (d->pixmap.isNull())-
5491 return QRectF();-
5492 if (d->flags & ItemIsSelectable) {-
5493 qreal pw = 1.0;-
5494 return QRectF(d->offset, d->pixmap.size() / d->pixmap.devicePixelRatio()).adjusted(-pw/2, -pw/2, pw/2, pw/2);-
5495 } else {-
5496 return QRectF(d->offset, d->pixmap.size() / d->pixmap.devicePixelRatio());-
5497 }-
5498}-
5499-
5500-
5501-
5502-
5503QPainterPath QGraphicsPixmapItem::shape() const-
5504{-
5505 const QGraphicsPixmapItemPrivate * const d = d_func();-
5506 if (!d->hasShape) {-
5507 QGraphicsPixmapItemPrivate *thatD = const_cast<QGraphicsPixmapItemPrivate *>(d);-
5508 thatD->updateShape();-
5509 thatD->hasShape = true;-
5510 }-
5511 return d_func()->shape;-
5512}-
5513-
5514-
5515-
5516-
5517bool QGraphicsPixmapItem::contains(const QPointF &point) const-
5518{-
5519 return QGraphicsItem::contains(point);-
5520}-
5521-
5522-
5523-
5524-
5525void QGraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,-
5526 QWidget *widget)-
5527{-
5528 QGraphicsPixmapItemPrivate * const d = d_func();-
5529 (void)widget;;-
5530-
5531 painter->setRenderHint(QPainter::SmoothPixmapTransform,-
5532 (d->transformationMode == Qt::SmoothTransformation));-
5533-
5534 painter->drawPixmap(d->offset, d->pixmap);-
5535-
5536 if (option->state & QStyle::State_Selected)-
5537 qt_graphicsItem_highlightSelected(this, painter, option);-
5538}-
5539-
5540-
5541-
5542-
5543bool QGraphicsPixmapItem::isObscuredBy(const QGraphicsItem *item) const-
5544{-
5545 return QGraphicsItem::isObscuredBy(item);-
5546}-
5547-
5548-
5549-
5550-
5551QPainterPath QGraphicsPixmapItem::opaqueArea() const-
5552{-
5553 return shape();-
5554}-
5555-
5556-
5557-
5558-
5559int QGraphicsPixmapItem::type() const-
5560{-
5561 return Type;-
5562}-
5563-
5564-
5565-
5566-
5567-
5568-
5569-
5570QGraphicsPixmapItem::ShapeMode QGraphicsPixmapItem::shapeMode() const-
5571{-
5572 return d_func()->shapeMode;-
5573}-
5574-
5575-
5576-
5577-
5578-
5579-
5580-
5581void QGraphicsPixmapItem::setShapeMode(ShapeMode mode)-
5582{-
5583 QGraphicsPixmapItemPrivate * const d = d_func();-
5584 if (d->shapeMode == mode)-
5585 return;-
5586 d->shapeMode = mode;-
5587 d->hasShape = false;-
5588}-
5589-
5590-
5591-
5592-
5593bool QGraphicsPixmapItem::supportsExtension(Extension extension) const-
5594{-
5595 (void)extension;;-
5596 return false;-
5597}-
5598-
5599-
5600-
5601-
5602void QGraphicsPixmapItem::setExtension(Extension extension, const QVariant &variant)-
5603{-
5604 (void)extension;;-
5605 (void)variant;;-
5606}-
5607-
5608-
5609-
5610-
5611QVariant QGraphicsPixmapItem::extension(const QVariant &variant) const-
5612{-
5613 (void)variant;;-
5614 return QVariant();-
5615}-
5616class QGraphicsTextItemPrivate-
5617{-
5618public:-
5619 QGraphicsTextItemPrivate()-
5620 : control(0), pageNumber(0), useDefaultImpl(false), tabChangesFocus(false), clickCausedFocus(0)-
5621 { }-
5622-
5623 mutable QWidgetTextControl *control;-
5624 QWidgetTextControl *textControl() const;-
5625-
5626 inline QPointF controlOffset() const-
5627 { return QPointF(0., pageNumber * control->document()->pageSize().height()); }-
5628 inline void sendControlEvent(QEvent *e)-
5629 { if (control) control->processEvent(e, controlOffset()); }-
5630-
5631 void _q_updateBoundingRect(const QSizeF &);-
5632 void _q_update(QRectF);-
5633 void _q_ensureVisible(QRectF);-
5634 bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *);-
5635-
5636 QRectF boundingRect;-
5637 int pageNumber;-
5638 bool useDefaultImpl;-
5639 bool tabChangesFocus;-
5640-
5641 uint clickCausedFocus : 1;-
5642-
5643 QGraphicsTextItem *qq;-
5644};-
5645QGraphicsTextItem::QGraphicsTextItem(const QString &text, QGraphicsItem *parent)-
5646 : QGraphicsObject(*new QGraphicsItemPrivate, parent),-
5647 dd(new QGraphicsTextItemPrivate)-
5648{-
5649 dd->qq = this;-
5650 if (!text.isEmpty())-
5651 setPlainText(text);-
5652 setAcceptDrops(true);-
5653 setAcceptHoverEvents(true);-
5654 setFlags(ItemUsesExtendedStyleOption);-
5655}-
5656-
5657-
5658-
5659-
5660-
5661-
5662-
5663QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent)-
5664 : QGraphicsObject(*new QGraphicsItemPrivate, parent),-
5665 dd(new QGraphicsTextItemPrivate)-
5666{-
5667 dd->qq = this;-
5668 setAcceptDrops(true);-
5669 setAcceptHoverEvents(true);-
5670 setFlag(ItemUsesExtendedStyleOption);-
5671}-
5672-
5673-
5674-
5675-
5676QGraphicsTextItem::~QGraphicsTextItem()-
5677{-
5678 delete dd;-
5679}-
5680-
5681-
5682-
5683-
5684-
5685-
5686QString QGraphicsTextItem::toHtml() const-
5687{-
5688-
5689 if (dd->control)-
5690 return dd->control->toHtml();-
5691-
5692 return QString();-
5693}-
5694void QGraphicsTextItem::setHtml(const QString &text)-
5695{-
5696 dd->textControl()->setHtml(text);-
5697}-
5698-
5699-
5700-
5701-
5702-
5703-
5704QString QGraphicsTextItem::toPlainText() const-
5705{-
5706 if (dd->control)-
5707 return dd->control->toPlainText();-
5708 return QString();-
5709}-
5710void QGraphicsTextItem::setPlainText(const QString &text)-
5711{-
5712 dd->textControl()->setPlainText(text);-
5713}-
5714-
5715-
5716-
5717-
5718-
5719-
5720QFont QGraphicsTextItem::font() const-
5721{-
5722 if (!dd->control)-
5723 return QFont();-
5724 return dd->control->document()->defaultFont();-
5725}-
5726-
5727-
5728-
5729-
5730-
5731-
5732void QGraphicsTextItem::setFont(const QFont &font)-
5733{-
5734 dd->textControl()->document()->setDefaultFont(font);-
5735}-
5736-
5737-
5738-
5739-
5740void QGraphicsTextItem::setDefaultTextColor(const QColor &col)-
5741{-
5742 QWidgetTextControl *c = dd->textControl();-
5743 QPalette pal = c->palette();-
5744 QColor old = pal.color(QPalette::Text);-
5745 pal.setColor(QPalette::Text, col);-
5746 c->setPalette(pal);-
5747 if (old != col)-
5748 update();-
5749}-
5750-
5751-
5752-
5753-
5754QColor QGraphicsTextItem::defaultTextColor() const-
5755{-
5756 return dd->textControl()->palette().color(QPalette::Text);-
5757}-
5758-
5759-
5760-
5761-
5762QRectF QGraphicsTextItem::boundingRect() const-
5763{-
5764 return dd->boundingRect;-
5765}-
5766-
5767-
5768-
5769-
5770QPainterPath QGraphicsTextItem::shape() const-
5771{-
5772 if (!dd->control)-
5773 return QPainterPath();-
5774 QPainterPath path;-
5775 path.addRect(dd->boundingRect);-
5776 return path;-
5777}-
5778-
5779-
5780-
5781-
5782bool QGraphicsTextItem::contains(const QPointF &point) const-
5783{-
5784 return dd->boundingRect.contains(point);-
5785}-
5786-
5787-
5788-
5789-
5790void QGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,-
5791 QWidget *widget)-
5792{-
5793 (void)widget;;-
5794 if (dd->control) {-
5795 painter->save();-
5796 QRectF r = option->exposedRect;-
5797 painter->translate(-dd->controlOffset());-
5798 r.translate(dd->controlOffset());-
5799-
5800 QTextDocument *doc = dd->control->document();-
5801 QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());-
5802-
5803-
5804-
5805 if (layout)-
5806 layout->setViewport(dd->boundingRect);-
5807-
5808 dd->control->drawContents(painter, r);-
5809-
5810 if (layout)-
5811 layout->setViewport(QRect());-
5812-
5813 painter->restore();-
5814 }-
5815-
5816 if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))-
5817 qt_graphicsItem_highlightSelected(this, painter, option);-
5818}-
5819-
5820-
5821-
5822-
5823bool QGraphicsTextItem::isObscuredBy(const QGraphicsItem *item) const-
5824{-
5825 return QGraphicsItem::isObscuredBy(item);-
5826}-
5827-
5828-
5829-
5830-
5831QPainterPath QGraphicsTextItem::opaqueArea() const-
5832{-
5833 return QGraphicsItem::opaqueArea();-
5834}-
5835-
5836-
5837-
5838-
5839int QGraphicsTextItem::type() const-
5840{-
5841 return Type;-
5842}-
5843void QGraphicsTextItem::setTextWidth(qreal width)-
5844{-
5845 dd->textControl()->setTextWidth(width);-
5846}-
5847qreal QGraphicsTextItem::textWidth() const-
5848{-
5849 if (!dd->control)-
5850 return -1;-
5851 return dd->control->textWidth();-
5852}-
5853-
5854-
5855-
5856-
5857void QGraphicsTextItem::adjustSize()-
5858{-
5859 if (dd->control)-
5860 dd->control->adjustSize();-
5861}-
5862-
5863-
5864-
5865-
5866void QGraphicsTextItem::setDocument(QTextDocument *document)-
5867{-
5868 dd->textControl()->setDocument(document);-
5869 dd->_q_updateBoundingRect(dd->control->size());-
5870}-
5871-
5872-
5873-
5874-
5875QTextDocument *QGraphicsTextItem::document() const-
5876{-
5877 return dd->textControl()->document();-
5878}-
5879-
5880-
5881-
5882-
5883bool QGraphicsTextItem::sceneEvent(QEvent *event)-
5884{-
5885 QEvent::Type t = event->type();-
5886 if (!dd->tabChangesFocus && (t == QEvent::KeyPress || t == QEvent::KeyRelease)) {-
5887 int k = ((QKeyEvent *)event)->key();-
5888 if (k == Qt::Key_Tab || k == Qt::Key_Backtab) {-
5889 dd->sendControlEvent(event);-
5890 return true;-
5891 }-
5892 }-
5893 bool result = QGraphicsItem::sceneEvent(event);-
5894-
5895-
5896 switch (event->type()) {-
5897 case QEvent::ContextMenu:-
5898 case QEvent::FocusIn:-
5899 case QEvent::FocusOut:-
5900 case QEvent::GraphicsSceneDragEnter:-
5901 case QEvent::GraphicsSceneDragLeave:-
5902 case QEvent::GraphicsSceneDragMove:-
5903 case QEvent::GraphicsSceneDrop:-
5904 case QEvent::GraphicsSceneHoverEnter:-
5905 case QEvent::GraphicsSceneHoverLeave:-
5906 case QEvent::GraphicsSceneHoverMove:-
5907 case QEvent::GraphicsSceneMouseDoubleClick:-
5908 case QEvent::GraphicsSceneMousePress:-
5909 case QEvent::GraphicsSceneMouseMove:-
5910 case QEvent::GraphicsSceneMouseRelease:-
5911 case QEvent::KeyPress:-
5912 case QEvent::KeyRelease:-
5913-
5914-
5915 if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut) {-
5916 QGuiApplication::inputMethod()->reset();-
5917 } else {-
5918 QGuiApplication::inputMethod()->update(Qt::ImQueryInput);-
5919 }-
5920 break;-
5921 case QEvent::ShortcutOverride:-
5922 dd->sendControlEvent(event);-
5923 return true;-
5924 default:-
5925 break;-
5926 }-
5927-
5928 return result;-
5929}-
5930-
5931-
5932-
5933-
5934void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)-
5935{-
5936 if ((QGraphicsItem::d_ptr->flags & (ItemIsSelectable | ItemIsMovable))-
5937 && (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) {-
5938-
5939-
5940 dd->useDefaultImpl = true;-
5941 } else if (event->buttons() == event->button()-
5942 && dd->control->textInteractionFlags() == Qt::NoTextInteraction) {-
5943-
5944 dd->useDefaultImpl = true;-
5945 }-
5946 if (dd->useDefaultImpl) {-
5947 QGraphicsItem::mousePressEvent(event);-
5948 if (!event->isAccepted())-
5949 dd->useDefaultImpl = false;-
5950 return;-
5951 }-
5952-
5953 dd->sendControlEvent(event);-
5954}-
5955-
5956-
5957-
5958-
5959void QGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)-
5960{-
5961 if (dd->useDefaultImpl) {-
5962 QGraphicsItem::mouseMoveEvent(event);-
5963 return;-
5964 }-
5965-
5966 dd->sendControlEvent(event);-
5967}-
5968-
5969-
5970-
5971-
5972void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)-
5973{-
5974 if (dd->useDefaultImpl) {-
5975 QGraphicsItem::mouseReleaseEvent(event);-
5976 if (dd->control->textInteractionFlags() == Qt::NoTextInteraction-
5977 && !event->buttons()) {-
5978-
5979 dd->useDefaultImpl = false;-
5980 } else if ((event->buttons() & Qt::LeftButton) == 0) {-
5981-
5982 dd->useDefaultImpl = false;-
5983 }-
5984 return;-
5985 }-
5986-
5987 QWidget *widget = event->widget();-
5988 if (widget && (dd->control->textInteractionFlags() & Qt::TextEditable) && boundingRect().contains(event->pos())) {-
5989 qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), dd->clickCausedFocus);-
5990 }-
5991 dd->clickCausedFocus = 0;-
5992 dd->sendControlEvent(event);-
5993}-
5994-
5995-
5996-
5997-
5998void QGraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)-
5999{-
6000 if (dd->useDefaultImpl) {-
6001 QGraphicsItem::mouseDoubleClickEvent(event);-
6002 return;-
6003 }-
6004-
6005 if (!hasFocus()) {-
6006 QGraphicsItem::mouseDoubleClickEvent(event);-
6007 return;-
6008 }-
6009-
6010 dd->sendControlEvent(event);-
6011}-
6012-
6013-
6014-
6015-
6016void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)-
6017{-
6018 dd->sendControlEvent(event);-
6019}-
6020-
6021-
6022-
6023-
6024void QGraphicsTextItem::keyPressEvent(QKeyEvent *event)-
6025{-
6026 dd->sendControlEvent(event);-
6027}-
6028-
6029-
6030-
6031-
6032void QGraphicsTextItem::keyReleaseEvent(QKeyEvent *event)-
6033{-
6034 dd->sendControlEvent(event);-
6035}-
6036-
6037-
6038-
6039-
6040void QGraphicsTextItem::focusInEvent(QFocusEvent *event)-
6041{-
6042 dd->sendControlEvent(event);-
6043 if (event->reason() == Qt::MouseFocusReason) {-
6044 dd->clickCausedFocus = 1;-
6045 }-
6046 update();-
6047}-
6048-
6049-
6050-
6051-
6052void QGraphicsTextItem::focusOutEvent(QFocusEvent *event)-
6053{-
6054 dd->sendControlEvent(event);-
6055 update();-
6056}-
6057-
6058-
6059-
6060-
6061void QGraphicsTextItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)-
6062{-
6063 dd->sendControlEvent(event);-
6064}-
6065-
6066-
6067-
6068-
6069void QGraphicsTextItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)-
6070{-
6071 dd->sendControlEvent(event);-
6072}-
6073-
6074-
6075-
6076-
6077void QGraphicsTextItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)-
6078{-
6079 dd->sendControlEvent(event);-
6080}-
6081-
6082-
6083-
6084-
6085void QGraphicsTextItem::dropEvent(QGraphicsSceneDragDropEvent *event)-
6086{-
6087 dd->sendControlEvent(event);-
6088}-
6089-
6090-
6091-
6092-
6093void QGraphicsTextItem::inputMethodEvent(QInputMethodEvent *event)-
6094{-
6095 dd->sendControlEvent(event);-
6096}-
6097-
6098-
6099-
6100-
6101void QGraphicsTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)-
6102{-
6103 dd->sendControlEvent(event);-
6104}-
6105-
6106-
6107-
6108-
6109void QGraphicsTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)-
6110{-
6111 dd->sendControlEvent(event);-
6112}-
6113-
6114-
6115-
6116-
6117void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)-
6118{-
6119 dd->sendControlEvent(event);-
6120}-
6121-
6122-
6123-
6124-
6125QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const-
6126{-
6127 QVariant v;-
6128 if (query == Qt::ImHints)-
6129 v = int(inputMethodHints());-
6130 else if (dd->control)-
6131 v = dd->control->inputMethodQuery(query, QVariant());-
6132 if (v.type() == QVariant::RectF)-
6133 v = v.toRectF().translated(-dd->controlOffset());-
6134 else if (v.type() == QVariant::PointF)-
6135 v = v.toPointF() - dd->controlOffset();-
6136 else if (v.type() == QVariant::Rect)-
6137 v = v.toRect().translated(-dd->controlOffset().toPoint());-
6138 else if (v.type() == QVariant::Point)-
6139 v = v.toPoint() - dd->controlOffset().toPoint();-
6140 return v;-
6141}-
6142-
6143-
6144-
6145-
6146bool QGraphicsTextItem::supportsExtension(Extension extension) const-
6147{-
6148 (void)extension;;-
6149 return false;-
6150}-
6151-
6152-
6153-
6154-
6155void QGraphicsTextItem::setExtension(Extension extension, const QVariant &variant)-
6156{-
6157 (void)extension;;-
6158 (void)variant;;-
6159}-
6160-
6161-
6162-
6163-
6164QVariant QGraphicsTextItem::extension(const QVariant &variant) const-
6165{-
6166 (void)variant;;-
6167 return QVariant();-
6168}-
6169-
6170-
6171-
6172-
6173void QGraphicsTextItemPrivate::_q_update(QRectF rect)-
6174{-
6175 if (rect.isValid()) {-
6176 rect.translate(-controlOffset());-
6177 } else {-
6178 rect = boundingRect;-
6179 }-
6180 if (rect.intersects(boundingRect))-
6181 qq->update(rect);-
6182}-
6183-
6184-
6185-
6186-
6187void QGraphicsTextItemPrivate::_q_updateBoundingRect(const QSizeF &size)-
6188{-
6189 if (!control) return;-
6190 const QSizeF pageSize = control->document()->pageSize();-
6191-
6192 if (size == boundingRect.size() || pageSize.height() != -1)-
6193 return;-
6194 qq->prepareGeometryChange();-
6195 boundingRect.setSize(size);-
6196 qq->update();-
6197}-
6198-
6199-
6200-
6201-
6202void QGraphicsTextItemPrivate::_q_ensureVisible(QRectF rect)-
6203{-
6204 if (qq->hasFocus()) {-
6205 rect.translate(-controlOffset());-
6206 qq->ensureVisible(rect, 0, 0);-
6207 }-
6208}-
6209-
6210QWidgetTextControl *QGraphicsTextItemPrivate::textControl() const-
6211{-
6212 if (!control) {-
6213 QGraphicsTextItem *that = const_cast<QGraphicsTextItem *>(qq);-
6214 control = new QWidgetTextControl(that);-
6215 control->setTextInteractionFlags(Qt::NoTextInteraction);-
6216-
6217 QObject::connect(control, qFlagLocation("2""updateRequest(QRectF)" "\0" __FILE__ ":" "10448""10538"),-
6218 qq, qFlagLocation("1""_q_update(QRectF)" "\0" __FILE__ ":" "10449""10539"));-
6219 QObject::connect(control, qFlagLocation("2""documentSizeChanged(QSizeF)" "\0" __FILE__ ":" "10450""10540"),-
6220 qq, qFlagLocation("1""_q_updateBoundingRect(QSizeF)" "\0" __FILE__ ":" "10451""10541"));-
6221 QObject::connect(control, qFlagLocation("2""visibilityRequest(QRectF)" "\0" __FILE__ ":" "10452""10542"),-
6222 qq, qFlagLocation("1""_q_ensureVisible(QRectF)" "\0" __FILE__ ":" "10453""10543"));-
6223 QObject::connect(control, qFlagLocation("2""linkActivated(QString)" "\0" __FILE__ ":" "10454""10544"),-
6224 qq, qFlagLocation("2""linkActivated(QString)" "\0" __FILE__ ":" "10455""10545"));-
6225 QObject::connect(control, qFlagLocation("2""linkHovered(QString)" "\0" __FILE__ ":" "10456""10546"),-
6226 qq, qFlagLocation("2""linkHovered(QString)" "\0" __FILE__ ":" "10457""10547"));-
6227-
6228 const QSizeF pgSize = control->document()->pageSize();-
6229 if (pgSize.height() != -1) {-
6230 qq->prepareGeometryChange();-
6231 that->dd->boundingRect.setSize(pgSize);-
6232 qq->update();-
6233 } else {-
6234 that->dd->_q_updateBoundingRect(control->size());-
6235 }-
6236 }-
6237 return control;-
6238}-
6239-
6240-
6241-
6242-
6243bool QGraphicsTextItemPrivate::_q_mouseOnEdge(QGraphicsSceneMouseEvent *event)-
6244{-
6245 QPainterPath path;-
6246 path.addRect(qq->boundingRect());-
6247-
6248 QPainterPath docPath;-
6249 const QTextFrameFormat format = control->document()->rootFrame()->frameFormat();-
6250 docPath.addRect(-
6251 qq->boundingRect().adjusted(-
6252 format.leftMargin(),-
6253 format.topMargin(),-
6254 -format.rightMargin(),-
6255 -format.bottomMargin()));-
6256-
6257 return path.subtracted(docPath).contains(event->pos());-
6258}-
6259void QGraphicsTextItem::setTextInteractionFlags(Qt::TextInteractionFlags flags)-
6260{-
6261 if (flags == Qt::NoTextInteraction)-
6262 setFlags(this->flags() & ~(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod));-
6263 else-
6264 setFlags(this->flags() | QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemAcceptsInputMethod);-
6265-
6266 dd->textControl()->setTextInteractionFlags(flags);-
6267}-
6268-
6269-
6270-
6271-
6272-
6273-
6274Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags() const-
6275{-
6276 if (!dd->control)-
6277 return Qt::NoTextInteraction;-
6278 return dd->control->textInteractionFlags();-
6279}-
6280void QGraphicsTextItem::setTabChangesFocus(bool b)-
6281{-
6282 dd->tabChangesFocus = b;-
6283}-
6284bool QGraphicsTextItem::tabChangesFocus() const-
6285{-
6286 return dd->tabChangesFocus;-
6287}-
6288void QGraphicsTextItem::setOpenExternalLinks(bool open)-
6289{-
6290 dd->textControl()->setOpenExternalLinks(open);-
6291}-
6292-
6293bool QGraphicsTextItem::openExternalLinks() const-
6294{-
6295 if (!dd->control)-
6296 return false;-
6297 return dd->control->openExternalLinks();-
6298}-
6299void QGraphicsTextItem::setTextCursor(const QTextCursor &cursor)-
6300{-
6301 dd->textControl()->setTextCursor(cursor);-
6302}-
6303-
6304QTextCursor QGraphicsTextItem::textCursor() const-
6305{-
6306 if (!dd->control)-
6307 return QTextCursor();-
6308 return dd->control->textCursor();-
6309}-
6310-
6311class QGraphicsSimpleTextItemPrivate : public QAbstractGraphicsShapeItemPrivate-
6312{-
6313 inline QGraphicsSimpleTextItem* q_func() { return static_cast<QGraphicsSimpleTextItem *>(q_ptr); } inline const QGraphicsSimpleTextItem* q_func() const { return static_cast<const QGraphicsSimpleTextItem *>(q_ptr); } friend class QGraphicsSimpleTextItem;-
6314public:-
6315 inline QGraphicsSimpleTextItemPrivate() {-
6316 pen.setStyle(Qt::NoPen);-
6317 brush.setStyle(Qt::SolidPattern);-
6318 }-
6319 QString text;-
6320 QFont font;-
6321 QRectF boundingRect;-
6322-
6323 void updateBoundingRect();-
6324};-
6325-
6326static QRectF setupTextLayout(QTextLayout *layout)-
6327{-
6328 layout->setCacheEnabled(true);-
6329 layout->beginLayout();-
6330 while (layout->createLine().isValid())-
6331 ;-
6332 layout->endLayout();-
6333 qreal maxWidth = 0;-
6334 qreal y = 0;-
6335 for (int i = 0; i < layout->lineCount(); ++i) {-
6336 QTextLine line = layout->lineAt(i);-
6337 maxWidth = qMax(maxWidth, line.naturalTextWidth());-
6338 line.setPosition(QPointF(0, y));-
6339 y += line.height();-
6340 }-
6341 return QRectF(0, 0, maxWidth, y);-
6342}-
6343-
6344void QGraphicsSimpleTextItemPrivate::updateBoundingRect()-
6345{-
6346 QGraphicsSimpleTextItem * const q = q_func();-
6347 QRectF br;-
6348 if (text.isEmpty()) {-
6349 br = QRectF();-
6350 } else {-
6351 QString tmp = text;-
6352 tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);-
6353 QStackTextEngine engine(tmp, font);-
6354 QTextLayout layout(&engine);-
6355 br = setupTextLayout(&layout);-
6356 }-
6357 if (br != boundingRect) {-
6358 q->prepareGeometryChange();-
6359 boundingRect = br;-
6360 q->update();-
6361 }-
6362}-
6363QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(QGraphicsItem *parent)-
6364 : QAbstractGraphicsShapeItem(*new QGraphicsSimpleTextItemPrivate, parent)-
6365{-
6366}-
6367QGraphicsSimpleTextItem::QGraphicsSimpleTextItem(const QString &text, QGraphicsItem *parent)-
6368 : QAbstractGraphicsShapeItem(*new QGraphicsSimpleTextItemPrivate, parent)-
6369{-
6370 setText(text);-
6371}-
6372-
6373-
6374-
6375-
6376QGraphicsSimpleTextItem::~QGraphicsSimpleTextItem()-
6377{-
6378}-
6379-
6380-
6381-
6382-
6383-
6384-
6385-
6386void QGraphicsSimpleTextItem::setText(const QString &text)-
6387{-
6388 QGraphicsSimpleTextItemPrivate * const d = d_func();-
6389 if (d->text == text)-
6390 return;-
6391 d->text = text;-
6392 d->updateBoundingRect();-
6393 update();-
6394}-
6395-
6396-
6397-
6398-
6399QString QGraphicsSimpleTextItem::text() const-
6400{-
6401 const QGraphicsSimpleTextItemPrivate * const d = d_func();-
6402 return d->text;-
6403}-
6404-
6405-
6406-
6407-
6408void QGraphicsSimpleTextItem::setFont(const QFont &font)-
6409{-
6410 QGraphicsSimpleTextItemPrivate * const d = d_func();-
6411 d->font = font;-
6412 d->updateBoundingRect();-
6413}-
6414-
6415-
6416-
6417-
6418QFont QGraphicsSimpleTextItem::font() const-
6419{-
6420 const QGraphicsSimpleTextItemPrivate * const d = d_func();-
6421 return d->font;-
6422}-
6423-
6424-
6425-
6426-
6427QRectF QGraphicsSimpleTextItem::boundingRect() const-
6428{-
6429 const QGraphicsSimpleTextItemPrivate * const d = d_func();-
6430 return d->boundingRect;-
6431}-
6432-
6433-
6434-
6435-
6436QPainterPath QGraphicsSimpleTextItem::shape() const-
6437{-
6438 const QGraphicsSimpleTextItemPrivate * const d = d_func();-
6439 QPainterPath path;-
6440 path.addRect(d->boundingRect);-
6441 return path;-
6442}-
6443-
6444-
6445-
6446-
6447bool QGraphicsSimpleTextItem::contains(const QPointF &point) const-
6448{-
6449 const QGraphicsSimpleTextItemPrivate * const d = d_func();-
6450 return d->boundingRect.contains(point);-
6451}-
6452-
6453-
6454-
6455-
6456void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)-
6457{-
6458 (void)widget;;-
6459 QGraphicsSimpleTextItemPrivate * const d = d_func();-
6460-
6461 painter->setFont(d->font);-
6462-
6463 QString tmp = d->text;-
6464 tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);-
6465 QStackTextEngine engine(tmp, d->font);-
6466 QTextLayout layout(&engine);-
6467-
6468 QPen p;-
6469 p.setBrush(d->brush);-
6470 painter->setPen(p);-
6471 if (d->pen.style() == Qt::NoPen && d->brush.style() == Qt::SolidPattern) {-
6472 painter->setBrush(Qt::NoBrush);-
6473 } else {-
6474 QTextLayout::FormatRange range;-
6475 range.start = 0;-
6476 range.length = layout.text().length();-
6477 range.format.setTextOutline(d->pen);-
6478 layout.setFormats(QVector<QTextLayout::FormatRange>(1, range));-
6479 }-
6480-
6481 setupTextLayout(&layout);-
6482 layout.draw(painter, QPointF(0, 0));-
6483-
6484 if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus))-
6485 qt_graphicsItem_highlightSelected(this, painter, option);-
6486}-
6487-
6488-
6489-
6490-
6491bool QGraphicsSimpleTextItem::isObscuredBy(const QGraphicsItem *item) const-
6492{-
6493 return QAbstractGraphicsShapeItem::isObscuredBy(item);-
6494}-
6495-
6496-
6497-
6498-
6499QPainterPath QGraphicsSimpleTextItem::opaqueArea() const-
6500{-
6501 return QAbstractGraphicsShapeItem::opaqueArea();-
6502}-
6503-
6504-
6505-
6506-
6507int QGraphicsSimpleTextItem::type() const-
6508{-
6509 return Type;-
6510}-
6511-
6512-
6513-
6514-
6515bool QGraphicsSimpleTextItem::supportsExtension(Extension extension) const-
6516{-
6517 (void)extension;;-
6518 return false;-
6519}-
6520-
6521-
6522-
6523-
6524void QGraphicsSimpleTextItem::setExtension(Extension extension, const QVariant &variant)-
6525{-
6526 (void)extension;;-
6527 (void)variant;;-
6528}-
6529-
6530-
6531-
6532-
6533QVariant QGraphicsSimpleTextItem::extension(const QVariant &variant) const-
6534{-
6535 (void)variant;;-
6536 return QVariant();-
6537}-
6538class QGraphicsItemGroupPrivate : public QGraphicsItemPrivate-
6539{-
6540public:-
6541 QRectF itemsBoundingRect;-
6542};-
6543-
6544-
6545-
6546-
6547-
6548-
6549-
6550QGraphicsItemGroup::QGraphicsItemGroup(QGraphicsItem *parent)-
6551 : QGraphicsItem(*new QGraphicsItemGroupPrivate, parent)-
6552{-
6553 setHandlesChildEvents(true);-
6554}-
6555-
6556-
6557-
6558-
6559QGraphicsItemGroup::~QGraphicsItemGroup()-
6560{-
6561}-
6562void QGraphicsItemGroup::addToGroup(QGraphicsItem *item)-
6563{-
6564 QGraphicsItemGroupPrivate * const d = d_func();-
6565 if (!item) {-
6566 QMessageLogger(__FILE__, 1099111081, __PRETTY_FUNCTION__).warning("QGraphicsItemGroup::addToGroup: cannot add null item");-
6567 return;-
6568 }-
6569 if (item == this) {-
6570 QMessageLogger(__FILE__, 1099511085, __PRETTY_FUNCTION__).warning("QGraphicsItemGroup::addToGroup: cannot add a group to itself");-
6571 return;-
6572 }-
6573-
6574-
6575 bool ok;-
6576 QTransform itemTransform = item->itemTransform(this, &ok);-
6577-
6578 if (!ok) {-
6579 QMessageLogger(__FILE__, 1100411094, __PRETTY_FUNCTION__).warning("QGraphicsItemGroup::addToGroup: could not find a valid transformation from item to group coordinates");-
6580 return;-
6581 }-
6582-
6583 QTransform newItemTransform(itemTransform);-
6584 item->setPos(mapFromItem(item, 0, 0));-
6585 item->setParentItem(this);-
6586-
6587-
6588 if (!item->pos().isNull())-
6589 newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y());-
6590-
6591-
6592 QPointF origin = item->transformOriginPoint();-
6593 QMatrix4x4 m;-
6594 QList<QGraphicsTransform*> transformList = item->transformations();-
6595 for (int i = 0; i < transformList.size(); ++i)-
6596 transformList.at(i)->applyTo(&m);-
6597 newItemTransform *= m.toTransform().inverted();-
6598 newItemTransform.translate(origin.x(), origin.y());-
6599 newItemTransform.rotate(-item->rotation());-
6600 newItemTransform.scale(1/item->scale(), 1/item->scale());-
6601 newItemTransform.translate(-origin.x(), -origin.y());-
6602-
6603-
6604-
6605 item->setTransform(newItemTransform);-
6606 item->d_func()->setIsMemberOfGroup(true);-
6607 prepareGeometryChange();-
6608 d->itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect());-
6609 update();-
6610}-
6611void QGraphicsItemGroup::removeFromGroup(QGraphicsItem *item)-
6612{-
6613 QGraphicsItemGroupPrivate * const d = d_func();-
6614 if (!item) {-
6615 QMessageLogger(__FILE__, 1104911139, __PRETTY_FUNCTION__).warning("QGraphicsItemGroup::removeFromGroup: cannot remove null item");-
6616 return;-
6617 }-
6618-
6619 QGraphicsItem *newParent = d_ptr->parent;-
6620-
6621-
6622 bool ok;-
6623 QTransform itemTransform;-
6624 if (newParent)-
6625 itemTransform = item->itemTransform(newParent, &ok);-
6626 else-
6627 itemTransform = item->sceneTransform();-
6628-
6629 QPointF oldPos = item->mapToItem(newParent, 0, 0);-
6630 item->setParentItem(newParent);-
6631 item->setPos(oldPos);-
6632-
6633-
6634 if (!item->pos().isNull())-
6635 itemTransform *= QTransform::fromTranslate(-item->x(), -item->y());-
6636-
6637-
6638-
6639 QPointF origin = item->transformOriginPoint();-
6640 QMatrix4x4 m;-
6641 QList<QGraphicsTransform*> transformList = item->transformations();-
6642 for (int i = 0; i < transformList.size(); ++i)-
6643 transformList.at(i)->applyTo(&m);-
6644 itemTransform *= m.toTransform().inverted();-
6645 itemTransform.translate(origin.x(), origin.y());-
6646 itemTransform.rotate(-item->rotation());-
6647 itemTransform.scale(1 / item->scale(), 1 / item->scale());-
6648 itemTransform.translate(-origin.x(), -origin.y());-
6649-
6650-
6651-
6652 item->setTransform(itemTransform);-
6653 item->d_func()->setIsMemberOfGroup(item->group() != 0);-
6654-
6655-
6656 prepareGeometryChange();-
6657 d->itemsBoundingRect = childrenBoundingRect();-
6658}-
6659-
6660-
6661-
6662-
6663-
6664-
6665QRectF QGraphicsItemGroup::boundingRect() const-
6666{-
6667 const QGraphicsItemGroupPrivate * const d = d_func();-
6668 return d->itemsBoundingRect;-
6669}-
6670-
6671-
6672-
6673-
6674void QGraphicsItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,-
6675 QWidget *widget)-
6676{-
6677 (void)widget;;-
6678 if (option->state & QStyle::State_Selected) {-
6679 QGraphicsItemGroupPrivate * const d = d_func();-
6680 painter->setBrush(Qt::NoBrush);-
6681 painter->drawRect(d->itemsBoundingRect);-
6682 }-
6683}-
6684-
6685-
6686-
6687-
6688bool QGraphicsItemGroup::isObscuredBy(const QGraphicsItem *item) const-
6689{-
6690 return QGraphicsItem::isObscuredBy(item);-
6691}-
6692-
6693-
6694-
6695-
6696QPainterPath QGraphicsItemGroup::opaqueArea() const-
6697{-
6698 return QGraphicsItem::opaqueArea();-
6699}-
6700-
6701-
6702-
6703-
6704int QGraphicsItemGroup::type() const-
6705{-
6706 return Type;-
6707}-
6708-
6709-
6710QRectF QGraphicsItemEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const-
6711{-
6712 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);-
6713 if (!info && deviceCoordinates) {-
6714-
6715 QMessageLogger(__FILE__, 1114911239, __PRETTY_FUNCTION__).warning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");-
6716 return QRectF();-
6717 }-
6718-
6719 QRectF rect = item->boundingRect();-
6720 if (!item->d_ptr->children.isEmpty())-
6721 rect |= item->childrenBoundingRect();-
6722-
6723 if (deviceCoordinates) {-
6724 ((!(info->painter)) ? qt_assert("info->painter",__FILE__,1115811248) : qt_noop());-
6725 rect = info->painter->worldTransform().mapRect(rect);-
6726 }-
6727-
6728 return rect;-
6729}-
6730-
6731void QGraphicsItemEffectSourcePrivate::draw(QPainter *painter)-
6732{-
6733 if (!info) {-
6734 QMessageLogger(__FILE__, 1116811258, __PRETTY_FUNCTION__).warning("QGraphicsEffectSource::draw: Can only begin as a result of QGraphicsEffect::draw");-
6735 return;-
6736 }-
6737-
6738 ((!(item->d_ptr->scene)) ? qt_assert("item->d_ptr->scene",__FILE__,1117211262) : qt_noop());-
6739 QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();-
6740 if (painter == info->painter) {-
6741 scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,-
6742 info->widget, info->opacity, info->effectTransform, info->wasDirtySceneTransform,-
6743 info->drawItem);-
6744 } else {-
6745 QTransform effectTransform = info->painter->worldTransform().inverted();-
6746 effectTransform *= painter->worldTransform();-
6747 scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,-
6748 info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,-
6749 info->drawItem);-
6750 }-
6751}-
6752-
6753-
6754QRect QGraphicsItemEffectSourcePrivate::paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode, const QRectF &sourceRect, bool *unpadded) const-
6755{-
6756 QRectF effectRectF;-
6757-
6758 if (unpadded)-
6759 *unpadded = false;-
6760-
6761 if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) {-
6762 if (info) {-
6763 QRectF deviceRect = system == Qt::DeviceCoordinates ? sourceRect : info->painter->worldTransform().mapRect(sourceRect);-
6764 effectRectF = item->graphicsEffect()->boundingRectFor(deviceRect);-
6765 if (unpadded)-
6766 *unpadded = (effectRectF.size() == sourceRect.size());-
6767 if (info && system == Qt::LogicalCoordinates)-
6768 effectRectF = info->painter->worldTransform().inverted().mapRect(effectRectF);-
6769 } else {-
6770-
6771 effectRectF = item->graphicsEffect()->boundingRectFor(sourceRect);-
6772 }-
6773 } else if (mode == QGraphicsEffect::PadToTransparentBorder) {-
6774-
6775 effectRectF = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5);-
6776 } else {-
6777 effectRectF = sourceRect;-
6778 if (unpadded)-
6779 *unpadded = true;-
6780 }-
6781-
6782 return effectRectF.toAlignedRect();-
6783}-
6784-
6785QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,-
6786 QGraphicsEffect::PixmapPadMode mode) const-
6787{-
6788 const bool deviceCoordinates = (system == Qt::DeviceCoordinates);-
6789 if (!info && deviceCoordinates) {-
6790-
6791 QMessageLogger(__FILE__, 1122511315, __PRETTY_FUNCTION__).warning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");-
6792 return QPixmap();-
6793 }-
6794 if (!item->d_ptr->scene)-
6795 return QPixmap();-
6796 QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();-
6797-
6798 bool unpadded;-
6799 const QRectF sourceRect = boundingRect(system);-
6800 QRect effectRect = paddedEffectRect(system, mode, sourceRect, &unpadded);-
6801-
6802 if (offset)-
6803 *offset = effectRect.topLeft();-
6804-
6805 bool untransformed = !deviceCoordinates-
6806 || info->painter->worldTransform().type() <= QTransform::TxTranslate;-
6807 if (untransformed && unpadded && isPixmap()) {-
6808 if (offset)-
6809 *offset = boundingRect(system).topLeft().toPoint();-
6810 return static_cast<QGraphicsPixmapItem *>(item)->pixmap();-
6811 }-
6812-
6813 if (effectRect.isEmpty())-
6814 return QPixmap();-
6815-
6816 QPixmap pixmap(effectRect.size());-
6817 pixmap.fill(Qt::transparent);-
6818 QPainter pixmapPainter(&pixmap);-
6819 pixmapPainter.setRenderHints(info ? info->painter->renderHints() : QPainter::TextAntialiasing);-
6820-
6821 QTransform effectTransform = QTransform::fromTranslate(-effectRect.x(), -effectRect.y());-
6822 if (deviceCoordinates && info->effectTransform)-
6823 effectTransform *= *info->effectTransform;-
6824-
6825 if (!info) {-
6826-
6827 QTransform sceneTransform = item->sceneTransform();-
6828 QTransform newEffectTransform = sceneTransform.inverted();-
6829 newEffectTransform *= effectTransform;-
6830 scened->draw(item, &pixmapPainter, 0, &sceneTransform, 0, 0, qreal(1.0),-
6831 &newEffectTransform, false, true);-
6832 } else if (deviceCoordinates) {-
6833-
6834 scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0,-
6835 info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,-
6836 info->drawItem);-
6837 } else {-
6838-
6839 QTransform newEffectTransform = info->transformPtr->inverted();-
6840 newEffectTransform *= effectTransform;-
6841 scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0,-
6842 info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform,-
6843 info->drawItem);-
6844 }-
6845-
6846 pixmapPainter.end();-
6847-
6848 return pixmap;-
6849}-
6850-
6851-
6852-
6853static void formatGraphicsItemHelper(QDebug debug, const QGraphicsItem *item)-
6854{-
6855 if (const QGraphicsItem *parent = item->parentItem())-
6856 debug << ", parent=" << static_cast<const void *>(parent);-
6857 debug << ", pos=";-
6858 QtDebugUtils::formatQPoint(debug, item->pos());-
6859 if (const qreal z = item->zValue())-
6860 debug << ", z=" << z;-
6861 if (item->flags())-
6862 debug << ", flags=" << item->flags();-
6863}-
6864-
6865-
6866QDebug operator<<(QDebug debug, QGraphicsItem *item)-
6867{-
6868 QDebugStateSaver saver(debug);-
6869 debug.nospace();-
6870-
6871 if (!item) {-
6872 debug << "QGraphicsItem(0)";-
6873 return debug;-
6874 }-
6875-
6876 if (QGraphicsObject *o = item->toGraphicsObject())-
6877 debug << o->metaObject()->className();-
6878 else-
6879 debug << "QGraphicsItem";-
6880 debug << '(' << static_cast<const void *>(item);-
6881 if (const QGraphicsProxyWidget *pw = qgraphicsitem_cast<const QGraphicsProxyWidget *>(item)) {-
6882 debug << ", widget=";-
6883 if (const QWidget *w = pw->widget()) {-
6884 debug << w->metaObject()->className() << '(' << static_cast<const void *>(w);-
6885 if (!w->objectName().isEmpty())-
6886 debug << ", name=" << w->objectName();-
6887 debug << ')';-
6888 } else {-
6889 debug << "QWidget(0)";-
6890 }-
6891 }-
6892 formatGraphicsItemHelper(debug, item);-
6893 debug << ')';-
6894 return debug;-
6895}-
6896-
6897-
6898QDebug operator<<(QDebug debug, QGraphicsObject *item)-
6899{-
6900 QDebugStateSaver saver(debug);-
6901 debug.nospace();-
6902-
6903 if (!item) {-
6904 debug << "QGraphicsObject(0)";-
6905 return debug;-
6906 }-
6907-
6908 debug << item->metaObject()->className() << '(' << static_cast<const void *>(item);-
6909 if (!item->objectName().isEmpty())-
6910 debug << ", name=" << item->objectName();-
6911 formatGraphicsItemHelper(debug, item);-
6912 debug << ')';-
6913 return debug;-
6914}-
6915-
6916QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemChange change)-
6917{-
6918 const char *str = "UnknownChange";-
6919 switch (change) {-
6920 case QGraphicsItem::ItemChildAddedChange:-
6921 str = "ItemChildAddedChange";-
6922 break;-
6923 case QGraphicsItem::ItemChildRemovedChange:-
6924 str = "ItemChildRemovedChange";-
6925 break;-
6926 case QGraphicsItem::ItemCursorChange:-
6927 str = "ItemCursorChange";-
6928 break;-
6929 case QGraphicsItem::ItemCursorHasChanged:-
6930 str = "ItemCursorHasChanged";-
6931 break;-
6932 case QGraphicsItem::ItemEnabledChange:-
6933 str = "ItemEnabledChange";-
6934 break;-
6935 case QGraphicsItem::ItemEnabledHasChanged:-
6936 str = "ItemEnabledHasChanged";-
6937 break;-
6938 case QGraphicsItem::ItemFlagsChange:-
6939 str = "ItemFlagsChange";-
6940 break;-
6941 case QGraphicsItem::ItemFlagsHaveChanged:-
6942 str = "ItemFlagsHaveChanged";-
6943 break;-
6944 case QGraphicsItem::ItemMatrixChange:-
6945 str = "ItemMatrixChange";-
6946 break;-
6947 case QGraphicsItem::ItemParentChange:-
6948 str = "ItemParentChange";-
6949 break;-
6950 case QGraphicsItem::ItemParentHasChanged:-
6951 str = "ItemParentHasChanged";-
6952 break;-
6953 case QGraphicsItem::ItemPositionChange:-
6954 str = "ItemPositionChange";-
6955 break;-
6956 case QGraphicsItem::ItemPositionHasChanged:-
6957 str = "ItemPositionHasChanged";-
6958 break;-
6959 case QGraphicsItem::ItemSceneChange:-
6960 str = "ItemSceneChange";-
6961 break;-
6962 case QGraphicsItem::ItemSceneHasChanged:-
6963 str = "ItemSceneHasChanged";-
6964 break;-
6965 case QGraphicsItem::ItemSelectedChange:-
6966 str = "ItemSelectedChange";-
6967 break;-
6968 case QGraphicsItem::ItemSelectedHasChanged:-
6969 str = "ItemSelectedHasChanged";-
6970 break;-
6971 case QGraphicsItem::ItemToolTipChange:-
6972 str = "ItemToolTipChange";-
6973 break;-
6974 case QGraphicsItem::ItemToolTipHasChanged:-
6975 str = "ItemToolTipHasChanged";-
6976 break;-
6977 case QGraphicsItem::ItemTransformChange:-
6978 str = "ItemTransformChange";-
6979 break;-
6980 case QGraphicsItem::ItemTransformHasChanged:-
6981 str = "ItemTransformHasChanged";-
6982 break;-
6983 case QGraphicsItem::ItemVisibleChange:-
6984 str = "ItemVisibleChange";-
6985 break;-
6986 case QGraphicsItem::ItemVisibleHasChanged:-
6987 str = "ItemVisibleHasChanged";-
6988 break;-
6989 case QGraphicsItem::ItemZValueChange:-
6990 str = "ItemZValueChange";-
6991 break;-
6992 case QGraphicsItem::ItemZValueHasChanged:-
6993 str = "ItemZValueHasChanged";-
6994 break;-
6995 case QGraphicsItem::ItemOpacityChange:-
6996 str = "ItemOpacityChange";-
6997 break;-
6998 case QGraphicsItem::ItemOpacityHasChanged:-
6999 str = "ItemOpacityHasChanged";-
7000 break;-
7001 case QGraphicsItem::ItemScenePositionHasChanged:-
7002 str = "ItemScenePositionHasChanged";-
7003 break;-
7004 case QGraphicsItem::ItemRotationChange:-
7005 str = "ItemRotationChange";-
7006 break;-
7007 case QGraphicsItem::ItemRotationHasChanged:-
7008 str = "ItemRotationHasChanged";-
7009 break;-
7010 case QGraphicsItem::ItemScaleChange:-
7011 str = "ItemScaleChange";-
7012 break;-
7013 case QGraphicsItem::ItemScaleHasChanged:-
7014 str = "ItemScaleHasChanged";-
7015 break;-
7016 case QGraphicsItem::ItemTransformOriginPointChange:-
7017 str = "ItemTransformOriginPointChange";-
7018 break;-
7019 case QGraphicsItem::ItemTransformOriginPointHasChanged:-
7020 str = "ItemTransformOriginPointHasChanged";-
7021 break;-
7022 }-
7023 debug << str;-
7024 return debug;-
7025}-
7026-
7027QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlag flag)-
7028{-
7029 const char *str = "UnknownFlag";-
7030 switch (flag) {-
7031 case QGraphicsItem::ItemIsMovable:-
7032 str = "ItemIsMovable";-
7033 break;-
7034 case QGraphicsItem::ItemIsSelectable:-
7035 str = "ItemIsSelectable";-
7036 break;-
7037 case QGraphicsItem::ItemIsFocusable:-
7038 str = "ItemIsFocusable";-
7039 break;-
7040 case QGraphicsItem::ItemClipsToShape:-
7041 str = "ItemClipsToShape";-
7042 break;-
7043 case QGraphicsItem::ItemClipsChildrenToShape:-
7044 str = "ItemClipsChildrenToShape";-
7045 break;-
7046 case QGraphicsItem::ItemIgnoresTransformations:-
7047 str = "ItemIgnoresTransformations";-
7048 break;-
7049 case QGraphicsItem::ItemIgnoresParentOpacity:-
7050 str = "ItemIgnoresParentOpacity";-
7051 break;-
7052 case QGraphicsItem::ItemDoesntPropagateOpacityToChildren:-
7053 str = "ItemDoesntPropagateOpacityToChildren";-
7054 break;-
7055 case QGraphicsItem::ItemStacksBehindParent:-
7056 str = "ItemStacksBehindParent";-
7057 break;-
7058 case QGraphicsItem::ItemUsesExtendedStyleOption:-
7059 str = "ItemUsesExtendedStyleOption";-
7060 break;-
7061 case QGraphicsItem::ItemHasNoContents:-
7062 str = "ItemHasNoContents";-
7063 break;-
7064 case QGraphicsItem::ItemSendsGeometryChanges:-
7065 str = "ItemSendsGeometryChanges";-
7066 break;-
7067 case QGraphicsItem::ItemAcceptsInputMethod:-
7068 str = "ItemAcceptsInputMethod";-
7069 break;-
7070 case QGraphicsItem::ItemNegativeZStacksBehindParent:-
7071 str = "ItemNegativeZStacksBehindParent";-
7072 break;-
7073 case QGraphicsItem::ItemIsPanel:-
7074 str = "ItemIsPanel";-
7075 break;-
7076 case QGraphicsItem::ItemIsFocusScope:-
7077 str = "ItemIsFocusScope";-
7078 break;-
7079 case QGraphicsItem::ItemSendsScenePositionChanges:-
7080 str = "ItemSendsScenePositionChanges";-
7081 break;-
7082 case QGraphicsItem::ItemStopsClickFocusPropagation:-
7083 str = "ItemStopsClickFocusPropagation";-
7084 break;-
7085 case QGraphicsItem::ItemStopsFocusHandling:-
7086 str = "ItemStopsFocusHandling";-
7087 break;-
7088 case QGraphicsItem::ItemContainsChildrenInShape:-
7089 str = "ItemContainsChildrenInShape";-
7090 break;-
7091 }-
7092 debug << str;-
7093 return debug;-
7094}-
7095-
7096QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags)-
7097{-
7098 debug << '(';-
7099 bool f = false;-
7100 for (int i = 0; i < 17; ++i) {-
7101 if (flags & (1 << i)) {-
7102 if (f)-
7103 debug << '|';-
7104 f = true;-
7105 debug << QGraphicsItem::GraphicsItemFlag(int(flags & (1 << i)));-
7106 }-
7107 }-
7108 debug << ')';-
7109 return debug;-
7110}-
7111-
7112-
7113-
7114-
7115-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9