summaryrefslogtreecommitdiffstats
path: root/framework/qml/TreeView.qml
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-14 23:29:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-07-15 20:14:49 +0200
commit0f01c1ea421eafc96630d1d9eded8bb044f3a88d (patch)
tree246ce8473995700dfd6838a3ba8c642359a2728a /framework/qml/TreeView.qml
parent9895d72ea197c3bdc7e5465f1d96a249081b0e77 (diff)
downloadkube-0f01c1ea421eafc96630d1d9eded8bb044f3a88d.tar.gz
kube-0f01c1ea421eafc96630d1d9eded8bb044f3a88d.zip
Moved non-folder specific treeview to separate file
Diffstat (limited to 'framework/qml/TreeView.qml')
-rw-r--r--framework/qml/TreeView.qml126
1 files changed, 126 insertions, 0 deletions
diff --git a/framework/qml/TreeView.qml b/framework/qml/TreeView.qml
new file mode 100644
index 00000000..aef0ee92
--- /dev/null
+++ b/framework/qml/TreeView.qml
@@ -0,0 +1,126 @@
1/*
2 Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net>
3 Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsystems.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20import QtQuick 2.4
21import QtQuick.Controls 1.4
22import QtQuick.Controls.Styles 1.4
23import QtQuick.Layouts 1.1
24import QtQml.Models 2.2
25
26import org.kube.framework 1.0 as Kube
27
28TreeView {
29 id: root
30
31 signal dropped(QtObject drop, QtObject model)
32
33 flickableItem.boundsBehavior: Flickable.StopAtBounds
34
35 selection: ItemSelectionModel {
36 model: root.model
37 //TODO once we don't loose focus to the next view
38 // onCurrentChanged: {
39 // treeView.activated(selection.currentIndex)
40 // }
41 }
42
43 onActiveFocusChanged: {
44 //Set an initially focused item when the list view receives focus
45 if (activeFocus && !selection.hasSelection) {
46 root.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect)
47 }
48 }
49
50 Keys.onDownPressed: {
51 if (!selection.hasSelection) {
52 root.selection.setCurrentIndex(model.index(0, 0), ItemSelectionModel.ClearAndSelect)
53 } else {
54 root.selection.setCurrentIndex(model.sibling(selection.currentIndex.row + 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect)
55 }
56 }
57
58 Keys.onUpPressed: {
59 root.selection.setCurrentIndex(model.sibling(selection.currentIndex.row - 1, 0, selection.currentIndex), ItemSelectionModel.ClearAndSelect)
60 }
61
62 Keys.onReturnPressed: {
63 root.activated(selection.currentIndex)
64 }
65
66 //Forward the signal because on a desktopsystem activated is only triggerd by double clicks
67 onClicked: treeView.activated(index)
68
69 alternatingRowColors: false
70 headerVisible: false
71
72 style: TreeViewStyle {
73
74 rowDelegate: Rectangle {
75 color: styleData.selected ? Kube.Colors.highlightColor : Kube.Colors.textColor
76 height: Kube.Units.gridUnit * 1.5
77 width: 20
78 }
79
80 frame: Rectangle {
81 color: Kube.Colors.textColor
82 }
83
84 branchDelegate: Item {
85 width: 16
86 height: 16
87
88 Kube.Label {
89 anchors.centerIn: parent
90
91 color: Kube.Colors.viewBackgroundColor
92 text: styleData.isExpanded ? "-" : "+"
93 }
94
95 //radius: styleData.isExpanded ? 0 : 100
96 }
97
98 itemDelegate: Rectangle {
99 color: styleData.selected ? Kube.Colors.highlightColor : Kube.Colors.textColor
100
101 DropArea {
102 anchors.fill: parent
103
104 Rectangle {
105 anchors.fill: parent
106 color: Kube.Colors.viewBackgroundColor
107 opacity: 0.3
108 visible: parent.containsDrag
109 }
110 onDropped: root.dropped(drop, model)
111 }
112
113 Kube.Label {
114 anchors {
115 verticalCenter: parent.verticalCenter
116 left: parent.left
117 }
118 text: styleData.value
119 color: Kube.Colors.viewBackgroundColor
120 }
121 }
122
123 backgroundColor: Kube.Colors.textColor
124 highlightedTextColor: Kube.Colors.highlightedTextColor
125 }
126}