Fix auto-repeat key navigation for GridView
authorBea Lam <bea.lam@nokia.com>
Thu, 28 Jul 2011 06:10:46 +0000 (16:10 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 28 Jul 2011 08:04:08 +0000 (10:04 +0200)
Shouldn't set moveReason=SetIndex in key navigation. ListView didn't
do this in its keyPress implementation.

Added extra tests for GridView and ListView.

Task-number: QTBUG-20408
Change-Id: Iaf0f331d3ba4f037c5bbc0a41418dd656b5a3695
Reviewed-on: http://codereview.qt.nokia.com/2318
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/items/qsggridview.cpp
tests/auto/declarative/qsggridview/tst_qsggridview.cpp
tests/auto/declarative/qsglistview/tst_qsglistview.cpp

index 7b0e4f3..26347c1 100644 (file)
@@ -1161,7 +1161,6 @@ void QSGGridView::keyPressEvent(QKeyEvent *event)
             return;
         }
     }
-    d->moveReason = QSGGridViewPrivate::Other;
     event->ignore();
     QSGItemView::keyPressEvent(event);
 }
index 9a401f6..e7dce4c 100644 (file)
@@ -895,6 +895,25 @@ void tst_QSGGridView::currentIndex()
     QTest::keyClick(canvas, Qt::Key_Up);
     QCOMPARE(gridview->currentIndex(), 0);
 
+    // hold down Key_Down
+    for (int i=0; i<(model.count() / 3) - 1; i++) {
+        QTest::simulateEvent(canvas, true, Qt::Key_Down, Qt::NoModifier, "", true);
+        QTRY_COMPARE(gridview->currentIndex(), i*3 + 3);
+    }
+    QTest::keyRelease(canvas, Qt::Key_Down);
+    QTRY_COMPARE(gridview->currentIndex(), 57);
+    QTRY_COMPARE(gridview->contentY(), 880.0);
+
+    // hold down Key_Up
+    for (int i=(model.count() / 3) - 1; i > 0; i--) {
+        QTest::simulateEvent(canvas, true, Qt::Key_Up, Qt::NoModifier, "", true);
+        QTRY_COMPARE(gridview->currentIndex(), i*3 - 3);
+    }
+    QTest::keyRelease(canvas, Qt::Key_Up);
+    QTRY_COMPARE(gridview->currentIndex(), 0);
+    QTRY_COMPARE(gridview->contentY(), 0.0);
+
+
     gridview->setFlow(QSGGridView::TopToBottom);
 
     qApp->setActiveWindow(canvas);
@@ -917,6 +936,24 @@ void tst_QSGGridView::currentIndex()
     QTest::keyClick(canvas, Qt::Key_Up);
     QCOMPARE(gridview->currentIndex(), 0);
 
+    // hold down Key_Right
+    for (int i=0; i<(model.count() / 5) - 1; i++) {
+        QTest::simulateEvent(canvas, true, Qt::Key_Right, Qt::NoModifier, "", true);
+        QTRY_COMPARE(gridview->currentIndex(), i*5 + 5);
+    }
+    QTest::keyRelease(canvas, Qt::Key_Right);
+    QTRY_COMPARE(gridview->currentIndex(), 55);
+    QTRY_COMPARE(gridview->contentX(), 720.0);
+
+    // hold down Key_Left
+    for (int i=(model.count() / 5) - 1; i > 0; i--) {
+        QTest::simulateEvent(canvas, true, Qt::Key_Left, Qt::NoModifier, "", true);
+        QTRY_COMPARE(gridview->currentIndex(), i*5 - 5);
+    }
+    QTest::keyRelease(canvas, Qt::Key_Left);
+    QTRY_COMPARE(gridview->currentIndex(), 0);
+    QTRY_COMPARE(gridview->contentX(), 0.0);
+
 
     // turn off auto highlight
     gridview->setHighlightFollowsCurrentItem(false);
index 43efea2..5ee13e8 100644 (file)
@@ -1447,6 +1447,25 @@ void tst_QSGListView::currentIndex()
     QTest::keyClick(canvas, Qt::Key_Up);
     QCOMPARE(listview->currentIndex(), 0);
 
+    // hold down Key_Down
+    for (int i=0; i<model.count()-1; i++) {
+        QTest::simulateEvent(canvas, true, Qt::Key_Down, Qt::NoModifier, "", true);
+        QTRY_COMPARE(listview->currentIndex(), i+1);
+    }
+    QTest::keyRelease(canvas, Qt::Key_Down);
+    QTRY_COMPARE(listview->currentIndex(), model.count()-1);
+    QTRY_COMPARE(listview->contentY(), 280.0);
+
+    // hold down Key_Up
+    for (int i=model.count()-1; i > 0; i--) {
+        QTest::simulateEvent(canvas, true, Qt::Key_Up, Qt::NoModifier, "", true);
+        QTRY_COMPARE(listview->currentIndex(), i-1);
+    }
+    QTest::keyRelease(canvas, Qt::Key_Up);
+    QTRY_COMPARE(listview->currentIndex(), 0);
+    QTRY_COMPARE(listview->contentY(), 0.0);
+
+
     // turn off auto highlight
     listview->setHighlightFollowsCurrentItem(false);
     QVERIFY(listview->highlightFollowsCurrentItem() == false);