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