summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-03-31 00:32:26 (GMT)
committerMartin Jones <martin.jones@nokia.com>2011-03-31 00:47:57 (GMT)
commitaf05f64d3edc860c3cf79c7f0bdf2377faae5f40 (patch)
tree947c708b9d100feb63751bccef18561326e0cd64
parent068652a52f0554b5ceb56798fe5ac4e5049bb9e3 (diff)
downloadQt-af05f64d3edc860c3cf79c7f0bdf2377faae5f40.zip
Qt-af05f64d3edc860c3cf79c7f0bdf2377faae5f40.tar.gz
Qt-af05f64d3edc860c3cf79c7f0bdf2377faae5f40.tar.bz2
Once Image sourceSize is set there is no way to clear it.
Image sourceSize lacked a RESET method to allow reverting to the natural size of the image. Change-Id: I4e9089d8e16991375745db553f891bd377143eab Task-number: QTBUG-18442 Reviewed-by: Yann Bodson
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp3
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp12
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p.h3
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp22
4 files changed, 39 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index ed5d5fc..a62d3d2 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -377,6 +377,9 @@ qreal QDeclarativeImage::paintedHeight() const
If the source is a non-scalable image (eg. JPEG), the loaded image will
be no greater than this property specifies. For some formats (currently only JPEG),
the whole image will never actually be loaded into memory.
+
+ Since QtQuick 1.1 the sourceSize can be cleared to the natural size of the image
+ by setting sourceSize to \c undefined.
\note \e {Changing this property dynamically causes the image source to be reloaded,
potentially even from the network, if it is not in the disk cache.}
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
index 8f4416f..daebac4 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
@@ -133,6 +133,18 @@ QSize QDeclarativeImageBase::sourceSize() const
return QSize(width != -1 ? width : d->pix.width(), height != -1 ? height : d->pix.height());
}
+void QDeclarativeImageBase::resetSourceSize()
+{
+ Q_D(QDeclarativeImageBase);
+ if (!d->explicitSourceSize)
+ return;
+ d->explicitSourceSize = false;
+ d->sourcesize = QSize();
+ emit sourceSizeChanged();
+ if (isComponentComplete())
+ load();
+}
+
bool QDeclarativeImageBase::cache() const
{
Q_D(const QDeclarativeImageBase);
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
index abee25d..1763bba 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
@@ -59,7 +59,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeImageBase : public QDeclarativeImplicitSizeI
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
Q_PROPERTY(bool cache READ cache WRITE setCache NOTIFY cacheChanged REVISION 1)
- Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged)
+ Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged)
Q_PROPERTY(bool mirror READ mirror WRITE setMirror NOTIFY mirrorChanged REVISION 1)
public:
@@ -80,6 +80,7 @@ public:
virtual void setSourceSize(const QSize&);
QSize sourceSize() const;
+ void resetSourceSize();
virtual void setMirror(bool mirror);
bool mirror() const;
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index 9e090d2..c5a3d14 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -91,6 +91,7 @@ private slots:
void sourceSize_QTBUG_14303();
void sourceSize_QTBUG_16389();
void nullPixmapPaint();
+ void resetSourceSize();
void testQtQuick11Attributes();
void testQtQuick11Attributes_data();
@@ -693,6 +694,27 @@ void tst_qdeclarativeimage::nullPixmapPaint()
delete image;
}
+void tst_qdeclarativeimage::resetSourceSize()
+{
+ QString src = QUrl::fromLocalFile(SRCDIR "/data/heart200.png").toString();
+ QString componentStr = "import QtQuick 1.1\nImage { function reset() { sourceSize = undefined }\nsource: \"" + src + "\"; sourceSize: Qt.size(100,100) }";
+
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());
+ QVERIFY(obj != 0);
+ QCOMPARE(obj->pixmap().width(), 100);
+ QCOMPARE(obj->pixmap().height(), 100);
+ QCOMPARE(obj->sourceSize().height(), 100);
+ QCOMPARE(obj->sourceSize().width(), 100);
+
+ QMetaObject::invokeMethod(obj, "reset");
+ QCOMPARE(obj->pixmap().width(), 200);
+ QCOMPARE(obj->pixmap().height(), 200);
+ QCOMPARE(obj->sourceSize().height(), 200);
+ QCOMPARE(obj->sourceSize().width(), 200);
+}
+
void tst_qdeclarativeimage::testQtQuick11Attributes()
{
QFETCH(QString, code);