summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-03-26 05:18:54 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-03-26 05:18:54 (GMT)
commitf16d60399b996b09b779d2a719b5e6e6b9a80903 (patch)
tree6fdb5a62ad77a5b59b57b65f284acf909a549139
parentca90afcf32d9ba083b34f5cef3c7bde6300844f4 (diff)
downloadQt-f16d60399b996b09b779d2a719b5e6e6b9a80903.zip
Qt-f16d60399b996b09b779d2a719b5e6e6b9a80903.tar.gz
Qt-f16d60399b996b09b779d2a719b5e6e6b9a80903.tar.bz2
sourceWidth/sourceHeight -> sourceSize
-rw-r--r--examples/declarative/images/images.qml23
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp21
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp38
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p.h9
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h3
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp7
6 files changed, 38 insertions, 63 deletions
diff --git a/examples/declarative/images/images.qml b/examples/declarative/images/images.qml
index 82848df..35ce1ab 100644
--- a/examples/declarative/images/images.qml
+++ b/examples/declarative/images/images.qml
@@ -15,14 +15,14 @@ Rectangle {
}
Image {
- sourceWidth: 50
- sourceHeight: 50
+ sourceSize.width: 50
+ sourceSize.height: 50
source: "content/lemonade.jpg"
}
Image {
- sourceWidth: 50
- sourceHeight: 50
+ sourceSize.width: 50
+ sourceSize.height: 50
smooth: true
source: "content/lemonade.jpg"
}
@@ -34,15 +34,15 @@ Rectangle {
Image {
scale: 1/3
- sourceWidth: 50
- sourceHeight: 50
+ sourceSize.width: 50
+ sourceSize.height: 50
source: "content/lemonade.jpg"
}
Image {
scale: 1/3
- sourceWidth: 50
- sourceHeight: 50
+ sourceSize.width: 50
+ sourceSize.height: 50
smooth: true
source: "content/lemonade.jpg"
}
@@ -54,15 +54,14 @@ Rectangle {
Image {
width: 50; height: 50; transform: Translate { x: 50 }
- sourceWidth: 50
- sourceHeight: 50
+ sourceSize.width: 50
+ sourceSize.height: 50
source: "content/lemonade.jpg"
}
Image {
width: 50; height: 50; transform: Translate { x: 50 }
- sourceWidth: 50
- sourceHeight: 50
+ sourceSize: "50x50" // syntactic sugar
smooth: true
source: "content/lemonade.jpg"
}
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index 8b93063..23a2350 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -267,28 +267,27 @@ qreal QDeclarativeImage::paintedHeight() const
*/
/*!
- \qmlproperty int Image::sourceWidth
- \qmlproperty int Image::sourceHeight
+ \qmlproperty QSize Image::sourceSize
- These properties are the size of the loaded image, in pixels.
+ This properties is the size of the loaded image, in pixels.
- If you set these properties explicitly, you can to control the storage
+ If you set this property explicitly, you can to control the storage
used by a loaded image. The image will be scaled down if its intrinsic size
- is greater than these values.
+ is greater than this value.
Unlike setting the width and height properties, which merely scale the painting
- of the image, these properties affect the number of pixels stored.
+ of the image, this property affects the number of pixels stored.
- \e{Changing these properties dynamically will lead to the image source being reloaded,
+ \e{Changing this property dynamically will lead to the image source being reloaded,
potentially even from the network if it is not in the disk cache.}
- If the source is an instrinsically scalable image (eg. SVG), these properties
- determine the size of the loaded image regardless of intrinsic size. You should
- avoid changing these properties dynamically - rendering an SVG is \e slow compared
+ If the source is an instrinsically scalable image (eg. SVG), this property
+ determines the size of the loaded image regardless of intrinsic size. You should
+ avoid changing this property dynamically - rendering an SVG is \e slow compared
to an image.
If the source is a non-scalable image (eg. JPEG), the loaded image will
- be no greater than these properties specify. For some formats (currently only JPEG),
+ be no greater than this property specifies. For some formats (currently only JPEG),
the whole image will never actually be loaded into memory.
*/
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
index 3b75a85..b8d67ff 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp
@@ -116,41 +116,23 @@ void QDeclarativeImageBase::setSource(const QUrl &url)
load();
}
-void QDeclarativeImageBase::setSourceWidth(int w)
+void QDeclarativeImageBase::setSourceSize(const QSize& size)
{
Q_D(QDeclarativeImageBase);
- if (d->sourcewidth == w)
+ if (d->sourcesize == size)
return;
- d->sourcewidth = w;
+ d->sourcesize = size;
emit sourceSizeChanged();
if (isComponentComplete())
load();
}
-int QDeclarativeImageBase::sourceWidth() const
+QSize QDeclarativeImageBase::sourceSize() const
{
Q_D(const QDeclarativeImageBase);
- return d->sourcewidth <= 0 ? implicitWidth() : d->sourcewidth;
+ return d->sourcesize.isValid() ? d->sourcesize : QSize(implicitWidth(),implicitHeight());
}
-void QDeclarativeImageBase::setSourceHeight(int h)
-{
- Q_D(QDeclarativeImageBase);
- if (d->sourceheight == h)
- return;
- d->sourceheight = h;
- emit sourceSizeChanged();
- if (isComponentComplete())
- load();
-}
-
-int QDeclarativeImageBase::sourceHeight() const
-{
- Q_D(const QDeclarativeImageBase);
- return d->sourceheight <= 0 ? implicitHeight() : d->sourceheight;
-}
-
-
void QDeclarativeImageBase::load()
{
Q_D(QDeclarativeImageBase);
@@ -169,8 +151,8 @@ void QDeclarativeImageBase::load()
update();
} else {
d->status = Loading;
- int reqwidth = d->sourcewidth;
- int reqheight = d->sourceheight;
+ int reqwidth = d->sourcesize.width();
+ int reqheight = d->sourcesize.width();
QSize impsize;
QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async, reqwidth, reqheight);
if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
@@ -205,7 +187,7 @@ void QDeclarativeImageBase::load()
if (d->status == Loading)
d->status = Ready;
- if (d->sourcewidth <= 0 || d->sourceheight <= 0)
+ if (!d->sourcesize.isValid())
emit sourceSizeChanged();
} else {
d->status = Error;
@@ -228,7 +210,7 @@ void QDeclarativeImageBase::requestFinished()
d->pendingPixmapCache = false;
QSize impsize;
- if (QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async, d->sourcewidth, d->sourceheight) != QDeclarativePixmapReply::Ready)
+ if (QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async, d->sourcesize.width(), d->sourcesize.height()) != QDeclarativePixmapReply::Ready)
d->status = Error;
setImplicitWidth(impsize.width());
setImplicitHeight(impsize.height());
@@ -238,7 +220,7 @@ void QDeclarativeImageBase::requestFinished()
d->progress = 1.0;
emit statusChanged(d->status);
emit progressChanged(1.0);
- if (d->sourcewidth <= 0 || d->sourceheight <= 0)
+ if (!d->sourcesize.isValid())
emit sourceSizeChanged();
pixmapChange();
update();
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
index 2653d0a..6c84456 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h
@@ -59,8 +59,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeImageBase : public QDeclarativeItem
Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
- Q_PROPERTY(int sourceWidth READ sourceWidth WRITE setSourceWidth NOTIFY sourceSizeChanged)
- Q_PROPERTY(int sourceHeight READ sourceHeight WRITE setSourceHeight NOTIFY sourceSizeChanged)
+ Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged)
public:
~QDeclarativeImageBase();
@@ -74,10 +73,8 @@ public:
bool asynchronous() const;
void setAsynchronous(bool);
- void setSourceWidth(int);
- int sourceWidth() const;
- void setSourceHeight(int);
- int sourceHeight() const;
+ void setSourceSize(const QSize&);
+ QSize sourceSize() const;
Q_SIGNALS:
void sourceChanged(const QUrl &);
diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h
index cced228..de8c93a 100644
--- a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h
@@ -68,7 +68,6 @@ public:
QDeclarativeImageBasePrivate()
: status(QDeclarativeImageBase::Null),
progress(0.0),
- sourcewidth(0), sourceheight(0),
pendingPixmapCache(false),
async(false)
{
@@ -79,7 +78,7 @@ public:
QDeclarativeImageBase::Status status;
QUrl url;
qreal progress;
- int sourcewidth, sourceheight;
+ QSize sourcesize;
bool pendingPixmapCache : 1;
bool async : 1;
};
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index c7dcbea..9073750 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -257,7 +257,7 @@ void tst_qdeclarativeimage::pixmap()
void tst_qdeclarativeimage::svg()
{
- QString componentStr = "import Qt 4.6\nImage { source: \"" SRCDIR "/data/heart.svg\"; sourceWidth: 300; sourceHeight: 300 }";
+ QString componentStr = "import Qt 4.6\nImage { source: \"" SRCDIR "/data/heart.svg\"; sourceSize.width: 300; sourceSize.height: 300 }";
QDeclarativeComponent component(&engine);
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());
@@ -268,8 +268,7 @@ void tst_qdeclarativeimage::svg()
QCOMPARE(obj->height(), 500.0);
QCOMPARE(obj->pixmap(), QPixmap(SRCDIR "/data/heart.png"));
- obj->setSourceWidth(200);
- obj->setSourceHeight(200);
+ obj->setSourceSize(QSize(200,200));
QCOMPARE(obj->pixmap().width(), 200);
QCOMPARE(obj->pixmap().height(), 200);
@@ -282,7 +281,7 @@ void tst_qdeclarativeimage::svg()
void tst_qdeclarativeimage::big()
{
- QString componentStr = "import Qt 4.6\nImage { source: \"" SRCDIR "/data/big.jpeg\"; sourceWidth: 256; sourceHeight: 256 }";
+ QString componentStr = "import Qt 4.6\nImage { source: \"" SRCDIR "/data/big.jpeg\"; sourceSize.width: 256; sourceSize.height: 256 }";
QDeclarativeComponent component(&engine);
component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());