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: if (control.action) {
51 control.action.trigger()
52 } else if (control.checkable && !control.checked) {
53 // A checkable AbstractButton clicked by a user would normally
54 // change the checked state first before emitting clicked().
55 control.toggle()
56 // Manually emit clicked() because action.trigger() is the only
57 // button related function that automatically emits clicked()
58 control.clicked()
59 }
60 }
61
62 contentItem: Private.IconLabel {
63 mirrored: control.mirrored
64 font: control.font
65 display: control.display
66 spacing: control.spacing
67 iconItem.implicitWidth: control.icon.width
68 iconItem.implicitHeight: control.icon.height
69 iconItem.source: control.icon.name || control.icon.source
70 iconItem.active: control.visualFocus
71 label.text: control.Kirigami.MnemonicData.richTextLabel
72 label.color: control.visualFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
73 Rectangle { // As long as we don't enable antialiasing, not rounding should be fine
74 parent: control.contentItem.label
75 width: Math.min(parent.width, parent.contentWidth)
76 height: 1
77 anchors.left: parent.left
78 anchors.top: parent.bottom
79 color: Kirigami.Theme.highlightColor
80 visible: control.visualFocus
81 }
82 }
83
84 background: KSvg.FrameSvgItem {
85 visible: !control.ListView.view || !control.ListView.view.highlightItem
86 imagePath: "widgets/tabbar"
87 prefix: control.T.TabBar.position === T.TabBar.Footer ? "south-active-tab" : "north-active-tab"
88 enabledBorders: {
89 const borders = KSvg.FrameSvgItem.LeftBorder | KSvg.FrameSvgItem.RightBorder
90 if (!visible || control.checked) {
91 return borders | KSvg.FrameSvgItem.TopBorder | KSvg.FrameSvgItem.BottomBorder
92 } else if (control.T.TabBar.position === T.TabBar.Footer) {
93 return borders | KSvg.FrameSvgItem.BottomBorder
94 } else {
95 return borders | KSvg.FrameSvgItem.TopBorder
96 }
97 }
98 }
99}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.