MauiKit Controls

TabButton.qml
1
2import QtQuick
3import QtQuick.Controls 2.15 as QQC
4import QtQuick.Layouts
5
6import org.mauikit.controls 1.3 as Maui
7
8/**
9 * @inherit QtQuick.Controls.TabButton
10 * @brief A expanded implementation of the QQC2 TabButton with a predefined horizontal layout.
11 *
12 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-tabbutton.html">This control inherits from QQC2 TabButton, to checkout its inherited properties refer to the Qt Docs.</a>
13 *
14 * By default the layout of this control is divided into three sections.
15 * Extra items can be appended to the left and right side areas, while the center area is reserved for the title text.
16 * @see leftContent
17 * @see rightContent
18 */
19QQC.TabButton
20{
21 id: control
22
23 /**
24 * @brief An alias exposed to append more elements into the main container of this control.
25 * @property list<QtObject> TabButton::content
26 */
27 default property alias content: _content.data
29 /**
30 * @brief Use this to append items to the left area of this control.
31 * @property list<QtObject> TabButton::leftContent
32 */
33 property alias leftContent: _leftContent.data
34
35 /**
36 * @brief Use this to append items to the right area of this control.
37 * @property list<QtObject> TabButton::rightContent
38 */
39 property alias rightContent: _rightContent.data
40
41 /**
42 * @brief Use this to add items between the background and the control contents.
43 * @property list<QtObject> TabButton::underlayContent
44 */
45 property alias underlayContent: _underlay.data
46
47 /**
48 * @brief Whether a close button should be shown in the far left area.
49 * If it is visible and pressed, a signal is emitted.
50 * @see closeClicked
51 * By default this is set to `true`.
52 */
53 property bool closeButtonVisible: true
54
55 /**
56 * @brief Emitted when the close button is pressed.
57 * @see closeButtonVisible
58 */
59 signal closeClicked()
60
61 /**
62 * @brief Emitted when the area of the control has been right clicked.
63 * This can be consumed in order to open a contextual menu, for example.
64 * @param mouse The object with information of the event.
65 */
66 signal rightClicked(var mouse)
67
68 contentItem: MouseArea
69 {
70 implicitWidth: _layout.implicitWidth
71 implicitHeight: _layout.implicitHeight
72
73 acceptedButtons: Qt.RightButton
74 propagateComposedEvents: true
75 preventStealing: false
76
77 onClicked: (mouse) =>
78 {
79 if(mouse.button === Qt.RightButton)
80 {
81 control.rightClicked(mouse)
82 }
83
84 mouse.accepted = false
85 }
86
87 Item
88 {
89 id: _underlay
90 anchors.fill: parent
91 }
92
93 RowLayout
94 {
95 id: _layout
96 anchors.fill: parent
97 spacing: control.spacing
98
99 Row
100 {
101 id: _leftContent
102 }
103
104 Maui.IconLabel
105 {
106 id: _content
107 Layout.fillWidth: true
108 Layout.fillHeight: true
109 opacity: control.checked || control.hovered ? 1 : 0.7
110
111 text: control.text
112 icon: control.icon
113 color: Maui.Theme.textColor
114 alignment: Qt.AlignHCenter
115 display: QQC.ToolButton.TextBesideIcon
116 font: control.font
117 }
118
119 Row
120 {
121 id: _rightContent
122 }
123
124 Loader
125 {
126 asynchronous: true
127 active: control.closeButtonVisible
128
129 Layout.alignment: Qt.AlignCenter
130
131 sourceComponent: Maui.CloseButton
132 {
133 opacity: Maui.Handy.isMobile ? 1 : (control.hovered || control.checked ? 1 : 0)
134 padding: 0
135
136 implicitHeight: 16
137 implicitWidth: 16
138
139 icon.width: 16
140 icon.height: 16
141
142 onClicked: control.closeClicked()
143
144 Behavior on opacity
145 {
146 NumberAnimation
147 {
148 duration: Maui.Style.units.longDuration
149 easing.type: Easing.InOutQuad
150 }
151 }
152 }
153 }
154 }
155 }
156}
157
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.