Dekko
Loading...
Searching...
No Matches
ExpandablePanel.qml
1import QtQuick 2.4
2import QtQuick.Controls.Suru 2.2
3import Lomiri.Components 1.3
4import Dekko.Components 1.0
5import Dekko.Lomiri.Constants 1.0
6
7Rectangle {
8 id: expandingPanel
9 default property alias content: content.data
10 property alias iconName: ai.name
11 property alias text: l.text
12 property alias countText: countLable.text
13 property int maxHeight
14 readonly property int expandedHeight: internalHeight > maxHeight ? maxHeight : internalHeight
15 readonly property int internalHeight: header.height + content.height
16 readonly property int collapsedHeight: expandingPanel.visible ? header.height : 0
17 readonly property bool expanded: state === "expanded"
18 color: Suru.backgroundColor
19
20 MouseArea {
21 anchors.fill: parent
22 acceptedButtons: Qt.LeftButton | Qt.RightButton
23 onClicked: mouse.accepted = true
24 onWheel: wheel.accepted = true
25 }
26
27 Line {
28 anchors {
29 left: parent.left
30 right: parent.right
31 top: parent.top
32 }
33 }
34
35 ListItem {
36 id: header
37 anchors {
38 left: parent.left
39 right: parent.right
40 top: parent.top
41 }
42 height: units.gu(6)
43 onClicked: d.isExpanded = !d.isExpanded
44
45 CachedImage {
46 id: ai
47 height: Style.defaultIconSize
48 width: height
49 anchors {
50 left: parent.left
51 leftMargin: Style.defaultSpacing
52 verticalCenter: parent.verticalCenter
53 }
54 }
55
56 Label {
57 id: l
58 anchors {
59 left: ai.right
60 leftMargin: Style.smallSpacing
61 verticalCenter: parent.verticalCenter
62 }
63 text: qsTr("Attachments")
64 }
65
66 LomiriShape {
67 id: shape
68 anchors {
69 left: l.right
70 leftMargin: Style.smallSpacing
71 verticalCenter: parent.verticalCenter
72 }
73 visible: countLable.text
74
75 aspect: LomiriShape.Flat
76 color: Suru.secondaryBackgroundColor
77 height: units.gu(2.2)
78 width: countLable.width < height ? height : countLable.width + Style.smallSpacing
79 Label {
80 id: countLable
81 anchors.margins: units.gu(0.5)
82 anchors.centerIn: parent
83 fontSize: "small"
84 }
85 }
86
87 Icon {
88 id: icon
89 name: "up"
90 anchors {
91 right: parent.right
92 rightMargin: Style.defaultSpacing
93 verticalCenter: parent.verticalCenter
94 }
95 color: LomiriColors.ash
96 rotation: expandingPanel.expanded ? 180 : 0
97 height: Style.defaultSpacing; width: height
98 state: expandingPanel.expanded ? "rotated" : "normal"
99 states: [
100 State {
101 name: "rotated"
102 PropertyChanges { target: icon; rotation: 180 }
103 },
104 State {
105 name: "normal"
106 PropertyChanges { target: icon; rotation: 0 }
107 }
108 ]
109 transitions: Transition {
110 RotationAnimation {
111 duration: LomiriAnimation.FastDuration
112 direction: icon.state === "normal" ? RotationAnimation.Clockwise : RotationAnimation.Counterclockwise
113 }
114 }
115 }
116 }
117 ScrollView {
118 anchors {
119 left: parent.left
120 top: header.bottom
121 right: parent.right
122 bottom: parent.bottom
123 }
124 Flickable {
125 anchors.fill: parent
126 contentHeight: content.height
127 clip: true
128 Column {
129 id: content
130 anchors {
131 left: parent.left
132 top: parent.top
133 right: parent.right
134 }
135 }
136 }
137 }
138 QtObject {
139 id: d
140 property bool isExpanded: false
141 }
142
143 Behavior on height {
144 LomiriNumberAnimation{}
145 }
146
147 state: d.isExpanded ? "expanded" : "collapsed"
148 states: [
149 State {
150 name: "collapsed"
151 PropertyChanges {
152 target: expandingPanel
153 height: collapsedHeight
154 }
155 },
156 State {
157 name: "expanded"
158 PropertyChanges {
159 target: expandingPanel
160 height: expandedHeight
161 }
162 }
163 ]
164}