summaryrefslogtreecommitdiffstats
path: root/framework/qml/TreeView.qml
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-15 16:47:09 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-15 20:15:03 +0200
commitae949b01fd512ccc4c9f9d1c7f1eefa2fc34e1e0 (patch)
treeba0c40fdd1fb5e6b38336fd9f7282ce0da333755 /framework/qml/TreeView.qml
parentd853c05bbcbb34d919afd6326bcadca6e40a60e4 (diff)
downloadkube-ae949b01fd512ccc4c9f9d1c7f1eefa2fc34e1e0.tar.gz
kube-ae949b01fd512ccc4c9f9d1c7f1eefa2fc34e1e0.zip
Put the TreeView into an extra flickable
...so it becomes scrollable just like the rest. Because the TreeView derives from ScrollView we can't just use the regular approach of making the flickable suck less at scrolling. Instead we expand the treeview to maximum length and wrap it in an extra Flickable that we can then handle with the ScrollHelper. This results in the treeview to have the same scrolling behvaiour as everything else.
Diffstat (limited to 'framework/qml/TreeView.qml')
-rw-r--r--framework/qml/TreeView.qml169
1 files changed, 103 insertions, 66 deletions
diff --git a/framework/qml/TreeView.qml b/framework/qml/TreeView.qml
index 367fd3c3..7abfe271 100644
--- a/framework/qml/TreeView.qml
+++ b/framework/qml/TreeView.qml
@@ -19,108 +19,145 @@
19 19
20import QtQuick 2.4 20import QtQuick 2.4
21import QtQuick.Controls 1.4 21import QtQuick.Controls 1.4
22import QtQuick.Controls 2 as Controls2
22import QtQuick.Controls.Styles 1.4 23import QtQuick.Controls.Styles 1.4
23import QtQuick.Layouts 1.1 24import QtQuick.Layouts 1.1
24import QtQml.Models 2.2 25import QtQml.Models 2.2
25 26
26import org.kube.framework 1.0 as Kube 27import org.kube.framework 1.0 as Kube
27 28
28TreeView { 29Flickable {
29 id: root 30 id: root
30 31
31 signal dropped(QtObject drop, QtObject model) 32 default property alias __columns: treeView.__columns
32 33 property alias model: treeView.model
33 flickableItem.boundsBehavior: Flickable.StopAtBounds 34 property alias currentIndex: treeView.currentIndex
34 35
35 selection: ItemSelectionModel { 36 signal dropped(QtObject drop, QtObject model)
36 model: root.model 37 signal activated(var index)
37 //TODO once we don't loose focus to the next view 38
38 // onCurrentChanged: { 39 Controls2.ScrollBar.vertical: Controls2.ScrollBar {}
39 // root.activated(selection.currentIndex) 40 clip: true
40 // } 41 contentWidth: treeView.width
42 contentHeight: treeView.implicitHeight
43 Kube.ScrollHelper {
44 id: scrollHelper
45 flickable: root
41 } 46 }
42 47
43 onActiveFocusChanged: { 48 TreeView {
44 //Set an initially focused item when the list view receives focus 49 id: treeView
45 if (activeFocus && !selection.hasSelection) {
46 root.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect)
47 }
48 }
49 50
50 Keys.onDownPressed: { 51 anchors {
51 if (!selection.hasSelection) { 52 left: parent.left
52 root.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect) 53 right: parent.right
53 } else {
54 root.selection.setCurrentIndex(model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect)
55 } 54 }
56 } 55 implicitHeight: __listView.contentItem.height
56 height: __listView.contentItem.height
57 57
58 Keys.onUpPressed: { 58 verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
59 root.selection.setCurrentIndex(model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect) 59 horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
60 }
61 60
62 Keys.onReturnPressed: { 61 Kube.MouseProxy {
63 root.activated(selection.currentIndex) 62 anchors.fill: parent
64 } 63 target: scrollHelper
64 forwardWheelEvents: true
65 }
65 66
66 //Forward the signal because on a desktopsystem activated is only triggerd by double clicks 67 flickableItem.boundsBehavior: Flickable.StopAtBounds
67 onClicked: root.activated(index)
68 68
69 alternatingRowColors: false 69 selection: ItemSelectionModel {
70 headerVisible: false 70 model: treeView.model
71 //TODO once we don't loose focus to the next view
72 // onCurrentChanged: {
73 // treeView.activated(selection.currentIndex)
74 // }
75 }
71 76
72 style: TreeViewStyle { 77 onActiveFocusChanged: {
78 //Set an initially focused item when the list view receives focus
79 if (activeFocus && !selection.hasSelection) {
80 treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect)
81 }
82 }
83
84 Keys.onDownPressed: {
85 if (!selection.hasSelection) {
86 treeView.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect)
87 } else {
88 treeView.selection.setCurrentIndex(model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect)
89 }
90 }
73 91
74 rowDelegate: Rectangle { 92 Keys.onUpPressed: {
75 color: styleData.selected ? Kube.Colors.highlightColor : Kube.Colors.textColor 93 treeView.selection.setCurrentIndex(model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect)
76 height: Kube.Units.gridUnit * 1.5
77 width: 20
78 } 94 }
79 95
80 frame: Rectangle { 96 Keys.onReturnPressed: {
81 color: Kube.Colors.textColor 97 treeView.activated(selection.currentIndex)
82 } 98 }
83 99
84 branchDelegate: Item { 100 //Forward the signal because on a desktopsystem activated is only triggerd by double clicks
85 width: 16 101 onClicked: treeView.activated(index)
86 height: 16
87 102
88 Kube.Label { 103 onActivated: root.activated(index)
89 anchors.centerIn: parent
90 104
91 color: Kube.Colors.viewBackgroundColor 105 alternatingRowColors: false
92 text: styleData.isExpanded ? "-" : "+" 106 headerVisible: false
107
108 style: TreeViewStyle {
109
110 rowDelegate: Rectangle {
111 color: styleData.selected ? Kube.Colors.highlightColor : Kube.Colors.textColor
112 height: Kube.Units.gridUnit * 1.5
113 width: 20
93 } 114 }
94 115
95 //radius: styleData.isExpanded ? 0 : 100 116 frame: Rectangle {
96 } 117 color: Kube.Colors.textColor
118 }
97 119
98 itemDelegate: Rectangle { 120 branchDelegate: Item {
99 color: styleData.selected ? Kube.Colors.highlightColor : Kube.Colors.textColor 121 width: 16
122 height: 16
100 123
101 DropArea { 124 Kube.Label {
102 anchors.fill: parent 125 anchors.centerIn: parent
103 126
104 Rectangle {
105 anchors.fill: parent
106 color: Kube.Colors.viewBackgroundColor 127 color: Kube.Colors.viewBackgroundColor
107 opacity: 0.3 128 text: styleData.isExpanded ? "-" : "+"
108 visible: parent.containsDrag
109 } 129 }
110 onDropped: root.dropped(drop, model) 130
131 //radius: styleData.isExpanded ? 0 : 100
111 } 132 }
112 133
113 Kube.Label { 134 itemDelegate: Rectangle {
114 anchors { 135 color: styleData.selected ? Kube.Colors.highlightColor : Kube.Colors.textColor
115 verticalCenter: parent.verticalCenter 136
116 left: parent.left 137 DropArea {
138 anchors.fill: parent
139
140 Rectangle {
141 anchors.fill: parent
142 color: Kube.Colors.viewBackgroundColor
143 opacity: 0.3
144 visible: parent.containsDrag
145 }
146 onDropped: root.dropped(drop, model)
147 }
148
149 Kube.Label {
150 anchors {
151 verticalCenter: parent.verticalCenter
152 left: parent.left
153 }
154 text: styleData.value
155 color: Kube.Colors.viewBackgroundColor
117 } 156 }
118 text: styleData.value
119 color: Kube.Colors.viewBackgroundColor
120 } 157 }
121 }
122 158
123 backgroundColor: Kube.Colors.textColor 159 backgroundColor: Kube.Colors.textColor
124 highlightedTextColor: Kube.Colors.highlightedTextColor 160 highlightedTextColor: Kube.Colors.highlightedTextColor
161 }
125 } 162 }
126} 163}