Files
pay/guis/mobile/Page.qml
T

138 lines
4.0 KiB
QML
Raw Permalink Normal View History

2022-11-15 11:38:28 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2022-2023 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
import QtQuick.Controls as QQC2
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 {
2023-02-21 16:40:46 +01:00
color: palette.light
2023-02-14 14:56:18 +01:00
}
leftPadding: 10
rightPadding: 10
topPadding: header.height
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
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
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
2023-02-14 14:56:18 +01:00
width: parent.width // + 20
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
Image {
id: backButton
2022-11-17 23:07:15 +01:00
x: 13
source: "qrc:/back-arrow.svg"
width: 20 * 1.1
height: 15 * 1.1
anchors.verticalCenter: parent.verticalCenter
2022-11-15 11:38:28 +01:00
MouseArea {
anchors.fill: parent
2022-11-17 23:07:15 +01:00
anchors.margins: -15
onClicked: thePile.pop();
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"
2022-11-21 19:29:46 +01:00
anchors.left: backButton.right
anchors.right: {
// we assume at most one of these two is in use.
if (headerButton.visible)
return headerButton.left;
if (hamburgerMenu.visible)
return hamburgerMenu.left;
return parent.right;
}
2022-11-21 19:29:46 +01:00
horizontalAlignment: Text.AlignHCenter
anchors.verticalCenter: parent.verticalCenter
}
Flowee.Button {
id: headerButton
visible: false
anchors.right: parent.right
2022-11-22 23:09:31 +01:00
anchors.rightMargin: 10
2022-11-21 19:29:46 +01:00
anchors.verticalCenter: parent.verticalCenter
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
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
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
}
Keys.onPressed: (event)=> {
if (event.key === Qt.Key_Back) {
event.accepted = true;
thePile.pop();
}
}
}