Bounding rectangle for image is wrong for PreserveAspectCrop
authorYann Bodson <yann.bodson@nokia.com>
Wed, 20 Jul 2011 02:56:38 +0000 (12:56 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 26 Jul 2011 02:46:56 +0000 (04:46 +0200)
Task-number: QTBUG-20300
Change-Id: I8aa84ec64f7be536e56cdc1c04a6c2f204e06c26
Reviewed-on: http://codereview.qt.nokia.com/1859
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/qtquick1/graphicsitems/qdeclarativeimage.cpp

index 89df7ab..4e2cd10 100644 (file)
@@ -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;
 }
 
 /*!