From 43d940fd30ea4728664de393479438f54e888b32 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 28 Jul 2011 16:10:46 +1000 Subject: [PATCH] Fix auto-repeat key navigation for GridView 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 Reviewed-by: Martin Jones --- src/declarative/items/qsggridview.cpp | 1 - .../declarative/qsggridview/tst_qsggridview.cpp | 37 ++++++++++++++++++++++ .../declarative/qsglistview/tst_qsglistview.cpp | 19 +++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index 7b0e4f3..26347c1 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -1161,7 +1161,6 @@ void QSGGridView::keyPressEvent(QKeyEvent *event) return; } } - d->moveReason = QSGGridViewPrivate::Other; event->ignore(); QSGItemView::keyPressEvent(event); } diff --git a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp index 9a401f6..e7dce4c 100644 --- a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp +++ b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp @@ -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); diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp index 43efea2..5ee13e8 100644 --- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp +++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp @@ -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; icurrentIndex(), 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); -- 2.7.4