Warning, /pim/kube/framework/qml/TreeView.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net> 0003 Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsystems.com> 0004 0005 This program is free software; you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation; either version 2 of the License, or 0008 (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License along 0016 with this program; if not, write to the Free Software Foundation, Inc., 0017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 import QtQuick 2 0021 import QtQuick.Controls 2 0022 import QtQuick.Layouts 1 0023 0024 import org.kube.framework 1.0 as Kube 0025 0026 FocusScope { 0027 id: root 0028 property var model: null 0029 property var currentIndex: null 0030 property alias count: listView.count 0031 0032 signal dropped(var index, var drop) 0033 0034 function clearSelection() { 0035 listView.currentIndex = -1 0036 } 0037 0038 function selectRootIndex() { 0039 if (listView.count >= 1) { 0040 listView.currentIndex = 0 0041 } 0042 } 0043 0044 function selectNext() { 0045 listView.incrementCurrentIndex() 0046 } 0047 0048 function selectPrevious() { 0049 listView.decrementCurrentIndex() 0050 } 0051 0052 Kube.ListView { 0053 id: listView 0054 0055 anchors.fill: parent 0056 focus: true 0057 0058 model: Kube.TreeModelAdaptor { 0059 id: modelAdaptor 0060 model: root.model 0061 } 0062 0063 onCurrentIndexChanged: { 0064 root.currentIndex = modelAdaptor.mapRowToModelIndex(listView.currentIndex) 0065 } 0066 0067 ScrollBar.vertical: Kube.ScrollBar { invertedColors: true } 0068 0069 delegate: Kube.ListDelegate { 0070 id: delegate 0071 width: listView.availableWidth 0072 height: Kube.Units.gridUnit * 1.5 0073 property bool isActive: listView.currentIndex === index 0074 0075 //FIXME The enabled property is specific to the folder model 0076 selectionEnabled: model.enabled 0077 hoverEnabled: selectionEnabled 0078 0079 DropArea { 0080 anchors.fill: parent 0081 0082 Rectangle { 0083 anchors.fill: parent 0084 color: Kube.Colors.viewBackgroundColor 0085 opacity: 0.3 0086 visible: parent.containsDrag 0087 } 0088 0089 onDropped: root.dropped(modelAdaptor.mapRowToModelIndex(index), drop) 0090 } 0091 0092 background: Kube.DelegateBackground { 0093 anchors.fill: parent 0094 color: Kube.Colors.textColor 0095 focused: delegate.activeFocus || delegate.hovered 0096 selected: isActive 0097 } 0098 0099 function toggleExpanded() { 0100 var idx = model._q_TreeView_ModelIndex 0101 if (modelAdaptor.isExpanded(idx)) { 0102 modelAdaptor.collapse(idx) 0103 } else { 0104 modelAdaptor.expand(idx) 0105 } 0106 } 0107 0108 Keys.onSpacePressed: toggleExpanded() 0109 0110 RowLayout { 0111 anchors { 0112 fill: parent 0113 leftMargin: Math.max(Kube.Units.smallSpacing, model._q_TreeView_ItemDepth * Kube.Units.largeSpacing) 0114 } 0115 0116 spacing: Kube.Units.smallSpacing 0117 Kube.Label { 0118 id: label 0119 Layout.fillWidth: true 0120 text: model.name 0121 color: delegate.selectionEnabled ? Kube.Colors.highlightedTextColor : Kube.Colors.disabledTextColor 0122 elide: Text.ElideLeft 0123 clip: false 0124 } 0125 Kube.IconButton { 0126 visible: model._q_TreeView_HasChildren 0127 iconName: model._q_TreeView_ItemExpanded ? Kube.Icons.goDown_inverted : Kube.Icons.goNext_inverted 0128 padding: 0 0129 width: Kube.Units.gridUnit 0130 height: Kube.Units.gridUnit 0131 onClicked: toggleExpanded() 0132 activeFocusOnTab: false 0133 hoverEnabled: false 0134 } 0135 } 0136 } 0137 } 0138 }