Unity 8
PreviewExpandable.qml
1 /*
2  * Copyright (C) 2014,2015 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.4
18 import Ubuntu.Components 1.3
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"]. This widget expands all child widgets
28  when initialized by specifying widgetData["expanded"] == true.
29  It's in unexpanded mode by default.
30  */
31 
32 PreviewWidget {
33  id: root
34  implicitHeight: childrenRect.height
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 : theme.palette.normal.baseText
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  Icon {
61  anchors.fill: parent
62  width: units.gu(3)
63  height: units.gu(3)
64  name: root.expanded ? "view-collapse" : "view-expand"
65  color: root.scopeStyle ? root.scopeStyle.foreground : theme.palette.normal.baseText
66  }
67  }
68 
69  Column {
70  anchors {
71  top: titleLabel.bottom
72  topMargin: units.gu(1)
73  left: parent.left
74  right: parent.right
75  }
76  spacing: units.gu(1)
77  Repeater {
78  id: repeater
79  objectName: "repeater"
80  model: widgetData["widgets"]
81  delegate: PreviewWidgetFactory {
82  height: visible ? implicitHeight : 0
83  width: parent.width
84  widgetId: model.widgetId
85  widgetType: model.type
86  widgetData: model.properties
87  isCurrentPreview: root.isCurrentPreview
88  scopeStyle: root.scopeStyle
89  anchors {
90  left: parent.left
91  right: parent.right
92  }
93  expanded: root.expanded
94  visible: root.expanded || index < root.widgetData["collapsed-widgets"]
95 
96  onTriggered: {
97  root.triggered(widgetId, actionId, data);
98  }
99  onMakeSureVisible: {
100  root.makeSureVisible(item)
101  }
102  }
103  }
104  }
105 }