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 contentItem: RowLayout { 0088 spacing: 0 0089 0090 Private.ContentItemLoader { 0091 Layout.rightMargin: visible ? root.leadingPadding : 0 0092 visible: root.leading 0093 implicitHeight: visible ? root.leading.implicitHeight : 0 0094 implicitWidth: visible ? root.leading.implicitWidth : 0 0095 contentItem: root.leading 0096 } 0097 0098 ColumnLayout { 0099 Layout.fillWidth: true 0100 spacing: Kirigami.Units.smallSpacing 0101 0102 Controls.Label { 0103 Layout.fillWidth: true 0104 text: root.text 0105 elide: Text.ElideRight 0106 wrapMode: Text.Wrap 0107 maximumLineCount: 2 0108 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0109 } 0110 0111 Controls.Label { 0112 visible: root.description !== "" 0113 Layout.fillWidth: true 0114 text: root.description 0115 wrapMode: Text.Wrap 0116 color: Kirigami.Theme.disabledTextColor 0117 } 0118 } 0119 0120 Controls.Switch { 0121 id: switchItem 0122 focusPolicy: Qt.NoFocus // provided by delegate 0123 Layout.leftMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0124 0125 enabled: root.enabled 0126 checked: root.checked 0127 0128 onToggled: root.toggled() 0129 onClicked: root.clicked() 0130 onPressAndHold: root.pressAndHold() 0131 onDoubleClicked: root.doubleClicked() 0132 0133 onCheckedChanged: { 0134 root.checked = checked; 0135 checked = Qt.binding(() => root.checked); 0136 } 0137 } 0138 0139 Private.ContentItemLoader { 0140 Layout.leftMargin: visible ? root.trailingPadding : 0 0141 visible: root.trailing 0142 implicitHeight: visible ? root.trailing.implicitHeight : 0 0143 implicitWidth: visible ? root.trailing.implicitWidth : 0 0144 contentItem: root.trailing 0145 } 0146 } 0147 }