Files
pay/guis/mobile/TextButton.qml
T

142 lines
4.0 KiB
QML
Raw Permalink Normal View History

/*
* This file is part of the Flowee project
2025-01-02 18:35:46 +01:00
* Copyright (C) 2022-2025 Tom Zander <tom@flowee.org>
*
* 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
2025-01-02 18:35:46 +01:00
import QtQuick.Layouts
import "../Flowee" as Flowee
Item {
id: root
width: parent.width
2025-01-02 18:35:46 +01:00
implicitWidth: label.x + Math.max(label.contentWidth, smallLabel.contentWidth)
2025-01-03 17:40:51 +01:00
+ ((rightIcon.implicitWidth === 0) ? 0 : (10 + rightIcon.implicitWidth))
2022-11-23 16:06:37 +01:00
height: label.height + (smallLabel.text === "" ? 0 : smallLabel.height + 6) + 20
2022-12-15 12:00:01 +01:00
baselineOffset: label.baselineOffset + 10
2025-01-02 18:35:46 +01:00
Layout.fillWidth: true
signal clicked
property alias text: label.text
2022-11-23 16:06:37 +01:00
property alias subtext: smallLabel.text
2022-12-05 18:35:02 +01:00
/// When true, show an arrow indicating we open a new page on click
2024-12-23 18:51:55 +01:00
property bool pageButton: false
2024-12-21 12:50:53 +01:00
2024-12-23 18:51:55 +01:00
/// when pageButton is false, place an image on the right side instead
2022-11-23 16:06:37 +01:00
property string imageSource: ""
2024-12-21 12:50:53 +01:00
property int imageWidth: 20
property int imageHeight: 20
2025-01-03 17:40:51 +01:00
property int buttonId: 0
2024-12-21 12:50:53 +01:00
/// Add an icon before the label
property string iconSource: ""
Image {
id: icon
visible: root.iconSource !== ""
source: root.iconSource
width: 28
height: 28
anchors.verticalCenter: parent.verticalCenter
}
Flowee.Label {
id: label
2022-11-23 16:06:37 +01:00
y: 10
2024-12-21 12:50:53 +01:00
x: icon.visible ? 38 : 0
width: parent.width - x
wrapMode: Text.WordWrap
2023-05-16 18:57:23 +02:00
color: enabled ? palette.windowText : palette.brightText
}
2025-01-03 17:40:51 +01:00
Rectangle {
id: newIndicator
color: Pay.useDarkSkin ? "#0b45a2" : "#0d61b4"
width: 14
height: 14
radius: 7
x: {
if (!visible)
return 0;
var w = label.contentWidth;
return w - 1;
}
y: {
if (!visible)
return 0;
return label.y + label.baselineOffset - height / 2 - label.font.pixelSize * 0.8
}
visible: {
var bID = root.buttonId;
if (bID === 0)
return false;
return NewIndicator.isNew(bID);
}
}
2022-11-23 16:06:37 +01:00
Flowee.Label {
id: smallLabel
anchors.top: label.bottom
anchors.topMargin: 6
2023-02-14 15:03:27 +01:00
font.pixelSize: label.font.pixelSize * 0.8
2022-11-23 16:06:37 +01:00
font.bold: false
2023-02-14 15:03:27 +01:00
color: palette.brightText
2024-12-21 12:50:53 +01:00
width: label.width
x: label.x
2023-02-14 15:03:27 +01:00
wrapMode: Text.WordWrap
2022-11-23 16:06:37 +01:00
}
MouseArea {
anchors.fill: parent
2025-01-03 17:40:51 +01:00
onClicked: {
var bID = root.buttonId;
if (bID !== 0) {
NewIndicator.seen(bID);
newIndicator.visible = false;
}
root.clicked()
}
}
2022-11-23 16:06:37 +01:00
Loader {
2025-01-02 18:35:46 +01:00
id: rightIcon
2022-11-23 16:06:37 +01:00
sourceComponent: {
2024-12-23 18:51:55 +01:00
if (root.pageButton)
2022-11-23 16:06:37 +01:00
return pageIcon;
if (root.imageSource !== "")
return genericImage;
return undefined;
}
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
Component {
id: pageIcon
Image {
width: 12
height: 8
source: Pay.useDarkSkin ? "qrc:/smallArrow-light.svg" : "qrc:/smallArrow.svg";
rotation: 270
}
}
Component {
id: genericImage
Image {
source: root.imageSource
width: root.imageWidth
height: root.imageHeight
}
}
}