peerplays_migrated/programs/light_client/qml/AccountPicker.qml

96 lines
3 KiB
QML
Raw Normal View History

2015-07-14 19:06:00 +00:00
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.2
import Graphene.Client 0.1
import "."
2015-07-17 20:39:01 +00:00
/// A component for choosing an Account from the chain
2015-07-14 19:06:00 +00:00
RowLayout {
2015-07-17 20:39:01 +00:00
property GrapheneApplication app
/// The text to show in the name field when it is empty
property alias placeholderText: accountNameField.placeholderText
/// Index into the balances Array of the balance to show beneath the name field
property int showBalance: -1
/// The Account object the user has selected
2015-07-14 19:06:00 +00:00
property Account account
2015-07-17 20:39:01 +00:00
/// An Array of Balance objects held by account
property var balances: account? Object.keys(account.balances).map(function(key){return account.balances[key]})
: null
2015-07-14 19:06:00 +00:00
2015-07-17 20:39:01 +00:00
/// Set the name field to have active focus
2015-07-14 19:06:00 +00:00
function setFocus() {
accountNameField.forceActiveFocus()
}
Identicon {
2015-07-15 22:14:48 +00:00
name: account && account.name == accountNameField.text? accountNameField.text : ""
2015-07-14 19:06:00 +00:00
width: Scaling.cm(2)
height: Scaling.cm(2)
}
Column {
Layout.fillWidth: true
TextField {
id: accountNameField
width: parent.width
2015-07-17 20:06:07 +00:00
2015-07-14 19:06:00 +00:00
onEditingFinished: accountDetails.update(text)
2015-07-17 20:06:07 +00:00
onTextChanged: if (account && account.name !== text) accountDetails.update("")
2015-07-14 19:06:00 +00:00
}
Text {
2015-07-14 19:06:00 +00:00
id: accountDetails
width: parent.width
height: text? implicitHeight : 0
Behavior on height { NumberAnimation{ easing.type: Easing.InOutQuad } }
2015-07-14 19:06:00 +00:00
function update(name) {
if (!name)
{
text = ""
account = null
2015-07-14 19:06:00 +00:00
return
}
account = app.model.getAccount(name)
if (account == null) {
2015-07-14 19:06:00 +00:00
text = qsTr("Error fetching account.")
} else {
2015-07-14 19:06:00 +00:00
text = Qt.binding(function() {
if (account == null)
return qsTr("Account does not exist.")
var text = qsTr("Account ID: %1").arg(account.id < 0? qsTr("Loading...")
: account.id)
if (showBalance >= 0) {
2015-07-17 20:06:07 +00:00
var bal = balances[showBalance]
text += "\n" + qsTr("Balance: %1 %2").arg(String(bal.amountReal())).arg(bal.type.symbol)
}
return text
2015-07-14 19:06:00 +00:00
})
}
2015-07-14 19:06:00 +00:00
}
Behavior on text {
SequentialAnimation {
PropertyAnimation {
target: accountDetails
property: "opacity"
from: 1; to: 0
duration: 100
}
PropertyAction { target: accountDetails; property: "text" }
PropertyAnimation {
target: accountDetails
property: "opacity"
from: 0; to: 1
duration: 100
}
}
}
2015-07-14 19:06:00 +00:00
}
}
}