2024-05-27 08:39:50 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
import StatusQ.Core 0.1
|
2024-05-27 08:39:50 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2024-08-30 19:00:39 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2024-05-27 08:39:50 +00:00
|
|
|
|
|
|
|
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-08-30 19:00:39 +00:00
|
|
|
readonly property bool valid: (customInput.activeFocus && customInput.valid) || 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-08-30 19:00:39 +00:00
|
|
|
property double valueTooHighThreshold: 5
|
|
|
|
|
2024-05-27 17:37:22 +00:00
|
|
|
function reset() {
|
|
|
|
value = d.defaultValue
|
2024-08-30 19:00:39 +00:00
|
|
|
customInput.focus = false
|
|
|
|
customButton.visible = true
|
2024-05-27 17:37:22 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 08:39:50 +00:00
|
|
|
onValueChanged: {
|
|
|
|
if (d.internalUpdate)
|
2024-08-30 19:00:39 +00:00
|
|
|
return
|
2024-05-27 08:39:50 +00:00
|
|
|
|
|
|
|
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-08-30 19:00:39 +00:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
spacing: buttons.spacing
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
StatusButtonRow {
|
|
|
|
id: buttons
|
|
|
|
model: ListModel {}
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
Binding on value {
|
|
|
|
value: customInput.activeFocus ? null : root.value
|
|
|
|
}
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
onValueChanged: {
|
|
|
|
if (value === null)
|
|
|
|
return
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
d.update(value)
|
|
|
|
}
|
|
|
|
onButtonClicked: customButton.visible = true
|
2024-05-27 08:39:50 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
StatusButton {
|
|
|
|
id: customButton
|
|
|
|
objectName: "customButton"
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
Layout.minimumWidth: 130
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
text: qsTr("Custom")
|
|
|
|
onClicked: {
|
|
|
|
visible = false
|
|
|
|
customInput.clear()
|
|
|
|
customInput.forceActiveFocus()
|
|
|
|
}
|
2024-05-27 08:39:50 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
CurrencyAmountInput {
|
|
|
|
id: customInput
|
|
|
|
objectName: "customInput"
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
Layout.minimumWidth: customButton.Layout.minimumWidth
|
2024-05-27 08:39:50 +00:00
|
|
|
|
2024-08-30 19:00:39 +00:00
|
|
|
visible: !customButton.visible
|
|
|
|
minValue: 0.01
|
2024-09-25 10:19:27 +00:00
|
|
|
maxValue: 99.99
|
2024-08-30 19:00:39 +00:00
|
|
|
maximumLength: 6 // 3 integral + separator + 2 decimals (e.g. "999.99")
|
|
|
|
currencySymbol: d.customSymbol
|
|
|
|
onValueChanged: d.update(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.alignment: Qt.AlignRight
|
|
|
|
visible: customInput.visible && !customInput.valid
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
|
|
|
color: Theme.palette.dangerColor1
|
|
|
|
text: {
|
|
|
|
if (customInput.length === 0)
|
|
|
|
return qsTr("Enter a slippage value")
|
|
|
|
|
|
|
|
if (customInput.value === 0)
|
|
|
|
return qsTr("Slippage should be more than 0")
|
|
|
|
|
|
|
|
return qsTr("Invalid value")
|
2024-05-27 17:37:22 +00:00
|
|
|
}
|
2024-05-27 08:39:50 +00:00
|
|
|
}
|
2024-08-30 19:00:39 +00:00
|
|
|
StatusBaseText {
|
|
|
|
Layout.alignment: Qt.AlignRight
|
|
|
|
visible: customInput.visible && customInput.valid && customInput.value > root.valueTooHighThreshold
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
|
|
|
color: Theme.palette.warningColor1
|
|
|
|
text: qsTr("Slippage may be higher than necessary")
|
|
|
|
}
|
2024-05-27 08:39:50 +00:00
|
|
|
}
|
|
|
|
}
|