Kirigami-addons

TreeViewDecoration.qml
1/*
2 * SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick 2.6
8import QtQuick.Layouts 1.4
9import QtQuick.Controls 2.2 as QQC2
10import QtQuick.Templates 2.2 as T2
11import org.kde.kitemmodels 1.0
12import org.kde.kirigami 2.14 as Kirigami
13
14/**
15 * The tree expander decorator for item views.
16 *
17 * It will have a "> v" expander button graphics, and will have indentation on the left
18 * depending on the level of the tree the item is in
19 *
20 * It is recommanded to directly use RoundedTreeDelegate instead of this component.
21 */
22RowLayout {
23 /**
24 * This property holds the delegate there this decoration will live in.
25 * It needs to be assigned explicitly by the developer.
26 */
27 required property T2.ItemDelegate parentDelegate
28
29 /**
30 * This property holds the KDescendantsProxyModel the view is showing.
31 * It needs to be assigned explicitly by the developer.
32 */
33 required property KDescendantsProxyModel model
34
35 /**
36 * This property holds the color of the decoration highlight.
37 */
38 property color decorationHighlightColor
39
40 /**
41 * This property holds the index of the item.
42 *
43 * Provided by the model/ListView
44 */
45 required property int index
46
47 /**
48 * This property holds the descendant level of the item.
49 *
50 * Provided by the model/ListView
51 */
52 required property int kDescendantLevel
53
54 /**
55 * This property holds whether this item has siblings.
56 *
57 * Provided by the model/ListView
58 */
59 required property var kDescendantHasSiblings
60
61 /**
62 * This property holds whether the item is expandable.
63 *
64 * Provided by the model/ListView
65 */
66 required property bool kDescendantExpandable
67
68 /**
69 * This property holds whether the item is expanded.
70 *
71 * Provided by the model/ListView
72 */
73 required property bool kDescendantExpanded
74
75 Layout.topMargin: -parentDelegate.topPadding
76 Layout.bottomMargin: -parentDelegate.bottomPadding
77 Repeater {
78 model: kDescendantLevel - 1
79 delegate: Item {
80 Layout.preferredWidth: controlRoot.width
81 Layout.fillHeight: true
82
83 Rectangle {
84 anchors {
85 horizontalCenter: parent.horizontalCenter
86 top: parent.top
87 bottom: parent.bottom
88 }
89 visible: kDescendantHasSiblings[modelData]
90 color: Kirigami.Theme.textColor
91 opacity: 0.5
92 width: 1
93 }
94 }
95 }
96 T2.Button {
97 id: controlRoot
98 Layout.preferredWidth: Kirigami.Units.gridUnit
99 Layout.fillHeight: true
100 enabled: kDescendantExpandable
101 onClicked: model.toggleChildren(parentDelegate.index)
102 contentItem: Item {
103 id: styleitem
104 implicitWidth: Kirigami.Units.gridUnit
105 Rectangle {
106 anchors {
107 horizontalCenter: parent.horizontalCenter
108 top: parent.top
109 bottom: expander.visible ? expander.top : parent.verticalCenter
110 }
111 color: Kirigami.Theme.textColor
112 opacity: 0.5
113 width: 1
114 }
115 Kirigami.Icon {
116 id: expander
117 anchors.centerIn: parent
118 width: Kirigami.Units.iconSizes.small
119 height: width
120 source: kDescendantExpanded ? "go-down-symbolic" : (Qt.application.layoutDirection == Qt.RightToLeft ? "go-previous-symbolic" : "go-next-symbolic")
121 isMask: true
122 color: controlRoot.hovered ? decorationLayout.decorationHighlightColor ? decorationLayout.decorationHighlightColor : Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
123 Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
124 Behavior on color { ColorAnimation { duration: Kirigami.Units.shortDuration; easing.type: Easing.InOutQuad } }
125 visible: kDescendantExpandable
126 }
127 Rectangle {
128 anchors {
129 horizontalCenter: parent.horizontalCenter
130 top: expander.visible ? expander.bottom : parent.verticalCenter
131 bottom: parent.bottom
132 }
133 visible: kDescendantHasSiblings[kDescendantHasSiblings.length - 1]
134 color: Kirigami.Theme.textColor
135 opacity: 0.5
136 width: 1
137 }
138 Rectangle {
139 anchors {
140 verticalCenter: parent.verticalCenter
141 left: expander.visible ? expander.right : parent.horizontalCenter
142 right: parent.right
143 }
144 color: Kirigami.Theme.textColor
145 opacity: 0.5
146 height: 1
147 }
148 }
149 background: Item {}
150 }
151}
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.