Warning, /libraries/kirigami-addons/src/formcard/FormCheckDelegate.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 checkbox.
0017  *
0018  * This component is used for individual settings that can be toggled on, off, or tristate, typically in conjunction with multiple other checkboxes.
0019  *
0020  * Use the inherited QtQuick.Controls.AbstractButton.text property to define the main text of the checkbox.
0021  *
0022  * If you need a purely on/off toggle for a single setting, consider using a FormSwitchDelegate.
0023  *
0024  * If you need multiple toggles for the same setting, use a FormRadioDelegate
0025  * instead.
0026  *
0027  * If you need multiple values for the same setting, use a
0028  * FormComboBoxDelegate instead.
0029  *
0030  * @since KirigamiAddons 0.11.0
0031  *
0032  * @see QtQuick.Controls.AbstractButton
0033  * @see FormSwitchDelegate
0034  * @see FormComboBoxDelegate
0035  * @see FormRadioDelegate
0036  *
0037  * @inherit QtQuick.Controls.CheckDelegate
0038  */
0039 T.CheckDelegate {
0040     id: root
0041 
0042     /**
0043      * @brief A label containing secondary text that appears under the
0044      * inherited text property.
0045      *
0046      * This provides additional information shown in a faint gray color.
0047      */
0048     property string description: ""
0049 
0050     /**
0051      * @brief This property holds an item that will be displayed to the left
0052      * of the delegate's contents.
0053      */
0054     property var leading: null
0055 
0056     /**
0057      * @brief This property holds the padding after the leading item.
0058      */
0059     property real leadingPadding: Kirigami.Units.smallSpacing
0060 
0061     /**
0062      * @brief This property holds an item that will be displayed to the right
0063      * of the delegate's contents.
0064      */
0065     property var trailing: null
0066 
0067     /**
0068      * @brief This property holds the padding before the trailing item.
0069      */
0070     property real trailingPadding: Kirigami.Units.smallSpacing
0071 
0072     /**
0073      * @brief This property allows to override the internal description
0074      * item (a QtQuick.Controls.Label) with a custom component.
0075      */
0076     property alias descriptionItem: internalDescriptionItem
0077 
0078     leftPadding: Kirigami.Units.gridUnit
0079     topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
0080     bottomPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
0081     rightPadding: Kirigami.Units.gridUnit
0082 
0083     implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
0084     implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
0085 
0086     focusPolicy: Qt.StrongFocus
0087     hoverEnabled: true
0088     background: FormDelegateBackground { control: root }
0089 
0090     Layout.fillWidth: true
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         Controls.CheckBox {
0104             id: checkBoxItem
0105             Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
0106             focusPolicy: Qt.NoFocus // provided by delegate
0107 
0108             checkState: root.checkState
0109             nextCheckState: root.nextCheckState
0110             tristate: root.tristate
0111 
0112             onToggled: {
0113                 root.toggle();
0114                 root.toggled();
0115             }
0116             onClicked: root.clicked()
0117             onPressAndHold: root.pressAndHold()
0118             onDoubleClicked: root.doubleClicked()
0119 
0120             enabled: root.enabled
0121             checked: root.checked
0122 
0123             Accessible.ignored: true
0124         }
0125 
0126         ColumnLayout {
0127             Layout.fillWidth: true
0128             spacing: Kirigami.Units.smallSpacing
0129             Controls.Label {
0130                 text: root.text
0131                 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
0132                 elide: Text.ElideRight
0133                 wrapMode: Text.Wrap
0134                 maximumLineCount: 2
0135                 Layout.fillWidth: true
0136                 Accessible.ignored: true
0137             }
0138 
0139             Controls.Label {
0140                 id: internalDescriptionItem
0141                 Layout.fillWidth: true
0142                 text: root.description
0143                 color: Kirigami.Theme.disabledTextColor
0144                 visible: root.description !== ""
0145                 wrapMode: Text.Wrap
0146             }
0147         }
0148 
0149         Private.ContentItemLoader {
0150             Layout.leftMargin: visible ? root.trailingPadding : 0
0151             visible: root.trailing
0152             implicitHeight: visible ? root.trailing.implicitHeight : 0
0153             implicitWidth: visible ? root.trailing.implicitWidth : 0
0154             contentItem: root.trailing
0155         }
0156     }
0157 }
0158