diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-07-30 23:13:06 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2009-07-30 23:34:05 (GMT) |
commit | 79672bc8164c199da096d645d3cb3390253a76cd (patch) | |
tree | b447e70c9254a4862f5cf654ff5ffc428d3aad3a /src/gui/graphicsview | |
parent | 2b5baa7d5eb68a908c392506d9f75a2bfdb0f720 (diff) | |
download | Qt-79672bc8164c199da096d645d3cb3390253a76cd.zip Qt-79672bc8164c199da096d645d3cb3390253a76cd.tar.gz Qt-79672bc8164c199da096d645d3cb3390253a76cd.tar.bz2 |
Fix offset bug in QGraphicsShadowEffect.
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/gui/graphicsview/qgraphicseffect.cpp b/src/gui/graphicsview/qgraphicseffect.cpp index 76a3feb..6025537 100644 --- a/src/gui/graphicsview/qgraphicseffect.cpp +++ b/src/gui/graphicsview/qgraphicseffect.cpp @@ -706,21 +706,36 @@ void QGraphicsShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc return; } + const QTransform &transform = painter->worldTransform(); + const QPointF offset(d->offset.x() * transform.m11(), d->offset.y() * transform.m22()); + const QPoint shadowOffset = offset.toPoint(); const QRectF sourceRect = source->boundingRect(Qt::DeviceCoordinates); - const QRectF shadowRect = sourceRect.translated(d->offset); + const QRectF shadowRect = sourceRect.translated(offset); + QRectF blurRect = shadowRect; qreal delta = d->radius * 3; blurRect.adjust(-delta, -delta, delta, delta); blurRect |= sourceRect; + QRect effectRect = blurRect.toAlignedRect(); - effectRect &= source->deviceRect(); + const QRect deviceRect = source->deviceRect(); + const bool fullyInsideDeviceRect = effectRect.x() >= deviceRect.x() + && effectRect.right() <= deviceRect.right() + && effectRect.y() >= deviceRect.y() + && effectRect.bottom() <= deviceRect.bottom(); + if (!fullyInsideDeviceRect) { + // Clip to device rect to avoid huge pixmaps. + effectRect &= source->deviceRect(); + effectRect |= effectRect.translated(-shadowOffset); + } QPixmap pixmap(effectRect.size()); pixmap.fill(Qt::transparent); QPainter pixmapPainter(&pixmap); pixmapPainter.setRenderHints(painter->renderHints()); pixmapPainter.setWorldTransform(painter->worldTransform()); - pixmapPainter.translate(-effectRect.topLeft()); + if (effectRect.x() != 0 || effectRect.y() != 0) + pixmapPainter.translate(-effectRect.topLeft()); source->draw(&pixmapPainter); pixmapPainter.end(); @@ -733,7 +748,7 @@ void QGraphicsShadowEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc // Draw using an untransformed painter. QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); - painter->drawImage(effectRect.topLeft() + d->offset, shadowImage); + painter->drawImage(effectRect.topLeft() + shadowOffset, shadowImage); painter->drawPixmap(effectRect.topLeft(), pixmap); painter->setWorldTransform(restoreTransform); } |