summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2010-04-19 04:47:11 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2010-04-19 04:51:21 (GMT)
commit16d2b97e03ff99583ab25977880affecc1c4463b (patch)
tree789958aaa319d18b49a56ef58df8401881d83934
parent7de92b5b4cee9179d7163a477c03ed411c3975d6 (diff)
downloadQt-16d2b97e03ff99583ab25977880affecc1c4463b.zip
Qt-16d2b97e03ff99583ab25977880affecc1c4463b.tar.gz
Qt-16d2b97e03ff99583ab25977880affecc1c4463b.tar.bz2
QDeclarativeImage should stretch in one direction when tiling in the other.
Task-number: QTBUG-6716 Reviewed-by: Michael Brasser
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp25
-rw-r--r--tests/auto/declarative/qdeclarativeimage/data/green.pngbin0 -> 314 bytes
-rw-r--r--tests/auto/declarative/qdeclarativeimage/data/tiling.qml16
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp77
4 files changed, 112 insertions, 6 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index 37b07bf..1ca8fe2 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -366,12 +366,27 @@ void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWi
if (width() != d->pix.width() || height() != d->pix.height()) {
if (d->fillMode >= Tile) {
- if (d->fillMode == Tile)
+ if (d->fillMode == Tile) {
p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix);
- else if (d->fillMode == TileVertically)
- p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix);
- else
- p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix);
+ } else {
+ qreal widthScale = width() / qreal(d->pix.width());
+ qreal heightScale = height() / qreal(d->pix.height());
+
+ QTransform scale;
+ if (d->fillMode == TileVertically) {
+ scale.scale(widthScale, 1.0);
+ QTransform old = p->transform();
+ p->setWorldTransform(scale * old);
+ p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix);
+ p->setWorldTransform(old);
+ } else {
+ scale.scale(1.0, heightScale);
+ QTransform old = p->transform();
+ p->setWorldTransform(scale * old);
+ p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix);
+ p->setWorldTransform(old);
+ }
+ }
} else {
qreal widthScale = width() / qreal(d->pix.width());
qreal heightScale = height() / qreal(d->pix.height());
diff --git a/tests/auto/declarative/qdeclarativeimage/data/green.png b/tests/auto/declarative/qdeclarativeimage/data/green.png
new file mode 100644
index 0000000..0a2e153
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeimage/data/green.png
Binary files differ
diff --git a/tests/auto/declarative/qdeclarativeimage/data/tiling.qml b/tests/auto/declarative/qdeclarativeimage/data/tiling.qml
new file mode 100644
index 0000000..32839bb
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeimage/data/tiling.qml
@@ -0,0 +1,16 @@
+import Qt 4.7
+
+Rectangle {
+ width: 800; height: 600
+
+ Image {
+ objectName: "vTiling"; height: 550; width: 200
+ source: "green.png"; fillMode: Image.TileVertically
+ }
+
+ Image {
+ objectName: "hTiling"; x: 225; height: 250; width: 550
+ source: "green.png"; fillMode: Image.TileHorizontally
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index f94692b..73aefaf 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -51,6 +51,7 @@
#include <private/qdeclarativeimagebase_p.h>
#include <private/qdeclarativeloader_p.h>
#include <QtDeclarative/qdeclarativecontext.h>
+#include <QtDeclarative/qdeclarativeexpression.h>
#include "../shared/testhttpserver.h"
@@ -86,8 +87,12 @@ private slots:
void pixmap();
void svg();
void big();
+ void tiling_QTBUG_6716();
private:
+ template<typename T>
+ T *findItem(QGraphicsObject *parent, const QString &id, int index=-1);
+
QDeclarativeEngine engine;
};
@@ -161,7 +166,7 @@ void tst_qdeclarativeimage::imageSource()
if (async)
QVERIFY(obj->asynchronous() == true);
-
+
if (remote || async)
TRY_WAIT(obj->status() == QDeclarativeImage::Loading);
@@ -339,6 +344,76 @@ void tst_qdeclarativeimage::big()
delete obj;
}
+void tst_qdeclarativeimage::tiling_QTBUG_6716()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/tiling.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QDeclarativeImage *vTiling = findItem<QDeclarativeImage>(canvas->rootObject(), "vTiling");
+ QDeclarativeImage *hTiling = findItem<QDeclarativeImage>(canvas->rootObject(), "hTiling");
+
+ QVERIFY(vTiling != 0);
+ QVERIFY(hTiling != 0);
+
+ {
+ QPixmap pm(vTiling->width(), vTiling->height());
+ QPainter p(&pm);
+ vTiling->paint(&p, 0, 0);
+
+ QImage img = pm.toImage();
+ for (int x = 0; x < vTiling->width(); ++x) {
+ for (int y = 0; y < vTiling->height(); ++y) {
+ QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
+ }
+ }
+ }
+
+ {
+ QPixmap pm(hTiling->width(), hTiling->height());
+ QPainter p(&pm);
+ hTiling->paint(&p, 0, 0);
+
+ QImage img = pm.toImage();
+ for (int x = 0; x < hTiling->width(); ++x) {
+ for (int y = 0; y < hTiling->height(); ++y) {
+ QVERIFY(img.pixel(x, y) == qRgb(0, 255, 0));
+ }
+ }
+ }
+}
+
+/*
+ Find an item with the specified objectName. If index is supplied then the
+ item must also evaluate the {index} expression equal to index
+*/
+template<typename T>
+T *tst_qdeclarativeimage::findItem(QGraphicsObject *parent, const QString &objectName, int index)
+{
+ const QMetaObject &mo = T::staticMetaObject;
+ //qDebug() << parent->childItems().count() << "children";
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(parent->childItems().at(i));
+ if(!item)
+ continue;
+ //qDebug() << "try" << item;
+ if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) {
+ if (index != -1) {
+ QDeclarativeExpression e(qmlContext(item), "index", item);
+ if (e.value().toInt() == index)
+ return static_cast<T*>(item);
+ } else {
+ return static_cast<T*>(item);
+ }
+ }
+ item = findItem<T>(item, objectName, index);
+ if (item)
+ return static_cast<T*>(item);
+ }
+
+ return 0;
+}
QTEST_MAIN(tst_qdeclarativeimage)