Files
pay/guis/mobile/TextButton.qml
T

142 lines
4.2 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))
implicitHeight: Math.max(60, label.height + (smallLabel.text === "" ? 0 : smallLabel.height) + 20)
height: implicitHeight
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
2025-02-17 12:05:45 +01:00
property alias horizontalAlignment: label.horizontalAlignment
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-02-25 19:38:39 +01:00
property alias buttonId: newIndicator.buttonId
2024-12-21 12:50:53 +01:00
/// Add an icon before the label
property string iconSource: ""
2025-03-02 19:31:36 +01:00
property var currentValue: undefined
2024-12-21 12:50:53 +01:00
Image {
id: icon
visible: root.iconSource !== ""
source: root.iconSource
width: 28
height: 28
anchors.verticalCenter: parent.verticalCenter
}
Flowee.Label {
id: label
y: smallLabel.text === "" ? (parent.height - height) / 2 : 10
2024-12-21 12:50:53 +01:00
x: icon.visible ? 38 : 0
2025-02-17 12:05:45 +01:00
width: {
var w = parent.width - x
if (horizontalAlignment === Text.AlignRight)
w = w - rightIcon.width - 10
return w;
}
elide: Text.ElideRight
2023-05-16 18:57:23 +02:00
color: enabled ? palette.windowText : palette.brightText
}
2025-03-02 19:31:36 +01:00
Flowee.Label {
id: currentValueLabel
y: label.y
text: {
if (typeof(root.currentValue) == "undefined")
return "";
if (typeof(root.currentValue) == "boolean")
return root.currentValue ? qsTr("Enabled") : qsTr("Disabled")
return "" + root.currentValue;
}
x: {
var x = parent.width - contentWidth
if (rightIcon.item != null)
x -= rightIcon.width + 10;
return x;
}
2025-03-04 11:14:54 +01:00
color: enabled ? palette.highlight : palette.brightText
2025-03-02 19:31:36 +01:00
}
2025-02-25 19:38:39 +01:00
NewIndicator {
2025-01-03 17:40:51 +01:00
id: newIndicator
2025-02-25 19:38:39 +01:00
buddy: label
2025-01-03 17:40:51 +01:00
}
2022-11-23 16:06:37 +01:00
Flowee.Label {
id: smallLabel
anchors.top: label.bottom
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: {
2025-02-25 19:38:39 +01:00
newIndicator.markSeen();
2025-01-03 17:40:51 +01:00
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
}
}
}