Skip to content

Commit 1705458

Browse files
committed
qml: Extract BitcoinAmountInputField from Send
1 parent 1e81bb6 commit 1705458

File tree

4 files changed

+128
-82
lines changed

4 files changed

+128
-82
lines changed

src/Makefile.qt.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ QML_RES_QML = \
404404
qml/components/BlockClock.qml \
405405
qml/components/BlockClockDisplayMode.qml \
406406
qml/components/BlockCounter.qml \
407+
qml/components/BitcoinAmountInputField.qml \
407408
qml/components/ConnectionOptions.qml \
408409
qml/components/ConnectionSettings.qml \
409410
qml/components/DeveloperOptions.qml \

src/qml/bitcoin_qml.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<file>components/BlockClock.qml</file>
55
<file>components/BlockClockDisplayMode.qml</file>
66
<file>components/BlockCounter.qml</file>
7+
<file>components/BitcoinAmountInputField.qml</file>
78
<file>components/ConnectionOptions.qml</file>
89
<file>components/ConnectionSettings.qml</file>
910
<file>components/DeveloperOptions.qml</file>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import QtQuick 2.15
2+
import QtQuick.Controls 2.15
3+
import QtQuick.Layouts 1.15
4+
import org.bitcoincore.qt 1.0
5+
6+
import "../controls"
7+
8+
ColumnLayout {
9+
id: root
10+
11+
property var amount
12+
property string errorText: ""
13+
property string labelText: qsTr("Amount")
14+
property bool enabled: true
15+
16+
signal editingFinished(string value)
17+
18+
Layout.fillWidth: true
19+
spacing: 4
20+
21+
Item {
22+
id: inputRow
23+
height: amountInput.height
24+
Layout.fillWidth: true
25+
26+
CoreText {
27+
id: lbl
28+
width: 110
29+
anchors.left: parent.left
30+
anchors.verticalCenter: parent.verticalCenter
31+
horizontalAlignment: Text.AlignLeft
32+
text: root.labelText
33+
font.pixelSize: 18
34+
}
35+
36+
TextField {
37+
id: amountInput
38+
anchors.left: lbl.right
39+
anchors.verticalCenter: parent.verticalCenter
40+
leftPadding: 0
41+
enabled: root.enabled
42+
font.family: "Inter"
43+
font.styleName: "Regular"
44+
font.pixelSize: 18
45+
color: Theme.color.neutral9
46+
placeholderTextColor: enabled ? Theme.color.neutral7 : Theme.color.neutral4
47+
background: Item {}
48+
placeholderText: "0.00000000"
49+
selectByMouse: true
50+
51+
text: root.amount ? root.amount.display : ""
52+
53+
onEditingFinished: {
54+
if (root.amount) {
55+
root.amount.display = text
56+
}
57+
root.editingFinished(text)
58+
}
59+
60+
onActiveFocusChanged: {
61+
if (!activeFocus && root.amount) {
62+
root.amount.display = text
63+
root.editingFinished(text)
64+
}
65+
}
66+
}
67+
68+
Item {
69+
width: unitLabel.width + flipIcon.width
70+
height: Math.max(unitLabel.height, flipIcon.height)
71+
anchors.right: parent.right
72+
anchors.verticalCenter: parent.verticalCenter
73+
opacity: root.enabled ? 1.0 : 0.5
74+
75+
MouseArea {
76+
anchors.fill: parent
77+
hoverEnabled: true
78+
cursorShape: Qt.PointingHandCursor
79+
enabled: root.enabled && root.amount
80+
onClicked: root.amount.flipUnit()
81+
}
82+
83+
CoreText {
84+
id: unitLabel
85+
anchors.right: flipIcon.left
86+
anchors.verticalCenter: parent.verticalCenter
87+
text: root.amount ? root.amount.unitLabel : ""
88+
font.pixelSize: 18
89+
color: enabled ? Theme.color.neutral7 : Theme.color.neutral4
90+
}
91+
92+
Icon {
93+
id: flipIcon
94+
anchors.right: parent.right
95+
anchors.verticalCenter: parent.verticalCenter
96+
source: "image://images/flip-vertical"
97+
icon.color: enabled ? Theme.color.neutral8 : Theme.color.neutral4
98+
size: 30
99+
}
100+
}
101+
}
102+
103+
RowLayout {
104+
id: errorRow
105+
Layout.fillWidth: true
106+
visible: root.errorText.length > 0
107+
108+
Icon {
109+
source: "image://images/alert-filled"
110+
size: 22
111+
color: Theme.color.red
112+
}
113+
114+
CoreText {
115+
text: root.errorText
116+
font.pixelSize: 15
117+
color: Theme.color.red
118+
horizontalAlignment: Text.AlignLeft
119+
Layout.fillWidth: true
120+
}
121+
}
122+
}

