4pragma ComponentBehavior: Bound
8import "../internal/MotionAnimation.js" as MotionAnimation
24 property bool accessibilityEnabled:
false
28 property string accessibleName:
""
32 property real value: 0
33 property real minimumValue: 0
34 property real maximumValue: 1
35 property real stepSize: 0
39 property var accessibilityIncreaseAction: null
40 property var accessibilityDecreaseAction: null
42 required
property string valueIndicatorText
43 required
property int labelBehavior
44 required
property bool handleHasFocus
45 required
property bool handlePressed
46 required
property bool handleHovered
47 required
property bool controlEnabled
48 required
property bool horizontal
49 required
property bool mirrored
50 required
property real controlWidth
51 required
property real controlHeight
52 required
property real activeHandleWidth
53 required
property real handleHeight
54 required
property real handleContainerSize
55 required
property color handleColor
56 required
property real handleOpacity
57 required
property color valueIndicatorContainerColor
58 required
property color valueIndicatorLabelColor
60 readonly
property bool valueIndicatorActive: {
61 if (root.labelBehavior === MD.Slider.LabelBehavior.Gone)
63 if (root.labelBehavior === MD.Slider.LabelBehavior.Visible)
64 return root.controlEnabled;
65 return root.controlEnabled && (root.handlePressed || root.handleHasFocus || root.handleHovered);
67 readonly
property real valueIndicatorWidth: valueIndicator.implicitWidth
68 readonly
property real valueIndicatorHeight: valueIndicator.implicitHeight
70 implicitWidth: horizontal ? handleContainerSize : handleHeight
71 implicitHeight: horizontal ? handleHeight : handleContainerSize
76 Accessible.role: Accessible.Slider
77 Accessible.name: accessibleName
78 Accessible.focusable: accessibilityEnabled
79 Accessible.focused: handleHasFocus
80 Accessible.ignored: !accessibilityEnabled
83 Accessible.onIncreaseAction: {
84 if (root.accessibilityIncreaseAction)
85 root.accessibilityIncreaseAction();
87 Accessible.onDecreaseAction: {
88 if (root.accessibilityDecreaseAction)
89 root.accessibilityDecreaseAction();
92 function __valueIndicatorOffset(preferred, alternative, handleOffset, indicatorSize, controlSize) {
93 if (root.labelBehavior !== MD.Slider.LabelBehavior.WithinBounds)
96 const firstAllowed = -handleOffset;
97 const lastAllowed = controlSize - handleOffset - indicatorSize;
98 if (lastAllowed < firstAllowed)
100 if (preferred >= firstAllowed && preferred <= lastAllowed)
102 if (alternative >= firstAllowed && alternative <= lastAllowed)
104 return Math.max(firstAllowed, Math.min(preferred, lastAllowed));
109 objectName:
"valueIndicator"
111 readonly
property real indicatorWidth: Math.max(MD.Tokens.slider.valueIndicatorMinWidth, contentItem.implicitWidth + leftPadding + rightPadding)
112 readonly
property real indicatorHeight: Math.max(MD.Tokens.slider.valueIndicatorMinHeight, contentItem.implicitHeight + topPadding + bottomPadding)
115 if (root.horizontal) {
116 const centered = (root.width - width) / 2;
117 return root.__valueIndicatorOffset(centered, centered, root.x, width, root.controlWidth);
120 const gap = MD.Tokens.slider.valueIndicatorActiveBottomSpace;
121 const beforeHandle = -width - gap;
122 const afterHandle = root.width + gap;
123 const preferred = root.mirrored ? afterHandle : beforeHandle;
124 const alternative = root.mirrored ? beforeHandle : afterHandle;
125 return root.__valueIndicatorOffset(preferred, alternative, root.x, width, root.controlWidth);
128 if (!root.horizontal) {
129 const centered = (root.height - height) / 2;
130 return root.__valueIndicatorOffset(centered, centered, root.y, height, root.controlHeight);
133 const gap = MD.Tokens.slider.valueIndicatorActiveBottomSpace;
134 const aboveHandle = -height - gap;
135 const belowHandle = root.height + gap;
136 return root.__valueIndicatorOffset(aboveHandle, belowHandle, root.y, height, root.controlHeight);
139 horizontalPadding: MD.Tokens.slider.valueIndicatorHorizontalPadding
140 verticalPadding: MD.Tokens.slider.valueIndicatorVerticalPadding
142 implicitWidth: indicatorWidth
143 implicitHeight: indicatorHeight
145 opacity: visible ? 1 : 0
146 scale: visible ? 1 : 0
147 visible: root.valueIndicatorActive
149 background: Rectangle {
150 implicitWidth: valueIndicator.indicatorWidth
151 implicitHeight: valueIndicator.indicatorHeight
153 color: root.valueIndicatorContainerColor
157 implicitWidth: valueIndicatorLabel.implicitWidth
158 implicitHeight: valueIndicatorLabel.implicitHeight
161 id: valueIndicatorLabel
162 objectName:
"valueIndicatorLabel"
164 anchors.centerIn: parent
165 text: root.valueIndicatorText
166 typescale: MD.Tokens.typescale.labelLarge
167 font.weight: MD.Tokens.typescale.bodyLarge.fontWeight
168 font.letterSpacing: MD.Tokens.typescale.bodyLarge.tracking
169 color: root.valueIndicatorLabelColor
176 duration: MotionAnimation.expressiveFastSpatialDuration
177 easing.type: Easing.BezierSpline
178 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
183 Behavior on opacity {
185 duration: MD.Tokens.motion.duration.short2
192 objectName:
"sliderHandle"
194 anchors.centerIn: parent
195 width: root.horizontal ? root.activeHandleWidth : root.handleHeight
196 height: root.horizontal ? root.handleHeight : root.activeHandleWidth
197 radius: Math.min(width, height) / 2
198 color: root.handleColor
199 opacity: root.handleOpacity
204 duration: MotionAnimation.expressiveFastSpatialDuration
205 easing.type: Easing.BezierSpline
206 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
214 duration: MotionAnimation.expressiveFastSpatialDuration
215 easing.type: Easing.BezierSpline
216 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
223 duration: MD.Tokens.motion.duration.short2
227 Behavior on opacity {
229 duration: MD.Tokens.motion.duration.short2