Warning, /libraries/kirigami-addons/src/formcard/FormSwitchDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2022 Devin Lin <devin@kde.org> 0003 * SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 import QtQuick 2.15 0007 import QtQuick.Templates 2.15 as T 0008 import QtQuick.Controls 2.15 as Controls 0009 import QtQuick.Layouts 1.15 0010 0011 import org.kde.kirigami 2.19 as Kirigami 0012 0013 import "private" as Private 0014 0015 /** 0016 * @brief A Form delegate that corresponds to a switch. 0017 * 0018 * This component is used to create a purely on/off toggle for a single 0019 * setting. 0020 * 0021 * Use the inherited QtQuick.Controls.AbstractButton.text property to define 0022 * the main text of the button. 0023 * 0024 * If you need an on/off/tristate toggle, use a FormCheckDelegate instead. 0025 * 0026 * If you need multiple values for the same setting, use a 0027 * FormComboBoxDelegate instead. 0028 * 0029 * If you need multiple toggles for the same setting, use a FormRadioDelegate 0030 * instead. 0031 * 0032 * @since KirigamiAddons 0.11.0 0033 * 0034 * @see QtQuick.Controls.AbstractButton 0035 * @see FormCheckDelegate 0036 * @see FormComboBoxDelegate 0037 * @see FormRadioDelegate 0038 * 0039 * @inherit QtQuick.Controls.SwitchDelegate 0040 */ 0041 T.SwitchDelegate { 0042 id: root 0043 0044 /** 0045 * @brief A label containing secondary text that appears under the inherited text property. 0046 * 0047 * This provides additional information shown in a faint gray color. 0048 */ 0049 property string description: "" 0050 0051 /** 0052 * @brief This property holds an item that will be displayed 0053 * to the left of the delegate's contents. 0054 */ 0055 property var leading: null 0056 0057 /** 0058 * @brief This property holds the padding after the leading item. 0059 */ 0060 property real leadingPadding: Kirigami.Units.smallSpacing 0061 0062 /** 0063 * @brief This property holds an item that will be displayed 0064 * to the right of the delegate's contents. 0065 */ 0066 property var trailing: null 0067 0068 /** 0069 * @brief This property holds the padding before the trailing item. 0070 */ 0071 property real trailingPadding: Kirigami.Units.smallSpacing 0072 0073 leftPadding: Kirigami.Units.gridUnit 0074 topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0075 bottomPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0076 rightPadding: Kirigami.Units.gridUnit 0077 0078 implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding 0079 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding 0080 0081 focusPolicy: Qt.StrongFocus 0082 hoverEnabled: true 0083 background: FormDelegateBackground { control: root } 0084 0085 Layout.fillWidth: true 0086 0087 Accessible.description: root.description 0088 Accessible.role: Accessible.CheckBox 0089 Accessible.onPressAction: switchItem.toggle() 0090 Accessible.onToggleAction: switchItem.toggle() 0091 0092 contentItem: RowLayout { 0093 spacing: 0 0094 0095 Private.ContentItemLoader { 0096 Layout.rightMargin: visible ? root.leadingPadding : 0 0097 visible: root.leading 0098 implicitHeight: visible ? root.leading.implicitHeight : 0 0099 implicitWidth: visible ? root.leading.implicitWidth : 0 0100 contentItem: root.leading 0101 } 0102 0103 ColumnLayout { 0104 Layout.fillWidth: true 0105 spacing: Kirigami.Units.smallSpacing 0106 0107 Controls.Label { 0108 Layout.fillWidth: true 0109 text: root.text 0110 elide: Text.ElideRight 0111 wrapMode: Text.Wrap 0112 maximumLineCount: 2 0113 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0114 Accessible.ignored: true 0115 } 0116 0117 Controls.Label { 0118 visible: root.description !== "" 0119 Layout.fillWidth: true 0120 text: root.description 0121 wrapMode: Text.Wrap 0122 color: Kirigami.Theme.disabledTextColor 0123 Accessible.ignored: true 0124 } 0125 } 0126 0127 Controls.Switch { 0128 id: switchItem 0129 focusPolicy: Qt.NoFocus // provided by delegate 0130 Layout.leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0131 0132 enabled: root.enabled 0133 checked: root.checked 0134 0135 onToggled: root.toggled() 0136 onClicked: root.clicked() 0137 onPressAndHold: root.pressAndHold() 0138 onDoubleClicked: root.doubleClicked() 0139 0140 onCheckedChanged: { 0141 root.checked = checked; 0142 checked = Qt.binding(() => root.checked); 0143 } 0144 0145 Accessible.ignored: true 0146 } 0147 0148 Private.ContentItemLoader { 0149 Layout.leftMargin: visible ? root.trailingPadding : 0 0150 visible: root.trailing 0151 implicitHeight: visible ? root.trailing.implicitHeight : 0 0152 implicitWidth: visible ? root.trailing.implicitWidth : 0 0153 contentItem: root.trailing 0154 } 0155 } 0156 }