@@ -0,0 +1,106 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import Ubuntu.Components 0.1
19+import "../../Components"
20+
21+/*! \brief Preview widget for expandable widgets.
22+
23+ This widget shows a list of widgets defined in widgetData["widgets"]
24+ Those widgets can be collapsed or uncollapsed. When uncollapsed
25+ all the widgets are shown, when collapsed only the first
26+ widgetData["collapsed-widgets"] are shown. It has a title that comes
27+ in via widgetData["title"]
28+ */
29+
30+PreviewWidget {
31+ id: root
32+ implicitHeight: childrenRect.height
33+
34+ expanded: false
35+
36+ Label {
37+ id: titleLabel
38+ objectName: "titleLabel"
39+ anchors {
40+ left: parent.left
41+ right: expandButton.left
42+ }
43+ fontSize: "large"
44+ color: root.scopeStyle ? root.scopeStyle.foreground : "grey"
45+ visible: text !== ""
46+ opacity: .8
47+ text: widgetData["title"] || ""
48+ wrapMode: Text.Wrap
49+ }
50+
51+ AbstractButton {
52+ id: expandButton
53+ objectName: "expandButton"
54+ width: titleLabel.height
55+ height: titleLabel.height
56+ anchors.right: parent.right
57+ onClicked: {
58+ root.expanded = !root.expanded;
59+ }
60+ // TODO Remove when "view-collapse" : "view-expand" are there
61+ Rectangle {
62+ anchors.fill: parent
63+ color: root.expanded ? "red" : "green"
64+ }
65+ Icon {
66+ anchors.fill: parent
67+ width: 64
68+ height: 64
69+ name: root.expanded ? "view-collapse" : "view-expand"
70+ }
71+ }
72+
73+ Column {
74+ anchors {
75+ top: titleLabel.bottom
76+ topMargin: units.gu(1)
77+ left: parent.left
78+ right: parent.right
79+ }
80+ spacing: units.gu(1)
81+ Repeater {
82+ id: repeater
83+ objectName: "repeater"
84+ model: widgetData["widgets"]
85+ delegate: PreviewWidgetFactory {
86+ height: visible ? implicitHeight : 0
87+ width: parent.width
88+ widgetId: modelData.widgetId
89+ widgetType: modelData.type
90+ widgetData: modelData.properties
91+ isCurrentPreview: root.isCurrentPreview
92+ scopeStyle: root.scopeStyle
93+ anchors {
94+ left: parent.left
95+ right: parent.right
96+ }
97+ expanded: root.expanded
98+ visible: root.expanded || index < root.widgetData["collapsed-widgets"]
99+
100+ onTriggered: {
101+ root.triggered(widgetId, actionId, data);
102+ }
103+ }
104+ }
105+ }
106+}