Files

115 lines
3.8 KiB
QML
Raw Permalink Normal View History

2023-03-13 10:24:15 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2022-2023 Tom Zander <tom@flowee.org>
*
* 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
2025-06-18 17:48:29 +02:00
import QtQuick.Controls.Basic as QQC2
2023-03-13 10:24:15 +01:00
import "../Flowee" as Flowee
2024-02-13 14:26:29 +01:00
/**
* This widget shows a single wallet and the balance.
* It allows the user to change the 'current' wallet as well via a popup.
*/
2023-03-13 10:24:15 +01:00
Rectangle {
2023-03-13 10:32:12 +01:00
id: root
2023-03-13 10:24:15 +01:00
x: -10
width: parent.width + 20
2023-03-13 16:58:05 +01:00
// if set to true, tapping on the account has no effect.
property bool stickyAccount: false
2023-03-13 16:58:05 +01:00
// list of actions to put in a menu when clicking on the 'balance' side.
property var balanceActions: [ ]
property var startingAccount: portfolio.current
property var selectedAccount: startingAccount
2023-03-13 16:58:05 +01:00
2023-03-13 10:24:15 +01:00
height: {
2026-03-14 21:14:42 +01:00
var w = 20 + currentWalletValue.implicitWidth
if (currentWalletLabel.visible)
2026-03-14 21:14:42 +01:00
w += currentWalletLabel.implicitWidth + 10 // right spacing.
if (hamburgerMenu.visible)
2026-03-14 21:14:42 +01:00
w += 10
2023-05-18 21:52:51 +02:00
if (width > w && (root.stickyAccount || portfolio.singleAccountSetup))
2026-03-14 21:14:42 +01:00
return currentWalletValue.height + 20 // all on one line
2023-03-13 10:24:15 +01:00
return currentWalletValue.height + currentWalletLabel.height + 25
}
color: palette.alternateBase
Flowee.HamburgerMenu {
id: hamburgerMenu
2023-03-13 10:24:15 +01:00
x: 10
anchors.verticalCenter: currentWalletLabel.verticalCenter
2023-05-18 21:52:51 +02:00
visible: root.stickyAccount === false && !portfolio.singleAccountSetup
2023-03-13 10:24:15 +01:00
}
Flowee.Label {
id: currentWalletLabel
y: 10
x: root.stickyAccount ? 10 : 20
2023-03-13 10:24:15 +01:00
width: parent.width - 30
text: root.selectedAccount.name
2023-03-13 10:24:15 +01:00
visible: !portfolio.singleAccountSetup
color: root.stickyAccount ? palette.brightText : palette.windowText
2023-03-13 10:24:15 +01:00
}
Flowee.BitcoinAmountLabel {
id: currentWalletValue
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 10
value: {
var wallet = root.selectedAccount
2026-03-14 21:14:42 +01:00
return wallet.balanceConfirmed + wallet.balanceUnconfirmed
2023-03-13 10:24:15 +01:00
}
2024-10-06 14:05:54 +02:00
colorize: false
2023-03-13 10:24:15 +01:00
}
MouseArea {
anchors.fill: parent
onClicked: (mouse) => {
2026-03-14 21:14:42 +01:00
var haveActions = balanceActions.length > 0
2024-10-06 14:05:54 +02:00
if (!haveActions || mouse.x < parent.width / 2) {
2023-05-18 21:52:51 +02:00
if (root.stickyAccount === false && !portfolio.singleAccountSetup)
2026-03-14 21:14:42 +01:00
accountSelector.open()
2024-10-06 14:05:54 +02:00
} else if (haveActions) {
2023-03-13 16:58:05 +01:00
while (priceMenu.count > 0) {
2026-03-14 21:14:42 +01:00
priceMenu.takeItem(0)
2023-03-13 16:58:05 +01:00
}
for (let i = 0; i < balanceActions.length; ++i) {
2026-03-14 21:14:42 +01:00
priceMenu.addAction(balanceActions[i])
2023-03-13 16:58:05 +01:00
}
priceMenu.x = root.width / 2
priceMenu.y = -40
2026-03-14 21:14:42 +01:00
priceMenu.open()
2023-03-13 16:58:05 +01:00
}
}
2023-03-13 10:24:15 +01:00
}
QQC2.Menu {
id: priceMenu
}
2023-03-13 10:32:12 +01:00
AccountSelectorPopup {
id: accountSelector
width: root.width
y: -10
onSelectedAccountChanged: root.selectedAccount = selectedAccount
selectedAccount: root.startingAccount
// when showing the selector widget these make little to no sense.
showTotalBalance: false
showEncryptedAccounts: false
2023-03-13 10:32:12 +01:00
}
2023-03-13 10:24:15 +01:00
}