59 #include <private/qgraphicsview_p.h> |
59 #include <private/qgraphicsview_p.h> |
60 #include "qgraphicstransform.h" |
60 #include "qgraphicstransform.h" |
61 #include <private/qgraphicstransform_p.h> |
61 #include <private/qgraphicstransform_p.h> |
62 |
62 |
63 #include <private/qgraphicseffect_p.h> |
63 #include <private/qgraphicseffect_p.h> |
|
64 #include <qgraphicseffect.h> |
64 |
65 |
65 #include <QtCore/qpoint.h> |
66 #include <QtCore/qpoint.h> |
66 |
67 |
67 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW |
68 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW |
68 |
69 |
149 hasBoundingRegionGranularity(0), |
150 hasBoundingRegionGranularity(0), |
150 isWidget(0), |
151 isWidget(0), |
151 dirty(0), |
152 dirty(0), |
152 dirtyChildren(0), |
153 dirtyChildren(0), |
153 localCollisionHack(0), |
154 localCollisionHack(0), |
154 dirtyClipPath(1), |
|
155 emptyClipPath(0), |
|
156 inSetPosHelper(0), |
155 inSetPosHelper(0), |
157 needSortChildren(1), // ### can be 0 by default? |
156 needSortChildren(1), // ### can be 0 by default? |
158 allChildrenDirty(0), |
157 allChildrenDirty(0), |
159 fullUpdatePending(0), |
158 fullUpdatePending(0), |
160 flags(0), |
159 flags(0), |
176 explicitActivate(0), |
175 explicitActivate(0), |
177 wantsActive(0), |
176 wantsActive(0), |
178 holesInSiblingIndex(0), |
177 holesInSiblingIndex(0), |
179 sequentialOrdering(1), |
178 sequentialOrdering(1), |
180 updateDueToGraphicsEffect(0), |
179 updateDueToGraphicsEffect(0), |
|
180 scenePosDescendants(0), |
181 globalStackingOrder(-1), |
181 globalStackingOrder(-1), |
182 q_ptr(0) |
182 q_ptr(0) |
183 { |
183 { |
184 } |
184 } |
185 |
185 |
217 virtual void setPosHelper(const QPointF &pos); |
217 virtual void setPosHelper(const QPointF &pos); |
218 void setTransformHelper(const QTransform &transform); |
218 void setTransformHelper(const QTransform &transform); |
219 void appendGraphicsTransform(QGraphicsTransform *t); |
219 void appendGraphicsTransform(QGraphicsTransform *t); |
220 void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); |
220 void setVisibleHelper(bool newVisible, bool explicitly, bool update = true); |
221 void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); |
221 void setEnabledHelper(bool newEnabled, bool explicitly, bool update = true); |
222 bool discardUpdateRequest(bool ignoreClipping = false, bool ignoreVisibleBit = false, |
222 bool discardUpdateRequest(bool ignoreVisibleBit = false, |
223 bool ignoreDirtyBit = false, bool ignoreOpacity = false) const; |
223 bool ignoreDirtyBit = false, bool ignoreOpacity = false) const; |
224 int depth() const; |
224 int depth() const; |
|
225 #ifndef QT_NO_GRAPHICSEFFECT |
225 void invalidateGraphicsEffectsRecursively(); |
226 void invalidateGraphicsEffectsRecursively(); |
|
227 #endif //QT_NO_GRAPHICSEFFECT |
226 void invalidateDepthRecursively(); |
228 void invalidateDepthRecursively(); |
227 void resolveDepth(); |
229 void resolveDepth(); |
228 void addChild(QGraphicsItem *child); |
230 void addChild(QGraphicsItem *child); |
229 void removeChild(QGraphicsItem *child); |
231 void removeChild(QGraphicsItem *child); |
230 void setParentItemHelper(QGraphicsItem *parent); |
232 void setParentItemHelper(QGraphicsItem *parent); |
232 void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, |
234 void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, |
233 const QRegion &exposedRegion, bool allItems = false) const; |
235 const QRegion &exposedRegion, bool allItems = false) const; |
234 QRectF effectiveBoundingRect() const; |
236 QRectF effectiveBoundingRect() const; |
235 QRectF sceneEffectiveBoundingRect() const; |
237 QRectF sceneEffectiveBoundingRect() const; |
236 |
238 |
|
239 QRectF effectiveBoundingRect(const QRectF &rect) const; |
|
240 |
237 virtual void resolveFont(uint inheritedMask) |
241 virtual void resolveFont(uint inheritedMask) |
238 { |
242 { |
239 for (int i = 0; i < children.size(); ++i) |
243 for (int i = 0; i < children.size(); ++i) |
240 children.at(i)->d_ptr->resolveFont(inheritedMask); |
244 children.at(i)->d_ptr->resolveFont(inheritedMask); |
241 } |
245 } |
301 |
305 |
302 QGraphicsItemCache *maybeExtraItemCache() const; |
306 QGraphicsItemCache *maybeExtraItemCache() const; |
303 QGraphicsItemCache *extraItemCache() const; |
307 QGraphicsItemCache *extraItemCache() const; |
304 void removeExtraItemCache(); |
308 void removeExtraItemCache(); |
305 |
309 |
306 inline void setCachedClipPath(const QPainterPath &path) |
|
307 { |
|
308 cachedClipPath = path; |
|
309 dirtyClipPath = 0; |
|
310 emptyClipPath = 0; |
|
311 } |
|
312 |
|
313 inline void setEmptyCachedClipPath() |
|
314 { |
|
315 emptyClipPath = 1; |
|
316 dirtyClipPath = 0; |
|
317 } |
|
318 |
|
319 void setEmptyCachedClipPathRecursively(const QRectF &emptyIfOutsideThisRect = QRectF()); |
|
320 |
|
321 inline void invalidateCachedClipPath() |
|
322 { /*static int count = 0 ;qWarning("%i", ++count);*/ dirtyClipPath = 1; emptyClipPath = 0; } |
|
323 |
|
324 void invalidateCachedClipPathRecursively(bool childrenOnly = false, const QRectF &emptyIfOutsideThisRect = QRectF()); |
|
325 void updateCachedClipPathFromSetPosHelper(const QPointF &newPos); |
|
326 void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem); |
310 void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem); |
327 inline void ensureSceneTransform() |
311 inline void ensureSceneTransform() |
328 { |
312 { |
329 QGraphicsItem *that = q_func(); |
313 QGraphicsItem *that = q_func(); |
330 ensureSceneTransformRecursive(&that); |
314 ensureSceneTransformRecursive(&that); |
403 return false; |
387 return false; |
404 } |
388 } |
405 return true; |
389 return true; |
406 } |
390 } |
407 |
391 |
408 inline bool isClippedAway() const |
|
409 { return !dirtyClipPath && q_func()->isClipped() && (emptyClipPath || cachedClipPath.isEmpty()); } |
|
410 |
|
411 inline bool childrenClippedToShape() const |
392 inline bool childrenClippedToShape() const |
412 { return (flags & QGraphicsItem::ItemClipsChildrenToShape) || children.isEmpty(); } |
393 { return (flags & QGraphicsItem::ItemClipsChildrenToShape) || children.isEmpty(); } |
413 |
394 |
414 inline bool isInvisible() const |
395 inline bool isInvisible() const |
415 { |
396 { |
416 return !visible |
397 return !visible || (childrenCombineOpacity() && isFullyTransparent()); |
417 || (childrenClippedToShape() && isClippedAway()) |
|
418 || (childrenCombineOpacity() && isFullyTransparent()); |
|
419 } |
398 } |
420 |
399 |
421 void setFocusHelper(Qt::FocusReason focusReason, bool climb); |
400 void setFocusHelper(Qt::FocusReason focusReason, bool climb); |
422 void setSubFocus(QGraphicsItem *rootItem = 0); |
401 void setSubFocus(QGraphicsItem *rootItem = 0); |
423 void clearSubFocus(QGraphicsItem *rootItem = 0); |
402 void clearSubFocus(QGraphicsItem *rootItem = 0); |
426 |
405 |
427 inline QTransform transformToParent() const; |
406 inline QTransform transformToParent() const; |
428 inline void ensureSortedChildren(); |
407 inline void ensureSortedChildren(); |
429 static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b); |
408 static inline bool insertionOrder(QGraphicsItem *a, QGraphicsItem *b); |
430 void ensureSequentialSiblingIndex(); |
409 void ensureSequentialSiblingIndex(); |
431 |
410 inline void sendScenePosChange(); |
432 QPainterPath cachedClipPath; |
411 virtual void siblingOrderChange(); |
|
412 |
433 QRectF childrenBoundingRect; |
413 QRectF childrenBoundingRect; |
434 QRectF needsRepaint; |
414 QRectF needsRepaint; |
435 QMap<QWidget *, QRect> paintedViewBoundingRects; |
415 QMap<QWidget *, QRect> paintedViewBoundingRects; |
436 QPointF pos; |
416 QPointF pos; |
437 qreal z; |
417 qreal z; |
450 QList<QGraphicsItem **> focusProxyRefs; |
430 QList<QGraphicsItem **> focusProxyRefs; |
451 QGraphicsItem *subFocusItem; |
431 QGraphicsItem *subFocusItem; |
452 QGraphicsItem *focusScopeItem; |
432 QGraphicsItem *focusScopeItem; |
453 Qt::InputMethodHints imHints; |
433 Qt::InputMethodHints imHints; |
454 QGraphicsItem::PanelModality panelModality; |
434 QGraphicsItem::PanelModality panelModality; |
455 QMap<Qt::GestureType, Qt::GestureContext> gestureContext; |
435 QMap<Qt::GestureType, Qt::GestureFlags> gestureContext; |
456 |
436 |
457 // Packed 32 bits |
437 // Packed 32 bits |
458 quint32 acceptedMouseButtons : 5; |
438 quint32 acceptedMouseButtons : 5; |
459 quint32 visible : 1; |
439 quint32 visible : 1; |
460 quint32 explicitlyHidden : 1; |
440 quint32 explicitlyHidden : 1; |
472 quint32 hasBoundingRegionGranularity : 1; |
452 quint32 hasBoundingRegionGranularity : 1; |
473 quint32 isWidget : 1; |
453 quint32 isWidget : 1; |
474 quint32 dirty : 1; |
454 quint32 dirty : 1; |
475 quint32 dirtyChildren : 1; |
455 quint32 dirtyChildren : 1; |
476 quint32 localCollisionHack : 1; |
456 quint32 localCollisionHack : 1; |
477 quint32 dirtyClipPath : 1; |
|
478 quint32 emptyClipPath : 1; |
|
479 quint32 inSetPosHelper : 1; |
457 quint32 inSetPosHelper : 1; |
480 quint32 needSortChildren : 1; |
458 quint32 needSortChildren : 1; |
481 quint32 allChildrenDirty : 1; |
459 quint32 allChildrenDirty : 1; |
482 |
460 |
483 // Packed 32 bits |
461 // Packed 32 bits |
484 quint32 fullUpdatePending : 1; |
462 quint32 fullUpdatePending : 1; |
485 quint32 flags : 16; |
463 quint32 flags : 17; |
486 quint32 dirtyChildrenBoundingRect : 1; |
464 quint32 dirtyChildrenBoundingRect : 1; |
487 quint32 paintedViewBoundingRectsNeedRepaint : 1; |
465 quint32 paintedViewBoundingRectsNeedRepaint : 1; |
488 quint32 dirtySceneTransform : 1; |
466 quint32 dirtySceneTransform : 1; |
489 quint32 geometryChanged : 1; |
467 quint32 geometryChanged : 1; |
490 quint32 inDestructor : 1; |
468 quint32 inDestructor : 1; |
495 quint32 acceptedTouchBeginEvent : 1; |
473 quint32 acceptedTouchBeginEvent : 1; |
496 quint32 filtersDescendantEvents : 1; |
474 quint32 filtersDescendantEvents : 1; |
497 quint32 sceneTransformTranslateOnly : 1; |
475 quint32 sceneTransformTranslateOnly : 1; |
498 quint32 notifyBoundingRectChanged : 1; |
476 quint32 notifyBoundingRectChanged : 1; |
499 quint32 notifyInvalidated : 1; |
477 quint32 notifyInvalidated : 1; |
|
478 |
|
479 // New 32 bits |
500 quint32 mouseSetsFocus : 1; |
480 quint32 mouseSetsFocus : 1; |
501 |
|
502 // New 32 bits |
|
503 quint32 explicitActivate : 1; |
481 quint32 explicitActivate : 1; |
504 quint32 wantsActive : 1; |
482 quint32 wantsActive : 1; |
505 quint32 holesInSiblingIndex : 1; |
483 quint32 holesInSiblingIndex : 1; |
506 quint32 sequentialOrdering : 1; |
484 quint32 sequentialOrdering : 1; |
507 quint32 updateDueToGraphicsEffect : 1; |
485 quint32 updateDueToGraphicsEffect : 1; |
|
486 quint32 scenePosDescendants : 1; |
508 |
487 |
509 // Optional stacking order |
488 // Optional stacking order |
510 int globalStackingOrder; |
489 int globalStackingOrder; |
511 QGraphicsItem *q_ptr; |
490 QGraphicsItem *q_ptr; |
512 }; |
491 }; |
540 QTransform x(transform); |
519 QTransform x(transform); |
541 if (!graphicsTransforms.isEmpty()) { |
520 if (!graphicsTransforms.isEmpty()) { |
542 QMatrix4x4 m; |
521 QMatrix4x4 m; |
543 for (int i = 0; i < graphicsTransforms.size(); ++i) |
522 for (int i = 0; i < graphicsTransforms.size(); ++i) |
544 graphicsTransforms.at(i)->applyTo(&m); |
523 graphicsTransforms.at(i)->applyTo(&m); |
545 x *= m.toTransform(0); |
524 x *= m.toTransform(); |
546 } |
525 } |
547 x.translate(xOrigin, yOrigin); |
526 x.translate(xOrigin, yOrigin); |
548 x.rotate(rotation); |
527 x.rotate(rotation); |
549 x.scale(scale, scale); |
528 x.scale(scale, scale); |
550 x.translate(-xOrigin, -yOrigin); |
529 x.translate(-xOrigin, -yOrigin); |
574 qreal opacity; |
553 qreal opacity; |
575 quint32 wasDirtySceneTransform : 1; |
554 quint32 wasDirtySceneTransform : 1; |
576 quint32 drawItem : 1; |
555 quint32 drawItem : 1; |
577 }; |
556 }; |
578 |
557 |
|
558 #ifndef QT_NO_GRAPHICSEFFECT |
579 class QGraphicsItemEffectSourcePrivate : public QGraphicsEffectSourcePrivate |
559 class QGraphicsItemEffectSourcePrivate : public QGraphicsEffectSourcePrivate |
580 { |
560 { |
581 public: |
561 public: |
582 QGraphicsItemEffectSourcePrivate(QGraphicsItem *i) |
562 QGraphicsItemEffectSourcePrivate(QGraphicsItem *i) |
583 : QGraphicsEffectSourcePrivate(), item(i), info(0) |
563 : QGraphicsEffectSourcePrivate(), item(i), info(0) |
584 {} |
564 {} |
585 |
565 |
586 inline void detach() |
566 inline void detach() |
587 { item->setGraphicsEffect(0); } |
567 { |
|
568 item->d_ptr->graphicsEffect = 0; |
|
569 item->prepareGeometryChange(); |
|
570 } |
588 |
571 |
589 inline const QGraphicsItem *graphicsItem() const |
572 inline const QGraphicsItem *graphicsItem() const |
590 { return item; } |
573 { return item; } |
591 |
574 |
592 inline const QWidget *widget() const |
575 inline const QWidget *widget() const |
601 inline void effectBoundingRectChanged() |
584 inline void effectBoundingRectChanged() |
602 { item->prepareGeometryChange(); } |
585 { item->prepareGeometryChange(); } |
603 |
586 |
604 inline bool isPixmap() const |
587 inline bool isPixmap() const |
605 { |
588 { |
606 return (item->type() == QGraphicsPixmapItem::Type); |
589 return item->type() == QGraphicsPixmapItem::Type |
607 //|| (item->d_ptr->isObject && qobject_cast<QFxImage *>(q_func())); |
590 && !(item->flags() & QGraphicsItem::ItemIsSelectable) |
|
591 && item->d_ptr->children.size() == 0; |
|
592 //|| (item->d_ptr->isObject && qobject_cast<QmlGraphicsImage *>(q_func())); |
608 } |
593 } |
609 |
594 |
610 inline const QStyleOption *styleOption() const |
595 inline const QStyleOption *styleOption() const |
611 { return info ? info->option : 0; } |
596 { return info ? info->option : 0; } |
612 |
597 |
619 return info->widget->rect(); |
604 return info->widget->rect(); |
620 } |
605 } |
621 |
606 |
622 QRectF boundingRect(Qt::CoordinateSystem system) const; |
607 QRectF boundingRect(Qt::CoordinateSystem system) const; |
623 void draw(QPainter *); |
608 void draw(QPainter *); |
624 QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset) const; |
609 QPixmap pixmap(Qt::CoordinateSystem system, |
|
610 QPoint *offset, |
|
611 QGraphicsEffect::PixmapPadMode mode) const; |
625 |
612 |
626 QGraphicsItem *item; |
613 QGraphicsItem *item; |
627 QGraphicsItemPaintInfo *info; |
614 QGraphicsItemPaintInfo *info; |
628 QTransform lastEffectTransform; |
615 QTransform lastEffectTransform; |
629 }; |
616 }; |
630 |
617 #endif //QT_NO_GRAPHICSEFFECT |
631 |
618 |
632 /*! |
619 /*! |
633 Returns true if \a item1 is on top of \a item2. |
620 Returns true if \a item1 is on top of \a item2. |
634 The items dont need to be siblings. |
621 The items dont need to be siblings. |
635 |
622 |