2020-05-24 13:20:03 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2021-01-05 14:03:30 +01:00
|
|
|
* Copyright (C) 2020 Tom Zander <tom@flowee.org>
|
2020-05-24 13:20:03 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
import QtQuick 2.14
|
2020-10-15 19:18:54 +02:00
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
|
import QtQuick.Layouts 1.14
|
2020-05-24 13:20:03 +02:00
|
|
|
|
2020-10-16 18:17:56 +02:00
|
|
|
/**
|
|
|
|
|
* This class displays a Bitcoin value using the current settings
|
|
|
|
|
* and renders it smartly to avoid it just being a long list of digits.
|
|
|
|
|
*/
|
2020-10-15 19:18:54 +02:00
|
|
|
RowLayout {
|
2020-05-24 13:20:03 +02:00
|
|
|
id: root
|
2020-10-15 20:04:10 +02:00
|
|
|
property double value: 5E8
|
2020-05-24 13:20:03 +02:00
|
|
|
property bool colorize: true
|
2020-10-15 19:18:54 +02:00
|
|
|
property bool includeUnit: true
|
2020-12-26 15:30:29 +01:00
|
|
|
property color textColor: Flowee.useDarkSkin ? "#fcfcfc" :"black"
|
2020-10-15 19:18:54 +02:00
|
|
|
property var fontPtSize: 8
|
2020-05-24 13:20:03 +02:00
|
|
|
|
2020-10-15 19:18:54 +02:00
|
|
|
height: main.height
|
|
|
|
|
baselineOffset: main.baselineOffset
|
2020-05-24 13:20:03 +02:00
|
|
|
|
2020-10-18 16:57:13 +02:00
|
|
|
// calculated
|
2020-10-15 20:04:10 +02:00
|
|
|
property string amountString: "";
|
|
|
|
|
Connections {
|
|
|
|
|
target: Flowee
|
|
|
|
|
function onUnitChanged(unit) {
|
|
|
|
|
root.calcString(root.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onValueChanged: calcString(value)
|
|
|
|
|
function calcString(sats) {
|
|
|
|
|
amountString = Flowee.priceToString(sats)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 19:18:54 +02:00
|
|
|
Label {
|
|
|
|
|
id: main
|
|
|
|
|
text: {
|
|
|
|
|
var s = root.amountString
|
|
|
|
|
var removeChars = Flowee.unitAllowedDecimals
|
|
|
|
|
if (removeChars > 3)
|
|
|
|
|
removeChars -= 3; // the next text field eats those
|
|
|
|
|
return s.substring(0, s.length - removeChars)
|
2020-05-24 13:20:03 +02:00
|
|
|
}
|
2020-10-17 20:26:36 +02:00
|
|
|
color: {
|
|
|
|
|
if (root.colorize) {
|
|
|
|
|
var num = root.value
|
|
|
|
|
if (num > 0)
|
|
|
|
|
// positive value
|
|
|
|
|
return Flowee.useDarkSkin ? "#86ffa8" : "green";
|
|
|
|
|
else if (num < 0) // negative
|
|
|
|
|
return Flowee.useDarkSkin ? "#ffdede" : "#444446";
|
|
|
|
|
// zero is shown without color, like below.
|
|
|
|
|
}
|
|
|
|
|
return root.textColor
|
|
|
|
|
}
|
2020-10-15 19:18:54 +02:00
|
|
|
Layout.alignment: Qt.AlignBaseline
|
|
|
|
|
font.pointSize: root.fontPtSize
|
|
|
|
|
}
|
2020-05-24 13:20:03 +02:00
|
|
|
|
2020-10-15 19:18:54 +02:00
|
|
|
Label {
|
|
|
|
|
text: {
|
|
|
|
|
var s = root.amountString
|
|
|
|
|
var pos = s.length - 5
|
|
|
|
|
return s.substring(pos, pos + 3);
|
2020-05-24 13:20:03 +02:00
|
|
|
}
|
2020-10-15 19:18:54 +02:00
|
|
|
font.pointSize: satsLabel.font.pointSize
|
|
|
|
|
color: main.color
|
|
|
|
|
opacity: (satsLabel.opacity !== 1 && text == "000") ? 0.3 : 1
|
|
|
|
|
Layout.alignment: Qt.AlignBaseline
|
|
|
|
|
visible: Flowee.unitAllowedDecimals === 8
|
|
|
|
|
}
|
|
|
|
|
Label {
|
|
|
|
|
id: satsLabel
|
|
|
|
|
text: {
|
|
|
|
|
var s = root.amountString
|
|
|
|
|
return s.substring(s.length - 2);
|
2020-05-24 13:20:03 +02:00
|
|
|
}
|
2020-10-15 19:18:54 +02:00
|
|
|
font.pointSize: main.font.pointSize / 10 * 8
|
|
|
|
|
color: main.color
|
|
|
|
|
opacity: text == "00" ? 0.3 : 1
|
|
|
|
|
Layout.alignment: Qt.AlignBaseline
|
|
|
|
|
visible: Flowee.unitAllowedDecimals >= 2
|
|
|
|
|
}
|
2020-05-24 13:20:03 +02:00
|
|
|
|
2020-10-15 19:18:54 +02:00
|
|
|
Label {
|
|
|
|
|
text: Flowee.unitName
|
|
|
|
|
color: main.color
|
|
|
|
|
visible: parent.includeUnit
|
|
|
|
|
Layout.alignment: Qt.AlignBaseline
|
2020-05-24 13:20:03 +02:00
|
|
|
}
|
|
|
|
|
}
|