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