4pragma ComponentBehavior: Bound
7import QtQuick.Templates as T
9import "../core/UiMetrics.js" as UiMetrics
42 property int size:
FAB.Size.Default
45 property int variant:
FAB.Variant.Primary
48 property bool lowered:
false
51 property bool mirrorIconInRtl:
false
54 property color containerColor: {
56 case FAB.Variant.Surface:
57 return lowered ? control.MD.Style.surfaceContainerLowColor : control.MD.Style.surfaceContainerHighColor;
58 case FAB.Variant.Primary:
59 return control.MD.Style.primaryContainerColor;
60 case FAB.Variant.Secondary:
61 return control.MD.Style.secondaryContainerColor;
62 case FAB.Variant.Tertiary:
63 return control.MD.Style.tertiaryContainerColor;
68 property color contentColor: {
70 case FAB.Variant.Surface:
71 return control.MD.Style.primaryColor;
72 case FAB.Variant.Primary:
73 return control.MD.Style.onPrimaryContainerColor;
74 case FAB.Variant.Secondary:
75 return control.MD.Style.onSecondaryContainerColor;
76 case FAB.Variant.Tertiary:
77 return control.MD.Style.onTertiaryContainerColor;
82 readonly
property color effectiveContentColor: state.contentColor
85 readonly
property color effectiveContainerColor: state.containerColor
88 readonly
property real effectiveElevation: state.elevation
91 readonly
property string effectiveIconName: icon.name
94 readonly
property url effectiveIconSource: icon.source
97 readonly
property color effectiveIconColor: icon.color.a > 0 ? icon.color : effectiveContentColor
100 readonly
property bool effectiveIconMirrored: mirrorIconInRtl && mirrored
102 icon.width: state.iconSize
103 icon.height: state.iconSize
105 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding)
106 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding)
116 focusPolicy: Qt.StrongFocus
118 Accessible.name: text
119 Accessible.role: Accessible.Button
124 readonly
property real containerWidth: {
125 switch (control.size) {
126 case FAB.Size.Default:
127 return MD.Tokens.fab.containerWidth;
128 case FAB.Size.Medium:
129 return MD.Tokens.fab.mediumContainerWidth;
131 return MD.Tokens.fab.largeContainerWidth;
134 readonly
property real containerHeight: {
135 switch (control.size) {
136 case FAB.Size.Default:
137 return MD.Tokens.fab.containerHeight;
138 case FAB.Size.Medium:
139 return MD.Tokens.fab.mediumContainerHeight;
141 return MD.Tokens.fab.largeContainerHeight;
144 readonly
property MD.shapeValue containerShape: {
145 switch (control.size) {
146 case FAB.Size.Default:
147 return MD.Tokens.fab.containerShape;
148 case FAB.Size.Medium:
149 return MD.Tokens.fab.mediumContainerShape;
151 return MD.Tokens.fab.largeContainerShape;
154 readonly
property real iconSize: {
155 switch (control.size) {
156 case FAB.Size.Default:
157 return MD.Tokens.fab.iconSize;
158 case FAB.Size.Medium:
159 return MD.Tokens.fab.mediumIconSize;
161 return MD.Tokens.fab.largeIconSize;
165 property color containerColor: control.containerColor
166 property color contentColor: control.contentColor
167 property color stateLayerColor:
"transparent"
169 property real elevation: control.lowered ? MD.Tokens.fab.loweredContainerElevation : MD.Tokens.fab.containerElevation
170 property real stateLayerOpacity: 0
176 when: control.down && control.enabled
179 state.elevation: control.lowered ? MD.Tokens.fab.loweredPressedContainerElevation : MD.Tokens.fab.pressedContainerElevation
180 state.stateLayerColor: control.effectiveIconColor
181 state.stateLayerOpacity: MD.Tokens.fab.pressedStateLayerOpacity
186 when: control.visualFocus && control.enabled
189 state.elevation: control.lowered ? MD.Tokens.fab.loweredFocusContainerElevation : MD.Tokens.fab.focusContainerElevation
190 state.stateLayerColor: control.effectiveIconColor
191 state.stateLayerOpacity: MD.Tokens.fab.focusStateLayerOpacity
196 when: control.hovered && control.enabled
199 state.elevation: control.lowered ? MD.Tokens.fab.loweredHoverContainerElevation : MD.Tokens.fab.hoverContainerElevation
200 state.stateLayerColor: control.effectiveIconColor
201 state.stateLayerOpacity: MD.Tokens.fab.hoverStateLayerOpacity
209 implicitWidth: control.icon.width
210 implicitHeight: control.icon.height
213 origin.x: iconContent.width / 2
214 origin.y: iconContent.height / 2
215 xScale: control.effectiveIconMirrored ? -1 : 1
221 objectName:
"fabSourceImage"
222 anchors.centerIn: parent
223 width: control.icon.width
224 height: control.icon.height
225 source: control.effectiveIconSource
226 sourceSize: Qt.size(control.icon.width, control.icon.height)
227 fillMode: Image.PreserveAspectFit
228 visible: control.effectiveIconSource.toString().length > 0
232 objectName:
"fabSymbol"
233 anchors.centerIn: parent
234 name: control.effectiveIconName
235 iconWidth: control.icon.width
236 iconHeight: control.icon.height
237 color: control.effectiveIconColor
238 visible: control.effectiveIconSource.toString().length === 0 && name.length > 0
242 background: MD.ElevationRectangle {
243 implicitWidth: state.containerWidth
244 implicitHeight: state.containerHeight
245 topLeftRadius: UiMetrics.resolveShapeRadius(state.containerShape.topLeft, width, height)
246 topRightRadius: UiMetrics.resolveShapeRadius(state.containerShape.topRight, width, height)
247 bottomLeftRadius: UiMetrics.resolveShapeRadius(state.containerShape.bottomLeft, width, height)
248 bottomRightRadius: UiMetrics.resolveShapeRadius(state.containerShape.bottomRight, width,
250 color: state.containerColor
251 elevation: state.elevation
254 objectName:
"fabRipple"
256 topLeftRadius: parent.topLeftRadius
257 topRightRadius: parent.topRightRadius
258 bottomLeftRadius: parent.bottomLeftRadius
259 bottomRightRadius: parent.bottomRightRadius
260 pressed: control.pressed
261 pressX: control.pressX
262 pressY: control.pressY
263 stateOpacity: state.stateLayerOpacity
264 color: state.stateLayerColor
A Material Design 3 Expressive floating action button.