Libplasma

RadioButton.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.Templates as T
10import org.kde.kirigami as Kirigami
11import "private" as Private
12
13T.RadioButton {
14 id: control
15
16 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
17 implicitContentWidth + leftPadding + rightPadding,
18 implicitIndicatorWidth + leftPadding + rightPadding)
19 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
20 implicitContentHeight + topPadding + bottomPadding,
21 implicitIndicatorHeight + topPadding + bottomPadding)
22
23 baselineOffset: contentItem.y + contentItem.baselineOffset
24 spacing: Kirigami.Units.smallSpacing
25 hoverEnabled: true
26
27 icon.width: Kirigami.Units.iconSizes.sizeForLabels
28 icon.height: Kirigami.Units.iconSizes.sizeForLabels
29
30 Kirigami.MnemonicData.enabled: enabled && visible
31 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.ActionElement
32 Kirigami.MnemonicData.label: text
33 Shortcut {
34 //in case of explicit & the button manages it by itself
35 enabled: !(RegExp(/\&[^\&]/).test(control.text))
36 sequence: control.Kirigami.MnemonicData.sequence
37 onActivated: control.animateClick()
38 }
39
40 indicator: RadioIndicator {
41 x: (control.text || control.icon.name || control.icon.source)
42 ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding)
43 : control.leftPadding + Math.round((control.availableWidth - width) / 2)
44 y: control.topPadding + Math.round((control.availableHeight - height) / 2)
45
46 control: control
47 }
48
49 contentItem: Private.IconLabel {
50 id: contentLabel
51
52 readonly property int effectiveIndicatorWidth: control.indicator && control.indicator.visible && control.indicator.width > 0
53 ? control.indicator.width + control.spacing : 0
54
55 mirrored: control.mirrored
56 leftPadding: !control.mirrored ? effectiveIndicatorWidth : 0
57 rightPadding: control.mirrored ? effectiveIndicatorWidth : 0
58
59 font: control.font
60 alignment: Qt.AlignLeft | Qt.AlignVCenter
61 display: control.display
62 spacing: control.spacing
63 iconItem.implicitWidth: control.icon.width
64 iconItem.implicitHeight: control.icon.height
65 iconItem.source: control.icon.name || control.icon.source
66 label.text: control.Kirigami.MnemonicData.richTextLabel
67
68 Rectangle { // As long as we don't enable antialiasing, not rounding should be fine
69 parent: contentLabel.label
70 width: Math.min(parent.width, contentLabel.label.contentWidth)
71 height: 1
72 anchors.left: parent.left
73 anchors.top: parent.bottom
74 color: Kirigami.Theme.highlightColor
75 visible: control.visualFocus
76 }
77 }
78}
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.