on 551c708 help sign in
unity8/plugins/Unity/Indicators/qml/SliderMenuItem.qml
106 lines 3.3 kB history raw
1/*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Nick Dedekind <nick.dedekind@canonical.com>
19 */
21import QtQuick 2.0
22import Ubuntu.Components 0.1 as Components
23import Unity.Indicators 0.1 as Indicators
25FramedMenuItem {
26 id: menuItem
28 property alias minimumValue: slider.minimumValue
29 property alias maximumValue: slider.maximumValue
30 property double value: 0.0
32 property alias minIcon: leftImage.source
33 property alias maxIcon: rightImage.source
35 property QtObject d: QtObject {
36 property bool enableValueConnection: true
37 }
39 signal changeState(real value)
41 onValueChanged: {
42 // TODO: look into adding a component to manage bi-directional bindings.
43 var oldEnable = d.enableValueConnection
44 d.enableValueConnection = false;
46 // Can't rely on binding. Slider value is assigned by user slide.
47 slider.value = value;
49 d.enableValueConnection = oldEnable;
50 }
52 control: Item {
53 id: row
54 width: menuItem.text ? units.gu(20) : menuItem.width - (2 * menuItem.__contentsMargins)
55 height: slider.height
57 Image {
58 id: leftImage
59 visible: status === Image.Ready
60 anchors.left: row.left
61 anchors.verticalCenter: row.verticalCenter
62 height: units.gu(4)
63 width: height
64 }
66 Components.Slider {
67 id: slider
68 anchors {
69 left: leftImage.visible ? leftImage.right : row.left
70 right: rightImage.visible ? rightImage.left : row.right
71 leftMargin: leftImage.visible ? units.gu(0.5) : 0
72 rightMargin: rightImage.visible ? units.gu(0.5) : 0
73 }
74 live: true
76 Component.onCompleted: {
77 value = menuItem.value
78 }
80 minimumValue: 0.0
81 maximumValue: 0.1
83 // FIXME - to be deprecated in Ubuntu.Components.
84 // Use this to disable the label, since there is not way to do it on the component.
85 function formatValue(v) {
86 return "";
87 }
89 Connections {
90 target: d.enableValueConnection ? slider : null
91 onValueChanged: {
92 menuItem.changeState(slider.value);
93 }
94 }
95 }
97 Image {
98 id: rightImage
99 visible: status === Image.Ready
100 anchors.right: row.right
101 anchors.verticalCenter: row.verticalCenter
102 height: units.gu(4)
103 width: height
104 }
105 }