diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-20 23:52:53 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-20 23:52:53 +0200 |
commit | fc7fac22a00c32511f87d8fa815a9bef553f72ea (patch) | |
tree | 89127569f1dc00ba6d977382450dfec2e4d6d300 /framework/qml/TreeView.qml | |
parent | 7035a202eecf200ba15d9118774f89ec680bfa49 (diff) | |
download | kube-fc7fac22a00c32511f87d8fa815a9bef553f72ea.tar.gz kube-fc7fac22a00c32511f87d8fa815a9bef553f72ea.zip |
Improved key-navigation for treeview
Diffstat (limited to 'framework/qml/TreeView.qml')
-rw-r--r-- | framework/qml/TreeView.qml | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/framework/qml/TreeView.qml b/framework/qml/TreeView.qml index 445ad673..6fd3084f 100644 --- a/framework/qml/TreeView.qml +++ b/framework/qml/TreeView.qml | |||
@@ -74,28 +74,57 @@ Flickable { | |||
74 | // } | 74 | // } |
75 | } | 75 | } |
76 | 76 | ||
77 | function selectFirst() | ||
78 | { | ||
79 | treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect) | ||
80 | } | ||
81 | |||
82 | function selectNext() | ||
83 | { | ||
84 | var nextIndex = model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex) | ||
85 | if (nextIndex.valid) { | ||
86 | treeView.selection.setCurrentIndex(nextIndex, ItemSelectionModel.ClearAndSelect) | ||
87 | } else { | ||
88 | var childIndex = model.index(0, 0, selection.currentIndex) | ||
89 | if (childIndex.valid) { | ||
90 | if (!treeView.isExpanded(selection.currentIndex)) { | ||
91 | treeView.expand(selection.currentIndex) | ||
92 | } | ||
93 | treeView.selection.setCurrentIndex(childIndex, ItemSelectionModel.ClearAndSelect) | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | function selectPrevious() | ||
99 | { | ||
100 | var previousIndex = model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex) | ||
101 | if (previousIndex.valid) { | ||
102 | treeView.selection.setCurrentIndex(previousIndex, ItemSelectionModel.ClearAndSelect) | ||
103 | } else { | ||
104 | var parentIndex = model.parent(selection.currentIndex) | ||
105 | if (parentIndex.valid) { | ||
106 | treeView.selection.setCurrentIndex(parentIndex, ItemSelectionModel.ClearAndSelect) | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | |||
77 | onActiveFocusChanged: { | 111 | onActiveFocusChanged: { |
78 | //Set an initially focused item when the list view receives focus | 112 | //Set an initially focused item when the list view receives focus |
79 | if (activeFocus && !selection.hasSelection) { | 113 | if (activeFocus && !selection.hasSelection) { |
80 | treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect) | 114 | selectFirst() |
81 | } | 115 | } |
82 | } | 116 | } |
83 | 117 | ||
84 | Keys.onDownPressed: { | 118 | Keys.onDownPressed: { |
85 | if (!selection.hasSelection) { | 119 | if (!selection.hasSelection) { |
86 | treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect) | 120 | selectFirst() |
87 | } else { | 121 | } else { |
88 | treeView.selection.setCurrentIndex(model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect) | 122 | selectNext(); |
89 | } | 123 | } |
90 | } | 124 | } |
91 | 125 | ||
92 | Keys.onUpPressed: { | 126 | Keys.onUpPressed: selectPrevious() |
93 | treeView.selection.setCurrentIndex(model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect) | 127 | Keys.onReturnPressed: treeView.activated(selection.currentIndex) |
94 | } | ||
95 | |||
96 | Keys.onReturnPressed: { | ||
97 | treeView.activated(selection.currentIndex) | ||
98 | } | ||
99 | 128 | ||
100 | //Forward the signal because on a desktopsystem activated is only triggerd by double clicks | 129 | //Forward the signal because on a desktopsystem activated is only triggerd by double clicks |
101 | onClicked: treeView.activated(index) | 130 | onClicked: treeView.activated(index) |