src/qml/pages/wallet/Send.qml

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -190,89 +190,11 @@ PageStack {
190190
Layout.fillWidth: true
191191
}
192192

193-
ColumnLayout {
193+
BitcoinAmountInputField {
194194
Layout.fillWidth: true
195-
196-
Item {
197-
height: amountInput.height
198-
Layout.fillWidth: true
199-
CoreText {
200-
id: amountLabel
201-
width: 110
202-
anchors.left: parent.left
203-
anchors.verticalCenter: parent.verticalCenter
204-
horizontalAlignment: Text.AlignLeft
205-
text: qsTr("Amount")
206-
font.pixelSize: 18
207-
}
208-
209-
TextField {
210-
id: amountInput
211-
anchors.left: amountLabel.right
212-
anchors.verticalCenter: parent.verticalCenter
213-
leftPadding: 0
214-
font.family: "Inter"
215-
font.styleName: "Regular"
216-
font.pixelSize: 18
217-
color: Theme.color.neutral9
218-
placeholderTextColor: enabled ? Theme.color.neutral7 : Theme.color.neutral4
219-
background: Item {}
220-
placeholderText: "0.00000000"
221-
selectByMouse: true
222-
text: root.recipient.amount.display
223-
onEditingFinished: root.recipient.amount.display = text
224-
onActiveFocusChanged: {
225-
if (!activeFocus) {
226-
root.recipient.amount.display = text
227-
}
228-
}
229-
}
230-
Item {
231-
width: unitLabel.width + flipIcon.width
232-
height: Math.max(unitLabel.height, flipIcon.height)
233-
anchors.right: parent.right
234-
anchors.verticalCenter: parent.verticalCenter
235-
MouseArea {
236-
anchors.fill: parent
237-
onClicked: root.recipient.amount.flipUnit()
238-
}
239-
CoreText {
240-
id: unitLabel
241-
anchors.right: flipIcon.left
242-
anchors.verticalCenter: parent.verticalCenter
243-
text: root.recipient.amount.unitLabel
244-
font.pixelSize: 18
245-
color: enabled ? Theme.color.neutral7 : Theme.color.neutral4
246-
}
247-
Icon {
248-
id: flipIcon
249-
anchors.right: parent.right
250-
anchors.verticalCenter: parent.verticalCenter
251-
source: "image://images/flip-vertical"
252-
icon.color: unitLabel.enabled ? Theme.color.neutral8 : Theme.color.neutral4
253-
size: 30
254-
}
255-
}
256-
}
257-
258-
RowLayout {
259-
Layout.fillWidth: true
260-
visible: root.recipient.amountError.length > 0
261-
262-
Icon {
263-
source: "image://images/alert-filled"
264-
size: 22
265-
color: Theme.color.red
266-
}
267-
268-
CoreText {
269-
text: root.recipient.amountError
270-
font.pixelSize: 15
271-
color: Theme.color.red
272-
horizontalAlignment: Text.AlignLeft
273-
Layout.fillWidth: true
274-
}
275-
}
195+
enabled: walletController.initialized
196+
amount: root.recipient.amount
197+
errorText: root.recipient.amountError
276198
}
277199

278200
Separator {

0 commit comments

Comments
 (0)