Debian Codegraph @

qml/Components/ExpandableListItem.qml

raw
1 /*
2 * This file is based on work taken from Ubuntu Weather app as on September 2019. Copyright (C) 2019 UBports
3 * Copyright (C) 2019 Joan Cibersheep
4 *
5 *
6 * This App is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3 as
8 * published by the Free Software Foundation.
9 *
10 *
11 * This App is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 import QtQuick 2.9
22 import Lomiri.Components 1.3
23
24 /*
25 Component which extends the SDK Expandable list item and provides a easy
26 to use component where the title, subtitle and a listview can be displayed. It
27 matches the design specification provided for clock.
28 */
29
30 ListItem {
31 id: expandableListItem
32
33 // Public APIs
34 property ListModel model
35 property Component delegate
36 property alias title: expandableHeader.title
37 property alias subText: expandableHeader.subtitle
38 property alias listViewHeight: expandableList.height
39
40 // For autopilot
41 readonly property double expansionHeight: expansion.height
42
43 highlightColor: root.highlightColor
44 height: expandableHeader.height + divider.height
45 divider.visible: false
46 expansion.height: contentColumn.height
47
48 onClicked: toggleExpansion()
49
50 function toggleExpansion() {
51 expansion.expanded = !expansion.expanded
52 }
53
54 Column {
55 id: contentColumn
56
57 anchors {
58 left: parent.left
59 right: parent.right
60 }
61
62 ListItem {
63 height: expandableHeader.height + divider.height
64 divider.visible: false
65 highlightColor: root.highlightColor
66
67 ListItemLayout {
68 id: expandableHeader
69
70 Icon {
71 id: arrow
72 width: units.gu(2)
73 height: width
74 SlotsLayout.position: SlotsLayout.Trailing
75 SlotsLayout.overrideVerticalPositioning: true
76 anchors.verticalCenter: parent.verticalCenter
77 name: "go-down"
78 rotation: expandableListItem.expansion.expanded ? 180 : 0
79
80 Behavior on rotation {
81 LomiriNumberAnimation {}
82 }
83 }
84 }
85 }
86
87 ListView {
88 id: expandableList
89 width: parent.width - units.gu(2)
90 anchors.right: parent.right
91 interactive: false
92 model: expandableListItem.model
93 delegate: expandableListItem.delegate
94 }
95 }
96
97 Connections {
98 target: bottomEdge
99
100 onCollapseStarted: expansion.expanded = false;
101 }
102 }