Unity 8
 All Classes Functions
HudParametrizedActionsPage.qml
1 /*
2  * Copyright (C) 2012, 2013 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 1.1
19 import Ubuntu.Components.Themes.Ambiance 1.1
20 import "../Components"
21 
22 Item {
23  property alias header: header.title
24  signal backPressed
25  signal confirmPressed
26  signal valuesUpdated
27  id: root
28 
29  ListModel {
30  id: actionItems
31  }
32 
33  function setItems(items) {
34  while (actionItems.count > 0) {
35  var item = actionItems.get(0).item
36  actionItems.remove(0)
37  item.visible = false
38  item.destroy()
39  }
40 
41  var sliderCreator = Qt.createComponent("SliderLabel.qml");
42  var first = true
43  var topAnchor = header.bottom
44  for (var i = 0; i < items.length; i++) {
45  var item = items[i]
46  if (item["parameter-type"] == "slider")
47  {
48  var slider = sliderCreator.createObject(flickableColumn);
49  slider.anchors.left = flickableColumn.left
50  slider.anchors.right = flickableColumn.right
51  slider.anchors.topMargin = first ? units.gu(1) : units.gu(2)
52  slider.anchors.top = topAnchor
53  slider.tooltip = tooltip
54  slider.sliderData = item
55  topAnchor = slider.bottom
56  actionItems.append({"item": slider})
57  slider.onValueChanged.connect(valueChanged)
58  }
59  first = false
60  }
61  }
62 
63  function valueChanged()
64  {
65  valuesUpdated()
66  }
67 
68  function values() {
69  var values = {}
70  for (var i = 0; i < actionItems.count; ++i) {
71  var item = actionItems.get(i).item
72  values[item.action] = item.value
73  }
74  return values
75  }
76 
77  Flickable {
78  anchors.top: parent.top
79  anchors.bottom: buttons.top
80  anchors.left: parent.left
81  anchors.right: parent.right
82  clip: true
83 
84  flickableDirection: Flickable.VerticalFlick
85  interactive: !tooltip.visible
86 
87  Item {
88  id: flickableColumn
89  anchors.top: parent.top
90  anchors.left: parent.left
91  anchors.right: parent.right
92 
93  PageHeadStyle {
94  id: header
95  anchors.top: parent.top
96  anchors.left: parent.left
97  anchors.right: parent.right
98  anchors.topMargin: units.gu(1)
99  height: units.gu(6.5)
100  contentHeight: height
101  separatorSource: ""
102  property var styledItem: header
103  property string title
104  property var config: PageHeadConfiguration { }
105  }
106  }
107  }
108  Item {
109  id: buttons
110  anchors.bottom: parent.bottom
111  anchors.left: parent.left
112  anchors.right: parent.right
113  anchors.margins: units.gu(1)
114  height: confirmButton.height
115 
116  Button {
117  id: backButton
118  anchors.left: parent.left
119  anchors.top: parent.top
120  anchors.bottom: parent.bottom
121  width: units.gu(7)
122  color: "black"
123  opacity: 0.25
124  MouseArea {
125  anchors.fill: parent
126  onClicked: backPressed()
127  }
128  }
129  Image {
130  anchors.centerIn: backButton
131  source: "graphics/icon_arrow.png"
132  }
133 
134  Button {
135  id: confirmButton
136  anchors.right: parent.right
137  width: units.gu(13)
138  height: units.gu(5)
139  text: i18n.tr("Confirm")
140  color: "#F05D22"
141  onClicked: confirmPressed()
142  }
143  }
144 
145  Item {
146  id: tooltip
147  property variant target: undefined
148  visible: target != undefined
149  y: visible ? root.mapFromItem(target.parent, 0, target.y).y - height : 0
150  x: visible ? target.anchors.leftMargin + target.__internals.thumb.x + target.__internals.thumb.width / 2 - width / 2 : 0
151 
152  width: childrenRect.width
153  height: childrenRect.height
154 
155  Rectangle {
156  id: tooltipRectangle
157  width: units.gu(8)
158  height: units.gu(6)
159  color: "white"
160  radius: units.gu(0.5)
161 
162  Label {
163  anchors.fill: parent
164  text: tooltip.target ? tooltip.target.realFormatValue(tooltip.target.value) : ""
165  horizontalAlignment: Text.AlignHCenter
166  verticalAlignment: Text.AlignVCenter
167  fontSize: "large"
168  }
169  }
170  Image {
171  id: tooltipTip
172  source: "graphics/popup_triangle.png"
173 
174  anchors.top: tooltipRectangle.bottom
175  anchors.horizontalCenter: parent.horizontalCenter
176  }
177 
178  }
179 }