aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickgridview
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@theqtcompany.com>2015-11-25 16:37:12 +0100
committerMitch Curtis <mitch.curtis@theqtcompany.com>2015-12-08 09:40:54 +0000
commit52954268e9202e33eb8c2db93a51d55a2596051b (patch)
treea803a43285bfdf8a30ab9c606fcf789891a7170f /tests/auto/quick/qquickgridview
parentd1fbfbbab7f78e0a1050acce3540c02660a0d68f (diff)
GridView: add keyNavigationEnabled property
It is useful for applications that need to selectively enable or disable mouse and keyboard interaction. [ChangeLog][QtQuick][GridView] added keyNavigationEnabled property to allow mouse and keyboard interaction to be selectively enabled/disabled. Change-Id: Idba0e00c2f228b79ca4c32d9856f22f7eaea98dd Task-number: QTBUG-17051 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick/qquickgridview')
-rw-r--r--tests/auto/quick/qquickgridview/tst_qquickgridview.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
index 3699bef56d..e8261be675 100644
--- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
@@ -211,6 +211,8 @@ private slots:
void QTBUG_45640();
+ void keyNavigationEnabled();
+
private:
QList<int> toIntList(const QVariantList &list);
void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
@@ -6566,6 +6568,71 @@ void tst_QQuickGridView::QTBUG_45640()
delete window;
}
+void tst_QQuickGridView::keyNavigationEnabled()
+{
+ QScopedPointer<QQuickView> window(createView());
+ window->setSource(testFileUrl("gridview4.qml"));
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
+ QQuickGridView *gridView = qobject_cast<QQuickGridView *>(window->rootObject());
+ QVERIFY(gridView);
+ QCOMPARE(gridView->isKeyNavigationEnabled(), true);
+
+ gridView->setFocus(true);
+ QVERIFY(gridView->hasActiveFocus());
+
+ gridView->setHighlightMoveDuration(0);
+
+ // If keyNavigationEnabled is not explicitly set to true, respect the original behavior
+ // of disabling both mouse and keyboard interaction.
+ QSignalSpy enabledSpy(gridView, SIGNAL(keyNavigationEnabledChanged()));
+ gridView->setInteractive(false);
+ QCOMPARE(enabledSpy.count(), 1);
+ QCOMPARE(gridView->isKeyNavigationEnabled(), false);
+
+ flick(window.data(), QPoint(200, 175), QPoint(200, 50), 100);
+ QVERIFY(!gridView->isMoving());
+ QCOMPARE(gridView->contentY(), 0.0);
+ QCOMPARE(gridView->currentIndex(), 0);
+
+ QTest::keyClick(window.data(), Qt::Key_Right);
+ QCOMPARE(gridView->currentIndex(), 0);
+
+ // Check that isKeyNavigationEnabled implicitly follows the value of interactive.
+ gridView->setInteractive(true);
+ QCOMPARE(enabledSpy.count(), 2);
+ QCOMPARE(gridView->isKeyNavigationEnabled(), true);
+
+ // Change it back again for the next check.
+ gridView->setInteractive(false);
+ QCOMPARE(enabledSpy.count(), 3);
+ QCOMPARE(gridView->isKeyNavigationEnabled(), false);
+
+ // Setting keyNavigationEnabled to true shouldn't enable mouse interaction.
+ gridView->setKeyNavigationEnabled(true);
+ QCOMPARE(enabledSpy.count(), 4);
+ flick(window.data(), QPoint(200, 175), QPoint(200, 50), 100);
+ QVERIFY(!gridView->isMoving());
+ QCOMPARE(gridView->contentY(), 0.0);
+ QCOMPARE(gridView->currentIndex(), 0);
+
+ // Should now work.
+ QTest::keyClick(window.data(), Qt::Key_Right);
+ QCOMPARE(gridView->currentIndex(), 1);
+
+ // Changing interactive now shouldn't result in keyNavigationEnabled changing,
+ // since we broke the "binding".
+ gridView->setInteractive(true);
+ QCOMPARE(enabledSpy.count(), 4);
+
+ // Keyboard interaction shouldn't work now.
+ gridView->setKeyNavigationEnabled(false);
+ QTest::keyClick(window.data(), Qt::Key_Right);
+ QCOMPARE(gridView->currentIndex(), 1);
+}
+
QTEST_MAIN(tst_QQuickGridView)
#include "tst_qquickgridview.moc"