From 9f38b5824b0300c615231729f1e7cdb17890083a Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 30 Mar 2010 09:03:46 +1000 Subject: Allow just one dimension to be set, the other scaled accordingly Task-number: QTBUG-8984 --- src/declarative/util/qdeclarativepixmapcache.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index fe5863f..a9c30f8 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -179,8 +179,16 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e bool scaled = false; if (req_width > 0 || req_height > 0) { QSize s = imgio.size(); - if (req_width && (force_scale || req_width < s.width())) { s.setWidth(req_width); scaled = true; } - if (req_height && (force_scale || req_height < s.height())) { s.setHeight(req_height); scaled = true; } + if (req_width && (force_scale || req_width < s.width())) { + if (req_height <= 0) + s.setHeight(s.height()*req_width/s.width()); + s.setWidth(req_width); scaled = true; + } + if (req_height && (force_scale || req_height < s.height())) { + if (req_width <= 0) + s.setWidth(s.width()*req_height/s.height()); + s.setHeight(req_height); scaled = true; + } if (scaled) { imgio.setScaledSize(s); } } @@ -596,7 +604,7 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP QDeclarativePixmapReply::Status status = QDeclarativePixmapReply::Unrequested; QByteArray key = url.toEncoded(QUrl::FormattingOption(0x100)); - if (req_width > 0 && req_height > 0) { + if (req_width > 0 || req_height > 0) { key += ':'; key += QByteArray::number(req_width); key += 'x'; -- cgit v0.12