Warning, /libraries/kirigami-addons/src/formcard/FormTextDelegate.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 text label and a description.
0016  *
0017  * This component is used to create primary text with the inherited
0018  * QtQuick.Controls.AbstractButton.text property, with an optional
0019  * ::description that serves as secondary text/subtitle.
0020  *
0021  * If you need just a secondary text component, use a FormSectionText
0022  * instead.
0023  *
0024  * @since KirigamiAddons 0.11.0
0025  *
0026  * @see FormSectionText
0027  * @see QtQuick.Controls.AbstractButton
0028  *
0029  * @inherit AbstractFormDelegate
0030  */
0031 AbstractFormDelegate {
0032     id: root
0033 
0034     /**
0035      * @brief A label containing secondary text that appears under the
0036      * inherited text property.
0037      *
0038      * This provides additional information shown in a faint gray color.
0039      */
0040     property string description: ""
0041 
0042     /**
0043      * @brief This property allows for access to the description label item.
0044      */
0045     property alias descriptionItem: internalDescriptionItem
0046 
0047     /**
0048      * @brief This property holds allows for access to the text label item.
0049      */
0050     property alias textItem: internalTextItem
0051 
0052     /**
0053      * @brief This property holds an item that will be displayed before
0054      * the delegate's contents.
0055      */
0056     property var leading: null
0057 
0058     /**
0059      * @brief This property holds the padding after the leading item.
0060      */
0061     property real leadingPadding: Kirigami.Units.smallSpacing
0062 
0063     /**
0064      * @brief This property holds an item that will be displayed after
0065      * the delegate's contents.
0066      */
0067     property var trailing: null
0068 
0069     /**
0070      * @brief This property holds the padding before the trailing item.
0071      */
0072     property real trailingPadding: Kirigami.Units.smallSpacing
0073 
0074     signal linkActivated(string link)
0075 
0076     focusPolicy: Qt.NoFocus
0077 
0078     background: null
0079 
0080     contentItem: RowLayout {
0081         spacing: 0
0082 
0083         Private.ContentItemLoader {
0084             Layout.rightMargin: visible ? root.leadingPadding : 0
0085             visible: root.leading
0086             implicitHeight: visible ? root.leading.implicitHeight : 0
0087             implicitWidth: visible ? root.leading.implicitWidth : 0
0088             contentItem: root.leading
0089         }
0090 
0091         Kirigami.Icon {
0092             visible: root.icon.name !== ""
0093             source: root.icon.name
0094             color: root.icon.color
0095             Layout.rightMargin: (root.icon.name !== "") ? Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing : 0
0096             implicitWidth: (root.icon.name !== "") ? Kirigami.Units.iconSizes.small : 0
0097             implicitHeight: (root.icon.name !== "") ? Kirigami.Units.iconSizes.small : 0
0098         }
0099 
0100         ColumnLayout {
0101             Layout.fillWidth: true
0102             spacing: Kirigami.Units.smallSpacing
0103 
0104             Label {
0105                 id: internalTextItem
0106                 Layout.fillWidth: true
0107                 text: root.text
0108                 elide: Text.ElideRight
0109                 onLinkActivated: root.linkActivated(link)
0110                 visible: root.text
0111                 Accessible.ignored: true // base class sets this text on root already
0112             }
0113 
0114             Label {
0115                 id: internalDescriptionItem
0116                 Layout.fillWidth: true
0117                 text: root.description
0118                 color: Kirigami.Theme.disabledTextColor
0119                 visible: root.description !== ""
0120                 onLinkActivated: root.linkActivated(link)
0121                 wrapMode: Text.Wrap
0122             }
0123         }
0124 
0125         Private.ContentItemLoader {
0126             Layout.leftMargin: visible ? root.trailingPadding : 0
0127             visible: root.trailing
0128             implicitHeight: visible ? root.trailing.implicitHeight : 0
0129             implicitWidth: visible ? root.trailing.implicitWidth : 0
0130             contentItem: root.trailing
0131         }
0132     }
0133 }
0134