Files
pay/guis/mobile/MainViewBase.qml
T

438 lines
14 KiB
QML
Raw Permalink Normal View History

2022-11-15 11:38:28 +01:00
/*
* This file is part of the Flowee project
2025-02-25 19:38:39 +01:00
* Copyright (C) 2022-2025 Tom Zander <tom@flowee.org>
2022-11-15 11:38:28 +01: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/>.
*/
2022-11-26 10:44:52 +01:00
import QtQuick
2025-06-18 17:48:29 +02:00
import QtQuick.Controls.Basic as QQC2
2022-11-26 10:44:52 +01:00
import QtQuick.Layouts
import QtQuick.Effects
import "../Flowee" as Flowee
2022-11-15 11:38:28 +01:00
QQC2.Control {
id: root
width: parent.width
height: parent.height
2023-02-14 14:56:18 +01:00
background: Rectangle {
color: palette.base
2023-02-14 14:56:18 +01:00
}
2024-10-22 19:44:14 +02:00
// This trick means any child items are actually added as the 'stack' item's children.
2022-11-15 11:38:28 +01:00
default property alias content: stack.children
property int currentIndex: 0
2024-10-22 00:03:58 +02:00
property bool showFilterIcon: false
2025-07-12 16:56:08 +02:00
/// the gradient at the bottom of the header
property bool showHeaderGradient: true
2024-10-22 00:03:58 +02:00
signal filterIconClicked;
2025-07-12 16:56:08 +02:00
onCurrentIndexChanged: stack.newCurrentItem()
Component.onCompleted: stack.newCurrentItem()
2024-10-22 00:03:58 +02:00
function switchToTab(index) {
currentIndex = index
}
2022-11-15 11:38:28 +01:00
// called from main when this page becomes active, as well as when we change tabs
function takeFocus() {
2022-11-15 11:38:28 +01:00
// try to make sure the current tab gets keyboard focus properly.
// We do some extra work in case the tab itself is a loader.
forceActiveFocus();
let visibleChild = stack.children[currentIndex];
2022-11-15 11:38:28 +01:00
visibleChild.focus = true
if (visibleChild instanceof Loader) {
var child = visibleChild.item;
if (child !== null)
child.focus = true;
}
}
2025-02-26 14:04:58 +01:00
Rectangle {
id: offlineNotice
color: mainWindow.errorRedBg
width: parent.width
height: visible ? 35 : 0
visible: Pay.deviceOffline
Flowee.Label {
text: qsTr("No Internet Available");
font.bold: true
anchors.centerIn: parent
}
Behavior on height { NumberAnimation { } }
}
2022-11-15 11:38:28 +01:00
Rectangle {
id: header
width: parent.width
2025-02-26 14:04:58 +01:00
y: offlineNotice.height
2022-11-23 16:06:37 +01:00
height: 50
2023-02-21 16:40:46 +01:00
color: Pay.useDarkSkin ? palette.window : mainWindow.floweeBlue
2022-11-15 11:38:28 +01:00
2023-02-06 19:44:53 +01:00
Flowee.HamburgerMenu {
2022-11-15 11:38:28 +01:00
id: menuButton
2025-03-09 22:03:32 +01:00
y: 14
2023-02-14 14:56:18 +01:00
color: "white"
2023-02-06 19:44:53 +01:00
wide: true
2025-03-09 22:03:32 +01:00
x: 20
2022-11-15 11:38:28 +01:00
}
MouseArea {
anchors.fill: menuButton
2023-03-15 13:35:03 +01:00
// make the touch area a lot bigger, its safe as its limited to the 'header' area anyway.
anchors.margins: -60
2022-11-15 11:38:28 +01:00
cursorShape: Qt.PointingHandCursor
onClicked: menuOverlay.open = true;
}
2022-12-15 15:03:43 +01:00
QQC2.Control {
id: logo
2022-11-17 00:12:17 +01:00
// Here we just want the text part. So clip that out.
clip: true
2025-03-09 22:03:32 +01:00
y: 15
x: 36
2022-11-17 00:12:17 +01:00
width: 122
height: 21
2022-12-15 15:03:43 +01:00
baselineOffset: 16
2022-11-17 00:12:17 +01:00
Image {
2022-11-17 23:07:15 +01:00
source: "qrc:/FloweePay.svg"
2022-11-17 00:12:17 +01:00
// ratio: 449 / 77
width: 150
height: 26
x: -28
y: -5
}
2022-11-15 11:38:28 +01:00
}
2022-12-15 15:03:43 +01:00
QQC2.Label {
id: currentWalletName
2023-02-24 23:48:26 +01:00
visible: !portfolio.singleAccountSetup
2022-12-15 15:03:43 +01:00
text: portfolio.current.name
color: "#fcfcfc"
clip: true
anchors.left: logo.right
2024-10-22 00:03:58 +02:00
anchors.right: filterIcon.left
2024-10-22 19:44:14 +02:00
anchors.margins: 10
2022-12-15 15:03:43 +01:00
anchors.baseline: logo.baseline
MouseArea {
anchors.fill: parent
2023-05-18 21:52:51 +02:00
onClicked: {
if (accountSelector.visible)
accountSelector.close();
else
accountSelector.open();
}
2022-12-15 15:03:43 +01:00
}
}
2024-10-22 19:44:14 +02:00
Image {
2024-10-22 00:03:58 +02:00
id: filterIcon
2024-10-22 19:44:14 +02:00
source: "qrc:/filter-light.svg"
2025-05-02 22:26:58 +02:00
opacity: root.showFilterIcon ? 1 : 0
visible: opacity > 0.1
2024-10-22 19:44:14 +02:00
anchors.right: parent.right
2025-03-09 22:03:32 +01:00
anchors.rightMargin: 16
2024-10-23 19:00:18 +02:00
anchors.bottom: parent.bottom
2025-03-09 22:03:32 +01:00
anchors.bottomMargin: 14
2024-10-22 19:44:14 +02:00
smooth: true
width: 25
height: 25
2024-10-22 00:03:58 +02:00
MouseArea {
anchors.fill: parent
2024-10-22 19:44:14 +02:00
anchors.margins: -10
2024-10-22 00:03:58 +02:00
onClicked: root.filterIconClicked();
}
2024-10-23 19:00:18 +02:00
// and a little counter for the number of filters active
// to make it easier to see if stuff may be hidden.
// Notice that the MainViewBase has one instance for the
// entire application, while the filters are per acccount.
// So we need a bit of extra work to notice changes as the
// two 'Connections' objects below show.
property int numFilters: calcNumFilters();
function calcNumFilters() {
var filterCount = 0;
var currentAccount = portfolio.current
2025-02-25 19:38:39 +01:00
if (currentAccount !== null)
2024-10-23 19:00:18 +02:00
filterCount = currentAccount.transactions.filterCount;
return filterCount;
}
Connections {
target: portfolio
function onCurrentChanged() {
filterChangedConnection.target = portfolio.current.transactions
filterIcon.numFilters = filterIcon.calcNumFilters();
}
}
Connections {
id: filterChangedConnection
target: portfolio.current.transactions
function onIncludeFlagsChanged() {
filterIcon.numFilters = filterIcon.calcNumFilters();
}
}
Rectangle {
color: "#1d6828"
width: 18
height: 18
radius: 9
anchors.bottom: parent.bottom
anchors.bottomMargin: -8
x: -4
visible: filterIcon.numFilters > 0
Text {
anchors.centerIn: parent
text: filterIcon.numFilters
color: "#fcfcfc"
}
}
2025-05-02 22:26:58 +02:00
Behavior on opacity {
NumberAnimation {
easing.type: Easing.OutExpo
duration: 250
}
}
2022-12-15 15:03:43 +01:00
}
2023-03-13 10:32:12 +01:00
AccountSelectorPopup {
2022-12-15 15:03:43 +01:00
id: accountSelector
width: root.width
2023-02-06 20:29:03 +01:00
y: header.height
2023-02-06 21:55:54 +01:00
onSelectedAccountChanged: portfolio.current = selectedAccount
2022-12-15 15:03:43 +01:00
}
2025-07-12 16:56:08 +02:00
property var headerGradient: Gradient {
2025-03-09 22:03:32 +01:00
GradientStop { position: 0.9; color: header.color }
GradientStop { position: 1; color: {
let c = header.color;
return Qt.rgba(c.r, c.g, c.b, 0);
}
}
}
2025-07-12 16:56:08 +02:00
gradient: root.showHeaderGradient ? headerGradient : undefined
2022-11-15 11:38:28 +01:00
}
Item {
id: stack
width: root.width
anchors.top: header.bottom; anchors.bottom: tabbar.top
2025-07-12 16:56:08 +02:00
function newCurrentItem() {
var current = root.currentIndex;
for (let i = 0; i < stack.children.length; ++i) {
let on = i === current
let child = stack.children[i];
child.visible = on;
}
root.takeFocus();
var page = stack.children[current];
var showGradient = true;
if (page !== null && typeof(page.showHeaderGradient) == "boolean") {
showGradient = page.showHeaderGradient;
}
root.showHeaderGradient = showGradient;
}
2022-11-15 11:38:28 +01:00
}
2023-02-14 18:44:53 +01:00
Rectangle {
anchors.fill: tabbar
2023-02-21 16:40:46 +01:00
color: palette.window
2023-02-14 18:44:53 +01:00
}
2022-11-15 11:38:28 +01:00
Row {
id: tabbar
anchors.bottom: parent.bottom
Repeater {
model: stack.children.length
2023-02-14 18:44:53 +01:00
delegate: Item {
2023-07-05 12:24:31 +02:00
height: 65
2022-11-15 11:38:28 +01:00
width: root.width / stack.children.length;
2023-02-14 18:44:53 +01:00
Rectangle {
x: 5
height: 4
width: parent.width - 10
2023-02-21 16:40:46 +01:00
color: palette.highlight
2023-02-14 18:44:53 +01:00
visible: modelData === root.currentIndex
}
Rectangle {
anchors.fill: parent
2023-02-21 16:40:46 +01:00
color: palette.highlight
2023-02-14 18:44:53 +01:00
visible: modelData === root.currentIndex
opacity: 0.15
2022-11-18 13:43:04 +01:00
}
Image {
source: stack.children[modelData].icon
2023-07-05 12:24:31 +02:00
width: 30
height: 30
2022-12-08 11:34:10 +01:00
smooth: true
2022-12-15 15:03:43 +01:00
y: 8
2022-11-18 13:43:04 +01:00
anchors.horizontalCenter: parent.horizontalCenter
}
Flowee.Label {
2025-02-25 19:38:39 +01:00
id: buttonLabel
2022-11-18 13:43:04 +01:00
text: stack.children[modelData].title
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
2022-12-15 15:03:43 +01:00
anchors.bottomMargin: 2
font.pixelSize: 14
2022-11-15 11:38:28 +01:00
}
2025-02-25 19:38:39 +01:00
NewIndicator {
id: newIndicator
buddy: buttonLabel
Component.onCompleted: {
var buttonId = stack.children[modelData].buttonId;
if (typeof(buttonId) === "number")
newIndicator.buttonId = buttonId;
}
}
2022-11-15 11:38:28 +01:00
MouseArea {
anchors.fill: parent
2025-02-25 19:38:39 +01:00
onClicked: {
newIndicator.markSeen();
root.currentIndex = modelData
}
2022-11-15 11:38:28 +01:00
}
}
}
}
Item {
id: floatingCard
width: mainText.width + 32
2025-05-20 21:54:05 +02:00
height: 28 + mainText.height + 10 + bgSyncButton.height + 10 + hideButtonLabel.height + 16
y: 330
x: 10
opacity: Pay.showBGSyncCard ? 1 : 0
visible: opacity > 0.1
onXChanged: if (x < -160 || x < 40 - width) visible = false;
Rectangle {
radius: 5
width: parent.width - 20
height: parent.height - 20
anchors.centerIn: parent
color: palette.window
}
Rectangle {
color: palette.highlight
opacity: 0.15
anchors.fill: parent
radius: 8
// soft shadow
layer.enabled: true
layer.effect: MultiEffect {
blurEnabled: true
blur: 1
}
}
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.AllButtons
hoverEnabled: true // eat all mouse activity
onClicked: (mouseEvent)=> {
floatingCard.opacity = 0;
if (mouseEvent.y > height - hideButtonLabel.height - 26) {
// the hide button was hit.
return;
}
2025-05-04 21:59:47 +02:00
thePile.push("./BackgroundSyncConfig.qml", { "autoEnableAll": "true" } );
}
}
DragHandler {
id: dragHandler
yAxis.minimum: header.height
yAxis.maximum: root.height - parent.height
xAxis.minimum: -200
xAxis.maximum: root.width - parent.width
}
Flowee.Label {
id: mainText
text: qsTr("For a better experience, enable Flowee Pay background synchronization.")
x: 16
2025-05-04 21:59:47 +02:00
y: 28
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
2025-06-24 22:19:37 +02:00
width: 220
}
2025-05-20 21:54:05 +02:00
Rectangle {
id: bgSyncButton
width: Math.max(160, bgSyncButtonLabel.width + 30)
height: bgSyncButtonLabel.height + 20
radius: 10
color: mainWindow.floweeGreen
anchors.top: mainText.bottom
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
Flowee.Label {
id: bgSyncButtonLabel
text: qsTr("Start")
color: "black"
anchors.centerIn: parent
}
}
Flowee.Label {
id: hideButtonLabel
text: qsTr("hide")
2025-05-20 21:54:05 +02:00
opacity: 0.6
anchors.top: bgSyncButton.bottom
anchors.topMargin: 10
2025-05-20 21:54:05 +02:00
anchors.horizontalCenter: parent.horizontalCenter
}
Behavior on opacity { NumberAnimation { } }
}
/*
* Fully encrypted wallet are useless to inspect or use until they are opened.
* This is an overlay that covers the entire screen except for the header to make
* unlocking a "modal" dialogue.
*/
Rectangle {
color: palette.window
anchors.top: header.bottom
anchors.bottom: parent.bottom
width: parent.width
visible: portfolio.current.needsPinToOpen && !portfolio.current.isDecrypted
// eat all taps / clicks.
MouseArea { anchors.fill: parent }
// to avoid using resources in the 99% of the time the user is not unlocking his wallet,
// we use a loader for the unlocking screen.
Loader {
id: unlockWalletWidget
anchors.fill: parent
source: parent.visible ? "./UnlockWalletPanel.qml" : ""
}
}
2023-11-06 15:55:10 +01:00
Keys.onPressed: (event)=> {
if (event.key === Qt.Key_Escape || event.key === Qt.Key_Back) {
// when we are on another tab, we can go to 'main' on back.
2025-06-25 00:17:08 +02:00
if (root.currentIndex !== 0) {
2023-11-06 15:55:10 +01:00
root.currentIndex = 0;
event.accepted = true;
}
}
// in all other cases, propagate the event up the stack.
}
2022-11-15 11:38:28 +01:00
}