4pragma ComponentBehavior: Bound
7import QtQuick.Templates as T
9import Fluid.Private as P
10import "../core/BadgeContent.js" as BadgeContent
11import "../internal" as Internal
107 readonly
property int effectiveVariant: _tabBar ? _tabBar.variant : MD.TabBar.Primary
109 property int maximumLineCount: 1
111 property MD.typescale typescale: MD.Tokens.typescale.titleSmall
113 property color containerColor: control.MD.Style.surfaceColor
115 property color contentColor: checked && effectiveVariant === MD.TabBar.Primary
116 ? control.MD.Style.primaryColor
117 : checked || hovered || visualFocus || down
118 ? control.MD.Style.onSurfaceColor : control.MD.Style.onSurfaceVariantColor
120 property color stateLayerColor: checked && effectiveVariant === MD.TabBar.Primary
121 ? control.MD.Style.primaryColor : control.MD.Style.onSurfaceColor
123 property bool tintSourceIcon:
true
125 property var badgeContent: _badgeAction ? _badgeAction.badgeContent :
""
127 property bool badgeNotification: _badgeAction ? _badgeAction.badgeNotification :
false
129 property bool badgeVisible: _badgeAction ? _badgeAction.badgeVisible :
true
131 property int badgeVariant: MD.Badge.Auto
133 property string badgeAccessibleDescription: _badgeAction ? _badgeAction.badgeAccessibleDescription :
""
135 readonly
property MD.TabBar _tabBar: T.TabBar.tabBar as MD.TabBar
136 property bool _destroying:
false
137 readonly
property MD.Action _badgeAction: action as MD.Action
138 readonly
property bool _showIcon: (icon.name.length > 0 || icon.source.toString().length > 0)
139 && display !== T.AbstractButton.TextOnly
140 readonly property
bool _showText: text.length > 0 && display !== T.AbstractButton.IconOnly
141 readonly property bool _stacked: effectiveVariant === MD.
TabBar.Primary
142 && display === T.AbstractButton.TextUnderIcon && _showIcon && _showText
143 readonly property bool _showBadge: badgeVisible
144 && (badgeNotification || BadgeContent.hasContent(badgeContent))
145 readonly property real _displayedContentWidth: tabContent.displayedContentWidth
146 readonly property real _primaryIndicatorWidth: Math.min(width,
147 Math.max(MD.
Tokens.tab.primaryActiveIndicatorMinimumWidth,
148 _displayedContentWidth - 2 * MD.
Tokens.tab.primaryActiveIndicatorHorizontalInset))
149 readonly property real _minimumWidth: Math.max(MD.
Tokens.tab.minimumInteractiveSize,
150 tabContent.overlayPaintWidth)
151 readonly property real _baselineHeight: _stacked
152 ? MD.
Tokens.tab.primaryWithIconAndLabelContainerHeight
153 : effectiveVariant === MD.
TabBar.Primary ? MD.
Tokens.tab.primaryContainerHeight
154 : MD.
Tokens.tab.secondaryContainerHeight
155 readonly property real _nominalContentHeight: _stacked
156 ? MD.
Tokens.tab.iconSize + MD.
Tokens.tab.stackedIconLabelGap
157 + MD.
Tokens.typescale.titleSmall.lineHeight
158 : Math.max(_showIcon ? MD.
Tokens.tab.iconSize : 0,
159 _showText ? MD.
Tokens.typescale.titleSmall.lineHeight : 0)
160 readonly property real _stateOpacity: !enabled ? 0
161 : down ? MD.
Tokens.tab.pressedStateLayerOpacity
162 : visualFocus ? MD.
Tokens.tab.focusStateLayerOpacity
163 : hovered ? MD.
Tokens.tab.hoverStateLayerOpacity : 0
165 implicitWidth: Math.max(MD.
Tokens.tab.minimumInteractiveSize,
166 implicitBackgroundWidth + leftInset + rightInset,
167 implicitContentWidth + leftPadding + rightPadding)
168 implicitHeight: Math.max(_baselineHeight,
169 implicitBackgroundHeight + topInset + bottomInset,
170 implicitContentHeight + topPadding + bottomPadding,
171 _baselineHeight + tabContent.contentHeight - _nominalContentHeight)
172 width: !visible ? 0 : _tabBar ? _tabBar._widthFor(control) : implicitWidth
173 height: _tabBar ? _tabBar.availableHeight : implicitHeight
175 leftPadding: MD.
Tokens.tab.horizontalPadding
176 rightPadding: MD.
Tokens.tab.horizontalPadding
177 display: effectiveVariant === MD.
TabBar.Primary ? T.AbstractButton.TextUnderIcon
178 : T.AbstractButton.TextBesideIcon
179 icon.width: MD.
Tokens.tab.iconSize
180 icon.height: MD.
Tokens.tab.iconSize
181 font.family: typescale.face === MD.Style.TypeFace.Brand
182 ? control.MD.Style.brandFontFamily : control.MD.Style.plainFontFamily
183 font.pixelSize: typescale.fontSize
184 font.weight: typescale.fontWeight
185 font.letterSpacing: typescale.tracking
188 focusPolicy: !_tabBar || _tabBar._isTabStop(control) || activeFocus
189 ? Qt.StrongFocus : Qt.ClickFocus
191 Accessible.name: BadgeContent.accessibleName(text, tabContent.accessibleBadgeDescription)
193 Accessible.selectable: true
194 Accessible.selected: checked
195 Accessible.onPressAction: {
196 if (control.enabled && control.visible)
200 onActiveFocusChanged: {
201 if (control._destroying)
203 const owner = control._tabBar;
204 if (!owner || owner._destroying)
207 owner._focusEntered(control);
209 Qt.callLater(control._notifyFocusLeft);
211 function _notifyFocusLeft() {
212 const owner = control._tabBar;
213 if (owner && !owner._destroying) owner._focusLeft();
215 function _notifyAvailability() {
216 const owner = control._tabBar;
217 if (owner && !owner._destroying) owner._availabilityChanged();
219 function _notifyGeometry() {
220 const owner = control._tabBar;
221 if (owner && !owner._destroying) owner._scheduleReveal();
223 onVisibleChanged:
if (!control._destroying) Qt.callLater(control._notifyAvailability)
224 onEnabledChanged:
if (!control._destroying) Qt.callLater(control._notifyAvailability)
225 onWidthChanged:
if (!control._destroying) Qt.callLater(control._notifyGeometry)
226 onCheckedChanged:
if (!control._destroying && checked) Qt.callLater(control._notifyGeometry)
227 Component.onDestruction: control._destroying =
true
229 Keys.priority: Keys.BeforeItem
230 Keys.onPressed:
event => {
231 if (event.isAutoRepeat && (event.key === Qt.Key_Space
232 || event.key === Qt.Key_Return || event.key === Qt.Key_Enter)) {
233 event.accepted =
true;
237 _tabBar._handleNavigation(event);
239 Keys.onReleased:
event => {
240 if (event.isAutoRepeat && (event.key === Qt.Key_Space
241 || event.key === Qt.Key_Return || event.key === Qt.Key_Enter))
242 event.accepted =
true;
245 P.TabKeyBridge { target: control }
247 FontMetrics { id: fontMetrics; font: control.font }
249 contentItem: Internal.TabContent {
252 iconName: control.icon.name
253 iconSource: control.icon.source
254 iconWidth: control.icon.width
255 iconHeight: control.icon.height
256 iconColor: control.icon.color.a > 0 ? control.icon.color : control.contentColor
257 contentColor: control.contentColor
258 textFont: control.font
259 textLineHeight: Math.max(control.typescale.lineHeight, fontMetrics.height)
260 showIcon: control._showIcon
261 showText: control._showText
262 stacked: control._stacked
263 layoutMirrored: control.mirrored
264 tintSourceIcon: control.tintSourceIcon
265 maximumLineCount: control.maximumLineCount
266 showBadge: control._showBadge
267 badgeContent: control.badgeContent
268 badgeNotification: control.badgeNotification
269 badgeVariant: control.badgeVariant
270 badgeAccessibleDescription: control.badgeAccessibleDescription
271 locale: control.locale
274 background: Rectangle {
275 color: control.containerColor
277 Internal.TabIndicator {
278 objectName:
"standaloneTabIndicator"
280 targetX: (control.width - targetWidth) / 2
281 targetWidth: control._primaryIndicatorWidth
282 y: control.height - height
283 indicatorColor: control.MD.Style.primaryColor
284 animationEnabled: false
285 visible: !control._tabBar && control.checked
289 objectName:
"tabStateLayer"
291 pressed: control.pressed || control.down
292 pressX: control.pressX
293 pressY: control.pressY
294 stateOpacity: control._stateOpacity
295 color: control.stateLayerColor
Material Design 3 design tokens.
A Material 3 primary or secondary tab strip.