diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-21 00:40:43 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-21 00:40:43 +0200 |
commit | 5df2e0584bb6b0610e2654f3a7d5432be7c6b31c (patch) | |
tree | 20c48cdb99a0de77b4c5c28fd58cf3c42719c69a /framework/qml/TreeView.qml | |
parent | 4c32da590f444c985b8ea3cc5edcbc36d37943fa (diff) | |
download | kube-5df2e0584bb6b0610e2654f3a7d5432be7c6b31c.tar.gz kube-5df2e0584bb6b0610e2654f3a7d5432be7c6b31c.zip |
Improved keyboard navigation
Diffstat (limited to 'framework/qml/TreeView.qml')
-rw-r--r-- | framework/qml/TreeView.qml | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/framework/qml/TreeView.qml b/framework/qml/TreeView.qml index bf2abddd..c0be01f3 100644 --- a/framework/qml/TreeView.qml +++ b/framework/qml/TreeView.qml | |||
@@ -81,16 +81,22 @@ Flickable { | |||
81 | 81 | ||
82 | function selectNext() | 82 | function selectNext() |
83 | { | 83 | { |
84 | var nextIndex = model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex) | 84 | //If we have already expanded children go to them instead |
85 | if (nextIndex.valid) { | 85 | var childIndex = model.index(0, 0, selection.currentIndex) |
86 | treeView.selection.setCurrentIndex(nextIndex, ItemSelectionModel.ClearAndSelect) | 86 | if (childIndex.valid && treeView.isExpanded(selection.currentIndex)) { |
87 | treeView.selection.setCurrentIndex(childIndex, ItemSelectionModel.ClearAndSelect) | ||
87 | } else { | 88 | } else { |
88 | var childIndex = model.index(0, 0, selection.currentIndex) | 89 | //Otherwise just advance to the next index, if we can |
89 | if (childIndex.valid) { | 90 | var nextIndex = model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex) |
90 | if (!treeView.isExpanded(selection.currentIndex)) { | 91 | if (nextIndex.valid) { |
91 | treeView.expand(selection.currentIndex) | 92 | treeView.selection.setCurrentIndex(nextIndex, ItemSelectionModel.ClearAndSelect) |
93 | } else { | ||
94 | //Try to go to the next of the parent instead TODO do this recursively | ||
95 | var parentIndex = model.parent(selection.currentIndex) | ||
96 | if (parentIndex.valid) { | ||
97 | var parentNext = model.sibling(parentIndex.row + 1, 0, parentIndex) | ||
98 | treeView.selection.setCurrentIndex(parentNext, ItemSelectionModel.ClearAndSelect) | ||
92 | } | 99 | } |
93 | treeView.selection.setCurrentIndex(childIndex, ItemSelectionModel.ClearAndSelect) | ||
94 | } | 100 | } |
95 | } | 101 | } |
96 | } | 102 | } |
@@ -100,6 +106,7 @@ Flickable { | |||
100 | var previousIndex = model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex) | 106 | var previousIndex = model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex) |
101 | if (previousIndex.valid) { | 107 | if (previousIndex.valid) { |
102 | treeView.selection.setCurrentIndex(previousIndex, ItemSelectionModel.ClearAndSelect) | 108 | treeView.selection.setCurrentIndex(previousIndex, ItemSelectionModel.ClearAndSelect) |
109 | //TODO if the previous index is expanded, go to the last visible child instead (recursively) | ||
103 | } else { | 110 | } else { |
104 | var parentIndex = model.parent(selection.currentIndex) | 111 | var parentIndex = model.parent(selection.currentIndex) |
105 | if (parentIndex.valid) { | 112 | if (parentIndex.valid) { |
@@ -125,6 +132,8 @@ Flickable { | |||
125 | 132 | ||
126 | Keys.onUpPressed: selectPrevious() | 133 | Keys.onUpPressed: selectPrevious() |
127 | Keys.onReturnPressed: treeView.activated(selection.currentIndex) | 134 | Keys.onReturnPressed: treeView.activated(selection.currentIndex) |
135 | Keys.onRightPressed: treeView.expand(selection.currentIndex) | ||
136 | Keys.onLeftPressed: treeView.collapse(selection.currentIndex) | ||
128 | 137 | ||
129 | //Forward the signal because on a desktopsystem activated is only triggerd by double clicks | 138 | //Forward the signal because on a desktopsystem activated is only triggerd by double clicks |
130 | onClicked: treeView.activated(index) | 139 | onClicked: treeView.activated(index) |