on d5e1bfa help sign in
unity8/plugins/Unity/Indicators/qml/SliderMenuItem.qml
64 lines 2.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 */
20import QtQuick 2.0
21import Ubuntu.Components 0.1
23MenuItem {
24 id: _sliderMenu
26 property alias minimumValue: slider.minimumValue
27 property alias maximumValue: slider.maximumValue
28 property alias value: slider.value
30 control: Slider {
31 id: slider
32 enabled: menuAction.valid
33 width: _sliderMenu.text ? units.gu(20) : _sliderMenu.width - units.gu(4)
34 anchors.verticalCenter: parent.verticalCenter
35 live: false
36 // FIXME: The interval should be [0.0 - 1.0]. Unfortunately, when
37 // reaching the boundaries (0.0 or 1.0), the value is converted
38 // to an integer when automatically wrapped in a variant when
39 // passed to QStateAction::updateState(…). The server chokes on
40 // those values, complaining that they’re not of the right type…
41 minimumValue: menu.extra.canonical_min ? menu.extra.canonical_min * 1.000001 : 0.0000001
42 maximumValue: {
43 var maximum = menu.extra.canonical_max ? menu.extra.canonical_max * 1.000001 : 0.9999999
44 if (maximum <= minimumValue) {
45 return minimumValue + 1;
46 }
47 return maximum;
48 }
50 // FIXME - to be deprecated in Ubuntu.Components.
51 // Use this to disable the label, since there is not way to do it on the component.
52 function formatValue(v) {
53 return "";
54 }
55 }
57 MenuActionBinding {
58 id: menuAction
59 actionGroup: _sliderMenu.actionGroup
60 action: menu ? menu.action : ""
61 target: slider
62 property: "value"
63 }