Unity 8
 All Classes Functions Properties
SliderLabel.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 
20 Item {
21  height: childrenRect.height
22  width: childrenRect.width
23  property variant tooltip
24 
25  property variant sliderData
26  property string action
27  property alias value: slider.value
28  onValueChanged: {
29  // TODO We should not need this but without it
30  // slider.onValueChanged.connect(valueChanged) in
31  // HudParametrizedActionsPage.qml doesn't work
32  // Michael thinks it's related to https://bugreports.qt-project.org/browse/QTBUG-29141
33  }
34 
35  onSliderDataChanged: {
36  label.text = sliderData["label"]
37  slider.minimumValue = sliderData["min"]
38  slider.maximumValue = sliderData["max"]
39  if("live" in sliderData)
40  slider.live = sliderData["live"]
41  // SDK Slider does not support step yet
42 // slider.step = sliderData["step"]
43  if("value" in sliderData)
44  slider.value = sliderData["value"]
45  action = sliderData["action"]
46  }
47 
48  Label {
49  id: label
50  anchors.top: parent.top
51  anchors.left: parent.left
52  anchors.right: parent.right
53  anchors.margins: units.gu(1)
54  anchors.leftMargin: units.gu(2)
55  color: "white"
56  }
57  Slider {
58  id: slider
59  anchors.top: label.bottom
60  anchors.left: parent.left
61  anchors.right: parent.right
62  anchors.margins: units.gu(1)
63  height: units.gu(6)
64  live: true
65  function realFormatValue(v) { return Math.round(v) + " %" }
66  function formatValue(v) { return tooltip.target == slider ? "" : realFormatValue(v) }
67  onPressedChanged: tooltip.target = pressed ? slider : undefined
68  }
69  BorderImage {
70  source: "graphics/divider.sci"
71  anchors.top: slider.bottom
72  anchors.left: parent.left
73  anchors.right: parent.right
74  anchors.topMargin: units.gu(2)
75  }
76 }