From 5971999e08e0a6f41e200c20d3ceb5720732ce6b Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 11:35:29 +1000 Subject: QmlGraphicsBorderImage autotests --- tests/auto/declarative/declarative.pro | 1 + .../qmlgraphicsborderimage/data/colors-round.sci | 7 + .../qmlgraphicsborderimage/data/colors.png | Bin 0 -> 1655 bytes .../qmlgraphicsborderimage.pro | 8 + .../tst_qmlgraphicsborderimage.cpp | 162 +++++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/data/colors.png create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro create mode 100644 tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 86cf175..321e91b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,7 @@ SUBDIRS += anchors \ qmldom \ qmlecmascript \ qmlgraphicstext \ + qmlgraphicsborderimage \ qmlfontloader \ qmllanguage \ qmllist \ diff --git a/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci b/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci new file mode 100644 index 0000000..5d2f49f --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/data/colors-round.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.right:30 +border.bottom:40 +horizontalTileRule:Round +verticalTileRule:Repeat +source:colors.png diff --git a/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png new file mode 100644 index 0000000..dfb62f3 Binary files /dev/null and b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png differ diff --git a/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro new file mode 100644 index 0000000..82da769 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/qmlgraphicsborderimage.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsborderimage.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp new file mode 100644 index 0000000..809d9fd --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + +class tst_qmlgraphicsborderimage : public QObject + +{ + Q_OBJECT +public: + tst_qmlgraphicsborderimage(); + +private slots: + void simple(); + void resized(); + void smooth(); + void tileModes(); + void sciFile(); + +private: + QmlEngine engine; +}; + +tst_qmlgraphicsborderimage::tst_qmlgraphicsborderimage() +{ +} + +void tst_qmlgraphicsborderimage::simple() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 120); + QVERIFY(obj->height() == 120); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::resized() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::smooth() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; smooth: true; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->smoothTransform() == true); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); + + delete obj; +} + +void tst_qmlgraphicsborderimage::tileModes() +{ + { + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 100; height: 300; horizontalTileMode: BorderImage.Repeat; verticalTileMode: BorderImage.Repeat }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 100); + QVERIFY(obj->height() == 300); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Repeat); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Repeat); + + delete obj; + } + { + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors.png\"; width: 300; height: 150; horizontalTileMode: BorderImage.Round; verticalTileMode: BorderImage.Round }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 150); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Round); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Round); + + delete obj; + } +} + +void tst_qmlgraphicsborderimage::sciFile() +{ + QString componentStr = "import Qt 4.6\nBorderImage { source: \"" SRCDIR "/data/colors-round.sci\"; width: 300; height: 300 }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsBorderImage *obj = qobject_cast(component.create()); + QVERIFY(obj != 0); + QVERIFY(obj->width() == 300); + QVERIFY(obj->height() == 300); + QVERIFY(obj->border()->left() == 10); + QVERIFY(obj->border()->top() == 20); + QVERIFY(obj->border()->right() == 30); + QVERIFY(obj->border()->bottom() == 40); + QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Round); + QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Repeat); + + delete obj; +} + +QTEST_MAIN(tst_qmlgraphicsborderimage) + +#include "tst_qmlgraphicsborderimage.moc" -- cgit v0.12 From 8b94bb526e11acca4a479e6e31375128c2b6163c Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 10:58:07 +1000 Subject: Basic autotest for QmlGraphicsParticles --- .../qmlgraphicsparticles/data/particle.png | Bin 0 -> 262 bytes .../qmlgraphicsparticles/data/particles.qml | 15 +++ .../qmlgraphicsparticles/qmlgraphicsparticles.pro | 8 ++ .../tst_qmlgraphicsparticles.cpp | 122 +++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particle.png create mode 100644 tests/auto/declarative/qmlgraphicsparticles/data/particles.qml create mode 100644 tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro create mode 100644 tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particle.png b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png new file mode 100644 index 0000000..defbde5 Binary files /dev/null and b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png differ diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml new file mode 100644 index 0000000..dccd2c7 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particles.qml @@ -0,0 +1,15 @@ +import Qt 4.6 +Rectangle{ + width: 100 + height: 100 + color: "black" + objectName: "rect" + Particles { id: particles + objectName: "particles" + width:1; height:1; anchors.centerIn: parent; opacity: 1 + lifeSpan: 100; lifeSpanDeviation: 20; count:1000; + fadeInDuration: 20; fadeOutDuration: 20; + angle: 0; angleDeviation: 360; velocity: 500; velocityDeviation:30 + source: "particle.png" + } +} diff --git a/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro b/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro new file mode 100644 index 0000000..94eeb4e --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/qmlgraphicsparticles.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +contains(QT_CONFIG,declarative): QT += declarative gui +macx:CONFIG -= app_bundle + +SOURCES += tst_qmlgraphicsparticles.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp new file mode 100644 index 0000000..e50437a --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/tst_qmlgraphicsparticles.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include + +class tst_QmlGraphicsParticles : public QObject +{ + Q_OBJECT +public: + tst_QmlGraphicsParticles(); + +private slots: + void properties(); + void runs(); +private: + QmlView *createView(const QString &filename); + +}; + +tst_QmlGraphicsParticles::tst_QmlGraphicsParticles() +{ +} + +void tst_QmlGraphicsParticles::properties() +{ + QmlView *canvas = createView(SRCDIR "/data/particles.qml"); + QVERIFY(canvas->root()); + QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(particles); + + particles->setSource(QUrl("file://" SRCDIR "/data/particle.png")); + QCOMPARE(particles->source(), QUrl("file://" SRCDIR "/data/particle.png")); + + particles->setLifeSpanDeviation(1000); + QCOMPARE(particles->lifeSpanDeviation(), 1000); + + particles->setFadeInDuration(1000); + QCOMPARE(particles->fadeInDuration(), 1000); + + particles->setFadeOutDuration(1000); + QCOMPARE(particles->fadeOutDuration(), 1000); + + particles->setAngle(100.0); + QCOMPARE(particles->angle(), 100.0); + + particles->setAngleDeviation(100.0); + QCOMPARE(particles->angleDeviation(), 100.0); + + particles->setVelocity(100.0); + QCOMPARE(particles->velocity(), 100.0); + + particles->setVelocityDeviation(100.0); + QCOMPARE(particles->velocityDeviation(), 100.0); + + particles->setEmitting(false); + QCOMPARE(particles->emitting(), false); +} + +void tst_QmlGraphicsParticles::runs() +{ + QmlView *canvas = createView(SRCDIR "/data/particles.qml"); + QVERIFY(canvas->root()); + QmlGraphicsParticles* particles = canvas->root()->findChild("particles"); + QVERIFY(particles); + QTest::qWait(1000);//Run for one second. Test passes if it doesn't crash. +} + +QmlView *tst_QmlGraphicsParticles::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + canvas->execute(); + + return canvas; +} +QTEST_MAIN(tst_QmlGraphicsParticles) + +#include "tst_qmlgraphicsparticles.moc" -- cgit v0.12 From 15c19e46a330a20700f9dd42162100a12d80dc57 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 4 Nov 2009 12:38:48 +1000 Subject: Test inserting items outside of the visible area. --- tests/auto/declarative/listview/tst_listview.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 441138b..e61dd55 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -356,6 +356,26 @@ void tst_QmlGraphicsListView::inserted() QVERIFY(item->y() == i*20); } + for (int i = model.count(); i < 30; ++i) + model.insertItem(i, "Hello", QString::number(i)); + QTest::qWait(1000); + + listview->setViewportY(80); + QTest::qWait(1000); + + // Insert item outside visible area + model.insertItem(1, "Hello", "1324"); + QTest::qWait(1000); + + QVERIFY(listview->viewportY() == 80); + + // Confirm items positioned correctly + int itemCount = findItems(viewport, "wrapper").count() - 1; + for (int i = 5; i < 5+itemCount; ++i) { + QmlGraphicsItem *item = findItem(viewport, "wrapper", i); + QVERIFY(item->y() == i*20 - 20); + } + delete canvas; } -- cgit v0.12 From 240f2732b808d4c23366f8a432136832b6dd86d5 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Wed, 4 Nov 2009 12:45:16 +1000 Subject: use same name for setter/getter and property --- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 8 ++++---- src/declarative/graphicsitems/qmlgraphicsitem.h | 6 +++--- src/declarative/graphicsitems/qmlgraphicstextedit.cpp | 2 +- src/declarative/graphicsitems/qmlgraphicstextinput.cpp | 2 +- .../qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp | 2 +- tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 5083f43..51b8365 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -2667,9 +2667,9 @@ void QmlGraphicsItem::setTransformOrigin(TransformOrigin origin) The default is false. - \sa setSmoothTransform() + \sa setSmooth() */ -bool QmlGraphicsItem::smoothTransform() const +bool QmlGraphicsItem::smooth() const { Q_D(const QmlGraphicsItem); return d->smooth; @@ -2679,9 +2679,9 @@ bool QmlGraphicsItem::smoothTransform() const Sets whether the item should be drawn with antialiasing and smooth pixmap filtering to \a smooth. - \sa smoothTransform() + \sa smooth() */ -void QmlGraphicsItem::setSmoothTransform(bool smooth) +void QmlGraphicsItem::setSmooth(bool smooth) { Q_D(QmlGraphicsItem); if (d->smooth == smooth) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.h b/src/declarative/graphicsitems/qmlgraphicsitem.h index bdfc245..f64964c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem.h @@ -91,7 +91,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsItem : public QGraphicsObject, public QmlP Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) Q_PROPERTY(QmlList* transform READ transform DESIGNABLE false FINAL) Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin) - Q_PROPERTY(bool smooth READ smoothTransform WRITE setSmoothTransform) + Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) Q_PROPERTY(QGraphicsEffect *effect READ graphicsEffect WRITE setGraphicsEffect) Q_ENUMS(TransformOrigin) Q_CLASSINFO("DefaultProperty", "data") @@ -144,8 +144,8 @@ public: TransformOrigin transformOrigin() const; void setTransformOrigin(TransformOrigin); - bool smoothTransform() const; - void setSmoothTransform(bool); + bool smooth() const; + void setSmooth(bool); QRectF boundingRect() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); diff --git a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp index 13df329..e84f514 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextedit.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextedit.cpp @@ -946,7 +946,7 @@ void QmlGraphicsTextEditPrivate::init() { Q_Q(QmlGraphicsTextEdit); - q->setSmoothTransform(smooth); + q->setSmooth(smooth); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemHasNoContents, false); q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); diff --git a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp index 9a4f627..42de2b6 100644 --- a/src/declarative/graphicsitems/qmlgraphicstextinput.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstextinput.cpp @@ -673,7 +673,7 @@ void QmlGraphicsTextInputPrivate::init() control->setCursorWidth(1); control->setPasswordCharacter(QLatin1Char('*')); control->setLayoutDirection(Qt::LeftToRight); - q->setSmoothTransform(smooth); + q->setSmooth(smooth); q->setAcceptedMouseButtons(Qt::LeftButton); q->setFlag(QGraphicsItem::ItemHasNoContents, false); q->setFlag(QGraphicsItem::ItemAcceptsInputMethod); diff --git a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp index 809d9fd..4174ccf 100644 --- a/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp +++ b/tests/auto/declarative/qmlgraphicsborderimage/tst_qmlgraphicsborderimage.cpp @@ -104,7 +104,7 @@ void tst_qmlgraphicsborderimage::smooth() QVERIFY(obj != 0); QVERIFY(obj->width() == 300); QVERIFY(obj->height() == 300); - QVERIFY(obj->smoothTransform() == true); + QVERIFY(obj->smooth() == true); QVERIFY(obj->horizontalTileMode() == QmlGraphicsBorderImage::Stretch); QVERIFY(obj->verticalTileMode() == QmlGraphicsBorderImage::Stretch); diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index b9c12ee..1a90575 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -502,13 +502,13 @@ void tst_qmlgraphicstext::smooth() QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); + QCOMPARE(textObject->smooth(), true); } { QString componentStr = "import Qt 4.6\nText { text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); + QCOMPARE(textObject->smooth(), false); } } for (int i = 0; i < richText.size(); i++) @@ -517,13 +517,13 @@ void tst_qmlgraphicstext::smooth() QString componentStr = "import Qt 4.6\nText { smooth: true; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), true); + QCOMPARE(textObject->smooth(), true); } { QString componentStr = "import Qt 4.6\nText { text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast(textComponent.create()); - QCOMPARE(textObject->smoothTransform(), false); + QCOMPARE(textObject->smooth(), false); } } } -- cgit v0.12 From 182e09689623679c46feedc66b44e27c558d575b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 10:55:21 +1000 Subject: DateTimeFormatter autotests. --- .../declarative/datetimeformatter/tst_datetimeformatter.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp index 1712b86..5899d8d 100644 --- a/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp +++ b/tests/auto/declarative/datetimeformatter/tst_datetimeformatter.cpp @@ -67,12 +67,16 @@ void tst_datetimeformatter::date() QVERIFY(formatter != 0); QDate date(2008,12,24); + QCOMPARE(formatter->date(), date); + QCOMPARE(formatter->dateTime().date(), date); QCOMPARE(formatter->dateText(),date.toString(Qt::SystemLocaleShortDate)); formatter->setLongStyle(true); + QVERIFY(formatter->longStyle()); QCOMPARE(formatter->dateText(),date.toString(Qt::SystemLocaleLongDate)); formatter->setDateFormat("ddd MMMM d yy"); + QCOMPARE(formatter->dateFormat(), QLatin1String("ddd MMMM d yy")); QCOMPARE(formatter->dateText(),date.toString("ddd MMMM d yy")); QVERIFY(formatter->timeText().isEmpty()); @@ -91,6 +95,7 @@ void tst_datetimeformatter::time() QTime time(14,15,38,200); QCOMPARE(formatter->time(),time); + QCOMPARE(formatter->dateTime().time(),time); QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleShortDate)); @@ -98,6 +103,7 @@ void tst_datetimeformatter::time() QCOMPARE(formatter->timeText(),time.toString(Qt::SystemLocaleLongDate)); formatter->setTimeFormat("H:m:s a"); + QCOMPARE(formatter->timeFormat(), QLatin1String("H:m:s a")); QCOMPARE(formatter->timeText(),time.toString("H:m:s a")); formatter->setTimeFormat("hh:mm:ss.zzz"); @@ -117,12 +123,16 @@ void tst_datetimeformatter::dateTime() QVERIFY(formatter != 0); QDateTime dateTime(QDate(1978,03,04),QTime(9,13,54)); + QCOMPARE(formatter->dateTime(),dateTime); + QCOMPARE(formatter->date(),dateTime.date()); + QCOMPARE(formatter->time(),dateTime.time()); QCOMPARE(formatter->dateTimeText(),dateTime.toString(Qt::SystemLocaleShortDate)); formatter->setLongStyle(true); QCOMPARE(formatter->dateTimeText(),dateTime.toString(Qt::SystemLocaleLongDate)); formatter->setDateTimeFormat("M/d/yy H:m:s a"); + QCOMPARE(formatter->dateTimeFormat(), QLatin1String("M/d/yy H:m:s a")); QCOMPARE(formatter->dateTimeText(),dateTime.toString("M/d/yy H:m:s a")); } -- cgit v0.12 From 89b7c36a40afa536c77fc1f3088a3747c070f887 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 12:49:19 +1000 Subject: States autotest + missing files. --- tests/auto/declarative/behaviors/data/empty.qml | 23 +++++ .../declarative/behaviors/data/nonSelecting.qml | 26 +++++ .../behaviors/data/reassignedAnimation.qml | 27 +++++ .../auto/declarative/states/data/anchorChanges.qml | 22 ++++ .../declarative/states/data/anchorChanges2.qml | 21 ++++ .../auto/declarative/states/data/parentChange.qml | 36 +++++++ .../auto/declarative/states/data/parentChange2.qml | 31 ++++++ .../auto/declarative/states/data/parentChange3.qml | 42 ++++++++ tests/auto/declarative/states/data/script.qml | 10 ++ tests/auto/declarative/states/tst_states.cpp | 113 +++++++++++++++++++++ 10 files changed, 351 insertions(+) create mode 100644 tests/auto/declarative/behaviors/data/empty.qml create mode 100644 tests/auto/declarative/behaviors/data/nonSelecting.qml create mode 100644 tests/auto/declarative/behaviors/data/reassignedAnimation.qml create mode 100644 tests/auto/declarative/states/data/anchorChanges.qml create mode 100644 tests/auto/declarative/states/data/anchorChanges2.qml create mode 100644 tests/auto/declarative/states/data/parentChange.qml create mode 100644 tests/auto/declarative/states/data/parentChange2.qml create mode 100644 tests/auto/declarative/states/data/parentChange3.qml create mode 100644 tests/auto/declarative/states/data/script.qml diff --git a/tests/auto/declarative/behaviors/data/empty.qml b/tests/auto/declarative/behaviors/data/empty.qml new file mode 100644 index 0000000..412e26c --- /dev/null +++ b/tests/auto/declarative/behaviors/data/empty.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior {} + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/nonSelecting.qml b/tests/auto/declarative/behaviors/data/nonSelecting.qml new file mode 100644 index 0000000..ae9a9f5 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/nonSelecting.qml @@ -0,0 +1,26 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior"; + NumberAnimation { target: rect; property: "y"; duration: 200; } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/behaviors/data/reassignedAnimation.qml b/tests/auto/declarative/behaviors/data/reassignedAnimation.qml new file mode 100644 index 0000000..693a595 --- /dev/null +++ b/tests/auto/declarative/behaviors/data/reassignedAnimation.qml @@ -0,0 +1,27 @@ +import Qt 4.6 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRect" + width: 100; height: 100; color: "green" + x: Behavior { + objectName: "MyBehavior" + NumberAnimation { duration: 200 } + NumberAnimation { duration: 1000 } + } + } + MouseRegion { + id: clicker + anchors.fill: parent + } + states: State { + name: "moved" + when: clicker.pressed + PropertyChanges { + target: rect + x: 200 + } + } +} diff --git a/tests/auto/declarative/states/data/anchorChanges.qml b/tests/auto/declarative/states/data/anchorChanges.qml new file mode 100644 index 0000000..bb17840 --- /dev/null +++ b/tests/auto/declarative/states/data/anchorChanges.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Rectangle { + id: container + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + width: 50; height: 50 + color: "green"; + anchors.left: parent.left + anchors.leftMargin: 5 + } + states: State { + name: "right" + AnchorChanges { + target: myRect; + reset: "left" + right: container.right + } + } +} diff --git a/tests/auto/declarative/states/data/anchorChanges2.qml b/tests/auto/declarative/states/data/anchorChanges2.qml new file mode 100644 index 0000000..545345e --- /dev/null +++ b/tests/auto/declarative/states/data/anchorChanges2.qml @@ -0,0 +1,21 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + id: myRect + objectName: "MyRect" + width: 50; height: 50 + color: "green"; + anchors.left: parent.left + anchors.leftMargin: 5 + } + states: State { + name: "right" + AnchorChanges { + target: myRect; + reset: "left" + right: parent.right + } + } +} diff --git a/tests/auto/declarative/states/data/parentChange.qml b/tests/auto/declarative/states/data/parentChange.qml new file mode 100644 index 0000000..94fbd69 --- /dev/null +++ b/tests/auto/declarative/states/data/parentChange.qml @@ -0,0 +1,36 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Item { + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + color: "red" + } + } + MouseRegion { + id: Clickable + anchors.fill: parent + } + + Item { + x: -100; y: -50 + Item { + id: newParent + x: 248; y: 360 + } + } + + states: State { + name: "reparented" + when: Clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/states/data/parentChange2.qml b/tests/auto/declarative/states/data/parentChange2.qml new file mode 100644 index 0000000..d1c6d6a --- /dev/null +++ b/tests/auto/declarative/states/data/parentChange2.qml @@ -0,0 +1,31 @@ +import Qt 4.6 + +Rectangle { + id: newParent + width: 400; height: 400 + Item { + scale: .5 + rotation: 15 + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + color: "red" + } + } + MouseRegion { + id: Clickable + anchors.fill: parent + } + + states: State { + name: "reparented" + when: Clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/states/data/parentChange3.qml b/tests/auto/declarative/states/data/parentChange3.qml new file mode 100644 index 0000000..c7b7bee --- /dev/null +++ b/tests/auto/declarative/states/data/parentChange3.qml @@ -0,0 +1,42 @@ +import Qt 4.6 + +Rectangle { + width: 400; height: 400 + Item { + scale: .5 + rotation: 15 + transformOrigin: "Center" + x: 10; y: 10 + Rectangle { + id: myRect + objectName: "MyRect" + x: 5 + width: 100; height: 100 + transformOrigin: "BottomLeft" + color: "red" + } + } + MouseRegion { + id: Clickable + anchors.fill: parent + } + + Item { + x: 200; y: 200 + rotation: 52; + scale: 2 + Item { + id: newParent + x: 100; y: 100 + } + } + + states: State { + name: "reparented" + when: Clickable.pressed + ParentChange { + target: myRect + parent: newParent + } + } +} diff --git a/tests/auto/declarative/states/data/script.qml b/tests/auto/declarative/states/data/script.qml new file mode 100644 index 0000000..6983419 --- /dev/null +++ b/tests/auto/declarative/states/data/script.qml @@ -0,0 +1,10 @@ +import Qt 4.6 +Rectangle { + id: MyRectangle + width: 100; height: 100 + color: "red" + states: State { + name: "blue" + StateChangeScript { script: MyRectangle.color = "blue"; } + } +} diff --git a/tests/auto/declarative/states/tst_states.cpp b/tests/auto/declarative/states/tst_states.cpp index 89e755e..a215ed8 100644 --- a/tests/auto/declarative/states/tst_states.cpp +++ b/tests/auto/declarative/states/tst_states.cpp @@ -54,6 +54,9 @@ private slots: void basicExtension(); void basicBinding(); void signalOverride(); + void parentChange(); + void anchorChanges(); + void script(); }; void tst_states::basicChanges() @@ -353,6 +356,116 @@ void tst_states::signalOverride() } } +void tst_states::parentChange() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(-133)); + QCOMPARE(innerRect->y(), qreal(-300)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange2.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(15)); + QCOMPARE(innerRect->scale(), qreal(.5)); + QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(12.4148145657)); + QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(10.6470476128)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/parentChange3.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("reparented"); + QCOMPARE(innerRect->rotation(), qreal(-37)); + QCOMPARE(innerRect->scale(), qreal(.25)); + QCOMPARE(QString("%1").arg(innerRect->x()), QString("%1").arg(-217.305)); + QCOMPARE(QString("%1").arg(innerRect->y()), QString("%1").arg(-164.413)); + + rect->setState(""); + QCOMPARE(innerRect->rotation(), qreal(0)); + QCOMPARE(innerRect->scale(), qreal(1)); + QCOMPARE(innerRect->x(), qreal(5)); + QCOMPARE(innerRect->y(), qreal(0)); + } +} + +void tst_states::anchorChanges() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("right"); + QCOMPARE(innerRect->x(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); + } + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/anchorChanges2.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QmlGraphicsRectangle *innerRect = qobject_cast(rect->findChild("MyRect")); + QVERIFY(innerRect != 0); + + rect->setState("right"); + QCOMPARE(innerRect->x(), qreal(150)); + + rect->setState(""); + QCOMPARE(innerRect->x(), qreal(5)); + } +} + +void tst_states::script() +{ + QmlEngine engine; + + { + QmlComponent rectComponent(&engine, SRCDIR "/data/script.qml"); + QmlGraphicsRectangle *rect = qobject_cast(rectComponent.create()); + QVERIFY(rect != 0); + + QCOMPARE(rect->color(),QColor("red")); + + rect->setState("blue"); + QCOMPARE(rect->color(),QColor("blue")); + + rect->setState(""); + QCOMPARE(rect->color(),QColor("blue")); // a script isn't reverted + } +} + QTEST_MAIN(tst_states) #include "tst_states.moc" -- cgit v0.12 From d11f0b71ba8cae27aafc70fedf027f20180837e2 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 4 Nov 2009 13:06:09 +1000 Subject: Rename QmlGraphicsPixmapCache to QmlPixmapCache. --- src/declarative/extra/qmlgraphicsparticles.cpp | 10 +- src/declarative/graphicsitems/graphicsitems.pri | 2 - .../graphicsitems/qmlgraphicsborderimage.cpp | 14 +- .../graphicsitems/qmlgraphicsimagebase.cpp | 10 +- .../graphicsitems/qmlgraphicspixmapcache.cpp | 282 -------------------- .../graphicsitems/qmlgraphicspixmapcache_p.h | 71 ------ .../graphicsitems/qmlgraphicsscalegrid_p_p.h | 2 +- src/declarative/util/qmlpixmapcache.cpp | 283 +++++++++++++++++++++ src/declarative/util/qmlpixmapcache_p.h | 71 ++++++ src/declarative/util/util.pri | 6 +- 10 files changed, 376 insertions(+), 375 deletions(-) delete mode 100644 src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp delete mode 100644 src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h create mode 100644 src/declarative/util/qmlpixmapcache.cpp create mode 100644 src/declarative/util/qmlpixmapcache_p.h diff --git a/src/declarative/extra/qmlgraphicsparticles.cpp b/src/declarative/extra/qmlgraphicsparticles.cpp index aba7e27..0349a4e 100644 --- a/src/declarative/extra/qmlgraphicsparticles.cpp +++ b/src/declarative/extra/qmlgraphicsparticles.cpp @@ -50,7 +50,7 @@ #ifndef INT_MAX #define INT_MAX 2147483647 #endif -#include +#include #include #include #include @@ -619,7 +619,7 @@ QmlGraphicsParticles::~QmlGraphicsParticles() { Q_D(QmlGraphicsParticles); if (d->pendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); } /*! @@ -641,7 +641,7 @@ void QmlGraphicsParticles::imageLoaded() { Q_D(QmlGraphicsParticles); d->pendingPixmapCache = false; - QmlGraphicsPixmapCache::find(d->url, &d->image); + QmlPixmapCache::find(d->url, &d->image); d->paintItem->updateSize(); d->paintItem->update(); } @@ -654,7 +654,7 @@ void QmlGraphicsParticles::setSource(const QUrl &name) return; if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } if (name.isEmpty()) { @@ -665,7 +665,7 @@ void QmlGraphicsParticles::setSource(const QUrl &name) } else { d->url = name; Q_ASSERT(!name.isRelative()); - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->image); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->image); if (reply) { connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded())); d->pendingPixmapCache = true; diff --git a/src/declarative/graphicsitems/graphicsitems.pri b/src/declarative/graphicsitems/graphicsitems.pri index 15d775c..cf71451 100644 --- a/src/declarative/graphicsitems/graphicsitems.pri +++ b/src/declarative/graphicsitems/graphicsitems.pri @@ -39,7 +39,6 @@ HEADERS += \ graphicsitems/qmlgraphicstextedit_p_p.h \ graphicsitems/qmlgraphicstext_p.h \ graphicsitems/qmlgraphicstext_p_p.h \ - graphicsitems/qmlgraphicspixmapcache_p.h \ graphicsitems/qmlgraphicsvisualitemmodel_p.h \ graphicsitems/qmlgraphicslistview_p.h \ graphicsitems/qmlgraphicsgraphicsobjectcontainer_p.h \ @@ -70,7 +69,6 @@ SOURCES += \ graphicsitems/qmlgraphicstextinput.cpp \ graphicsitems/qmlgraphicstext.cpp \ graphicsitems/qmlgraphicstextedit.cpp \ - graphicsitems/qmlgraphicspixmapcache.cpp \ graphicsitems/qmlgraphicsvisualitemmodel.cpp \ graphicsitems/qmlgraphicslistview.cpp \ graphicsitems/qmlgraphicsgraphicsobjectcontainer.cpp \ diff --git a/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp b/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp index ed39a2b..89bbe91 100644 --- a/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsborderimage.cpp @@ -80,7 +80,7 @@ QmlGraphicsBorderImage::~QmlGraphicsBorderImage() if (d->sciReply) d->sciReply->deleteLater(); if (d->sciPendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); + QmlPixmapCache::cancelGet(d->sciurl, this); } /*! \qmlproperty enum BorderImage::status @@ -160,11 +160,11 @@ void QmlGraphicsBorderImage::setSource(const QUrl &url) } if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } if (d->sciPendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->sciurl, this); + QmlPixmapCache::cancelGet(d->sciurl, this); d->sciPendingPixmapCache = false; } @@ -203,7 +203,7 @@ void QmlGraphicsBorderImage::setSource(const QUrl &url) this, SLOT(sciRequestFinished())); } } else { - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (reply) { d->pendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -320,7 +320,7 @@ void QmlGraphicsBorderImage::setGridScaledImage(const QmlGraphicsGridScaledImage d->verticalTileMode = sci.verticalTileRule(); d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->sciurl, &d->pix); if (reply) { d->sciPendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -348,10 +348,10 @@ void QmlGraphicsBorderImage::requestFinished() if (d->url.path().endsWith(QLatin1String(".sci"))) { d->sciPendingPixmapCache = false; - QmlGraphicsPixmapCache::find(d->sciurl, &d->pix); + QmlPixmapCache::find(d->sciurl, &d->pix); } else { d->pendingPixmapCache = false; - if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) + if (!QmlPixmapCache::find(d->url, &d->pix)) d->status = Error; } setImplicitWidth(d->pix.width()); diff --git a/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp b/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp index 283fb04..e86b53d 100644 --- a/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsimagebase.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -65,7 +65,7 @@ QmlGraphicsImageBase::~QmlGraphicsImageBase() { Q_D(QmlGraphicsImageBase); if (d->pendingPixmapCache) - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); } QmlGraphicsImageBase::Status QmlGraphicsImageBase::status() const @@ -95,7 +95,7 @@ void QmlGraphicsImageBase::setSource(const QUrl &url) return; if (d->pendingPixmapCache) { - QmlGraphicsPixmapCache::cancelGet(d->url, this); + QmlPixmapCache::cancelGet(d->url, this); d->pendingPixmapCache = false; } @@ -117,7 +117,7 @@ void QmlGraphicsImageBase::setSource(const QUrl &url) update(); } else { d->status = Loading; - QNetworkReply *reply = QmlGraphicsPixmapCache::get(qmlEngine(this), d->url, &d->pix); + QNetworkReply *reply = QmlPixmapCache::get(qmlEngine(this), d->url, &d->pix); if (reply) { d->pendingPixmapCache = true; connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); @@ -147,7 +147,7 @@ void QmlGraphicsImageBase::requestFinished() d->pendingPixmapCache = false; - if (!QmlGraphicsPixmapCache::find(d->url, &d->pix)) + if (!QmlPixmapCache::find(d->url, &d->pix)) d->status = Error; setImplicitWidth(d->pix.width()); setImplicitHeight(d->pix.height()); diff --git a/src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp b/src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp deleted file mode 100644 index fdf489c..0000000 --- a/src/declarative/graphicsitems/qmlgraphicspixmapcache.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qmlgraphicspixmapcache_p.h" -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QSharedNetworkReply; -typedef QHash QmlGraphicsSharedNetworkReplyHash; -static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; - -class QSharedNetworkReply -{ -public: - QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} - ~QSharedNetworkReply() - { - reply->deleteLater(); - } - QNetworkReply *reply; - QPixmap pixmap; // ensure reference to pixmap to QPixmapCache does not discard - - int refCount; - void addRef() - { - ++refCount; - } - void release() - { - Q_ASSERT(refCount > 0); - --refCount; - if (refCount == 0) { - QString key = reply->url().toString(); - qfxActiveNetworkReplies.remove(key); - delete this; - } - } -}; - -static bool readImage(QIODevice *dev, QPixmap *pixmap) - { - QImageReader imgio(dev); - -//#define QT_TEST_SCALED_SIZE -#ifdef QT_TEST_SCALED_SIZE - /* - Some mechanism is needed for loading images at a limited size, especially - for remote images. Loading only thumbnails of remote progressive JPEG - images can be efficient. (Qt jpeg handler does not do so currently) - */ - - QSize limit(60,60); - QSize sz = imgio.size(); - if (sz.width() > limit.width() || sz.height() > limit.height()) { - sz.scale(limit,Qt::KeepAspectRatio); - imgio.setScaledSize(sz); - } -#endif - - QImage img; - if (imgio.read(&img)) { -#ifdef QT_TEST_SCALED_SIZE - if (!sz.isValid()) - img = img.scaled(limit,Qt::KeepAspectRatio); -#endif - *pixmap = QPixmap::fromImage(img); - return true; - } else { - qWarning() << imgio.errorString(); - return false; - } - } - -/*! - \internal - \class QmlGraphicsPixmapCache - \brief Enacapsultes a pixmap for QmlGraphics items. - - This class is NOT reentrant. - */ - -static QString toLocalFileOrQrc(const QUrl& url) -{ - QString r = url.toLocalFile(); - if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) - r = QLatin1Char(':') + url.path(); - return r; -} - -/*! - Finds the cached pixmap corresponding to \a url. - A previous call to get() must have requested the URL, - and the QNetworkReply must have finished before calling - this function. - - Returns true if the image was loaded without error. -*/ -bool QmlGraphicsPixmapCache::find(const QUrl& url, QPixmap *pixmap) -{ -#ifdef Q_ENABLE_PERFORMANCE_LOG - QmlPerfTimer perf; -#endif - - QString key = url.toString(); - bool ok = true; - if (!QPixmapCache::find(key,pixmap)) { -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(url); - if (!lf.isEmpty()) { - QFile f(lf); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - ok = false; - } - } else { - *pixmap = QPixmap(); - ok = false; - } - } else -#endif - { - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - // API usage error - qWarning() << "QmlGraphicsPixmapCache: URL not loaded" << url; - ok = false; - } else { - if ((*iter)->reply->error()) { - qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); - *pixmap = QPixmap(); - ok = false; - } else if (!readImage((*iter)->reply, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - ok = false; - } else { - if ((*iter)->refCount > 1) - (*iter)->pixmap = *pixmap; - } - (*iter)->release(); - } - } - QPixmapCache::insert(key, *pixmap); - } else { - ok = !pixmap->isNull(); -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - if (url.scheme()!=QLatin1String("file")) -#endif - // We may be the second finder. Still need to check for active replies. - { - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter != qfxActiveNetworkReplies.end()) - (*iter)->release(); - } - } - return ok; -} - -/*! - Starts a network request to load \a url. - - Returns a QNetworkReply if the image is not immediately available, otherwise - returns 0. Caller should connect to QNetworkReply::finished() to then call - find() when the image is available. - - The returned QNetworkReply will be deleted when all get() calls are - matched by a corresponding find() call. -*/ -QNetworkReply *QmlGraphicsPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) -{ -#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML - QString lf = toLocalFileOrQrc(url); - if (!lf.isEmpty()) { - QString key = url.toString(); - if (!QPixmapCache::find(key,pixmap)) { - QFile f(lf); - if (f.open(QIODevice::ReadOnly)) { - if (!readImage(&f, pixmap)) { - qWarning() << "Format error loading" << url; - *pixmap = QPixmap(); - } - } else - *pixmap = QPixmap(); - QPixmapCache::insert(key, *pixmap); - } - return 0; - } -#endif - - QString key = url.toString(); - if (QPixmapCache::find(key,pixmap)) { - return 0; - } - - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) { - QNetworkRequest req(url); - QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); - iter = qfxActiveNetworkReplies.insert(key, item); - } else { - (*iter)->addRef(); - } - - return (*iter)->reply; -} - -/*! - Cancels a previous call to get(). - - May also cancel loading (eg. if no other pending request). - - Any connections from the QNetworkReply returned by get() to \a obj will be - disconnected. -*/ -void QmlGraphicsPixmapCache::cancelGet(const QUrl& url, QObject* obj) -{ - QString key = url.toString(); - QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); - if (iter == qfxActiveNetworkReplies.end()) - return; - if (obj) - QObject::disconnect((*iter)->reply, 0, obj, 0); - (*iter)->release(); -} - -/*! - This function is mainly for test verification. It returns the number of - requests that are still unfinished. -*/ -int QmlGraphicsPixmapCache::pendingRequests() -{ - return qfxActiveNetworkReplies.count(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h b/src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h deleted file mode 100644 index 29de98d..0000000 --- a/src/declarative/graphicsitems/qmlgraphicspixmapcache_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLGRAPHICSPIXMAPCACHE_H -#define QMLGRAPHICSPIXMAPCACHE_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QmlEngine; -class QNetworkReply; -class Q_DECLARATIVE_EXPORT QmlGraphicsPixmapCache -{ -public: - static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); - static void cancelGet(const QUrl& url, QObject* obj); - - static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlGraphicsPixmapCache::get, and any returned reply finished. - - static int pendingRequests(); // mainly for test verification -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QMLGRAPHICSPIXMAPCACHE_H diff --git a/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h b/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h index b66a5a5..d4ae0a6 100644 --- a/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsscalegrid_p_p.h @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include "qmlgraphicsborderimage_p.h" diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp new file mode 100644 index 0000000..f5904c0 --- /dev/null +++ b/src/declarative/util/qmlpixmapcache.cpp @@ -0,0 +1,283 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmlpixmapcache_p.h" +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QSharedNetworkReply; +typedef QHash QmlGraphicsSharedNetworkReplyHash; +static QmlGraphicsSharedNetworkReplyHash qfxActiveNetworkReplies; + +class QSharedNetworkReply +{ +public: + QSharedNetworkReply(QNetworkReply *r) : reply(r), refCount(1) {} + ~QSharedNetworkReply() + { + reply->deleteLater(); + } + QNetworkReply *reply; + QPixmap pixmap; // ensure reference to pixmap to QPixmapCache does not discard + + int refCount; + void addRef() + { + ++refCount; + } + void release() + { + Q_ASSERT(refCount > 0); + --refCount; + if (refCount == 0) { + QString key = reply->url().toString(); + qfxActiveNetworkReplies.remove(key); + delete this; + } + } +}; + +static bool readImage(QIODevice *dev, QPixmap *pixmap) + { + QImageReader imgio(dev); + +//#define QT_TEST_SCALED_SIZE +#ifdef QT_TEST_SCALED_SIZE + /* + Some mechanism is needed for loading images at a limited size, especially + for remote images. Loading only thumbnails of remote progressive JPEG + images can be efficient. (Qt jpeg handler does not do so currently) + */ + + QSize limit(60,60); + QSize sz = imgio.size(); + if (sz.width() > limit.width() || sz.height() > limit.height()) { + sz.scale(limit,Qt::KeepAspectRatio); + imgio.setScaledSize(sz); + } +#endif + + QImage img; + if (imgio.read(&img)) { +#ifdef QT_TEST_SCALED_SIZE + if (!sz.isValid()) + img = img.scaled(limit,Qt::KeepAspectRatio); +#endif + *pixmap = QPixmap::fromImage(img); + return true; + } else { + qWarning() << imgio.errorString(); + return false; + } + } + +/*! + \internal + \class QmlPixmapCache + \brief Enacapsultes a pixmap for QmlGraphics items. + + This class is NOT reentrant. + */ + +static QString toLocalFileOrQrc(const QUrl& url) +{ + QString r = url.toLocalFile(); + if (r.isEmpty() && url.scheme() == QLatin1String("qrc")) + r = QLatin1Char(':') + url.path(); + return r; +} + +/*! + Finds the cached pixmap corresponding to \a url. + A previous call to get() must have requested the URL, + and the QNetworkReply must have finished before calling + this function. + + Returns true if the image was loaded without error. +*/ +bool QmlPixmapCache::find(const QUrl& url, QPixmap *pixmap) +{ +#ifdef Q_ENABLE_PERFORMANCE_LOG + QmlPerfTimer perf; +#endif + + QString key = url.toString(); + bool ok = true; + if (!QPixmapCache::find(key,pixmap)) { +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + QFile f(lf); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + ok = false; + } + } else { + *pixmap = QPixmap(); + ok = false; + } + } else +#endif + { + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + // API usage error + qWarning() << "QmlPixmapCache: URL not loaded" << url; + ok = false; + } else { + if ((*iter)->reply->error()) { + qWarning() << "Network error loading" << url << (*iter)->reply->errorString(); + *pixmap = QPixmap(); + ok = false; + } else if (!readImage((*iter)->reply, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + ok = false; + } else { + if ((*iter)->refCount > 1) + (*iter)->pixmap = *pixmap; + } + (*iter)->release(); + } + } + QPixmapCache::insert(key, *pixmap); + } else { + ok = !pixmap->isNull(); +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + if (url.scheme()!=QLatin1String("file")) +#endif + // We may be the second finder. Still need to check for active replies. + { + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter != qfxActiveNetworkReplies.end()) + (*iter)->release(); + } + } + return ok; +} + +/*! + Starts a network request to load \a url. + + Returns a QNetworkReply if the image is not immediately available, otherwise + returns 0. Caller should connect to QNetworkReply::finished() to then call + find() when the image is available. + + The returned QNetworkReply will be deleted when all get() calls are + matched by a corresponding find() call. +*/ +QNetworkReply *QmlPixmapCache::get(QmlEngine *engine, const QUrl& url, QPixmap *pixmap) +{ +#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML + QString lf = toLocalFileOrQrc(url); + if (!lf.isEmpty()) { + QString key = url.toString(); + if (!QPixmapCache::find(key,pixmap)) { + QFile f(lf); + if (f.open(QIODevice::ReadOnly)) { + if (!readImage(&f, pixmap)) { + qWarning() << "Format error loading" << url; + *pixmap = QPixmap(); + } + } else + *pixmap = QPixmap(); + QPixmapCache::insert(key, *pixmap); + } + return 0; + } +#endif + + QString key = url.toString(); + if (QPixmapCache::find(key,pixmap)) { + return 0; + } + + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) { + QNetworkRequest req(url); + QSharedNetworkReply *item = new QSharedNetworkReply(engine->networkAccessManager()->get(req)); + iter = qfxActiveNetworkReplies.insert(key, item); + } else { + (*iter)->addRef(); + } + + return (*iter)->reply; +} + +/*! + Cancels a previous call to get(). + + May also cancel loading (eg. if no other pending request). + + Any connections from the QNetworkReply returned by get() to \a obj will be + disconnected. +*/ +void QmlPixmapCache::cancelGet(const QUrl& url, QObject* obj) +{ + QString key = url.toString(); + QmlGraphicsSharedNetworkReplyHash::Iterator iter = qfxActiveNetworkReplies.find(key); + if (iter == qfxActiveNetworkReplies.end()) + return; + if (obj) + QObject::disconnect((*iter)->reply, 0, obj, 0); + (*iter)->release(); +} + +/*! + This function is mainly for test verification. It returns the number of + requests that are still unfinished. +*/ +int QmlPixmapCache::pendingRequests() +{ + return qfxActiveNetworkReplies.count(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/util/qmlpixmapcache_p.h b/src/declarative/util/qmlpixmapcache_p.h new file mode 100644 index 0000000..e6ed452 --- /dev/null +++ b/src/declarative/util/qmlpixmapcache_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLPIXMAPCACHE_H +#define QMLPIXMAPCACHE_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QmlEngine; +class QNetworkReply; +class Q_DECLARATIVE_EXPORT QmlPixmapCache +{ +public: + static QNetworkReply *get(QmlEngine *, const QUrl& url, QPixmap *pixmap); + static void cancelGet(const QUrl& url, QObject* obj); + + static bool find(const QUrl& url, QPixmap *pixmap); // url must have been passed to QmlPixmapCache::get, and any returned reply finished. + + static int pendingRequests(); // mainly for test verification +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QMLPIXMAPCACHE_H diff --git a/src/declarative/util/util.pri b/src/declarative/util/util.pri index 87ccb58..f955ef6 100644 --- a/src/declarative/util/util.pri +++ b/src/declarative/util/util.pri @@ -20,7 +20,8 @@ SOURCES += \ util/qmltimeline.cpp \ util/qmltimer.cpp \ util/qmlbind.cpp \ - util/qmlpropertymap.cpp + util/qmlpropertymap.cpp \ + util/qmlpixmapcache.cpp HEADERS += \ util/qmlview.h \ @@ -47,4 +48,5 @@ HEADERS += \ util/qmltimeline_p_p.h \ util/qmltimer_p.h \ util/qmlbind_p.h \ - util/qmlpropertymap_p.h + util/qmlpropertymap_p.h \ + util/qmlpixmapcache_p.h -- cgit v0.12 From 684fe7af0b6d8133973132fd5b6b01cc16957a10 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 4 Nov 2009 13:47:40 +1000 Subject: Add closestAngle function to Qt object to help with rotation animations. Includes test and doc. --- doc/src/declarative/globalobject.qdoc | 3 +++ src/declarative/qml/qmlengine.cpp | 20 ++++++++++++++++++++ src/declarative/qml/qmlengine_p.h | 1 + tests/auto/declarative/qmlqt/data/closestangle.qml | 12 ++++++++++++ tests/auto/declarative/qmlqt/tst_qmlqt.cpp | 18 ++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 tests/auto/declarative/qmlqt/data/closestangle.qml diff --git a/doc/src/declarative/globalobject.qdoc b/doc/src/declarative/globalobject.qdoc index f1d440f..06f6bdc 100644 --- a/doc/src/declarative/globalobject.qdoc +++ b/doc/src/declarative/globalobject.qdoc @@ -114,6 +114,9 @@ This function returns a color 50% darker than \c baseColor. See QColor::lighter( \image declarative-rect_tint.png Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color. +\section3 Qt.closestAngle(number fromAngle, number toAngle) +This function returns an equivalent angle to toAngle, such that the difference between fromAngle and toAngle is never more than 180 degrees. This is useful when animating angles using a NumberAnimation, which does not know about equivalent angles, when you always want to take the shortest path. + \section3 Qt.playSound(url soundLocation) This function plays the audio file located at \c soundLocation. Only .wav files are supported. diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index c562e02..2926791 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -147,6 +147,7 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e) qtObject.setProperty(QLatin1String("tint"), scriptEngine.newFunction(QmlEnginePrivate::tint, 2)); //misc methods + qtObject.setProperty(QLatin1String("closestAngle"), scriptEngine.newFunction(QmlEnginePrivate::closestAngle, 2)); qtObject.setProperty(QLatin1String("playSound"), scriptEngine.newFunction(QmlEnginePrivate::playSound, 1)); qtObject.setProperty(QLatin1String("openUrlExternally"),scriptEngine.newFunction(desktopOpenUrl, 1)); @@ -810,6 +811,25 @@ QScriptValue QmlEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngin return e->newVariant(QVariant(ret)); } +QScriptValue QmlEnginePrivate::closestAngle(QScriptContext *ctxt, QScriptEngine *e) +{ + if(ctxt->argumentCount() < 2) + return e->newVariant(QVariant(0.0)); + qreal a = ctxt->argument(0).toNumber(); + qreal b = ctxt->argument(1).toNumber(); + qreal ret = b; + qreal diff = b-a; + while(diff > 180.0){ + ret -= 360.0; + diff -= 360.0; + } + while(diff < -180.0){ + ret += 360.0; + diff += 360.0; + } + return e->newVariant(QVariant(ret)); +} + QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine) { if(ctxt->argumentCount() != 2) diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index b050ef6..3c60b5c 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -269,6 +269,7 @@ public: static QScriptValue darker(QScriptContext*, QScriptEngine*); static QScriptValue tint(QScriptContext*, QScriptEngine*); + static QScriptValue closestAngle(QScriptContext*, QScriptEngine*); static QScriptValue playSound(QScriptContext*, QScriptEngine*); static QScriptValue desktopOpenUrl(QScriptContext*, QScriptEngine*); diff --git a/tests/auto/declarative/qmlqt/data/closestangle.qml b/tests/auto/declarative/qmlqt/data/closestangle.qml new file mode 100644 index 0000000..8f999e3 --- /dev/null +++ b/tests/auto/declarative/qmlqt/data/closestangle.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Object { + property var testSame: Qt.closestAngle(0,1) + property var testLess: Qt.closestAngle(0,-359) + property var testMore: Qt.closestAngle(0,361) + property var testFail: Qt.closestAngle(0) + property var test5: Qt.closestAngle(0,1,2) + property var test6: Qt.closestAngle(123.45465768,1.11) + property var test7: Qt.closestAngle(-3.1415,1.11) +} + diff --git a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp index 10402ae..cc9b94d 100644 --- a/tests/auto/declarative/qmlqt/tst_qmlqt.cpp +++ b/tests/auto/declarative/qmlqt/tst_qmlqt.cpp @@ -64,6 +64,7 @@ private slots: void lighter(); void darker(); void tint(); + void closestAngle(); void playSound(); void openUrlExternally(); @@ -249,6 +250,23 @@ void tst_qmlqt::tint() delete object; } +void tst_qmlqt::closestAngle() +{ + QmlComponent component(&engine, TEST_FILE("closestangle.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(qvariant_cast(object->property("testSame")), 1.0); + QCOMPARE(qvariant_cast(object->property("testLess")), 1.0); + QCOMPARE(qvariant_cast(object->property("testMore")), 1.0); + QCOMPARE(qvariant_cast(object->property("testFail")), 0.0); + QCOMPARE(qvariant_cast(object->property("test5")), 1.0); + QCOMPARE(qvariant_cast(object->property("test6")), 1.11); + QCOMPARE(qvariant_cast(object->property("test7")), 1.11); + + delete object; +} + void tst_qmlqt::playSound() { QEXPECT_FAIL("", "How do we test this?", Abort); -- cgit v0.12