diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2010-10-05 05:34:59 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2010-10-05 05:34:59 (GMT) |
commit | 47284ca360c1875663207996740bf6ed6e93d364 (patch) | |
tree | 02496fb98624fc56cd8614067028118f55710ed1 | |
parent | 4bc735e48020c23aaa99c006ed014214a82c1a68 (diff) | |
download | Qt-47284ca360c1875663207996740bf6ed6e93d364.zip Qt-47284ca360c1875663207996740bf6ed6e93d364.tar.gz Qt-47284ca360c1875663207996740bf6ed6e93d364.tar.bz2 |
Document and test paintedWidth and paintedHeight properties of Image
Task-number: QTBUG-14197
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeimage.cpp | 9 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp | 41 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 9cd9ad6..08d237f 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -253,6 +253,15 @@ void QDeclarativeImage::setFillMode(FillMode mode) emit fillModeChanged(); } +/*! + + \qmlproperty real Image::paintedWidth + \qmlproperty real 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 \c fillMode like + \c PreserveAspectFit \c paintedWidth or \c paintedHeight can be smaller than \c width and \c height. +*/ qreal QDeclarativeImage::paintedWidth() const { Q_D(const QDeclarativeImage); diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 6fce2ad..8f9b2ea 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -83,6 +83,7 @@ private slots: void big(); void tiling_QTBUG_6716(); void noLoading(); + void paintedWidthHeight(); private: template<typename T> @@ -395,6 +396,46 @@ void tst_qdeclarativeimage::noLoading() QTRY_COMPARE(statusSpy.count(), 2); } +void tst_qdeclarativeimage::paintedWidthHeight() +{ + { + QString src = QUrl::fromLocalFile(SRCDIR "/data/heart.png").toString(); + QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; width: 200; height: 25; fillMode: Image.PreserveAspectFit }"; + + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create()); + QVERIFY(obj != 0); + QCOMPARE(obj->pixmap().width(), 300); + QCOMPARE(obj->pixmap().height(), 300); + QCOMPARE(obj->width(), 200.0); + QCOMPARE(obj->height(), 25.0); + QCOMPARE(obj->paintedWidth(), 25.0); + QCOMPARE(obj->paintedHeight(), 25.0); + QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); + + delete obj; + } + + { + QString src = QUrl::fromLocalFile(SRCDIR "/data/heart.png").toString(); + QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; width: 26; height: 175; fillMode: Image.PreserveAspectFit }"; + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create()); + QVERIFY(obj != 0); + QCOMPARE(obj->pixmap().width(), 300); + QCOMPARE(obj->pixmap().height(), 300); + QCOMPARE(obj->width(), 26.0); + QCOMPARE(obj->height(), 175.0); + QCOMPARE(obj->paintedWidth(), 26.0); + QCOMPARE(obj->paintedHeight(), 26.0); + QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); + + delete obj; + } +} + /* Find an item with the specified objectName. If index is supplied then the item must also evaluate the {index} expression equal to index |