on cfda370 help sign in
unity8/plugins/Unity/Indicators/qml/SliderMenuItem.qml
120 lines 4.1 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
27 objectName: menuAction.name
28 enabled: menuAction.active
30 property alias minimumValue: slider.minimumValue
31 property alias maximumValue: slider.maximumValue
32 readonly property double value: menu ? menuAction.state : 0.0
34 property QtObject d: QtObject {
35 property bool enableValueConnection: true
36 }
38 onValueChanged: {
39 // TODO: look into adding a component to manage bi-directional bindings.
40 var oldEnable = d.enableValueConnection
41 d.enableValueConnection = false;
43 // Can't rely on binding. Slider value is assigned by user slide.
44 slider.value = value;
46 d.enableValueConnection = oldEnable;
47 }
49 control: Item {
50 id: row
51 width: sliderMenu.text ? units.gu(20) : menuItem.width - (2 * menuItem.__contentsMargins)
52 height: slider.height
54 Image {
55 id: leftImage
56 visible: source != ""
57 anchors.left: row.left
58 anchors.verticalCenter: row.verticalCenter
59 height: units.gu(4)
60 width: height
61 source: menu.ext.minIcon
62 }
64 Components.Slider {
65 id: slider
66 anchors {
67 left: leftImage.visible ? leftImage.right : row.left
68 right: rightImage.visible ? rightImage.left : row.right
69 leftMargin: leftImage.visible ? units.gu(0.5) : 0
70 rightMargin: rightImage.visible ? units.gu(0.5) : 0
71 }
72 live: false
74 Component.onCompleted: {
75 value = menuItem.value
76 }
78 // FIXME: The interval should be [0.0 - 1.0]. Unfortunately, when
79 // reaching the boundaries (0.0 or 1.0), the value is converted
80 // to an integer when automatically wrapped in a variant when
81 // passed to QStateAction::updateState(…). The server chokes on
82 // those values, complaining that they’re not of the right type…
83 minimumValue: menu.ext.minValue ? menu.ext.minValue * 1.000001 : 0.0000001
84 maximumValue: {
85 var maximum = menu.ext.maxValue ? menu.ext.maxValue * 1.000001 : 0.9999999
86 if (maximum <= minimumValue) {
87 return minimumValue + 1;
88 }
89 return maximum;
90 }
92 // FIXME - to be deprecated in Ubuntu.Components.
93 // Use this to disable the label, since there is not way to do it on the component.
94 function formatValue(v) {
95 return "";
96 }
98 Connections {
99 target: d.enableValueConnection ? slider : null
100 onValueChanged: {
101 menuItem.changeState(slider.value);
102 }
103 }
104 }
106 Image {
107 id: rightImage
108 anchors.right: row.right
109 anchors.verticalCenter: row.verticalCenter
110 height: units.gu(4)
111 width: height
112 source: menu.ext.maxIcon
113 }
114 }
116 Indicators.MenuAction {
117 id: menuAction
118 menu: menuItem.menu
119 }