diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2010-08-25 05:31:00 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2010-08-25 05:31:00 (GMT) |
commit | b4bf4f754ba65da3ea751dd5508d29244a4b4db2 (patch) | |
tree | 8e60970e0510da8bef0f8129fbaa210075555ce3 | |
parent | 675188b766b7b0f7eb65c2e9f3ee7d6017e63453 (diff) | |
download | Qt-b4bf4f754ba65da3ea751dd5508d29244a4b4db2.zip Qt-b4bf4f754ba65da3ea751dd5508d29244a4b4db2.tar.gz Qt-b4bf4f754ba65da3ea751dd5508d29244a4b4db2.tar.bz2 |
Setting one dimension of the sourceSize should set the other dimension.
The implicit width and height should also be set to the sourceSize.
Task-number: 13002
3 files changed, 26 insertions, 40 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index ba40443..d6b935b 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -147,10 +147,15 @@ void QDeclarativeImageBase::load() setImplicitWidth(0); setImplicitHeight(0); emit statusChanged(d->status); + d->sourcesize.setWidth(0); + d->sourcesize.setHeight(0); + emit sourceSizeChanged(); pixmapChange(); update(); } else { + d->status = Loading; + emit statusChanged(d->status); d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); @@ -169,53 +174,34 @@ void QDeclarativeImageBase::load() d->pix.connectDownloadProgress(this, thisRequestProgress); } else { - QSize impsize = d->pix.implicitSize(); - setImplicitWidth(impsize.width()); - setImplicitHeight(impsize.height()); - - if (d->pix.isReady()) { - d->status = Ready; - - if (!d->sourcesize.isValid()) - emit sourceSizeChanged(); - - } else { - d->status = Error; - qmlInfo(this) << d->pix.error(); - } - d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(d->progress); - pixmapChange(); - update(); + requestFinished(); } - } - - emit statusChanged(d->status); } void QDeclarativeImageBase::requestFinished() { Q_D(QDeclarativeImageBase); - QSize impsize = d->pix.implicitSize(); - if (d->pix.isError()) { d->status = Error; qmlInfo(this) << d->pix.error(); + } else { + d->status = Ready; } + emit statusChanged(d->status); - setImplicitWidth(impsize.width()); - setImplicitHeight(impsize.height()); + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); - if (d->status == Loading) - d->status = Ready; d->progress = 1.0; - emit statusChanged(d->status); - emit progressChanged(1.0); - if (!d->sourcesize.isValid()) + emit progressChanged(d->progress); + + if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) { + d->sourcesize.setWidth(d->pix.width()); + d->sourcesize.setHeight(d->pix.height()); emit sourceSizeChanged(); + } pixmapChange(); update(); } diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 0f1050e..8cfb487 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -272,8 +272,8 @@ void tst_qdeclarativeimage::svg() QVERIFY(obj != 0); QCOMPARE(obj->pixmap().width(), 300); QCOMPARE(obj->pixmap().height(), 300); - QCOMPARE(obj->width(), 550.0); - QCOMPARE(obj->height(), 500.0); + QCOMPARE(obj->width(), 300.0); + QCOMPARE(obj->height(), 300.0); #if defined(Q_OS_LINUX) QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png")); #elif defined(Q_OS_WIN32) @@ -284,8 +284,8 @@ void tst_qdeclarativeimage::svg() QCOMPARE(obj->pixmap().width(), 200); QCOMPARE(obj->pixmap().height(), 200); - QCOMPARE(obj->width(), 550.0); - QCOMPARE(obj->height(), 500.0); + QCOMPARE(obj->width(), 200.0); + QCOMPARE(obj->height(), 200.0); #if defined(Q_OS_LINUX) QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart200.png")); #elif defined(Q_OS_WIN32) @@ -300,7 +300,7 @@ void tst_qdeclarativeimage::big() // have to build a 400 MB image. That would be a bug in the JPEG loader. QString src = QUrl::fromLocalFile(SRCDIR "/data/big.jpeg").toString(); - QString componentStr = "import Qt 4.7\nImage { source: \"" + src + "\"; sourceSize.width: 256; sourceSize.height: 256 }"; + QString componentStr = "import Qt 4.7\nImage { source: \"" + src + "\"; width: 100; sourceSize.height: 256 }"; QDeclarativeComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); @@ -308,8 +308,8 @@ void tst_qdeclarativeimage::big() QVERIFY(obj != 0); QCOMPARE(obj->pixmap().width(), 256); QCOMPARE(obj->pixmap().height(), 256); - QCOMPARE(obj->width(), 10240.0); - QCOMPARE(obj->height(), 10240.0); + QCOMPARE(obj->width(), 100.0); + QCOMPARE(obj->height(), 256.0); QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/big256.png")); delete obj; diff --git a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp index 4a9224e..6d5a357 100644 --- a/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp +++ b/tests/auto/declarative/qdeclarativeimageprovider/tst_qdeclarativeimageprovider.cpp @@ -221,8 +221,8 @@ void tst_qdeclarativeimageprovider::runTest(bool async, QDeclarativeImageProvide TRY_WAIT(obj->status() == QDeclarativeImage::Ready); else QVERIFY(obj->status() == QDeclarativeImage::Ready); - QCOMPARE(obj->width(), 100.0); - QCOMPARE(obj->height(), 100.0); + QCOMPARE(obj->width(), qreal(size.width())); + QCOMPARE(obj->height(), qreal(size.height())); QCOMPARE(obj->pixmap().width(), size.width()); QCOMPARE(obj->pixmap().height(), size.height()); QCOMPARE(obj->fillMode(), QDeclarativeImage::Stretch); |