diff options
author | Yann Bodson <yann.bodson@nokia.com> | 2009-11-06 05:34:03 (GMT) |
---|---|---|
committer | Yann Bodson <yann.bodson@nokia.com> | 2009-11-06 05:34:03 (GMT) |
commit | 43d005442b66612bc4a16362c09a3e31f519d46c (patch) | |
tree | b54858ca861a555947bb172721e7f6fa416e39a7 /tests | |
parent | 8d8315df292482d75148a435b9e2bcc4636c57a3 (diff) | |
parent | 3a051866fb139afa08fcf1a0c17a171bce567480 (diff) | |
download | Qt-43d005442b66612bc4a16362c09a3e31f519d46c.zip Qt-43d005442b66612bc4a16362c09a3e31f519d46c.tar.gz Qt-43d005442b66612bc4a16362c09a3e31f519d46c.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'tests')
3 files changed, 97 insertions, 0 deletions
diff --git a/tests/auto/declarative/qmlgraphicsitem/data/keynavigation.qml b/tests/auto/declarative/qmlgraphicsitem/data/keynavigation.qml new file mode 100644 index 0000000..9281a17 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsitem/data/keynavigation.qml @@ -0,0 +1,39 @@ +import Qt 4.6 + +Grid { + columns: 2 + width: 100; height: 100 + Rectangle { + id: item1 + objectName: "item1" + focus: true + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.right: item2 + KeyNavigation.down: item3 + } + Rectangle { + id: item2 + objectName: "item2" + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.left: item1 + KeyNavigation.down: item4 + } + Rectangle { + id: item3 + objectName: "item3" + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.right: item4 + KeyNavigation.up: item1 + } + Rectangle { + id: item4 + objectName: "item4" + width: 50; height: 50 + color: focus ? "red" : "lightgray" + KeyNavigation.left: item3 + KeyNavigation.up: item2 + } +} diff --git a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp index b3b5374..b4b3eaf 100644 --- a/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp +++ b/tests/auto/declarative/qmlgraphicsitem/tst_qmlgraphicsitem.cpp @@ -213,6 +213,9 @@ void tst_QmlGraphicsItem::keyNavigation() template<typename T> T *tst_QmlGraphicsItem::findItem(QmlGraphicsItem *parent, const QString &objectName) { + if (!parent) + return 0; + const QMetaObject &mo = T::staticMetaObject; //qDebug() << parent->QGraphicsObject::children().count() << "children"; for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) { diff --git a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp index 2a3cdde..1e10873 100644 --- a/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp +++ b/tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp @@ -45,6 +45,7 @@ #include <private/qmlgraphicstext_p.h> #include <private/qmlvaluetype_p.h> #include <QFontMetrics> +#include <QGraphicsSceneMouseEvent> #include <math.h> class tst_qmlgraphicstext : public QObject @@ -78,6 +79,8 @@ private slots: void letterSpacing(); void wordSpacing(); + void clickLink(); + private: QStringList standard; QStringList richText; @@ -258,6 +261,10 @@ void tst_qmlgraphicstext::wrap() QVERIFY(textObject != 0); QCOMPARE(textObject->width(), 30.); QVERIFY(textObject->height() > textHeight); + + int oldHeight = textObject->height(); + textObject->setWidth(100); + QVERIFY(textObject->height() < oldHeight); } for (int i = 0; i < richText.size(); i++) @@ -730,6 +737,54 @@ void tst_qmlgraphicstext::wordSpacing() } } +class EventSender : public QGraphicsItem +{ +public: + void sendEvent(QEvent *event) { sceneEvent(event); } +}; + +class LinkTest : public QObject +{ + Q_OBJECT +public: + LinkTest() {} + + QString link; + +public slots: + void linkClicked(QString l) { link = l; } +}; + +void tst_qmlgraphicstext::clickLink() +{ + { + QString componentStr = "import Qt 4.6\nText { text: \"<a href=\\\"http://qt.nokia.com\\\">Hello world!</a>\" }"; + QmlComponent textComponent(&engine, componentStr.toLatin1(), QUrl("file://")); + QmlGraphicsText *textObject = qobject_cast<QmlGraphicsText*>(textComponent.create()); + + QVERIFY(textObject != 0); + + LinkTest test; + QObject::connect(textObject, SIGNAL(linkActivated(QString)), &test, SLOT(linkClicked(QString))); + + { + QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMousePress); + me.setPos(QPointF(textObject->x()/2, textObject->y()/2)); + me.setButton(Qt::LeftButton); + static_cast<EventSender*>(static_cast<QGraphicsItem*>(textObject))->sendEvent(&me); + } + + { + QGraphicsSceneMouseEvent me(QEvent::GraphicsSceneMouseRelease); + me.setPos(QPointF(textObject->x()/2, textObject->y()/2)); + me.setButton(Qt::LeftButton); + static_cast<EventSender*>(static_cast<QGraphicsItem*>(textObject))->sendEvent(&me); + } + + QCOMPARE(test.link, QLatin1String("http://qt.nokia.com")); + } +} + QTEST_MAIN(tst_qmlgraphicstext) #include "tst_qmlgraphicstext.moc" |