diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-07-30 05:55:28 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-07-30 05:55:28 (GMT) |
commit | 2b5baa7d5eb68a908c392506d9f75a2bfdb0f720 (patch) | |
tree | 26c5225c3fe6dd9b4e414f202a127eaf2f2881ac /src/gui/graphicsview | |
parent | 2444a2e92ae959d350ce5e4c2c984c1e5b714421 (diff) | |
download | Qt-2b5baa7d5eb68a908c392506d9f75a2bfdb0f720.zip Qt-2b5baa7d5eb68a908c392506d9f75a2bfdb0f720.tar.gz Qt-2b5baa7d5eb68a908c392506d9f75a2bfdb0f720.tar.bz2 |
Make sure we don't create pixmaps that are bigger than the device rect.
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.cpp | 6 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.h | 1 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect_p.h | 1 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 26 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 9 |
5 files changed, 41 insertions, 2 deletions
diff --git a/src/gui/graphicsview/qgraphicseffect.cpp b/src/gui/graphicsview/qgraphicseffect.cpp index f9a99fc..76a3feb 100644 --- a/src/gui/graphicsview/qgraphicseffect.cpp +++ b/src/gui/graphicsview/qgraphicseffect.cpp @@ -108,6 +108,9 @@ QGraphicsEffectSource::QGraphicsEffectSource(QGraphicsEffectSourcePrivate &dd, Q QGraphicsEffectSource::~QGraphicsEffectSource() {} +QRect QGraphicsEffectSource::deviceRect() const +{ return d_func()->deviceRect(); } + QRectF QGraphicsEffectSource::boundingRect(Qt::CoordinateSystem system) const { return d_func()->boundingRect(system); } @@ -709,7 +712,8 @@ void QGraphicsShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc qreal delta = d->radius * 3; blurRect.adjust(-delta, -delta, delta, delta); blurRect |= sourceRect; - const QRect effectRect = blurRect.toAlignedRect(); + QRect effectRect = blurRect.toAlignedRect(); + effectRect &= source->deviceRect(); QPixmap pixmap(effectRect.size()); pixmap.fill(Qt::transparent); diff --git a/src/gui/graphicsview/qgraphicseffect.h b/src/gui/graphicsview/qgraphicseffect.h index 8cf80b9..0125ebc 100644 --- a/src/gui/graphicsview/qgraphicseffect.h +++ b/src/gui/graphicsview/qgraphicseffect.h @@ -74,6 +74,7 @@ public: void update(); QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const; + QRect deviceRect() const; QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint *offset = 0) const; protected: diff --git a/src/gui/graphicsview/qgraphicseffect_p.h b/src/gui/graphicsview/qgraphicseffect_p.h index 5348ae9..9e6e2a1 100644 --- a/src/gui/graphicsview/qgraphicseffect_p.h +++ b/src/gui/graphicsview/qgraphicseffect_p.h @@ -74,6 +74,7 @@ public: virtual ~QGraphicsEffectSourcePrivate() {} virtual void detach() = 0; virtual QRectF boundingRect(Qt::CoordinateSystem system) const = 0; + virtual QRect deviceRect() const = 0; virtual const QGraphicsItem *graphicsItem() const = 0; virtual const QStyleOption *styleOption() const = 0; virtual void draw(QPainter *p) = 0; diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 9d9c3af..976ffa3 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -10048,10 +10048,34 @@ QPixmap QGraphicsItemEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QP QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func(); const QRectF sourceRect = boundingRect(system); - const QRect effectRect = item->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); + QRect effectRect = item->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); if (offset) *offset = sourceRect.toAlignedRect().topLeft(); + if (deviceCoordinates) { + // Clip to viewport rect. + int left, top, right, bottom; + effectRect.getCoords(&left, &top, &right, &bottom); + if (left < 0) { + if (offset) + offset->rx() += -left; + effectRect.setX(0); + } + if (top < 0) { + if (offset) + offset->ry() += -top; + effectRect.setY(0); + } + // NB! We use +-1 for historical reasons (see QRect documentation). + if (right + 1 > info->widget->width()) + effectRect.setRight(info->widget->width() - 1); + if (bottom + 1 > info->widget->height()) + effectRect.setBottom(info->widget->height() -1); + } + + if (effectRect.isEmpty()) + return QPixmap(); + QPixmap pixmap(effectRect.size()); pixmap.fill(Qt::transparent); QPainter pixmapPainter(&pixmap); diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 69d8b5f..8b7f5b5 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -557,6 +557,15 @@ public: inline const QStyleOption *styleOption() const { return info ? info->option : 0; } + inline QRect deviceRect() const + { + if (!info || !info->widget) { + qWarning("QGraphicsEffectSource::deviceRect: Not yet implemented, lacking device context"); + return QRect(); + } + return info->widget->rect(); + } + QRectF boundingRect(Qt::CoordinateSystem system) const; void draw(QPainter *); QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset) const; |