diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-11-04 08:07:44 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-11-05 07:04:45 (GMT) |
commit | d2c204a93f30238c705209e65e2e8bce148825cd (patch) | |
tree | 4541764826a3bcbb99ccc17e869a1299a9732ad0 /tests/auto/declarative | |
parent | 2abf7cbc2258cc8a11094923a2da796d7529b08f (diff) | |
download | Qt-d2c204a93f30238c705209e65e2e8bce148825cd.zip Qt-d2c204a93f30238c705209e65e2e8bce148825cd.tar.gz Qt-d2c204a93f30238c705209e65e2e8bce148825cd.tar.bz2 |
Image bounding rect should always include the area being painted
This didn't always happend with fillMode PreserveAspectCrop,
resulting in drawing artifacts.
Task-number: QT-3933
Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r-- | tests/auto/declarative/qdeclarativeimage/data/rect.png | bin | 0 -> 171 bytes | |||
-rw-r--r-- | tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp | 74 |
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeimage/data/rect.png b/tests/auto/declarative/qdeclarativeimage/data/rect.png Binary files differnew file mode 100644 index 0000000..d564a2d --- /dev/null +++ b/tests/auto/declarative/qdeclarativeimage/data/rect.png diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index f1e026f..bf779ad 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -80,6 +80,8 @@ private slots: void preserveAspectRatio(); void smooth(); void svg(); + void geometry(); + void geometry_data(); void big(); void tiling_QTBUG_6716(); void noLoading(); @@ -288,6 +290,78 @@ void tst_qdeclarativeimage::svg() delete obj; } +void tst_qdeclarativeimage::geometry_data() +{ + QTest::addColumn<QString>("fillMode"); + QTest::addColumn<bool>("explicitWidth"); + QTest::addColumn<bool>("explicitHeight"); + QTest::addColumn<double>("itemWidth"); + QTest::addColumn<double>("paintedWidth"); + QTest::addColumn<double>("boundingWidth"); + QTest::addColumn<double>("itemHeight"); + QTest::addColumn<double>("paintedHeight"); + QTest::addColumn<double>("boundingHeight"); + + // tested image has width 200, height 100 + + // bounding rect and item rect are equal with fillMode PreserveAspectFit, painted rect may be smaller if the aspect ratio doesn't match + QTest::newRow("PreserveAspectFit") << "PreserveAspectFit" << false << false << 200.0 << 200.0 << 200.0 << 100.0 << 100.0 << 100.0; + QTest::newRow("PreserveAspectFit explicit width 300") << "PreserveAspectFit" << true << false << 300.0 << 200.0 << 300.0 << 100.0 << 100.0 << 100.0; + QTest::newRow("PreserveAspectFit explicit height 400") << "PreserveAspectFit" << false << true << 200.0 << 200.0 << 200.0 << 400.0 << 100.0 << 400.0; + QTest::newRow("PreserveAspectFit explicit width 300, height 400") << "PreserveAspectFit" << true << true << 300.0 << 300.0 << 300.0 << 400.0 << 150.0 << 400.0; + + // bounding rect and painted rect are equal with fillMode PreserveAspectCrop, item rect may be smaller if the aspect ratio doesn't match + QTest::newRow("PreserveAspectCrop") << "PreserveAspectCrop" << false << false << 200.0 << 200.0 << 200.0 << 100.0 << 100.0 << 100.0; + QTest::newRow("PreserveAspectCrop explicit width 300") << "PreserveAspectCrop" << true << false << 300.0 << 300.0 << 300.0 << 100.0 << 150.0 << 150.0; + QTest::newRow("PreserveAspectCrop explicit height 400") << "PreserveAspectCrop" << false << true << 200.0 << 800.0 << 800.0 << 400.0 << 400.0 << 400.0; + QTest::newRow("PreserveAspectCrop explicit width 300, height 400") << "PreserveAspectCrop" << true << true << 300.0 << 800.0 << 800.0 << 400.0 << 400.0 << 400.0; + + // bounding rect, painted rect and item rect are equal in stretching and tiling images + QStringList fillModes; + fillModes << "Stretch" << "Tile" << "TileVertically" << "TileHorizontally"; + foreach (QString fillMode, fillModes) { + QTest::newRow(fillMode.toLatin1()) << fillMode << false << false << 200.0 << 200.0 << 200.0 << 100.0 << 100.0 << 100.0; + QTest::newRow(QString(fillMode + " explicit width 300").toLatin1()) << fillMode << true << false << 300.0 << 300.0 << 300.0 << 100.0 << 100.0 << 100.0; + QTest::newRow(QString(fillMode + " explicit height 400").toLatin1()) << fillMode << false << true << 200.0 << 200.0 << 200.0 << 400.0 << 400.0 << 400.0; + QTest::newRow(QString(fillMode + " explicit width 300, height 400").toLatin1()) << fillMode << true << true << 300.0 << 300.0 << 300.0 << 400.0 << 400.0 << 400.0; + } +} + +void tst_qdeclarativeimage::geometry() +{ + QFETCH(QString, fillMode); + QFETCH(bool, explicitWidth); + QFETCH(bool, explicitHeight); + QFETCH(double, itemWidth); + QFETCH(double, itemHeight); + QFETCH(double, paintedWidth); + QFETCH(double, paintedHeight); + QFETCH(double, boundingWidth); + QFETCH(double, boundingHeight); + + QString src = QUrl::fromLocalFile(SRCDIR "/data/rect.png").toString(); + QString componentStr = "import QtQuick 1.0\nImage { source: \"" + src + "\"; fillMode: Image." + fillMode + "; "; + + if (explicitWidth) + componentStr.append("width: 300; "); + if (explicitHeight) + componentStr.append("height: 400; "); + componentStr.append("}"); + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create()); + QVERIFY(obj != 0); + + QCOMPARE(obj->width(), itemWidth); + QCOMPARE(obj->paintedWidth(), paintedWidth); + QCOMPARE(obj->boundingRect().width(), boundingWidth); + + QCOMPARE(obj->height(), itemHeight); + QCOMPARE(obj->paintedHeight(), paintedHeight); + QCOMPARE(obj->boundingRect().height(), boundingHeight); + delete obj; +} + void tst_qdeclarativeimage::big() { // If the JPEG loader does not implement scaling efficiently, it would |