peerplays_migrated/programs/light_client/qml/AccountPicker.qml
2015-07-17 16:06:39 -04:00

88 lines
2.6 KiB
QML

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 "."
RowLayout {
property Account account
property var balances: account? Object.keys(account.balances).map(function(key){return account.balances[key]})
: null
property alias placeholderText: accountNameField.placeholderText
property int showBalance: -1
function setFocus() {
accountNameField.forceActiveFocus()
}
Identicon {
name: account && account.name == accountNameField.text? accountNameField.text : ""
width: Scaling.cm(2)
height: Scaling.cm(2)
}
Column {
Layout.fillWidth: true
TextField {
id: accountNameField
width: parent.width
onEditingFinished: accountDetails.update(text)
onTextChanged: if (account && account.name !== text) accountDetails.update("")
}
Text {
id: accountDetails
width: parent.width
height: text? implicitHeight : 0
Behavior on height { NumberAnimation{ easing.type: Easing.InOutQuad } }
function update(name) {
if (!name)
{
text = ""
account = null
return
}
account = app.model.getAccount(name)
if (account == null) {
text = qsTr("Error fetching account.")
} else {
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) {
var bal = balances[showBalance]
text += "\n" + qsTr("Balance: %1 %2").arg(String(bal.amountReal())).arg(bal.type.symbol)
}
return text
})
}
}
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
}
}
}
}
}
}