From: Yann Bodson Date: Wed, 20 Jul 2011 02:56:38 +0000 (+1000) Subject: Bounding rectangle for image is wrong for PreserveAspectCrop X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=245b16b4fb50620aaf49683eb85a93807defea6a;p=konrad%2Fqtdeclarative.git Bounding rectangle for image is wrong for PreserveAspectCrop Task-number: QTBUG-20300 Change-Id: I8aa84ec64f7be536e56cdc1c04a6c2f204e06c26 Reviewed-on: http://codereview.qt.nokia.com/1859 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- diff --git a/src/qtquick1/graphicsitems/qdeclarativeimage.cpp b/src/qtquick1/graphicsitems/qdeclarativeimage.cpp index 89df7ab..4e2cd10 100644 --- a/src/qtquick1/graphicsitems/qdeclarativeimage.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativeimage.cpp @@ -446,7 +446,22 @@ void QDeclarative1Image::geometryChanged(const QRectF &newGeometry, const QRectF QRectF QDeclarative1Image::boundingRect() const { Q_D(const QDeclarative1Image); - return QRectF(0, 0, qMax(d->mWidth, d->paintedWidth), qMax(d->mHeight, d->paintedHeight)); + QRectF boundingRect(0, 0, qMax(d->mWidth, d->paintedWidth), qMax(d->mHeight, d->paintedHeight)); + + if (d->fillMode == PreserveAspectCrop) { + if (!d->pix.width() || !d->pix.height()) + return boundingRect; + qreal widthScale = width() / qreal(d->pix.width()); + qreal heightScale = height() / qreal(d->pix.height()); + if (widthScale < heightScale) { + widthScale = heightScale; + boundingRect.moveTo((width() - widthScale * d->pix.width()) / 2, 0); + } else if (heightScale < widthScale) { + heightScale = widthScale; + boundingRect.moveTo(0, (height() - heightScale * d->pix.height()) / 2); + } + } + return boundingRect; } /*!