Files

239 lines
8.0 KiB
QML
Raw Permalink Normal View History

2025-06-24 22:19:37 +02:00
/*
* This file is part of the Flowee project
2026-02-04 19:28:03 +01:00
* Copyright (C) 2025-2026 Tom Zander <tom@flowee.org>
2025-06-24 22:19:37 +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
import QtQuick.Controls.Basic as QQC2
import "../Flowee" as Flowee
import "../Utils.js" as Utils
2026-02-04 19:28:03 +01:00
import Flowee.org.pay
2025-06-24 22:19:37 +02:00
ListView {
id: root
2026-03-08 22:40:30 +01:00
property bool hideQRScanButton: true
2026-03-16 11:44:46 +01:00
property bool active: false // true when this is the current tab
2025-06-24 22:19:37 +02:00
2025-08-11 16:40:11 +02:00
model: RepeatPaymentsModel {
id: repeatPaymentsModel
combineWallets: allWalletsEntrySelected
currentAccount: portfolio.current
2025-08-11 16:40:11 +02:00
}
2026-03-16 11:44:46 +01:00
onActiveChanged: {
if (!active) // move 'approved' items to the proper section
2026-02-04 15:02:32 +01:00
model.updateOrdering()
}
2025-06-24 22:19:37 +02:00
clip: true
focus: true
section.property: "section"
section.labelPositioning: ViewSection.InlineLabels + ViewSection.CurrentLabelAtStart
section.delegate: Item {
height: label.height + 3
width: root.width
Flowee.Label {
id: label
x: 10
font.bold: true
font.pixelSize: mainWindow.font.pixelSize * 1.1
text: {
if (section == 1) // yes, 2 equals
return qsTr("Payments to Approve")
if (section == 2) // yes, 2 equals
return qsTr("Approved Payments")
return qsTr("Inactive Payments")
}
}
MouseArea { anchors.fill: parent } // eat all taps
}
2026-02-04 19:28:03 +01:00
delegate: Rectangle {
2025-06-26 00:02:57 +02:00
id: delegateRoot
width: ListView.view.width
2026-03-16 11:44:46 +01:00
height: 16 + amountFiat.height + 6 + comment.height + 6
+ approvedLine.height + 6 + walletChoice.height + 24
2026-02-04 19:28:03 +01:00
color: palette.base
2025-06-26 00:02:57 +02:00
2025-08-12 21:16:19 +02:00
property QtObject payment: model.payment
2026-02-04 19:28:03 +01:00
Rectangle {
anchors.fill: parent
anchors.margins: 10
gradient: Gradient {
GradientStop {
position: Pay.useDarkSkin ? 2 : 1
color: Pay.useDarkSkin ? palette.midlight : palette.mid
}
GradientStop {
position: 0
color: palette.base
2025-08-11 16:40:11 +02:00
}
}
2026-02-04 19:28:03 +01:00
radius: 10
MouseArea {
anchors.fill: parent
2026-03-16 11:44:46 +01:00
onClicked: thePile.push("RepeatPaymentDetails.qml", { "savedPayment": model.payment })
2026-02-04 19:28:03 +01:00
}
2025-06-26 00:02:57 +02:00
}
2025-08-11 16:40:11 +02:00
2025-06-26 00:02:57 +02:00
Flowee.BitcoinAmountLabel {
id: amountBch
2025-08-11 16:40:11 +02:00
value: model.valueSats
2026-02-04 19:28:03 +01:00
x: 16
y: 24
2025-06-26 00:02:57 +02:00
showFiat: false
colorize: false
2025-08-11 16:40:11 +02:00
anchors.top: nextDate.bottom
2025-06-26 00:02:57 +02:00
anchors.topMargin: 6
2026-02-04 19:28:03 +01:00
visible: model.fiatFollows // check if the payment prefers fiat over sats
2025-06-26 00:02:57 +02:00
}
Flowee.Label {
id: amountFiat
2026-02-04 19:28:03 +01:00
text: {
let txt = Fiat.formattedPrice(model.valueFiat)
if (amountBch.visible)
2026-03-16 11:44:46 +01:00
return "(" + txt + ")"
2026-02-04 19:28:03 +01:00
return txt
}
x: 16 + (amountBch.visible ? amountBch.width + 10 : 0)
y: 24
anchors.left: amountBch.visible ? amountBch.right : parent.left
anchors.leftMargin: amountBch.visible ? 6 : 16
2025-06-26 00:02:57 +02:00
}
2026-02-04 19:28:03 +01:00
Flowee.Label {
id: comment
text: model.comment
width: parent.width - 32
elide: Text.ElideRight
x: 16
anchors.top: amountFiat.bottom
2026-03-16 11:44:46 +01:00
height: text === "" ? 0 : contentHeight
2025-08-12 21:16:19 +02:00
}
Item {
2026-02-04 19:28:03 +01:00
id: approvedLine
property bool isEnabled: delegateRoot.payment.enabled
2026-02-04 19:28:03 +01:00
anchors.top: comment.bottom
anchors.topMargin: 6
x: 16
width: checkLabel.contentWidth + 20
height: Math.max(24, checkLabel.contentHeight)
2025-08-12 21:16:19 +02:00
Rectangle {
radius: 4
color: palette.base
border.color: palette.highlight
border.width: 1.3
width: 24
height: 24
visible: approvedLine.isEnabled
anchors.bottom: checkLabel.bottom
2025-08-12 21:16:19 +02:00
}
Flowee.Label {
visible: approvedLine.isEnabled
id: checkLabel
2025-08-12 21:16:19 +02:00
x: 30
2026-02-04 19:28:03 +01:00
text: {
let d = model.upcomingDate
let now = new Date()
// close to 'now', or in the past
if (d - now < 18 * 3600 * 1000) // 18h in ms
return qsTr("Approve to pay: today")
return qsTr("Approve to pay on %1", "The arg is a date").arg(Pay.formatDate(d))
}
2025-08-12 21:16:19 +02:00
}
Flowee.CheckShape {
id: check
transformOrigin: Item.BottomLeft
smooth: true
scale: 1.6
anchors.bottom: parent.bottom
anchors.bottomMargin: 3
visible: approvedLine.isEnabled && model.isApproved
}
MouseArea {
anchors {
margins: -10
left: parent.left
top: parent.top
right: checkLabel.right
bottom: checkLabel.bottom
}
onClicked: delegateRoot.payment.approved = !delegateRoot.payment.approved
2025-08-12 21:16:19 +02:00
}
Flowee.Label {
visible: !approvedLine.isEnabled
text: qsTr("Paused")
font.italic: true
}
2025-06-26 00:02:57 +02:00
}
2026-02-04 19:28:03 +01:00
Flowee.Label {
id: walletChoice
anchors.left: approvedLine.left
anchors.top: approvedLine.bottom
anchors.topMargin: 6
visible: !portfolio.singleAccountSetup && allWalletsEntrySelected
2026-02-04 19:28:03 +01:00
text: qsTr("From wallet: %1").arg(delegateRoot.payment.accountName)
height: visible ? contentHeight : 0
2025-08-11 16:40:11 +02:00
}
Flowee.HamburgerMenu {
anchors.right: parent.right
anchors.rightMargin: 25
anchors.top: amountBch.top
MouseArea {
id: mouseArea
anchors.fill: parent
anchors.margins: -20
onClicked: contextMenu.open()
}
Flowee.Popup {
id: contextMenu
x: -width - 5
width: Math.max(150, Math.max(button1.implicitWidth, button2.implicitWidth))
height: col.height
Column {
id: col
width: parent.width - 20
x: 10
spacing: 10
TextButton {
id: button1
text: delegateRoot.payment.enabled ? qsTr("Pause") : qsTr("Resume")
onClicked: delegateRoot.payment.enabled = !delegateRoot.payment.enabled
}
TextButton {
id: button2
text: qsTr("Delete...")
2026-03-16 11:44:46 +01:00
onClicked: {
contextMenu.close()
okDeleteDiag.open()
}
}
}
}
}
Flowee.Dialog {
id: okDeleteDiag
title: qsTr("Confirm delete")
text: qsTr("Do you really want to delete this repeating-payment?")
onAccepted: Pay.removeRepeatPayment(delegateRoot.payment.payment)
}
2025-06-24 22:19:37 +02:00
}
}