Files
pay/desktop/BitcoinValueField.qml
T

113 lines
3.0 KiB
QML
Raw Permalink Normal View History

2020-10-15 19:18:54 +02:00
/*
* This file is part of the Flowee project
2021-01-06 15:07:01 +01:00
* Copyright (C) 2020-2021 Tom Zander <tom@flowee.org>
2020-10-15 19:18:54 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2020-06-12 20:53:01 +02:00
import QtQuick 2.14
2020-10-15 19:18:54 +02:00
import QtQuick.Controls 2.14
2020-06-12 20:53:01 +02:00
import Flowee.org.pay 1.0
2020-10-16 18:17:56 +02:00
/*
* Similar to TextField, this is a wrapper around BitcoinAmountLabel
* in order to provide a background and ediing capabilities.
*/
2020-06-12 20:53:01 +02:00
FocusScope {
2020-06-12 23:37:32 +02:00
id: root
2020-06-12 20:53:01 +02:00
height: balance.height + 16
width: balance.width + 16
activeFocusOnTab: true
property alias value: privValue.value
2020-06-12 23:37:32 +02:00
property alias valueObject: privValue
2020-10-24 12:50:18 +02:00
property alias fontPtSize: balance.fontPtSize
2021-01-18 14:27:24 +01:00
property bool enabled: true
2021-05-08 00:03:07 +02:00
property double baselineOffset: balance.baselineOffset + balance.y
2021-01-18 14:27:24 +01:00
onEnabledChanged: {
if (!enabled)
root.focus = false
}
2020-06-12 20:53:01 +02:00
function reset() {
privValue.enteredString = "0";
privValue.value = 0;
}
BitcoinValue {
id: privValue
}
MouseArea {
2021-01-06 15:07:01 +01:00
cursorShape: Qt.IBeamCursor
2020-06-12 20:53:01 +02:00
anchors.fill: parent
2021-01-18 14:27:24 +01:00
enabled: root.enabled
2021-01-06 15:07:01 +01:00
onClicked: {
root.focus = true
root.forceActiveFocus()
}
2020-06-12 20:53:01 +02:00
}
2020-10-15 19:18:54 +02:00
2020-06-12 20:53:01 +02:00
BitcoinAmountLabel {
id: balance
x: 8
y: 8
2020-06-12 23:37:32 +02:00
value: root.value
2020-06-12 20:53:01 +02:00
colorize: false
2020-06-12 23:37:32 +02:00
visible: !root.activeFocus
2020-10-15 19:18:54 +02:00
textColor: mainWindow.palette.text
2021-05-08 00:03:07 +02:00
showFiat: false
2020-06-12 20:53:01 +02:00
}
2020-10-15 19:18:54 +02:00
Label {
2020-06-12 20:53:01 +02:00
text: privValue.enteredString
2020-06-12 23:37:32 +02:00
visible: root.activeFocus
2020-06-12 20:53:01 +02:00
x: 8
y: 8
}
2020-10-15 19:18:54 +02:00
Label {
2020-06-12 20:53:01 +02:00
id: unit
text: Flowee.unitName
y: 8
anchors.right: parent.right
anchors.rightMargin: 8
2020-06-12 23:37:32 +02:00
visible: root.activeFocus
2020-06-12 20:53:01 +02:00
}
2020-10-15 19:18:54 +02:00
Rectangle { // focus indicator
2020-06-12 20:53:01 +02:00
anchors.fill: parent
2020-10-15 19:18:54 +02:00
border.color: root.activeFocus ? unit.palette.highlight : unit.palette.mid
2021-01-18 15:04:56 +01:00
border.width: 1
2020-06-12 20:53:01 +02:00
color: "#00000000" // transparant
}
2020-10-15 19:18:54 +02:00
2020-06-12 20:53:01 +02:00
Keys.onPressed: {
if (event.key >= Qt.Key_0 && event.key <= Qt.Key_9) {
privValue.addNumber(event.key);
event.accepted = true
}
else if (event.key === 44 || event.key === 46) {
privValue.addSeparator();
event.accepted = true
}
else if (event.key === Qt.Key_Backspace) {
privValue.backspacePressed();
event.accepted = true
}
}
2020-06-22 12:14:13 +02:00
Shortcut {
sequence: StandardKey.Paste
onActivated: privValue.paste()
}
2020-06-12 20:53:01 +02:00
}