From 8abc68d262c40c1f035a2d77779e76f038261a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 1 Sep 2009 15:22:21 +0200 Subject: Make sure the BSP is updated when a graphics effect changes bounding rect. In the case of applying an effect to a QGraphicsItem, we have to notify the scene's BSP that the item's bounding rect has changed. We do this by calling prepareGeometryChange(). In the case of QWidget, it's sub-optimal that we update its parent, but there's no other way to solve it at the moment. --- src/gui/effects/qgraphicseffect.cpp | 4 ++-- src/gui/effects/qgraphicseffect_p.h | 1 + src/gui/graphicsview/qgraphicsitem_p.h | 3 +++ src/gui/kernel/qwidget_p.h | 10 ++++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 2be6a49..6624cfb 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -335,7 +335,7 @@ void QGraphicsEffect::setEnabled(bool enable) d->isEnabled = enable; if (d->source) - d->source->update(); + d->source->d_func()->effectBoundingRectChanged(); emit enabledChanged(enable); } @@ -390,7 +390,7 @@ void QGraphicsEffect::updateBoundingRect() { Q_D(QGraphicsEffect); if (d->source) - d->source->update(); + d->source->d_func()->effectBoundingRectChanged(); } /*! diff --git a/src/gui/effects/qgraphicseffect_p.h b/src/gui/effects/qgraphicseffect_p.h index bfabfc0..24b605f 100644 --- a/src/gui/effects/qgraphicseffect_p.h +++ b/src/gui/effects/qgraphicseffect_p.h @@ -76,6 +76,7 @@ public: virtual void update() = 0; virtual bool isPixmap() const = 0; virtual QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset = 0) const = 0; + virtual void effectBoundingRectChanged() = 0; friend class QGraphicsScenePrivate; friend class QGraphicsItem; friend class QGraphicsItemPrivate; diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 1090620..49361cf 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -572,6 +572,9 @@ public: inline void update() { item->update(); } + inline void effectBoundingRectChanged() + { item->prepareGeometryChange(); } + inline bool isPixmap() const { return (item->type() == QGraphicsPixmapItem::Type); diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index ff0c453..f69c3a7 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -727,6 +727,16 @@ public: inline bool isPixmap() const { return false; } + inline void effectBoundingRectChanged() + { + // ### This function should take a rect parameter; then we can avoid + // updating too much on the parent widget. + if (QWidget *parent = m_widget->parentWidget()) + parent->update(); + else + m_widget->update(); + } + inline const QStyleOption *styleOption() const { return 0; } -- cgit v0.12