/****************************************************************************
**
-** 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.
**
/*!
\qmlclass Image QDeclarative1Image
- \since 4.7
+ \inqmlmodule QtQuick 1
+ \since QtQuick 1.0
\ingroup qml-basic-visual-elements
\brief The Image element displays an image in a declarative user interface
\inherits Item
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
}
/*!
- \qmlproperty enumeration Image::fillMode
+ \qmlproperty enumeration QtQuick1::Image::fillMode
Set this property to define what happens when the source image has a different size
than the item.
/*!
- \qmlproperty real Image::paintedWidth
- \qmlproperty real Image::paintedHeight
+ \qmlproperty real QtQuick1::Image::paintedWidth
+ \qmlproperty real QtQuick1::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
}
/*!
- \qmlproperty enumeration Image::status
+ \qmlproperty enumeration QtQuick1::Image::status
This property holds the status of image loading. It can be one of:
\list
*/
/*!
- \qmlproperty real Image::progress
+ \qmlproperty real QtQuick1::Image::progress
This property holds the progress of image loading, from 0.0 (nothing loaded)
to 1.0 (finished).
*/
/*!
- \qmlproperty bool Image::smooth
+ \qmlproperty bool QtQuick1::Image::smooth
Set this property if you want the image to be smoothly filtered when scaled or
transformed. Smooth filtering gives better visual quality, but is slower. If
*/
/*!
- \qmlproperty QSize Image::sourceSize
+ \qmlproperty QSize QtQuick1::Image::sourceSize
This property holds the actual width and height of the loaded image.
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;
}
/*!
- \qmlproperty url Image::source
+ \qmlproperty url QtQuick1::Image::source
Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt.
*/
/*!
- \qmlproperty bool Image::asynchronous
+ \qmlproperty bool QtQuick1::Image::asynchronous
Specifies that images on the local filesystem should be loaded
asynchronously in a separate thread. The default value is
*/
/*!
- \qmlproperty bool Image::cache
+ \qmlproperty bool QtQuick1::Image::cache
\since Quick 1.1
Specifies whether the image should be cached. The default value is
*/
/*!
- \qmlproperty bool Image::mirror
+ \qmlproperty bool QtQuick1::Image::mirror
\since Quick 1.1
This property holds whether the image should be horizontally inverted