Warning, /libraries/kirigami-addons/src/formcard/FormButtonDelegate.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.Controls 2.15
0008 import QtQuick.Layouts 1.15
0009 
0010 import org.kde.kirigami 2.19 as Kirigami
0011 
0012 import "private" as Private
0013 
0014 /**
0015  * @brief A Form delegate that corresponds to a clickable button.
0016  *
0017  * Use the inherited QtQuick.Controls.AbstractButton.text property to define
0018  * the main text of the button.
0019  *
0020  * The trailing property (right-most side of the button) includes an arrow
0021  * pointing to the right by default and cannot be overridden.
0022  *
0023  * @since KirigamiAddons 0.11.0
0024  *
0025  * @inherit AbstractFormDelegate
0026  */
0027 AbstractFormDelegate {
0028     id: root
0029 
0030     /**
0031      * @brief A label containing secondary text that appears under the
0032      * inherited text property.
0033      *
0034      * This provides additional information shown in a faint gray color.
0035      *
0036      * This is supposed to be a short text and the API user should avoid
0037      * making it longer than two lines.
0038      */
0039     property string description: ""
0040 
0041     /**
0042      * @brief This property allows to override the internal description
0043      * item (a QtQuick.Controls.Label) with a custom component.
0044      */
0045     property alias descriptionItem: internalDescriptionItem
0046 
0047     /**
0048      * @brief This property holds an item that will be displayed to the
0049      * left of the delegate's contents.
0050      *
0051      * default: `null`
0052      */
0053     property var leading: null
0054 
0055     /**
0056      * @brief This property holds the padding after the leading item.
0057      *
0058      * It is recommended to use Kirigami.Units here instead of direct values.
0059      *
0060      * @see Kirigami.Units
0061      */
0062     property real leadingPadding: Kirigami.Units.smallSpacing
0063 
0064     focusPolicy: Qt.StrongFocus
0065 
0066     icon {
0067         width: Kirigami.Units.iconSizes.small
0068         height: Kirigami.Units.iconSizes.small
0069     }
0070 
0071     contentItem: RowLayout {
0072         spacing: 0
0073 
0074         Private.ContentItemLoader {
0075             Layout.rightMargin: visible ? root.leadingPadding : 0
0076             visible: root.leading
0077             implicitHeight: visible ? root.leading.implicitHeight : 0
0078             implicitWidth: visible ? root.leading.implicitWidth : 0
0079             contentItem: root.leading
0080         }
0081 
0082         Kirigami.Icon {
0083             visible: root.icon.name !== ""
0084             source: root.icon.name
0085             color: root.icon.color
0086             Layout.rightMargin: (root.icon.name !== "") ? Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing : 0
0087             implicitWidth: (root.icon.name !== "") ? root.icon.width : 0
0088             implicitHeight: (root.icon.name !== "") ? root.icon.height : 0
0089         }
0090 
0091         ColumnLayout {
0092             Layout.fillWidth: true
0093             spacing: Kirigami.Units.smallSpacing
0094 
0095             Label {
0096                 Layout.fillWidth: true
0097                 text: root.text
0098                 elide: Text.ElideRight
0099                 wrapMode: Text.Wrap
0100                 maximumLineCount: 2
0101                 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
0102                 Accessible.ignored: true // base class sets this text on root already
0103             }
0104 
0105             Label {
0106                 id: internalDescriptionItem
0107                 Layout.fillWidth: true
0108                 text: root.description
0109                 color: Kirigami.Theme.disabledTextColor
0110                 elide: Text.ElideRight
0111                 visible: root.description !== ""
0112                 wrapMode: Text.Wrap
0113                 Accessible.ignored: !visible
0114             }
0115         }
0116 
0117         FormArrow {
0118             Layout.leftMargin: Kirigami.Units.smallSpacing
0119             Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
0120             direction: Qt.RightArrow
0121             visible: root.background.visible
0122         }
0123     }
0124 
0125     Accessible.onPressAction: action ? action.trigger() : root.clicked()
0126 }