From 245b16b4fb50620aaf49683eb85a93807defea6a Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 20 Jul 2011 12:56:38 +1000 Subject: [PATCH] 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 --- src/qtquick1/graphicsitems/qdeclarativeimage.cpp | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) 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; } /*! -- 1.7.2.5