graphicsview/qgraphicsitem.cpp

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

Generated by Squish Coco Non-Commercial