diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-11-04 08:07:44 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-11-05 07:04:45 (GMT) |
commit | d2c204a93f30238c705209e65e2e8bce148825cd (patch) | |
tree | 4541764826a3bcbb99ccc17e869a1299a9732ad0 /src/declarative | |
parent | 2abf7cbc2258cc8a11094923a2da796d7529b08f (diff) | |
download | Qt-d2c204a93f30238c705209e65e2e8bce148825cd.zip Qt-d2c204a93f30238c705209e65e2e8bce148825cd.tar.gz Qt-d2c204a93f30238c705209e65e2e8bce148825cd.tar.bz2 |
Image bounding rect should always include the area being painted
This didn't always happend with fillMode PreserveAspectCrop,
resulting in drawing artifacts.
Task-number: QT-3933
Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeimage.cpp | 27 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeimage_p.h | 1 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 1f1e93d..3b08a9b 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -259,8 +259,10 @@ void QDeclarativeImage::setFillMode(FillMode mode) \qmlproperty real Image::paintedHeight These properties hold the size of the image that is actually painted. - In most cases it is the same as \c width and \c height, but when using a \c fillMode like - \c PreserveAspectFit \c paintedWidth or \c paintedHeight can be smaller than \c width and \c height. + In most cases it is the same as \c width and \c height, but when using a + \c fillMode \c PreserveAspectFit or \c fillMode \c PreserveAspectCrop + \c paintedWidth or \c paintedHeight can be smaller or larger than + \c width and \c height of the Image element. */ qreal QDeclarativeImage::paintedWidth() const { @@ -399,6 +401,19 @@ void QDeclarativeImage::updatePaintedGeometry() if (heightValid() && !widthValid()) { setImplicitWidth(d->paintedWidth); } + } else if (d->fillMode == PreserveAspectCrop) { + if (!d->pix.width() || !d->pix.height()) + return; + qreal widthScale = width() / qreal(d->pix.width()); + qreal heightScale = height() / qreal(d->pix.height()); + if (widthScale < heightScale) { + widthScale = heightScale; + } else if(heightScale < widthScale) { + heightScale = widthScale; + } + + d->paintedHeight = heightScale * qreal(d->pix.height()); + d->paintedWidth = widthScale * qreal(d->pix.width()); } else { d->paintedWidth = width(); d->paintedHeight = height(); @@ -412,6 +427,12 @@ void QDeclarativeImage::geometryChanged(const QRectF &newGeometry, const QRectF updatePaintedGeometry(); } +QRectF QDeclarativeImage::boundingRect() const +{ + Q_D(const QDeclarativeImage); + return QRectF(0, 0, qMax(d->mWidth, d->paintedWidth), qMax(d->mHeight, d->paintedHeight)); +} + /*! \qmlproperty url Image::source @@ -496,7 +517,7 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi } if (clip()) { p->save(); - p->setClipRect(boundingRect(), Qt::IntersectClip); + p->setClipRect(QRectF(0, 0, d->mWidth, d->mHeight), Qt::IntersectClip); } scale.scale(widthScale, heightScale); QTransform old = p->transform(); diff --git a/src/declarative/graphicsitems/qdeclarativeimage_p.h b/src/declarative/graphicsitems/qdeclarativeimage_p.h index c8bb30b..0e8034e 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimage_p.h @@ -76,6 +76,7 @@ public: qreal paintedHeight() const; void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + QRectF boundingRect() const; Q_SIGNALS: void fillModeChanged(); |