2
* Copyright 2016 Canonical Ltd.
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.
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.
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/>.
18
import Ubuntu.Components 1.3
21
The default slider style consists of a bar and a thumb shape.
23
This style is themed using the following properties:
24
- thumbSpacing: spacing between the thumb and the bar
29
// CUSTOM: This was defined as UbuntuColors.blue
30
//property color foregroundColor: theme.palette.normal.activity
31
property color foregroundColor: UbuntuColors.blue
32
// CUSTOM: This was defined as UbuntuColors.ash (#888888)
33
//property color backgroundColor: theme.palette.normal.base
34
property color backgroundColor: "#888888"
36
property real thumbSpacing: units.gu(0)
37
property Item bar: background
38
property Item thumb: thumb
40
implicitWidth: units.gu(38)
41
implicitHeight: units.gu(5)
46
verticalCenter: parent.verticalCenter
51
backgroundColor: sliderStyle.backgroundColor
52
aspect: UbuntuShape.Flat
53
overlayColor: sliderStyle.foregroundColor
54
overlayRect: Qt.application.layoutDirection == Qt.LeftToRight ?
55
Qt.rect(0.0, 0.0, thumb.x / thumb.barMinusThumbWidth, 1.0) :
56
Qt.rect(1.0 - (thumb.x / thumb.barMinusThumbWidth), 0.0, 1.0, 1.0)
63
verticalCenter: parent.verticalCenter
64
topMargin: thumbSpacing
65
bottomMargin: thumbSpacing
68
property real barMinusThumbWidth: background.width - (thumb.width + 2.0*thumbSpacing)
69
property real position: thumbSpacing + SliderUtils.normalizedValue(styledItem) * barMinusThumbWidth
70
property bool pressed: SliderUtils.isPressed(styledItem)
71
property bool positionReached: x == position
74
/* Enable the animation on x when pressing the slider.
75
Disable it when x has reached the target position.
77
onPressedChanged: if (pressed) xBehavior.enabled = true;
78
onPositionReachedChanged: if (positionReached) xBehavior.enabled = false;
83
duration: UbuntuAnimation.FastDuration
88
// CUSTOM: This was defined as #FFFFFFolors.blue
89
//backgroundColor: theme.palette.normal.raised
90
backgroundColor: "#FFFFFF"
92
// CUSTOM: Commented out to avoid pulling in more dependencies
100
property real minimumWidth: units.gu(6)
101
property real horizontalPadding: units.gu(1)
103
width: label.implicitWidth + 2*horizontalPadding
104
height: label.implicitHeight + 2*horizontalPadding
106
// FIXME: very temporary implementation
107
property real minX: 0.0
108
property real maxX: background.width - width
109
property real pointerSize: units.dp(6)
110
property real targetMargin: units.gu(1)
111
property point globalTarget: Qt.point(thumb.x + thumb.width / 2.0, thumb.y - targetMargin)
113
x: MathUtils.clamp(globalTarget.x - width / 2.0, minX, maxX)
114
y: globalTarget.y - height - pointerSize
115
target: Qt.point(globalTarget.x - x, globalTarget.y - y)
117
property bool pressed: SliderUtils.isPressed(styledItem)
118
property bool shouldShow: pressed && label.text != ""
119
onShouldShowChanged: if (shouldShow) {
127
anchors.centerIn: parent
128
text: styledItem.formatValue(SliderUtils.liveValue(styledItem))
129
textSize: Label.Medium
130
color: theme.palette.normal.overlayText