diff --git a/electrum/gui/qml/components/Receive.qml b/electrum/gui/qml/components/Receive.qml index b6648001e..24c11d6db 100644 --- a/electrum/gui/qml/components/Receive.qml +++ b/electrum/gui/qml/components/Receive.qml @@ -36,27 +36,10 @@ Pane { Layout.rightMargin: constants.paddingXLarge } - TextField { + BtcField { id: amount - font.family: FixedFont + fiatfield: amountFiat Layout.preferredWidth: parent.width /2 - placeholderText: qsTr('Amount') - inputMethodHints: Qt.ImhPreferNumbers - - property Amount textAsSats - onTextChanged: { - textAsSats = Config.unitsToSats(amount.text) - if (amountFiat.activeFocus) - return - amountFiat.text = text == '' ? '' : Daemon.fx.fiatValue(amount.textAsSats) - } - - Connections { - target: Config - function onBaseUnitChanged() { - amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : '' - } - } } Label { @@ -68,17 +51,11 @@ Pane { Item { visible: Daemon.fx.enabled; width: 1; height: 1 } - TextField { + FiatField { id: amountFiat + btcfield: amount visible: Daemon.fx.enabled - font.family: FixedFont Layout.preferredWidth: parent.width /2 - placeholderText: qsTr('Amount') - inputMethodHints: Qt.ImhDigitsOnly - onTextChanged: { - if (amountFiat.activeFocus) - amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text)) - } } Label { diff --git a/electrum/gui/qml/components/Send.qml b/electrum/gui/qml/components/Send.qml index 55de55518..d4c6ca75f 100644 --- a/electrum/gui/qml/components/Send.qml +++ b/electrum/gui/qml/components/Send.qml @@ -71,26 +71,10 @@ Pane { text: qsTr('Amount') } - TextField { + BtcField { id: amount - font.family: FixedFont - placeholderText: qsTr('Amount') + fiatfield: amountFiat Layout.preferredWidth: parent.width /2 - inputMethodHints: Qt.ImhPreferNumbers - property Amount textAsSats - onTextChanged: { - textAsSats = Config.unitsToSats(amount.text) - if (amountFiat.activeFocus) - return - amountFiat.text = Daemon.fx.fiatValue(amount.textAsSats) - } - - Connections { - target: Config - function onBaseUnitChanged() { - amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : '' - } - } } Label { @@ -103,17 +87,11 @@ Pane { Item { width: 1; height: 1; visible: Daemon.fx.enabled } - TextField { + FiatField { id: amountFiat + btcfield: amount visible: Daemon.fx.enabled - font.family: FixedFont Layout.preferredWidth: parent.width /2 - placeholderText: qsTr('Amount') - inputMethodHints: Qt.ImhPreferNumbers - onTextChanged: { - if (amountFiat.activeFocus) - amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text)) - } } Label { diff --git a/electrum/gui/qml/components/controls/BtcField.qml b/electrum/gui/qml/components/controls/BtcField.qml new file mode 100644 index 000000000..552c5fc77 --- /dev/null +++ b/electrum/gui/qml/components/controls/BtcField.qml @@ -0,0 +1,28 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +import org.electrum 1.0 + +TextField { + id: amount + + required property TextField fiatfield + + font.family: FixedFont + placeholderText: qsTr('Amount') + inputMethodHints: Qt.ImhPreferNumbers + property Amount textAsSats + onTextChanged: { + textAsSats = Config.unitsToSats(amount.text) + if (fiatfield.activeFocus) + return + fiatfield.text = text == '' ? '' : Daemon.fx.fiatValue(amount.textAsSats) + } + + Connections { + target: Config + function onBaseUnitChanged() { + amount.text = amount.textAsSats != 0 ? Config.satsToUnits(amount.textAsSats) : '' + } + } +} diff --git a/electrum/gui/qml/components/controls/FiatField.qml b/electrum/gui/qml/components/controls/FiatField.qml new file mode 100644 index 000000000..cff9a7cad --- /dev/null +++ b/electrum/gui/qml/components/controls/FiatField.qml @@ -0,0 +1,18 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +import org.electrum 1.0 + +TextField { + id: amountFiat + + required property TextField btcfield + + font.family: FixedFont + placeholderText: qsTr('Amount') + inputMethodHints: Qt.ImhPreferNumbers + onTextChanged: { + if (amountFiat.activeFocus) + btcfield.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text)) + } +}