diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-09-29 23:11:21 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-09-29 23:11:21 (GMT) |
commit | 4dc235f50a686d40bc63d7108027145f23d2c18a (patch) | |
tree | ce9e90a081c0440092f95d5ee656de0d541386a9 | |
parent | 603f738642891773c46308663fb7733055cf3cdc (diff) | |
parent | 275d62f364da0eee08726d95888bca2a8e0fb6e6 (diff) | |
download | Qt-4dc235f50a686d40bc63d7108027145f23d2c18a.zip Qt-4dc235f50a686d40bc63d7108027145f23d2c18a.tar.gz Qt-4dc235f50a686d40bc63d7108027145f23d2c18a.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r-- | tests/auto/declarative/qfxtextedit/data/navigation.qml | 23 | ||||
-rw-r--r-- | tests/auto/declarative/qfxtextedit/qfxtextedit.pro | 3 | ||||
-rw-r--r-- | tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp | 56 |
3 files changed, 81 insertions, 1 deletions
diff --git a/tests/auto/declarative/qfxtextedit/data/navigation.qml b/tests/auto/declarative/qfxtextedit/data/navigation.qml new file mode 100644 index 0000000..5b8613f --- /dev/null +++ b/tests/auto/declarative/qfxtextedit/data/navigation.qml @@ -0,0 +1,23 @@ +import Qt 4.6 + +Rectangle { + property var myInput: Input + + width: 800; height: 600; color: "blue" + + Item { + id: FirstItem; + KeyNavigation.right: Input + } + + TextEdit { id: Input; focus: true + KeyNavigation.left: FirstItem + KeyNavigation.right: LastItem + KeyNavigation.up: FirstItem + KeyNavigation.down: LastItem + } + Item { + id: LastItem + KeyNavigation.left: Input + } +} diff --git a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro index 59ab6e5..90546a4 100644 --- a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro +++ b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro @@ -1,3 +1,6 @@ load(qttest_p4) contains(QT_CONFIG,declarative): QT += declarative gui SOURCES += tst_qfxtextedit.cpp + +# Define SRCDIR equal to test's source directory +DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp index e38e0e7..7ab598f 100644 --- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp +++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp @@ -1,4 +1,6 @@ #include <qtest.h> +#include "../../../shared/util.h" +#include <QFile> #include <QTextDocument> #include <QtDeclarative/qmlengine.h> #include <QtDeclarative/qmlcontext.h> @@ -6,6 +8,7 @@ #include <QtDeclarative/qmlcomponent.h> #include <QtDeclarative/qfxtextedit.h> #include <QFontMetrics> +#include <QmlView> class tst_qfxtextedit : public QObject @@ -27,8 +30,12 @@ private slots: void selection(); void cursorDelegate(); + void navigation(); private: + void simulateKey(QmlView *, int key); + QmlView *createView(const QString &filename); + QStringList standard; QStringList richText; @@ -424,7 +431,6 @@ void tst_qfxtextedit::selection() QVERIFY(textEditObject->selectedText().size() == 10); } -#include <QmlView> void tst_qfxtextedit::cursorDelegate() { QmlView* view = new QmlView(0); @@ -452,6 +458,54 @@ void tst_qfxtextedit::cursorDelegate() QVERIFY(!textEditObject->findChild<QFxItem*>("cursorInstance")); } +/* +TextEdit element should only handle left/right keys until the cursor reaches +the extent of the text, then they should ignore the keys. +*/ +void tst_qfxtextedit::navigation() +{ + QmlView *canvas = createView(SRCDIR "/data/navigation.qml"); + canvas->execute(); + canvas->show(); + + QVERIFY(canvas->root() != 0); + + QFxItem *input = qobject_cast<QFxItem *>(qvariant_cast<QObject *>(canvas->root()->property("myInput"))); + + QVERIFY(input != 0); + QTRY_VERIFY(input->hasFocus() == true); + simulateKey(canvas, Qt::Key_Left); + QVERIFY(input->hasFocus() == false); + simulateKey(canvas, Qt::Key_Right); + QVERIFY(input->hasFocus() == true); + simulateKey(canvas, Qt::Key_Right); + QVERIFY(input->hasFocus() == false); + simulateKey(canvas, Qt::Key_Left); + QVERIFY(input->hasFocus() == true); +} + +void tst_qfxtextedit::simulateKey(QmlView *view, int key) +{ + QKeyEvent press(QKeyEvent::KeyPress, key, 0); + QKeyEvent release(QKeyEvent::KeyRelease, key, 0); + + QApplication::sendEvent(view, &press); + QApplication::sendEvent(view, &release); +} + +QmlView *tst_qfxtextedit::createView(const QString &filename) +{ + QmlView *canvas = new QmlView(0); + + QFile file(filename); + file.open(QFile::ReadOnly); + QString xml = file.readAll(); + canvas->setQml(xml, filename); + + return canvas; +} + + QTEST_MAIN(tst_qfxtextedit) #include "tst_qfxtextedit.moc" |