diff --git a/autotests/tst_listskeynavigation.qml b/autotests/tst_listskeynavigation.qml new file mode 100644 --- /dev/null +++ b/autotests/tst_listskeynavigation.qml @@ -0,0 +1,58 @@ +/* + * Copyright 2016 Aleix Pol Gonzalez + * Copyright 2016 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Window 2.1 +import org.kde.kirigami 2.0 as Kirigami +import QtTest 1.0 +import "../tests" + +TestCase { + id: testCase + width: 400 + height: 400 + when: mainWindow.visible + name: "KeyboardListsNavigation" + + KeyboardListTest { + id: mainWindow + width: 480 + height: 360 + visible: true + } + + SignalSpy { + id: spyActive + target: mainWindow + signalName: "activeChanged" + } + + function test_press() { + compare(mainWindow.pageStack.depth, 1) + compare(mainWindow.pageStack.currentIndex, 0) + if (!mainWindow.active) + spyActive.wait(5000) + verify(mainWindow.active) + compare(mainWindow.pageStack.currentItem.flickable.currentIndex, 0) + keyClick(Qt.Key_Down) + compare(mainWindow.pageStack.currentItem.flickable.currentIndex, 1) + } +} diff --git a/examples/gallery/contents/ui/MainPage.qml b/examples/gallery/contents/ui/MainPage.qml --- a/examples/gallery/contents/ui/MainPage.qml +++ b/examples/gallery/contents/ui/MainPage.qml @@ -59,6 +59,7 @@ ListView { id: mainListView + currentIndex: -1 model: ListModel { ListElement { @@ -129,6 +130,7 @@ ownPage = root.pageStack.push(Qt.resolvedUrl("gallery/" + model.component + "Gallery.qml")); } checked: ownPage && root.pageStack.lastItem == ownPage + highlighted: focus && ListView.isCurrentItem } } } diff --git a/src/controls/AbstractApplicationWindow.qml b/src/controls/AbstractApplicationWindow.qml --- a/src/controls/AbstractApplicationWindow.qml +++ b/src/controls/AbstractApplicationWindow.qml @@ -140,7 +140,7 @@ * To achieve a titlebar that stays completely fixed just set the 3 sizes as the same * //FIXME: this should become an actual ApplicationHeader */ - header: undefined + //header: undefined /** * controlsVisible: bool diff --git a/src/controls/ScrollablePage.qml b/src/controls/ScrollablePage.qml --- a/src/controls/ScrollablePage.qml +++ b/src/controls/ScrollablePage.qml @@ -92,6 +92,16 @@ */ default property QtObject mainItem + /** + * keyboardNavigationEnabled: bool + * If true, and if flickable is an item view, like a ListView or + * a GridView, it will be possible to navigate the list current item + * to next and previous items with keyboard up/down arrow buttons. + * Also, any key event will be forwarded to the current list item. + * default is true. + */ + property bool keyboardNavigationEnabled: true + RefreshableScrollView { id: scrollView z: 0 @@ -109,6 +119,17 @@ anchors.topMargin: 0 + Keys.onUpPressed: { + if (root.keyboardNavigationEnabled && root.flickable.decrementCurrentIndex) { + root.flickable.decrementCurrentIndex() + } + } + Keys.onDownPressed: { + if (root.keyboardNavigationEnabled && root.flickable.incrementCurrentIndex) { + root.flickable.incrementCurrentIndex() + } + } + Keys.forwardTo: root.keyboardNavigationEnabled && ("currentItem" in root.flickable) ? [ root.flickable.currentItem ] : [] Item { id: overlay parent: root diff --git a/src/styles/Desktop/OverlayDrawer.qml b/src/styles/Desktop/OverlayDrawer.qml --- a/src/styles/Desktop/OverlayDrawer.qml +++ b/src/styles/Desktop/OverlayDrawer.qml @@ -118,6 +118,7 @@ } } + focus: false //default to a sidebar in desktop mode modal: edge == Qt.TopEdge || edge == Qt.BottomEdge drawerOpen: true diff --git a/tests/KeyboardListTest.qml b/tests/KeyboardListTest.qml new file mode 100644 --- /dev/null +++ b/tests/KeyboardListTest.qml @@ -0,0 +1,45 @@ +/* + * Copyright 2016 Aleix Pol Gonzalez + * Copyright 2016 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import org.kde.kirigami 2.0 as Kirigami + +Kirigami.ApplicationWindow +{ + id: main + Component { + id: keyPage + Kirigami.ScrollablePage { + ListView { + model: 10 + delegate: Rectangle { + width: 100 + height: 30 + color: ListView.isCurrentItem ? "red" : "white" + } + } + } + } + + Component.onCompleted: { + main.pageStack.push(keyPage) + } +}