/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Contact: http://www.qt-project.org/
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
The following example shows the simplest usage of the Image element.
- \snippet doc/src/snippets/declarative/image.qml document
+ \snippet doc/src/snippets/qtquick1/image.qml document
\beginfloatleft
\image declarative-qtlogo.png
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;
}
/*!