diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-04 02:22:10 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-04 02:22:10 (GMT) |
commit | e87f1cfec926aab2336063729d21059ebc9767e5 (patch) | |
tree | 09fed41e441c59be0f0dc283d61ae8992f99c79d | |
parent | 4a185128d214acd29ee7c6d7f641311306e06fe5 (diff) | |
parent | 8b94bb526e11acca4a479e6e31375128c2b6163c (diff) | |
download | Qt-e87f1cfec926aab2336063729d21059ebc9767e5.zip Qt-e87f1cfec926aab2336063729d21059ebc9767e5.tar.gz Qt-e87f1cfec926aab2336063729d21059ebc9767e5.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
26 files changed, 626 insertions, 32 deletions
diff --git a/src/declarative/extra/qmlfontloader.cpp b/src/declarative/extra/qmlfontloader.cpp index 8c17d0f..e8db649 100644 --- a/src/declarative/extra/qmlfontloader.cpp +++ b/src/declarative/extra/qmlfontloader.cpp @@ -163,6 +163,8 @@ void QmlFontLoader::setName(const QString &name) return; d->name = name; emit nameChanged(); + d->status = Ready; + emit statusChanged(); } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicstext.cpp b/src/declarative/graphicsitems/qmlgraphicstext.cpp index 6790923..d640fc9 100644 --- a/src/declarative/graphicsitems/qmlgraphicstext.cpp +++ b/src/declarative/graphicsitems/qmlgraphicstext.cpp @@ -534,7 +534,7 @@ void QmlGraphicsTextPrivate::updateSize() void QmlGraphicsTextPrivate::drawOutline() { - QPixmap img = QPixmap(imgCache.size()); + QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2); img.fill(Qt::transparent); QPainter ppm(&img); @@ -558,7 +558,7 @@ void QmlGraphicsTextPrivate::drawOutline() void QmlGraphicsTextPrivate::drawOutline(int yOffset) { - QPixmap img = QPixmap(imgCache.size()); + QPixmap img = QPixmap(imgStyleCache.width()+2,imgStyleCache.height()+2); img.fill(Qt::transparent); QPainter ppm(&img); diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 686c0da..80b2458 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -617,6 +617,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -654,6 +656,8 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) this, SLOT(_q_rowsRemoved(const QModelIndex &,int,int))); QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), this, SLOT(_q_dataChanged(const QModelIndex&,const QModelIndex&))); + QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), + this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); return; } if ((d->m_visualItemModel = qvariant_cast<QmlGraphicsVisualDataModel *>(model))) { @@ -978,9 +982,10 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) for (QHash<int,QmlGraphicsVisualDataModelPrivate::ObjectRef>::Iterator iter = d->m_cache.begin(); iter != d->m_cache.end(); ) { + int diff = from > to ? count : -count; if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) { QmlGraphicsVisualDataModelPrivate::ObjectRef objRef = *iter; - int index = iter.key() + from - to; + int index = iter.key() + diff; iter = d->m_cache.erase(iter); items.insert(index, objRef); @@ -996,20 +1001,35 @@ void QmlGraphicsVisualDataModel::_q_itemsMoved(int from, int to, int count) emit itemsMoved(from, to, count); } -void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsInserted(const QModelIndex &parent, int begin, int end) { - _q_itemsInserted(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsInserted(begin, end - begin + 1); } -void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &, int begin, int end) +void QmlGraphicsVisualDataModel::_q_rowsRemoved(const QModelIndex &parent, int begin, int end) { - _q_itemsRemoved(begin, end - begin + 1); + if (!parent.isValid()) + _q_itemsRemoved(begin, end - begin + 1); +} + +void QmlGraphicsVisualDataModel::_q_rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) +{ + const int count = sourceEnd - sourceStart + 1; + if (!destinationParent.isValid() && !sourceParent.isValid()) { + _q_itemsMoved(sourceStart, destinationRow, count); + } else if (!sourceParent.isValid()) { + _q_itemsRemoved(sourceStart, count); + } else if (!destinationParent.isValid()) { + _q_itemsInserted(destinationRow, count); + } } void QmlGraphicsVisualDataModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end) { Q_D(QmlGraphicsVisualDataModel); - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); + if (!begin.parent().isValid()) + _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles); } void QmlGraphicsVisualDataModel::_q_createdPackage(int index, QmlPackage *package) diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h index 8b0a8f5..3ff2a74 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel_p.h @@ -183,6 +183,7 @@ private Q_SLOTS: void _q_itemsMoved(int from, int to, int count); void _q_rowsInserted(const QModelIndex &,int,int); void _q_rowsRemoved(const QModelIndex &,int,int); + void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int); void _q_dataChanged(const QModelIndex&,const QModelIndex&); void _q_createdPackage(int index, QmlPackage *package); void _q_destroyingPackage(QmlPackage *package); diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 6978b6c..1aad385 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -958,6 +958,8 @@ QString QTextDocument::defaultStyleSheet() const /*! Returns true if undo is available; otherwise returns false. + + \sa isRedoAvailable(), availableUndoSteps() */ bool QTextDocument::isUndoAvailable() const { @@ -967,6 +969,8 @@ bool QTextDocument::isUndoAvailable() const /*! Returns true if redo is available; otherwise returns false. + + \sa isUndoAvailable(), availableRedoSteps() */ bool QTextDocument::isRedoAvailable() const { @@ -974,6 +978,29 @@ bool QTextDocument::isRedoAvailable() const return d->isRedoAvailable(); } +/*! \since 4.6 + + Returns the number of available undo steps. + + \sa isUndoAvailable() +*/ +int QTextDocument::availableUndoSteps() const +{ + Q_D(const QTextDocument); + return d->availableUndoSteps(); +} + +/*! \since 4.6 + + Returns the number of available redo steps. + + \sa isRedoAvailable() +*/ +int QTextDocument::availableRedoSteps() const +{ + Q_D(const QTextDocument); + return d->availableRedoSteps(); +} /*! \since 4.4 diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index e52716a..d217a4d 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -142,6 +142,9 @@ public: bool isUndoAvailable() const; bool isRedoAvailable() const; + int availableUndoSteps() const; + int availableRedoSteps() const; + int revision() const; void setDocumentLayout(QAbstractTextDocumentLayout *layout); diff --git a/src/gui/text/qtextdocument_p.h b/src/gui/text/qtextdocument_p.h index ce25c57..c10855b 100644 --- a/src/gui/text/qtextdocument_p.h +++ b/src/gui/text/qtextdocument_p.h @@ -212,6 +212,9 @@ public: inline bool isUndoAvailable() const { return undoEnabled && undoState > 0; } inline bool isRedoAvailable() const { return undoEnabled && undoState < undoStack.size(); } + inline int availableUndoSteps() const { return undoEnabled ? undoState : 0; } + inline int availableRedoSteps() const { return undoEnabled ? qMax(undoStack.size() - undoState - 1, 0) : 0; } + inline QString buffer() const { return text; } QString plainText() const; inline int length() const { return fragments.length(); } diff --git a/tests/auto/declarative/animatedimage/data/stickman.qml b/tests/auto/declarative/animatedimage/data/stickman.qml new file mode 100644 index 0000000..a70db5d --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickman.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" +} diff --git a/tests/auto/declarative/animatedimage/data/stickmanpause.qml b/tests/auto/declarative/animatedimage/data/stickmanpause.qml new file mode 100644 index 0000000..7ab17d4 --- /dev/null +++ b/tests/auto/declarative/animatedimage/data/stickmanpause.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +AnimatedImage { + source: "stickman.gif" + paused: true + currentFrame: 2 +} diff --git a/tests/auto/declarative/behaviors/tst_behaviors.cpp b/tests/auto/declarative/behaviors/tst_behaviors.cpp index 29c631d..da910d9 100644 --- a/tests/auto/declarative/behaviors/tst_behaviors.cpp +++ b/tests/auto/declarative/behaviors/tst_behaviors.cpp @@ -225,11 +225,9 @@ void tst_behaviors::reassignedAnimation() QTest::ignoreMessage(QtWarningMsg, "QML QmlBehavior (file://" SRCDIR "/data/reassignedAnimation.qml:9:12) Can't change the animation assigned to a Behavior."); QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle*>(c.create()); QVERIFY(rect); - - rect->setState("moved"); - QTest::qWait(200 + 100); - qreal x = qobject_cast<QmlGraphicsRectangle*>(rect->findChild<QmlGraphicsRectangle*>("MyRect"))->x(); - QCOMPARE(x, qreal(200)); //i.e. the right behavior has been triggered + QCOMPARE(qobject_cast<QmlNumberAnimation*>( + qobject_cast<QmlBehavior*>( + rect->findChild<QmlBehavior*>("MyBehavior"))->animation())->duration(), 200); } QTEST_MAIN(tst_behaviors) diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index 73269e1..321e91b 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -19,6 +19,8 @@ SUBDIRS += anchors \ qmldom \ qmlecmascript \ qmlgraphicstext \ + qmlgraphicsborderimage \ + qmlfontloader \ qmllanguage \ qmllist \ qmllistaccessor \ diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml index 9039b55..b7b838b 100644 --- a/tests/auto/declarative/listview/data/listview.qml +++ b/tests/auto/declarative/listview/data/listview.qml @@ -6,7 +6,7 @@ Rectangle { color: "#ffffff" resources: [ Component { - id: Delegate + id: myDelegate Rectangle { id: wrapper objectName: "wrapper" @@ -41,6 +41,6 @@ Rectangle { width: 240 height: 320 model: testModel - delegate: Delegate + delegate: myDelegate } } diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 42d4900..441138b 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -66,11 +66,15 @@ private slots: void qListModelInterface_removed(); void qAbstractItemModel_removed(); + void qListModelInterface_moved(); + void qAbstractItemModel_moved(); + private: template <class T> void items(); template <class T> void changed(); template <class T> void inserted(); template <class T> void removed(); + template <class T> void moved(); QmlView *createView(const QString &filename); template<typename T> T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); @@ -140,6 +144,11 @@ public: emit itemsRemoved(index, 1); } + void moveItem(int from, int to) { + list.move(from, to); + emit itemsMoved(from, to, 1); + } + void modifyItem(int index, const QString &name, const QString &number) { list[index] = QPair<QString,QString>(name, number); emit itemsChanged(index, 1, roles()); @@ -195,6 +204,12 @@ public: emit endRemoveRows(); } + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + void modifyItem(int idx, const QString &name, const QString &number) { list[idx] = QPair<QString,QString>(name, number); emit dataChanged(index(idx,0), index(idx,0)); @@ -454,6 +469,100 @@ void tst_QmlGraphicsListView::removed() delete canvas; } +template <class T> +void tst_QmlGraphicsListView::moved() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.moveItem(1, 4); + + // let transitions settle. + QTest::qWait(1000); + + QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem<QmlGraphicsText>(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + name = findItem<QmlGraphicsText>(viewport, "textName", 4); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(4)); + number = findItem<QmlGraphicsText>(viewport, "textNumber", 4); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(4)); + + // Confirm items positioned correctly + int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setViewportY(80); + + // move outside visible area + model.moveItem(1, 18); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem<QmlGraphicsText>(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem<QmlGraphicsText>(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + // move from outside visible into visible + model.moveItem(20, 4); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem<QmlGraphicsText>(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem<QmlGraphicsText>(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items<TestModel>(); @@ -494,6 +603,17 @@ void tst_QmlGraphicsListView::qAbstractItemModel_removed() removed<TestModel2>(); } +void tst_QmlGraphicsListView::qListModelInterface_moved() +{ + moved<TestModel>(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_moved() +{ + moved<TestModel2>(); +} + + QmlView *tst_QmlGraphicsListView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); diff --git a/tests/auto/declarative/qmlfontloader/data/dummy.ttf b/tests/auto/declarative/qmlfontloader/data/dummy.ttf new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/auto/declarative/qmlfontloader/data/dummy.ttf diff --git a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro index 0ecfde0..bc89639 100644 --- a/tests/auto/declarative/qmlfontloader/qmlfontloader.pro +++ b/tests/auto/declarative/qmlfontloader/qmlfontloader.pro @@ -3,3 +3,6 @@ contains(QT_CONFIG,declarative): QT += declarative gui macx:CONFIG -= app_bundle SOURCES += tst_qmlfontloader.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp index 464ae5d..efc86cd 100644 --- a/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp +++ b/tests/auto/declarative/qmlfontloader/tst_qmlfontloader.cpp @@ -52,10 +52,12 @@ public: tst_qmlfontloader(); private slots: - void nofont(); - void namedfont(); - void localfont(); - void webfont(); + void noFont(); + void namedFont(); + void localFont(); + void failLocalFont(); + void webFont(); + void failWebFont(); private slots: @@ -67,7 +69,7 @@ tst_qmlfontloader::tst_qmlfontloader() { } -void tst_qmlfontloader::nofont() +void tst_qmlfontloader::noFont() { QString componentStr = "import Qt 4.6\nFontLoader { }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -75,9 +77,12 @@ void tst_qmlfontloader::nofont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Null); + + delete fontObject; } -void tst_qmlfontloader::namedfont() +void tst_qmlfontloader::namedFont() { QString componentStr = "import Qt 4.6\nFontLoader { name: \"Helvetica\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -85,19 +90,32 @@ void tst_qmlfontloader::namedfont() QVERIFY(fontObject != 0); QCOMPARE(fontObject->name(), QString("Helvetica")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); +} + +void tst_qmlfontloader::localFont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/Fontin-Bold.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("Fontin")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); } -void tst_qmlfontloader::localfont() +void tst_qmlfontloader::failLocalFont() { - QString componentStr = "import Qt 4.6\nFontLoader { source: \"data/Fontin-Bold.ttf\" }"; + QString componentStr = "import Qt 4.6\nFontLoader { source: \"" SRCDIR "/data/dummy.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create()); QVERIFY(fontObject != 0); - QCOMPARE(fontObject->name(), QString("Fontin")); + QTRY_COMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } -void tst_qmlfontloader::webfont() +void tst_qmlfontloader::webFont() { QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://www.princexml.com/fonts/steffmann/Starburst.ttf\" }"; QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); @@ -105,6 +123,18 @@ void tst_qmlfontloader::webfont() QVERIFY(fontObject != 0); QTRY_COMPARE(fontObject->name(), QString("Starburst")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Ready); +} + +void tst_qmlfontloader::failWebFont() +{ + QString componentStr = "import Qt 4.6\nFontLoader { source: \"http://wrong.address.com/Starburst.ttf\" }"; + QmlComponent component(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlFontLoader *fontObject = qobject_cast<QmlFontLoader*>(component.create()); + + QVERIFY(fontObject != 0); + QTRY_COMPARE(fontObject->name(), QString("")); + QTRY_VERIFY(fontObject->status() == QmlFontLoader::Error); } QTEST_MAIN(tst_qmlfontloader) 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 Binary files differnew file mode 100644 index 0000000..dfb62f3 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsborderimage/data/colors.png 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 <qtest.h> +#include <QTextDocument> +#include <QtDeclarative/qmlengine.h> +#include <QtDeclarative/qmlcomponent.h> +#include <private/qmlgraphicsborderimage_p.h> +#include <private/qmlgraphicsimagebase_p.h> +#include <private/qmlgraphicsscalegrid_p_p.h> + +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<QmlGraphicsBorderImage*>(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<QmlGraphicsBorderImage*>(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<QmlGraphicsBorderImage*>(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<QmlGraphicsBorderImage*>(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<QmlGraphicsBorderImage*>(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<QmlGraphicsBorderImage*>(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" diff --git a/tests/auto/declarative/qmlgraphicsparticles/data/particle.png b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png Binary files differnew file mode 100644 index 0000000..defbde5 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsparticles/data/particle.png 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 <QtTest/QtTest> +#include <qmlview.h> +#include <private/qmlgraphicsparticles_p.h> + +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<QmlGraphicsParticles*>("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<QmlGraphicsParticles*>("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" diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index d53de59..b9c12ee 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -57,6 +57,7 @@ private slots: void width(); void wrap(); void elide(); + void textFormat(); // ### these tests may be trivial void horizontalAlignment(); @@ -145,6 +146,9 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), QString("")); + QVERIFY(textObject->width() == 0); + + delete textObject; } for (int i = 0; i < standard.size(); i++) @@ -155,6 +159,7 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QCOMPARE(textObject->text(), standard.at(i)); + QVERIFY(textObject->width() > 0); } for (int i = 0; i < richText.size(); i++) @@ -166,6 +171,7 @@ void tst_qmlgraphicstext::text() QVERIFY(textObject != 0); QString expected = richText.at(i); QCOMPARE(textObject->text(), expected.replace("\\\"", "\"")); + QVERIFY(textObject->width() > 0); } } @@ -176,6 +182,7 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"\" }", QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 0.); } @@ -189,7 +196,9 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), qreal(metricWidth)); + QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText); } for (int i = 0; i < richText.size(); i++) @@ -204,7 +213,9 @@ void tst_qmlgraphicstext::width() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), qreal(documentWidth)); + QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText); } } @@ -217,6 +228,8 @@ void tst_qmlgraphicstext::wrap() QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); textHeight = textObject->height(); + QVERIFY(textObject != 0); + QVERIFY(textObject->wrap() == true); QCOMPARE(textObject->width(), 300.); } @@ -226,6 +239,7 @@ void tst_qmlgraphicstext::wrap() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); } @@ -236,6 +250,7 @@ void tst_qmlgraphicstext::wrap() QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); } @@ -246,38 +261,56 @@ void tst_qmlgraphicstext::elide() { for (Qt::TextElideMode m = Qt::ElideLeft; m<=Qt::ElideNone; m=Qt::TextElideMode(int(m)+1)) { const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"}; - QString elide = "elide: \""+QString(elidename[int(m)])+"\";"; + QString elide = "elide: Text." + QString(elidename[int(m)]) + ";"; // XXX Poor coverage. { - QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 300 }").toLatin1(), QUrl("file://")); + QmlComponent textComponent(&engine, ("import Qt 4.6\nText { text: \"\"; "+elide+" width: 100 }").toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + standard.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } // richtext - does nothing for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nText { "+elide+" width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nText { "+elide+" width: 100; text: \"" + richText.at(i) + "\" }"; QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); - QCOMPARE(textObject->width(), 300.); + QCOMPARE(textObject->width(), 100.); } } } +void tst_qmlgraphicstext::textFormat() +{ + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"Hello\"; textFormat: Text.RichText }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + + QVERIFY(textObject != 0); + QVERIFY(textObject->textFormat() == QmlGraphicsText::RichText); + } + { + QmlComponent textComponent(&engine, "import Qt 4.6\nText { text: \"<b>Hello</b>\"; textFormat: Text.PlainText }", QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + + QVERIFY(textObject != 0); + QVERIFY(textObject->textFormat() == QmlGraphicsText::PlainText); + } +} + //the alignment tests may be trivial o.oa void tst_qmlgraphicstext::horizontalAlignment() { diff --git a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp index a7211bd..9be77e8 100644 --- a/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp +++ b/tests/auto/declarative/qmlpropertymap/tst_qmlpropertymap.cpp @@ -55,6 +55,7 @@ public: private slots: void insert(); void operatorInsert(); + void operatorValue(); void clear(); void changed(); void count(); @@ -66,6 +67,7 @@ void tst_QmlPropertyMap::insert() map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); QVERIFY(map.keys().count() == 2); + QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); @@ -88,6 +90,20 @@ void tst_QmlPropertyMap::operatorInsert() QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); } +void tst_QmlPropertyMap::operatorValue() +{ + QmlPropertyMap map; + map.insert(QLatin1String("key1"),100); + map.insert(QLatin1String("key2"),200); + QVERIFY(map.keys().count() == 2); + QVERIFY(map.contains(QLatin1String("key1"))); + + QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); + QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); + QCOMPARE(map[QLatin1String("key1")], map.value(QLatin1String("key1"))); + QCOMPARE(map[QLatin1String("key2")], map.value(QLatin1String("key2"))); +} + void tst_QmlPropertyMap::clear() { QmlPropertyMap map; @@ -98,6 +114,7 @@ void tst_QmlPropertyMap::clear() map.clear(QLatin1String("key1")); QVERIFY(map.keys().count() == 1); + QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant()); } @@ -143,6 +160,7 @@ void tst_QmlPropertyMap::count() //clearing doesn't remove the key map.clear(QLatin1String("key3")); QCOMPARE(map.count(), 3); + QCOMPARE(map.size(), map.count()); } QTEST_MAIN(tst_QmlPropertyMap) |