From e377de4c7a00e8306142300f0786d96013cb9ad1 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 29 Sep 2009 15:21:37 +1000 Subject: Another focusscope test --- examples/declarative/focusscope/test4.qml | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 examples/declarative/focusscope/test4.qml diff --git a/examples/declarative/focusscope/test4.qml b/examples/declarative/focusscope/test4.qml new file mode 100644 index 0000000..dee2c9f --- /dev/null +++ b/examples/declarative/focusscope/test4.qml @@ -0,0 +1,75 @@ +import Qt 4.6 + +Rectangle { + color: "white" + width: 800 + height: 600 + + Keys.onDigit9Pressed: print("Success - Root") + + FocusScope { + id: MyScope + + Keys.onDigit9Pressed: print("Error - FocusScope") + + Rectangle { + height: 120 + width: 420 + + color: "transparent" + border.width: 5 + border.color: MyScope.wantsFocus?"blue":"black" + + Rectangle { + id: Item1 + x: 10; y: 10 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: wantsFocus?"blue":"black" + Keys.onDigit9Pressed: print("Error - Top Left"); + KeyNavigation.right: Item2 + focus: true + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + + Rectangle { + id: Item2 + x: 310; y: 10 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: wantsFocus?"blue":"black" + KeyNavigation.left: Item1 + Keys.onDigit9Pressed: print("Error - Top Right"); + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + } + KeyNavigation.down: Item3 + } + + Text { x:100; y:170; text: "There should be no blue borders, or red squares.\nPressing \"9\" should print a success message.\nArrow keys should have no effect." } + + Rectangle { + id: Item3 + x: 10; y: 300 + width: 100; height: 100; color: "green" + border.width: 5 + border.color: wantsFocus?"blue":"black" + + Keys.onDigit9Pressed: print("Error - Bottom Left"); + KeyNavigation.up: MyScope + + Rectangle { + width: 50; height: 50; anchors.centerIn: parent + color: parent.focus?"red":"transparent" + } + } + +} -- cgit v0.12 From 26afe9477e9b63d258631c96549de95556f0d97c Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 29 Sep 2009 15:34:22 +1000 Subject: Update test --- examples/declarative/focusscope/test4.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/declarative/focusscope/test4.qml b/examples/declarative/focusscope/test4.qml index dee2c9f..f366543 100644 --- a/examples/declarative/focusscope/test4.qml +++ b/examples/declarative/focusscope/test4.qml @@ -5,7 +5,7 @@ Rectangle { width: 800 height: 600 - Keys.onDigit9Pressed: print("Success - Root") + Keys.onDigit9Pressed: print("Error - Root") FocusScope { id: MyScope @@ -54,7 +54,7 @@ Rectangle { KeyNavigation.down: Item3 } - Text { x:100; y:170; text: "There should be no blue borders, or red squares.\nPressing \"9\" should print a success message.\nArrow keys should have no effect." } + Text { x:100; y:170; text: "There should be no blue borders, or red squares.\nPressing \"9\" should do nothing.\nArrow keys should have no effect." } Rectangle { id: Item3 -- cgit v0.12 From 1d65aff4f6c0339752c92f859ce78f1a59450a28 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 29 Sep 2009 16:10:49 +1000 Subject: Some fixes for ListView key handling. Accept auto repeated keys in wrap mode even at the ends. Allow Keys.onLeftPressed, etc. to override default key handling. --- src/declarative/fx/qfxlistview.cpp | 35 ++++++++++++++++++++++++++++++----- src/declarative/fx/qfxlistview.h | 7 ++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 5de9bf3..3584892 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1339,13 +1339,19 @@ qreal QFxListView::maxXExtent() const void QFxListView::keyPressEvent(QKeyEvent *event) { Q_D(QFxListView); + QFxFlickable::keyPressEvent(event); + if (event->isAccepted()) + return; + if (d->model && d->model->count() && d->interactive) { if ((d->orient == Qt::Horizontal && event->key() == Qt::Key_Left) || (d->orient == Qt::Vertical && event->key() == Qt::Key_Up)) { if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) { d->moveReason = QFxListViewPrivate::Key; - int index = currentIndex()-1; - d->updateCurrent(index >= 0 ? index : d->model->count()-1); + decrementCurrentIndex(); + event->accept(); + return; + } else if (d->wrap) { event->accept(); return; } @@ -1353,8 +1359,10 @@ void QFxListView::keyPressEvent(QKeyEvent *event) || (d->orient == Qt::Vertical && event->key() == Qt::Key_Down)) { if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) { d->moveReason = QFxListViewPrivate::Key; - int index = currentIndex()+1; - d->updateCurrent(index < d->model->count() ? index : 0); + incrementCurrentIndex(); + event->accept(); + return; + } else if (d->wrap) { event->accept(); return; } @@ -1362,7 +1370,24 @@ void QFxListView::keyPressEvent(QKeyEvent *event) } d->moveReason = QFxListViewPrivate::Other; event->ignore(); - QFxFlickable::keyPressEvent(event); +} + +void QFxListView::incrementCurrentIndex() +{ + Q_D(QFxListView); + if (currentIndex() < d->model->count() - 1 || d->wrap) { + int index = currentIndex()+1; + d->updateCurrent(index < d->model->count() ? index : 0); + } +} + +void QFxListView::decrementCurrentIndex() +{ + Q_D(QFxListView); + if (currentIndex() > 0 || d->wrap) { + int index = currentIndex()-1; + d->updateCurrent(index >= 0 ? index : d->model->count()-1); + } } void QFxListView::componentComplete() diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index cc3d910..fc15967 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -50,9 +50,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -//### incrementCurrentIndex(), decrementCurrentIndex() slots -//### default Keys.OnUp/DownPressed handler - class QFxVisualModel; class QFxListViewAttached; @@ -131,6 +128,10 @@ public: static QFxListViewAttached *qmlAttachedProperties(QObject *); +public Q_SLOTS: + void incrementCurrentIndex(); + void decrementCurrentIndex(); + Q_SIGNALS: void countChanged(); void spacingChanged(); -- cgit v0.12 From 275d62f364da0eee08726d95888bca2a8e0fb6e6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 29 Sep 2009 16:34:58 +1000 Subject: TextEdit navigation testcase --- .../declarative/qfxtextedit/data/navigation.qml | 23 +++++++++ tests/auto/declarative/qfxtextedit/qfxtextedit.pro | 3 ++ .../declarative/qfxtextedit/tst_qfxtextedit.cpp | 56 +++++++++++++++++++++- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qfxtextedit/data/navigation.qml 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 +#include "../../../shared/util.h" +#include #include #include #include @@ -6,6 +8,7 @@ #include #include #include +#include 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 void tst_qfxtextedit::cursorDelegate() { QmlView* view = new QmlView(0); @@ -452,6 +458,54 @@ void tst_qfxtextedit::cursorDelegate() QVERIFY(!textEditObject->findChild("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(qvariant_cast(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" -- cgit v0.12 From 603f738642891773c46308663fb7733055cf3cdc Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 30 Sep 2009 09:10:08 +1000 Subject: Make sure the delayed press event is exactly the same as the original. --- src/declarative/fx/qfxflickable.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 5c1cccf..a83ee66 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -744,12 +744,19 @@ void QFxFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event) if (event->buttons() & i) { Qt::MouseButton button = Qt::MouseButton(i); delayedPressEvent->setButtonDownPos(button, event->buttonDownPos(button)); + delayedPressEvent->setButtonDownScenePos(button, event->buttonDownScenePos(button)); + delayedPressEvent->setButtonDownScreenPos(button, event->buttonDownScreenPos(button)); } } - delayedPressEvent->setScenePos(event->scenePos()); - delayedPressEvent->setLastScenePos(event->lastScenePos()); + delayedPressEvent->setButtons(event->buttons()); + delayedPressEvent->setButton(event->button()); delayedPressEvent->setPos(event->pos()); + delayedPressEvent->setScenePos(event->scenePos()); + delayedPressEvent->setScreenPos(event->screenPos()); delayedPressEvent->setLastPos(event->lastPos()); + delayedPressEvent->setLastScenePos(event->lastScenePos()); + delayedPressEvent->setLastScreenPos(event->lastScreenPos()); + delayedPressEvent->setModifiers(event->modifiers()); delayedPressTimer.start(pressDelay, q); } -- cgit v0.12