Libplasma

TabButton.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 SPDX-FileCopyrightText: 2022 ivan (@ratijas) tkachenko <me@ratijas.tk>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8import QtQuick
9import QtQuick.Layouts
10import QtQuick.Controls
11import QtQml.Models
12import QtQuick.Templates as T
13import org.kde.ksvg as KSvg
14//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
15import org.kde.plasma.core as PlasmaCore
16import org.kde.kirigami as Kirigami
17import "private" as Private
18
19T.TabButton {
20 id: control
21
22 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
23 implicitContentWidth + leftPadding + rightPadding,
24 implicitIndicatorWidth + leftPadding + rightPadding)
25 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
26 implicitContentHeight + topPadding + bottomPadding,
27 implicitIndicatorHeight + topPadding + bottomPadding)
28
29 baselineOffset: contentItem.y + contentItem.baselineOffset
30 hoverEnabled: true
31
32 topPadding: (background as KSvg.FrameSvgItem)?.margins.top ?? undefined
33 leftPadding: (background as KSvg.FrameSvgItem)?.margins.left ?? undefined
34 rightPadding: (background as KSvg.FrameSvgItem)?.margins.right ?? undefined
35 bottomPadding: (background as KSvg.FrameSvgItem)?.margins.bottom ?? undefined
36
37 spacing: Kirigami.Units.smallSpacing
38
39 icon.width: Kirigami.Units.iconSizes.smallMedium
40 icon.height: Kirigami.Units.iconSizes.smallMedium
41
42 Kirigami.MnemonicData.enabled: control.enabled && control.visible
43 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.SecondaryControl
44 Kirigami.MnemonicData.label: control.text
45
46 Shortcut {
47 //in case of explicit & the button manages it by itself
48 enabled: !(RegExp(/\&[^\&]/).test(control.text))
49 sequence: control.Kirigami.MnemonicData.sequence
50 onActivated: control.animateClick()
51 }
52
53 contentItem: Private.IconLabel {
54 mirrored: control.mirrored
55 font: control.font
56 display: control.display
57 spacing: control.spacing
58 iconItem.implicitWidth: control.icon.width
59 iconItem.implicitHeight: control.icon.height
60 iconItem.source: control.icon.name || control.icon.source
61 iconItem.active: control.visualFocus
62 label.text: control.Kirigami.MnemonicData.richTextLabel
63 label.color: control.visualFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
64 Rectangle { // As long as we don't enable antialiasing, not rounding should be fine
65 parent: control.contentItem.label
66 width: Math.min(parent.width, parent.contentWidth)
67 height: 1
68 anchors.left: parent.left
69 anchors.top: parent.bottom
70 color: Kirigami.Theme.highlightColor
71 visible: control.visualFocus
72 }
73 }
74
75 background: KSvg.FrameSvgItem {
76 visible: !control.ListView.view || !control.ListView.view.highlightItem
77 imagePath: "widgets/tabbar"
78 prefix: control.T.TabBar.position === T.TabBar.Footer ? "south-active-tab" : "north-active-tab"
79 enabledBorders: {
80 const borders = KSvg.FrameSvgItem.LeftBorder | KSvg.FrameSvgItem.RightBorder
81 if (!visible || control.checked) {
82 return borders | KSvg.FrameSvgItem.TopBorder | KSvg.FrameSvgItem.BottomBorder
83 } else if (control.T.TabBar.position === T.TabBar.Footer) {
84 return borders | KSvg.FrameSvgItem.BottomBorder
85 } else {
86 return borders | KSvg.FrameSvgItem.TopBorder
87 }
88 }
89 }
90}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:57:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.