2024-05-27 08:39:50 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
|
|
|
Control {
|
|
|
|
id: root
|
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
property double value: d.defaultValue
|
2024-06-18 22:51:49 +00:00
|
|
|
readonly property double defaultValue: d.defaultValue
|
2024-05-27 17:37:22 +00:00
|
|
|
readonly property bool valid: customInput.activeFocus && customInput.valid
|
2024-05-27 08:39:50 +00:00
|
|
|
|| buttons.value !== null
|
2024-06-04 11:58:37 +00:00
|
|
|
readonly property bool isEdited: root.value !== d.defaultValue
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
function reset() {
|
|
|
|
value = d.defaultValue
|
|
|
|
}
|
|
|
|
|
2024-05-27 08:39:50 +00:00
|
|
|
onValueChanged: {
|
|
|
|
if (d.internalUpdate)
|
|
|
|
return false
|
|
|
|
|
|
|
|
const custom = !d.values.includes(value)
|
|
|
|
|
|
|
|
if (custom) {
|
|
|
|
customButton.visible = false
|
|
|
|
customInput.value = value
|
2024-05-27 17:37:22 +00:00
|
|
|
customInput.forceActiveFocus()
|
2024-05-27 08:39:50 +00:00
|
|
|
} else {
|
|
|
|
customButton.visible = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2024-05-27 17:37:22 +00:00
|
|
|
buttons.model.append(d.values.map((i) => ({ text: "%L1 %2".arg(i).arg(d.customSymbol), value: i })))
|
2024-05-27 08:39:50 +00:00
|
|
|
valueChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2024-05-27 13:21:35 +00:00
|
|
|
readonly property string customSymbol: "%"
|
2024-05-27 08:39:50 +00:00
|
|
|
readonly property var values: [0.1, 0.5, 1]
|
2024-05-27 17:37:22 +00:00
|
|
|
readonly property double defaultValue: 0.5
|
2024-05-27 08:39:50 +00:00
|
|
|
property bool internalUpdate: false
|
|
|
|
|
|
|
|
function update(value) {
|
|
|
|
internalUpdate = true
|
|
|
|
root.value = value
|
|
|
|
internalUpdate = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
background: null
|
2024-05-27 08:39:50 +00:00
|
|
|
contentItem: RowLayout {
|
|
|
|
spacing: buttons.spacing
|
|
|
|
|
|
|
|
StatusButtonRow {
|
|
|
|
id: buttons
|
|
|
|
model: ListModel {}
|
|
|
|
|
|
|
|
Binding on value {
|
2024-05-27 17:37:22 +00:00
|
|
|
value: customInput.activeFocus ? null : root.value
|
2024-05-27 08:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onValueChanged: {
|
|
|
|
if (value === null)
|
|
|
|
return
|
|
|
|
|
|
|
|
d.update(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: customButton
|
|
|
|
objectName: "customButton"
|
|
|
|
|
|
|
|
Layout.minimumWidth: 130
|
|
|
|
|
|
|
|
text: qsTr("Custom")
|
|
|
|
onClicked: {
|
|
|
|
visible = false
|
|
|
|
customInput.clear()
|
|
|
|
customInput.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrencyAmountInput {
|
|
|
|
id: customInput
|
|
|
|
objectName: "customInput"
|
|
|
|
|
|
|
|
Layout.minimumWidth: customButton.Layout.minimumWidth
|
|
|
|
|
|
|
|
visible: !customButton.visible
|
|
|
|
minValue: 0.01
|
|
|
|
maxValue: 100.0
|
2024-05-27 13:21:35 +00:00
|
|
|
currencySymbol: d.customSymbol
|
2024-05-27 08:39:50 +00:00
|
|
|
onValueChanged: d.update(value)
|
2024-05-27 17:37:22 +00:00
|
|
|
onFocusChanged: {
|
|
|
|
if (focus && valid)
|
|
|
|
d.update(value)
|
|
|
|
else if (!valid)
|
|
|
|
clear()
|
|
|
|
}
|
2024-05-27 08:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|