@@ -0,0 +1,116 @@
1+import QtQuick 2.0
2+import Ubuntu.Components 0.1
3+import Ubuntu.Components.ListItems 0.1 as ListItem
4+import Ubuntu.Components.Popups 0.1
5+
6+UbuntuShape {
7+ id: optionToggle
8+
9+ property bool expanded
10+ property var model
11+ property int startIndex
12+ readonly property double itemHeight: units.gu(5)
13+
14+ Behavior on height {
15+ UbuntuNumberAnimation {
16+ duration: UbuntuAnimation.SnapDuration
17+ }
18+ }
19+
20+ color: Theme.palette.normal.base
21+ borderSource: "none"
22+ height: expanded ? (model.count - startIndex) * itemHeight : itemHeight
23+ width: parent.width
24+ radius: "medium"
25+ clip: true
26+
27+ onExpandedChanged: {
28+ print("expanded changed to:", expanded ? "true" : "false")
29+ print("height:", height)
30+ print("count:", model.count)
31+ optionToggle.height = expanded ? (model.count - startIndex) * itemHeight : itemHeight
32+ }
33+
34+ Column {
35+ id: optionToggleContent
36+ width: parent.width
37+ //property double itemHeight: units.gu(5)
38+
39+ Repeater {
40+ model: optionToggle.model
41+
42+ delegate: Loader {
43+ asynchronous: true
44+ visible: status === Loader.Ready
45+ property string actionLabel: label
46+ readonly property var splitLabel: actionLabel.match(/(^([-a-z0-9]+):)?(.*)$/)
47+
48+ Component {
49+ id: optionToggleEntry
50+
51+ MouseArea {
52+ width: optionToggleContent.width
53+ height: optionToggle.itemHeight
54+
55+ onClicked: {
56+ if (index === startIndex) {
57+ optionToggle.expanded = optionToggle.expanded ? false : true
58+ } else {
59+ print("clicked on", label)
60+ }
61+ }
62+
63+ ListItem.ThinDivider {
64+ visible: index > startIndex
65+ }
66+
67+ Icon {
68+ id: delegateIcon
69+ anchors {
70+ left: parent.left
71+ leftMargin: units.gu(2)
72+ verticalCenter: parent.verticalCenter
73+ }
74+ visible: index !== startIndex
75+ width: units.gu(2)
76+ height: width
77+ name: splitLabel[2] !== undefined ? splitLabel[2] : ""
78+ }
79+
80+ Label {
81+ id: delegateLabel
82+ anchors {
83+ left: delegateIcon.visible ? delegateIcon.right : parent.left
84+ leftMargin: delegateIcon.visible ? units.gu(1) : units.gu(2)
85+ right: parent.right
86+ rightMargin: units.gu(2)
87+ verticalCenter: delegateIcon.visible ? delegateIcon.verticalCenter : parent.verticalCenter
88+ }
89+
90+ width: parent.width
91+ text: splitLabel[3]
92+ color:"#5d5d5d"
93+ fontSize: "small"
94+ maximumLineCount: 1
95+ elide: Text.ElideRight
96+ }
97+
98+ Icon {
99+ anchors {
100+ right: parent.right
101+ rightMargin: units.gu(2)
102+ verticalCenter: delegateIcon.verticalCenter
103+ }
104+
105+ visible: index === startIndex
106+ name: optionToggle.height === optionToggle.itemHeight ? "down" : "up"
107+ width: units.gu(2)
108+ height: width
109+ }
110+ }
111+ }
112+ sourceComponent: (index >= startIndex) ? optionToggleEntry : undefined
113+ }
114+ }
115+ }
116+}