Warning, /libraries/kirigami-addons/src/formcard/FormSpinBoxDelegate.qml is written in an unsupported language. File is not indexed.
0001 // Copyright 2023 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 import QtQuick 2.15 0005 import QtQuick.Controls 2.15 as QQC2 0006 import QtQuick.Layouts 1.15 0007 0008 import org.kde.kirigami 2.19 as Kirigami 0009 import 'private' as P 0010 0011 /** 0012 * @brief A Form delegate that corresponds to a spinbox. 0013 * 0014 * This component is used to select a number. By default, the spinbox will be 0015 * initialized with a minimum of 0 and a maximum of 99. 0016 * 0017 * Example code: 0018 * ```qml 0019 * MobileForm.FormCard { 0020 * contentItem: ColumnLayout { 0021 * spacing: 0 0022 * 0023 * MobileForm.FormCardHeader { 0024 * title: "Information" 0025 * } 0026 * 0027 * MobileForm.FormSpinBoxDelegate { 0028 * label: "Amount" 0029 * } 0030 * } 0031 * } 0032 * ``` 0033 * 0034 * @since KirigamiAddons 0.11.0 0035 * 0036 * @inherit AbstractFormDelegate 0037 */ 0038 AbstractFormDelegate { 0039 id: root 0040 0041 /** 0042 * @brief A label that appears above the spinbox. 0043 * 0044 */ 0045 required property string label 0046 0047 /** 0048 * @brief This property holds the `value` of the internal spinbox. 0049 */ 0050 property alias value: spinbox.value 0051 0052 /** 0053 * @brief This property holds the `from` of the internal spinbox. 0054 */ 0055 property alias from: spinbox.from 0056 0057 /** 0058 * @brief This property holds the `to` of the internal spinbox. 0059 */ 0060 property alias to: spinbox.to 0061 0062 /** 0063 * @brief This property holds the `stepSize` of the internal spinbox. 0064 */ 0065 property alias stepSize: spinbox.stepSize 0066 0067 /** 0068 * @brief This property holds the `textFromValue` of the internal spinbox. 0069 */ 0070 property alias textFromValue: spinbox.textFromValue 0071 0072 /** 0073 * @brief This property holds the `valueFromText` of the internal spinbox. 0074 */ 0075 property alias valueFromText: spinbox.valueFromText 0076 0077 /** 0078 * @brief This property holds the `displayText` of the internal spinbox. 0079 */ 0080 property alias displayText: spinbox.displayText 0081 0082 /** 0083 * @brief This property holds the current type of status displayed in 0084 * the text field. 0085 * 0086 * Depending on the status of the text field, the statusMessage property 0087 * will look different 0088 * 0089 * Accepted values: 0090 * - Kirigami.MessageType.Information 0091 * - Kirigami.MessageType.Positive 0092 * - Kirigami.MessageType.Warning 0093 * - Kirigami.MessageType.Error 0094 * 0095 * @see Kirigami.MessageType 0096 */ 0097 property var status: Kirigami.MessageType.Information 0098 0099 /** 0100 * This property holds the current status message of the text field. 0101 */ 0102 property string statusMessage: "" 0103 0104 /** 0105 * Increases the value by stepSize, or 1 if stepSize is not defined. 0106 */ 0107 function increase() { 0108 spinbox.increase(); 0109 } 0110 0111 /** 0112 * Decreases the value by stepSize, or 1 if stepSize is not defined. 0113 */ 0114 function decrease() { 0115 spinbox.decrease(); 0116 } 0117 0118 focusPolicy: Kirigami.Settings.isMobile ? Qt.StrongFocus : Qt.NoFocus 0119 0120 onClicked: spinbox.forceActiveFocus() 0121 background: null 0122 0123 contentItem: ColumnLayout { 0124 RowLayout { 0125 Layout.fillWidth: true 0126 spacing: 0 0127 0128 QQC2.Label { 0129 Layout.fillWidth: true 0130 text: label 0131 elide: Text.ElideRight 0132 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor 0133 wrapMode: Text.Wrap 0134 maximumLineCount: 2 0135 } 0136 0137 P.SpinButton { 0138 onClicked: root.decrease() 0139 icon.name: 'list-remove-symbolic' 0140 visible: Kirigami.Settings.isMobile 0141 0142 isStart: true 0143 isEnd: false 0144 } 0145 0146 QQC2.Pane { 0147 focusPolicy: Qt.NoFocus 0148 leftPadding: Kirigami.Units.largeSpacing * 2 0149 rightPadding: Kirigami.Units.largeSpacing * 2 0150 visible: Kirigami.Settings.isMobile 0151 contentItem: QQC2.Label { 0152 text: root.textFromValue(root.value, root.locale) 0153 } 0154 background: Item { 0155 implicitHeight: Kirigami.Units.gridUnit * 2 0156 Rectangle { 0157 color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.15) 0158 height: 1 0159 anchors { 0160 left: parent.left 0161 right: parent.right 0162 top: parent.top 0163 } 0164 } 0165 0166 Rectangle { 0167 color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.15) 0168 height: 1 0169 anchors { 0170 left: parent.left 0171 right: parent.right 0172 bottom: parent.bottom 0173 } 0174 } 0175 } 0176 } 0177 0178 P.SpinButton { 0179 onClicked: root.increase() 0180 visible: Kirigami.Settings.isMobile 0181 icon.name: 'list-add' 0182 0183 isStart: false 0184 isEnd: true 0185 } 0186 } 0187 0188 QQC2.SpinBox { 0189 id: spinbox 0190 Layout.fillWidth: true 0191 visible: !Kirigami.Settings.isMobile 0192 locale: root.locale 0193 } 0194 0195 Kirigami.InlineMessage { 0196 id: formErrorHandler 0197 visible: root.statusMessage.length > 0 0198 Layout.topMargin: visible ? Kirigami.Units.smallSpacing : 0 0199 Layout.fillWidth: true 0200 text: root.statusMessage 0201 type: root.status 0202 } 0203 } 0204 }