2 * Copyright (C) 2015 Canonical, Ltd.
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.
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.
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/>.
18 import QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.3
21 /*! Value Slider Filter Widget. */
26 implicitHeight: childrenRect.height + units.gu(2)
30 // One would think that this is not needed since
31 // we have value: widgetData.value on the slider
32 // but it is, otherwise reset doesn't seem to work
34 if (widgetData.value !== slider.value) {
35 slider.value = widgetData.value;
46 topMargin: units.gu(1)
48 leftMargin: units.gu(2)
50 rightMargin: units.gu(2)
53 minimumValue: widgetData.minValue
54 maximumValue: widgetData.maxValue
55 value: widgetData.value
57 widgetData.value = value;
60 if (pressed) forceActiveFocus();
63 readonly property Item thumb: __internals.thumb
64 readonly property real barMinusThumb: __internals.barMinusThumb
68 objectName: "repeater"
69 model: widgetData.values
73 // The slider is too tall, so move a bit up
74 topMargin: -units.gu(1)
77 visible: value <= widgetData.maxValue && value >= widgetData.minValue
79 var halfThumbDifference = (width - slider.thumb.width) / 2;
80 var result = (value - widgetData.minValue) * slider.barMinusThumb / (widgetData.maxValue - widgetData.minValue) - halfThumbDifference;
81 result = Math.max(result, 0);
82 result = Math.min(result, slider.width - width);
83 return units.gu(2) + result;