Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/RadioButton.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2017 The Qt Company Ltd. 0004 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0005 0006 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0007 */ 0008 0009 0010 import QtQuick 2.6 0011 import QtQuick.Templates 2.15 as T 0012 import QtQuick.Controls 2.15 0013 import org.kde.kirigami 2.4 as Kirigami 0014 import "private" 0015 0016 T.RadioButton { 0017 id: controlRoot 0018 0019 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, 0020 implicitContentWidth + leftPadding + rightPadding, 0021 implicitIndicatorWidth + leftPadding + rightPadding) 0022 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, 0023 implicitContentHeight + topPadding + bottomPadding, 0024 implicitIndicatorHeight + topPadding + bottomPadding) 0025 baselineOffset: contentItem.y + contentItem.baselineOffset 0026 0027 spacing: indicator && typeof indicator.pixelMetric === "function" ? indicator.pixelMetric("radiobuttonlabelspacing") : Kirigami.Units.smallSpacing 0028 0029 hoverEnabled: true 0030 0031 indicator: CheckIndicator { 0032 elementType: "radiobutton" 0033 x: if (control.contentItem !== null && control.contentItem.width > 0) { 0034 return control.mirrored ? 0035 control.width - width - control.rightPadding : control.leftPadding 0036 } else { 0037 return control.leftPadding + (control.availableWidth - width) / 2 0038 } 0039 y: if (control.contentItem !== null 0040 && (control.contentItem instanceof Text || control.contentItem instanceof TextEdit) 0041 && control.contentItem.lineCount > 1) { 0042 return control.topPadding 0043 } else { 0044 return control.topPadding + Math.round((control.availableHeight - height) / 2) 0045 } 0046 control: controlRoot 0047 } 0048 0049 Kirigami.MnemonicData.enabled: controlRoot.enabled && controlRoot.visible 0050 Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.ActionElement 0051 Kirigami.MnemonicData.label: controlRoot.text 0052 Shortcut { 0053 //in case of explicit & the button manages it by itself 0054 enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text)) 0055 sequence: controlRoot.Kirigami.MnemonicData.sequence 0056 onActivated: controlRoot.checked = true 0057 } 0058 0059 contentItem: Label { 0060 readonly property int indicatorEffectiveWidth: ( 0061 controlRoot.indicator 0062 && typeof controlRoot.indicator.pixelMetric === "function" 0063 && controlRoot.icon.name === "" 0064 && controlRoot.icon.source.toString() === "" 0065 ) ? controlRoot.indicator.pixelMetric("exclusiveindicatorwidth") + controlRoot.spacing 0066 : controlRoot.indicator.width 0067 0068 property FontMetrics fontMetrics: FontMetrics {} 0069 // Ensure consistent vertical position relative to indicator with multiple lines. 0070 // No need to round because .5 from the top will add with .5 from the bottom becoming 1. 0071 topPadding: Math.max(0, (controlRoot.implicitIndicatorHeight - fontMetrics.height) / 2) 0072 bottomPadding: topPadding 0073 leftPadding: controlRoot.indicator && !controlRoot.mirrored ? indicatorEffectiveWidth : 0 0074 rightPadding: controlRoot.indicator && controlRoot.mirrored ? indicatorEffectiveWidth : 0 0075 opacity: controlRoot.enabled ? 1 : 0.6 0076 text: controlRoot.Kirigami.MnemonicData.richTextLabel 0077 font: controlRoot.font 0078 elide: Text.ElideRight 0079 visible: controlRoot.text 0080 horizontalAlignment: Text.AlignLeft 0081 verticalAlignment: Text.AlignVCenter 0082 0083 FocusRect { 0084 control: controlRoot 0085 0086 anchors { 0087 top: parent.top 0088 left: parent.left 0089 bottom: parent.bottom 0090 topMargin: parent.topPadding - 1 0091 leftMargin: (controlRoot.mirrored ? parent.rightPadding : parent.leftPadding) - Kirigami.Units.smallSpacing / 2 0092 bottomMargin: parent.bottomPadding - 1 0093 } 0094 0095 width: parent.paintedWidth + Kirigami.Units.smallSpacing 0096 visible: control.activeFocus 0097 } 0098 } 0099 }