diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-06 05:03:55 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-06 05:03:55 (GMT) |
commit | 336cfc8ec78977458b485c3da364af7c0890911e (patch) | |
tree | b463e01577765139dbe5ceed0b43d52dee127f67 /tests/auto/declarative/qmlgraphicstext | |
parent | 74d768ec05d5acfa8ef5b65535c908f2935f2783 (diff) | |
download | Qt-336cfc8ec78977458b485c3da364af7c0890911e.zip Qt-336cfc8ec78977458b485c3da364af7c0890911e.tar.gz Qt-336cfc8ec78977458b485c3da364af7c0890911e.tar.bz2 |
More test coverage for Text
Diffstat (limited to 'tests/auto/declarative/qmlgraphicstext')
-rw-r--r-- | tests/auto/declarative/qmlgraphicstext/tst_qmlgraphicstext.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
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" |