magpie/qml/Forms/Asset.qml

112 lines
2.6 KiB
QML

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
import magpie
import magpie.Components as Components
Item {
property string name: qsTr("New asset")
property string icon: "wallet"
property color color: "green"
property int currency: 1
property string title: qsTr("New asset")
signal confirm (name: string, icon: string, color: color, currency: int)
signal cancel
id: form
Column {
id: inner
spacing: 5
anchors.centerIn: parent
Label {
anchors.horizontalCenter: parent.horizontalCenter
text: title
font.pixelSize: 14
}
Grid {
anchors.horizontalCenter: parent.horizontalCenter
columns: 2
columnSpacing: 10
rowSpacing: 5
verticalItemAlignment: Grid.AlignVCenter
horizontalItemAlignment: Grid.AlignRight
Label {
text: qsTr("Title") + ":";
}
TextField {
id: titleField
text: name
onTextChanged: name = text
}
Label {
text: qsTr("Icon") + ":";
}
Components.IconPicker {
id: iconField
icon: form.icon
onIconChanged: form.icon = icon
}
Label {
text: qsTr("Color") + ":";
}
Components.ColorPicker {
id: colorField
color: form.color
onColorChanged: form.color = colorField.color
}
Label {
text: qsTr("Currency") + ":";
}
ComboBox {
id: currencyField
textRole: "title" //"code"
valueRole: "id"
model: Magpie.currencies
Component.onCompleted: currentIndex = indexOfValue(currency)
onActivated: index => currency = currentValue
}
}
Row {
spacing: 5
anchors.horizontalCenter: parent.horizontalCenter
Button {
text: qsTr("Cancel")
onClicked: cancel()
}
Button {
text: qsTr("Confirm")
onClicked: inner.onConfirmClick()
}
}
function onConfirmClick () {
//TODO validation
confirm(name, icon, form.color, currency);
}
}
}