5import QtQuick.Templates as T
6import QtQuick.Controls.impl as TImpl
8import "../core/UiMetrics.js" as UiMetrics
9import "../internal/MotionAnimation.js" as MotionAnimation
27 component IconData: QtObject {
31 property bool fill:
false
94 property int widthVariant:
IconButton.Width.Default
97 property var __buttonGroup: null
98 property real __groupTopLeftRadius: -1
99 property real __groupTopRightRadius: -1
100 property real __groupBottomLeftRadius: -1
101 property real __groupBottomRightRadius: -1
109 property IconData checkedIcon: IconData {}
112 property bool mirrorIconInRtl:
false
118 property bool tintSourceIcon:
true
124 property color contentColor: {
127 return checked ? MD.Style.onPrimaryColor : MD.Style.onSurfaceVariantColor;
129 return checked ? MD.Style.onSecondaryColor : MD.Style.onSecondaryContainerColor;
131 return checked ? MD.Style.inverseOnSurfaceColor : MD.Style.onSurfaceVariantColor;
133 return checked ? MD.Style.primaryColor : MD.Style.onSurfaceVariantColor;
141 property color containerColor: {
144 return checked ? MD.Style.primaryColor : MD.Style.surfaceContainerColor;
146 return checked ? MD.Style.secondaryColor : MD.Style.secondaryContainerColor;
148 return checked ? MD.Style.inverseSurfaceColor :
"transparent";
150 return "transparent";
155 property color disabledContentColor: MD.Style.onSurfaceColor
158 property color disabledContainerColor: MD.Style.onSurfaceColor
161 property color outlineColor: MD.Style.outlineVariantColor
164 readonly
property color effectiveContentColor: state.contentColor
167 readonly
property real effectiveContentOpacity: state.contentOpacity
170 readonly
property color effectiveContainerColor: state.containerColor
173 readonly
property bool usingCheckedIcon: checked && (checkedIcon.name.length > 0 || checkedIcon.source.toString().length > 0)
176 readonly property
string effectiveIconName: usingCheckedIcon ? checkedIcon.name : icon.name
179 readonly property url effectiveIconSource: usingCheckedIcon ? checkedIcon.source : icon.source
182 readonly property color effectiveIconColor: {
183 const explicitColor = usingCheckedIcon ? checkedIcon.color : icon.color;
184 return explicitColor.a > 0 ? explicitColor : effectiveContentColor;
188 readonly
property bool effectiveIconFill: checked && (usingCheckedIcon ? checkedIcon.fill :
true)
191 readonly property
bool effectiveIconMirrored: mirrorIconInRtl && mirrored
193 icon.width: state.iconSize.width
194 icon.height: state.iconSize.height
196 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding)
197 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding)
199 leftInset: state.inset.width / 2
200 rightInset: state.inset.width / 2
201 topInset: state.inset.height / 2
202 bottomInset: state.inset.height / 2
209 focusPolicy: Qt.StrongFocus
213 __buttonGroup.__childCheckedChanged(control);
215 onActiveFocusChanged: {
216 if (activeFocus && __buttonGroup)
217 __buttonGroup.__childFocused(control);
221 __buttonGroup.__childGeometryChanged();
223 onImplicitWidthChanged: {
225 __buttonGroup.__childGeometryChanged();
229 __buttonGroup.__childrenChanged();
233 __buttonGroup.__childrenChanged();
235 Keys.onPressed:
event => {
236 if (__buttonGroup && __buttonGroup.__handleKey(control, event))
237 event.accepted =
true;
241 enabled: control.__buttonGroup && control.__buttonGroup.__geometryInitialized
242 && control.__buttonGroup.variant === control.__buttonGroup.__standardVariant
244 easing.type: Easing.BezierSpline
245 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
246 duration: MotionAnimation.expressiveFastSpatialDuration
250 enabled: control.__buttonGroup && control.__buttonGroup.__geometryInitialized
251 && control.__buttonGroup.variant === control.__buttonGroup.__standardVariant
253 easing.type: Easing.BezierSpline
254 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
255 duration: MotionAnimation.expressiveFastSpatialDuration
259 Accessible.role: __buttonGroup && __buttonGroup.selectionMode === __buttonGroup.__singleSelectionMode
260 ? Accessible.RadioButton
261 : (__buttonGroup && __buttonGroup.selectionMode === __buttonGroup.__multiSelectionMode
262 ? Accessible.CheckBox : Accessible.Button)
263 Accessible.checkable: checkable
264 Accessible.checked: checked
269 readonly property real currentContainerHeight: {
270 switch (control.size) {
278 readonly
property real currentIconSize: {
279 switch (control.size) {
287 readonly
property real currentLeadingSpace: {
288 if (control.widthVariant ===
IconButton.Width.Narrow) {
289 switch (control.size) {
297 if (control.widthVariant ===
IconButton.Width.Wide) {
298 switch (control.size) {
306 switch (control.size) {
314 readonly
property real currentTrailingSpace: {
315 if (control.widthVariant ===
IconButton.Width.Narrow) {
316 switch (control.size) {
324 if (control.widthVariant ===
IconButton.Width.Wide) {
325 switch (control.size) {
333 switch (control.size) {
341 readonly
property real outlineWidth: {
342 switch (control.size) {
350 property size buttonSize: Qt.size(currentIconSize + currentLeadingSpace + currentTrailingSpace, currentContainerHeight)
351 property size iconSize: Qt.size(currentIconSize, currentIconSize)
353 property size inset: {
354 const minimum = MD.Tokens.iconButton.minimumInteractiveSize;
355 return Qt.size(Math.max(minimum, state.buttonSize.width) - state.buttonSize.width,
356 Math.max(minimum, state.buttonSize.height) - state.buttonSize.height);
359 property MD.shapeValue containerShape: {
360 const tokens = MD.Tokens.iconButton;
361 if (control.pressed) {
362 switch (control.size) {
370 if (control.checked) {
371 if (control.shape ===
IconButton.Shape.Square)
372 return tokens.selectedContainerShapeSquare;
373 switch (control.size) {
382 return tokens.containerShapeRound;
383 switch (control.size) {
392 property color containerColor: control.containerColor
393 property color contentColor: control.contentColor
394 property color stateLayerColor:
"transparent"
396 property real contentOpacity: 1.0
397 property real containerOpacity: 1.0
398 property real stateLayerOpacity: 0.0
404 when: !control.enabled
407 state.containerColor: control.type ===
IconButton.Type.Standard ?
"transparent" : control.disabledContainerColor
408 state.contentColor: control.disabledContentColor
410 state.contentOpacity: MD.Tokens.iconButton.disabledIconOpacity
415 when: control.down && control.enabled
418 state.stateLayerColor: control.effectiveIconColor
419 state.stateLayerOpacity: MD.Tokens.iconButton.pressedStateLayerOpacity
424 when: control.visualFocus && control.enabled
427 state.stateLayerColor: control.effectiveIconColor
428 state.stateLayerOpacity: MD.Tokens.iconButton.focusStateLayerOpacity
433 when: control.hovered && control.enabled
436 state.stateLayerColor: control.effectiveIconColor
437 state.stateLayerOpacity: MD.Tokens.iconButton.hoverStateLayerOpacity
445 implicitWidth: control.icon.width
446 implicitHeight: control.icon.height
449 origin.x: iconContent.width / 2
450 origin.y: iconContent.height / 2
451 xScale: control.effectiveIconMirrored ? -1 : 1
457 objectName:
"iconButtonSourceImage"
458 anchors.centerIn: parent
459 width: control.icon.width
460 height: control.icon.height
461 source: control.effectiveIconSource
462 sourceSize: Qt.size(control.icon.width, control.icon.height)
463 fillMode: Image.PreserveAspectFit
464 color: control.tintSourceIcon ? control.effectiveIconColor :
"transparent"
465 opacity: state.contentOpacity
466 visible: control.effectiveIconSource.toString().length > 0
470 objectName:
"iconButtonSymbol"
471 anchors.centerIn: parent
472 name: control.effectiveIconName
473 iconWidth: control.icon.width
474 iconHeight: control.icon.height
475 color: control.effectiveIconColor
476 opacity: state.contentOpacity
477 fill: control.effectiveIconFill
478 visible: control.effectiveIconSource.toString().length === 0 && name.length > 0
482 background: Rectangle {
483 implicitWidth: state.buttonSize.width
484 implicitHeight: state.buttonSize.height
486 topLeftRadius: control.__groupTopLeftRadius >= 0 ? control.__groupTopLeftRadius : UiMetrics.resolveShapeRadius(state.containerShape.topLeft, width, height)
487 topRightRadius: control.__groupTopRightRadius >= 0 ? control.__groupTopRightRadius : UiMetrics.resolveShapeRadius(state.containerShape.topRight, width, height)
488 bottomLeftRadius: control.__groupBottomLeftRadius >= 0 ? control.__groupBottomLeftRadius : UiMetrics.resolveShapeRadius(state.containerShape.bottomLeft, width, height)
489 bottomRightRadius: control.__groupBottomRightRadius >= 0 ? control.__groupBottomRightRadius : UiMetrics.resolveShapeRadius(state.containerShape.bottomRight, width, height)
491 Behavior on topLeftRadius {
492 enabled: !control.__buttonGroup || control.__buttonGroup.__geometryInitialized
494 easing.type: Easing.BezierSpline
495 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
496 duration: MotionAnimation.expressiveFastSpatialDuration
499 Behavior on topRightRadius {
500 enabled: !control.__buttonGroup || control.__buttonGroup.__geometryInitialized
502 easing.type: Easing.BezierSpline
503 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
504 duration: MotionAnimation.expressiveFastSpatialDuration
507 Behavior on bottomLeftRadius {
508 enabled: !control.__buttonGroup || control.__buttonGroup.__geometryInitialized
510 easing.type: Easing.BezierSpline
511 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
512 duration: MotionAnimation.expressiveFastSpatialDuration
515 Behavior on bottomRightRadius {
516 enabled: !control.__buttonGroup || control.__buttonGroup.__geometryInitialized
518 easing.type: Easing.BezierSpline
519 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
520 duration: MotionAnimation.expressiveFastSpatialDuration
524 border.width: control.type ===
IconButton.Type.Outlined && !control.checked ? state.outlineWidth : 0
525 border.color: control.outlineColor
527 opacity: state.containerOpacity
528 color: state.containerColor
533 topLeftRadius: parent.topLeftRadius
534 topRightRadius: parent.topRightRadius
535 bottomLeftRadius: parent.bottomLeftRadius
536 bottomRightRadius: parent.bottomRightRadius
538 pressed: control.pressed
539 pressX: control.pressX
540 pressY: control.pressY
542 stateOpacity: state.stateLayerOpacity
543 color: state.stateLayerColor