diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-04-06 05:46:35 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-04-07 03:47:36 (GMT) |
commit | 051a76c1d65d698f71dc75c89f91ae9021357eae (patch) | |
tree | 3a5120fc40ef877014deba478bdf5ad67c0acaf8 /src/declarative | |
parent | 5f741649cff218367100f3a9d7cdf9e0d393e327 (diff) | |
download | Qt-051a76c1d65d698f71dc75c89f91ae9021357eae.zip Qt-051a76c1d65d698f71dc75c89f91ae9021357eae.tar.gz Qt-051a76c1d65d698f71dc75c89f91ae9021357eae.tar.bz2 |
Image w/ PreserveAspectFit has its width changed once more than needed.
Avoid an extra setImplicitWidth/setImplicitHeight on image load.
Change-Id: I8bec1c97244068000c7a7f5fb3e937f80f3b36f5
Task-number: QTBUG-18573
Reviewed-by: Michael Brasser
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeimage.cpp | 20 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeimagebase.cpp | 12 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index a62d3d2..b776532 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -136,12 +136,10 @@ void QDeclarativeImagePrivate::setPixmap(const QPixmap &pixmap) Q_Q(QDeclarativeImage); pix.setPixmap(pixmap); - q->setImplicitWidth(pix.width()); - q->setImplicitHeight(pix.height()); + q->pixmapChange(); status = pix.isNull() ? QDeclarativeImageBase::Null : QDeclarativeImageBase::Ready; q->update(); - q->pixmapChange(); } /*! @@ -390,8 +388,11 @@ void QDeclarativeImage::updatePaintedGeometry() Q_D(QDeclarativeImage); if (d->fillMode == PreserveAspectFit) { - if (!d->pix.width() || !d->pix.height()) + if (!d->pix.width() || !d->pix.height()) { + setImplicitWidth(0); + setImplicitHeight(0); return; + } qreal w = widthValid() ? width() : d->pix.width(); qreal widthScale = w / qreal(d->pix.width()); qreal h = heightValid() ? height() : d->pix.height(); @@ -405,9 +406,13 @@ void QDeclarativeImage::updatePaintedGeometry() } if (widthValid() && !heightValid()) { setImplicitHeight(d->paintedHeight); + } else { + setImplicitHeight(d->pix.height()); } if (heightValid() && !widthValid()) { setImplicitWidth(d->paintedWidth); + } else { + setImplicitWidth(d->pix.width()); } } else if (d->fillMode == PreserveAspectCrop) { if (!d->pix.width() || !d->pix.height()) @@ -566,6 +571,13 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi void QDeclarativeImage::pixmapChange() { + Q_D(QDeclarativeImage); + // PreserveAspectFit calculates the implicit size differently so we + // don't call our superclass pixmapChange(), since that would + // result in the implicit size being set incorrectly, then updated + // in updatePaintedGeometry() + if (d->fillMode != PreserveAspectFit) + QDeclarativeImageBase::pixmapChange(); updatePaintedGeometry(); } diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index daebac4..81eac78 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -191,11 +191,9 @@ void QDeclarativeImageBase::load() d->pix.clear(this); d->status = Null; d->progress = 0.0; - setImplicitWidth(0); - setImplicitHeight(0); + pixmapChange(); emit progressChanged(d->progress); emit statusChanged(d->status); - pixmapChange(); update(); } else { QDeclarativePixmap::Options options; @@ -246,8 +244,7 @@ void QDeclarativeImageBase::requestFinished() d->progress = 1.0; - setImplicitWidth(d->pix.width()); - setImplicitHeight(d->pix.height()); + pixmapChange(); if (d->sourcesize.width() != d->pix.width() || d->sourcesize.height() != d->pix.height()) emit sourceSizeChanged(); @@ -256,7 +253,7 @@ void QDeclarativeImageBase::requestFinished() emit statusChanged(d->status); if (d->progress != oldProgress) emit progressChanged(d->progress); - pixmapChange(); + update(); } @@ -279,6 +276,9 @@ void QDeclarativeImageBase::componentComplete() void QDeclarativeImageBase::pixmapChange() { + Q_D(QDeclarativeImageBase); + setImplicitWidth(d->pix.width()); + setImplicitHeight(d->pix.height()); } QT_END_NAMESPACE |