Files
pay/guis/mobile/Page.qml
T

165 lines
5.4 KiB
QML
Raw Permalink Normal View History

2022-11-15 11:38:28 +01:00
/*
* This file is part of the Flowee project
2025-10-29 22:03:19 +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 "../Flowee" as Flowee
2022-11-15 11:38:28 +01:00
QQC2.Control {
id: root
2023-02-14 14:56:18 +01:00
width: parent == null ? 10 : parent.width
height: parent == null ? 10 : parent.height
2022-11-15 11:38:28 +01:00
2023-02-14 14:56:18 +01:00
background: Rectangle {
2025-08-03 14:01:38 +02:00
color: palette.light
2023-02-14 14:56:18 +01:00
}
2025-09-05 12:22:40 +02:00
leftPadding: fullScreen ? 0 : Pay.screenInsets.x + 10
rightPadding: fullScreen ? 0 : Pay.screenInsets.width + 10
2024-10-06 22:36:10 +02:00
topPadding: header.height
2025-09-05 12:22:40 +02:00
bottomPadding: fullScreen ? 0 : Pay.screenInsets.height
2024-10-06 22:36:10 +02:00
wheelEnabled: true // eat wheel events
2023-02-14 14:56:18 +01:00
default property alias content: focusScope.children
2022-11-15 11:38:28 +01:00
property alias headerText: headerLabel.text
2022-11-21 19:29:46 +01:00
property alias headerButtonVisible: headerButton.visible
property alias headerButtonText: headerButton.text
property alias headerButtonEnabled: headerButton.enabled
2025-09-05 12:22:40 +02:00
/*
* Enable this to remove all insets and the header that
* are normally added by the Page to surround child content.
* Please do take care to honor Pay.ScreenInsets yourself if
* you set this to true.
*/
property bool fullScreen: false // TODO rename
2023-02-08 14:11:26 +01:00
/**
* A list of action objects to populate the menu with
* Setting this will make a hamburger button show up in the header
*/
property var menuItems: [ ]
2022-11-21 19:29:46 +01:00
signal headerButtonClicked
2022-11-15 11:38:28 +01:00
2024-04-29 11:20:41 +02:00
/**
* Handler called when the 'back' button in the page header is called.
* Replace this with your own function if the inheriting page needs to
* do something diffrent.
* Notice that you likely to call `thePile.pop()` from your handler.
*/
2026-03-14 21:14:42 +01:00
property var backHandler: function handler() { thePile.pop() }
2024-04-29 11:20:41 +02:00
2025-10-29 22:03:19 +01:00
/**
* Returns the actual available height to the page.
* Due to us using the default property concept, classes inheriting from
* this Page will not be able to use 'height' in a useful way as that doesn't
* account for things like the header. Giving them a too large number.
* This provides a simple way for inheriting users to get the available space.
*/
property alias pageHeight: focusScope.height
function takeFocus() {
2026-03-14 21:14:42 +01:00
focusScope.forceActiveFocus()
}
2023-05-31 15:20:11 +02:00
function closeHeaderMenu() {
2026-03-14 21:14:42 +01:00
headerMenu.close()
2023-05-31 15:20:11 +02:00
}
2023-02-08 14:11:26 +01:00
onMenuItemsChanged: {
// remove old ones first
while (headerMenu.count > 0) {
2026-03-14 21:14:42 +01:00
headerMenu.takeItem(0)
2023-02-08 14:11:26 +01:00
}
// set new ones
for (let i = 0; i < menuItems.length; ++i) {
2026-03-14 21:14:42 +01:00
headerMenu.addAction(menuItems[i])
2023-02-08 14:11:26 +01:00
}
}
2022-11-15 11:38:28 +01:00
Rectangle {
id: header
2024-10-06 22:36:10 +02:00
width: parent.width
2025-09-05 12:22:40 +02:00
height: root.fullScreen ? 0 : (Pay.screenInsets.y + 50)
2023-02-21 16:40:46 +01:00
color: Pay.useDarkSkin ? palette.window : mainWindow.floweeBlue
2025-09-05 12:22:40 +02:00
visible: !root.fullScreen
2022-11-15 11:38:28 +01:00
2025-03-09 22:03:32 +01:00
gradient: Gradient {
GradientStop { position: 0.9; color: header.color }
GradientStop { position: 1; color: {
2026-03-14 21:14:42 +01:00
let c = header.color
return Qt.rgba(c.r, c.g, c.b, 0)
2025-03-09 22:03:32 +01:00
}
}
}
2025-08-30 10:39:01 +02:00
Item {
id: headerContent // header without all the insets
height: parent.height - Pay.screenInsets.y
anchors.bottom: parent.bottom
x: Pay.screenInsets.x
width: parent.width - x - Pay.screenInsets.width
}
2022-11-15 11:38:28 +01:00
Image {
id: backButton
2025-08-30 10:39:01 +02:00
x: headerContent.x + 13
2022-11-17 23:07:15 +01:00
source: "qrc:/back-arrow.svg"
width: 20 * 1.1
height: 15 * 1.1
2025-08-30 10:39:01 +02:00
anchors.verticalCenter: headerContent.verticalCenter
2022-11-15 11:38:28 +01:00
MouseArea {
anchors.fill: parent
2022-11-17 23:07:15 +01:00
anchors.margins: -15
2026-03-14 21:14:42 +01:00
onClicked: root.backHandler()
2022-11-15 11:38:28 +01:00
}
}
2022-11-18 13:43:04 +01:00
QQC2.Label {
2022-11-15 11:38:28 +01:00
id: headerLabel
2022-11-17 23:07:15 +01:00
color: "white"
2025-08-30 10:39:01 +02:00
anchors.centerIn: headerContent
2022-11-21 19:29:46 +01:00
}
Flowee.Button {
id: headerButton
visible: false
2025-08-30 10:39:01 +02:00
anchors.right: headerContent.right
2022-11-22 23:09:31 +01:00
anchors.rightMargin: 10
2025-08-30 10:39:01 +02:00
anchors.verticalCenter: headerContent.verticalCenter
2022-11-21 19:29:46 +01:00
onClicked: root.headerButtonClicked()
2022-11-15 11:38:28 +01:00
}
2023-02-08 14:11:26 +01:00
Flowee.HamburgerMenu {
id: hamburgerMenu
2023-02-08 14:11:26 +01:00
visible: root.menuItems.length > 0
2025-08-30 10:39:01 +02:00
anchors.right: headerContent.right
2023-02-08 14:11:26 +01:00
anchors.rightMargin: 15
2025-08-30 10:39:01 +02:00
anchors.verticalCenter: headerContent.verticalCenter
2023-10-16 20:27:48 +02:00
color: "white"
2023-02-08 14:11:26 +01:00
MouseArea {
anchors.fill: parent
anchors.margins: -15
2026-03-14 21:14:42 +01:00
onClicked: headerMenu.open()
2023-02-08 14:11:26 +01:00
}
QQC2.Menu {
id: headerMenu
}
}
2022-11-15 11:38:28 +01:00
}
2023-02-14 14:56:18 +01:00
contentItem: FocusScope {
2022-12-05 20:31:00 +01:00
id: focusScope
2022-11-15 11:38:28 +01:00
}
}