5import QtQuick.Templates as T
7import "../core/UiMetrics.js" as UiMetrics
8import "../internal/MotionAnimation.js" as MotionAnimation
26 enum IconConfiguration {
36 property MD.typescale typescale: MD.Tokens.typescale.labelLarge
43 property int iconConfiguration:
Switch.IconConfiguration.NoIcons
45 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding)
46 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding, implicitIndicatorHeight + topPadding + bottomPadding)
49 spacing: MD.Tokens.switch.contentSpacing
52 focusPolicy: Qt.StrongFocus
57 implicitWidth: MD.Tokens.switch.trackWidth
58 implicitHeight: MD.Tokens.switch.trackHeight
60 readonly
property real handleCenterX: height / 2 + control.visualPosition * (width - height)
62 x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2
63 y: control.topPadding + (control.availableHeight - height) / 2
69 property color trackColor: {
71 return control.checked ? control.MD.Style.onSurfaceColor : control.MD.Style.surfaceContainerHighestColor;
72 return control.checked ? control.MD.Style.primaryColor : control.MD.Style.surfaceContainerHighestColor;
74 property real trackOpacity: control.enabled ? 1.0 : MD.Tokens.switch.disabledTrackOpacity
75 property real borderWidth: control.checked ? 0 : MD.Tokens.switch.trackOutlineWidth
76 property color borderColor: control.enabled ? control.MD.Style.outlineColor : control.MD.Style.onSurfaceColor
79 property color handleColor: {
81 return control.checked ? control.MD.Style.surfaceColor : control.MD.Style.onSurfaceColor;
83 return control.MD.Style.onPrimaryColor;
84 return control.iconConfiguration ===
Switch.IconConfiguration.BothIcons ? control.MD.Style.onSurfaceVariantColor : control.MD.Style.outlineColor;
86 property real handleSize: control.pressed ? MD.Tokens.switch.
pressedHandleSize : (control.checked ? MD.Tokens.switch.selectedHandleSize : (control.iconConfiguration ===
Switch.IconConfiguration.BothIcons ? MD.Tokens.switch.
withIconHandleSize : MD.Tokens.switch.unselectedHandleSize))
87 property real handleOpacity: !control.enabled ? (control.checked ? MD.Tokens.switch.disabledSelectedHandleOpacity : MD.Tokens.switch.disabledUnselectedHandleOpacity) : 1.0
90 property bool showIcon: control.iconConfiguration ===
Switch.IconConfiguration.BothIcons || (control.iconConfiguration ===
Switch.IconConfiguration.SelectedIcon && control.checked)
91 property string iconName: {
93 return control.icon.name.length > 0 ? control.icon.name :
"check";
94 if (control.iconConfiguration ===
Switch.IconConfiguration.BothIcons)
97 return control.icon.name.length > 0 ? control.icon.name :
"check";
99 property color iconColor: control.checked ? control.MD.Style.primaryColor : control.MD.Style.surfaceContainerHighestColor
102 property color stateLayerColor: control.checked ? control.MD.Style.primaryColor : control.MD.Style.onSurfaceVariantColor
103 property real stateLayerOpacity: 0
109 when: control.hovered && control.enabled && !control.pressed
111 indicatorState.stateLayerOpacity: MD.Tokens.switch.hoverStateLayerOpacity
116 when: control.visualFocus && control.enabled && !control.pressed
118 indicatorState.stateLayerOpacity: MD.Tokens.switch.focusStateLayerOpacity
123 when: control.pressed && control.enabled
125 indicatorState.stateLayerOpacity: MD.Tokens.switch.pressedStateLayerOpacity
132 objectName:
"switchTrack"
134 topLeftRadius: UiMetrics.resolveShapeRadius(MD.Tokens.switch.trackShape.topLeft,
136 topRightRadius: UiMetrics.resolveShapeRadius(MD.Tokens.switch.trackShape.topRight,
138 bottomLeftRadius: UiMetrics.resolveShapeRadius(MD.Tokens.switch.trackShape.bottomLeft,
140 bottomRightRadius: UiMetrics.resolveShapeRadius(
141 MD.Tokens.switch.trackShape.bottomRight, width, height)
142 color: indicatorState.trackColor
143 opacity: indicatorState.trackOpacity
144 border.width: indicatorState.borderWidth
145 border.color: indicatorState.borderColor
149 duration: MD.Tokens.motion.duration.short2
152 Behavior on border.color {
154 duration: MD.Tokens.motion.duration.short2
157 Behavior on border.width {
159 duration: MD.Tokens.motion.duration.short2
170 height: MD.Tokens.switch.stateLayerSize
171 y: (parent.height - height) / 2
172 x: switchIndicator.handleCenterX - width / 2
176 easing.type: Easing.BezierSpline
177 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
178 duration: MotionAnimation.expressiveFastSpatialDuration
183 objectName:
"switchStateLayer"
185 topLeftRadius: UiMetrics.resolveShapeRadius(
186 MD.
Tokens.switch.stateLayerShape.topLeft, width, height)
187 topRightRadius: UiMetrics.resolveShapeRadius(
188 MD.
Tokens.switch.stateLayerShape.topRight, width, height)
189 bottomLeftRadius: UiMetrics.resolveShapeRadius(
190 MD.
Tokens.switch.stateLayerShape.bottomLeft, width, height)
191 bottomRightRadius: UiMetrics.resolveShapeRadius(
192 MD.
Tokens.switch.stateLayerShape.bottomRight, width,
194 pressed: control.pressed
197 stateOpacity: indicatorState.stateLayerOpacity
198 color: indicatorState.stateLayerColor
202 objectName:
"switchHandle"
203 anchors.centerIn: parent
204 width: indicatorState.handleSize
206 topLeftRadius: UiMetrics.resolveShapeRadius(MD.
Tokens.switch.handleShape.topLeft,
208 topRightRadius: UiMetrics.resolveShapeRadius(MD.
Tokens.switch.handleShape.topRight,
210 bottomLeftRadius: UiMetrics.resolveShapeRadius(
211 MD.
Tokens.switch.handleShape.bottomLeft, width, height)
212 bottomRightRadius: UiMetrics.resolveShapeRadius(
213 MD.
Tokens.switch.handleShape.bottomRight, width, height)
214 color: indicatorState.handleColor
215 opacity: indicatorState.handleOpacity
219 easing.type: Easing.BezierSpline
220 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
221 duration: MotionAnimation.expressiveFastSpatialDuration
227 duration: MD.
Tokens.motion.duration.short2
232 anchors.centerIn: parent
233 iconWidth: control.checked ? MD.
Tokens.switch.selectedIconSize : MD.
Tokens.switch.unselectedIconSize
234 iconHeight: iconWidth
235 name: indicatorState.iconName
236 color: indicatorState.iconColor
237 opacity: indicatorState.showIcon ? 1.0 : 0.0
239 Behavior on opacity {
241 duration: MD.
Tokens.motion.duration.short2
247 duration: MD.
Tokens.motion.duration.short2
255 contentItem: MD.
Label {
256 leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0
257 rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0
260 typescale: control.typescale
261 color: control.enabled ? control.MD.Style.onSurfaceColor : control.MD.Style.onSurfaceVariantColor
262 elide: Text.ElideRight
263 verticalAlignment: Text.AlignVCenter
Material Design 3 design tokens.
Displays text using a selectable Material 3 type scale.
Material Design 3 switch tokens.
Material Symbols icon tokens.