-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathBitcoinAmountInputField.qml
More file actions
134 lines (114 loc) · 3.89 KB
/
BitcoinAmountInputField.qml
File metadata and controls
134 lines (114 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) 2025-2026 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import org.bitcoincore.qt 1.0
import "../controls"
ColumnLayout {
id: root
property var amount
property string errorText: ""
property string labelText: qsTr("Amount")
property bool enabled: true
signal editingFinished(string value)
Layout.fillWidth: true
spacing: 4
Item {
id: inputRow
height: amountInput.height
Layout.fillWidth: true
CoreText {
id: lbl
width: 110
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignLeft
text: root.labelText
font.pixelSize: 18
}
TextField {
id: amountInput
anchors.left: lbl.right
anchors.verticalCenter: parent.verticalCenter
leftPadding: 0
enabled: root.enabled
font.family: "BitcoinCoreSans"
font.styleName: "Regular"
font.pixelSize: 18
color: Theme.color.neutral9
placeholderTextColor: enabled ? Theme.color.neutral7 : Theme.color.neutral4
background: Item {}
placeholderText: root.amount && root.amount.unit === BitcoinAmount.SAT ? "0" : "0.00000000"
selectByMouse: true
text: root.amount ? root.amount.display : ""
onEditingFinished: {
if (root.amount) {
root.amount.display = text
}
root.editingFinished(text)
}
onActiveFocusChanged: {
if (!activeFocus && root.amount) {
root.amount.display = text
root.editingFinished(text)
}
}
validator: RegExpValidator {
regExp: /^(0|[1-9]\d*)(\.\d{0,8})?$/
}
maximumLength: 17
}
Item {
width: unitLabel.width + flipIcon.width
height: Math.max(unitLabel.height, flipIcon.height)
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
opacity: root.enabled ? 1.0 : 0.5
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
enabled: root.enabled && root.amount
onClicked: {
root.amount.display = amountInput.text
root.amount.flipUnit()
}
}
CoreText {
id: unitLabel
anchors.right: flipIcon.left
anchors.verticalCenter: parent.verticalCenter
text: root.amount ? root.amount.unitLabel : ""
font.pixelSize: 18
color: root.enabled ? Theme.color.neutral7 : Theme.color.neutral4
}
Icon {
id: flipIcon
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
source: "image://images/flip-vertical"
icon.color: enabled ? Theme.color.neutral8 : Theme.color.neutral4
size: 30
}
}
}
RowLayout {
id: errorRow
Layout.fillWidth: true
visible: root.errorText.length > 0
Icon {
source: "image://images/alert-filled"
size: 22
color: Theme.color.red
}
CoreText {
text: root.errorText
font.pixelSize: 15
color: Theme.color.red
horizontalAlignment: Text.AlignLeft
Layout.fillWidth: true
}
}
}