Files
pay/guis/mobile/Page.qml
T

156 lines
4.9 KiB
QML
Raw Permalink Normal View History

2022-11-15 11:38:28 +01:00
/*
* This file is part of the Flowee project
2024-04-29 11:20:41 +02:00
* Copyright (C) 2022-2024 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.
*/
property var backHandler: function handler() { thePile.pop(); }
function takeFocus() {
focusScope.forceActiveFocus();
}
2023-05-31 15:20:11 +02:00
function closeHeaderMenu() {
headerMenu.close();
}
2023-02-08 14:11:26 +01:00
onMenuItemsChanged: {
// remove old ones first
while (headerMenu.count > 0) {
headerMenu.takeItem(0);
}
// set new ones
for (let i = 0; i < menuItems.length; ++i) {
headerMenu.addAction(menuItems[i]);
}
}
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: {
let c = header.color;
return Qt.rgba(c.r, c.g, c.b, 0);
}
}
}
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
2024-04-29 11:20:41 +02: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
onClicked: headerMenu.open();
}
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
}
}