2023-03-11 22:44:27 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
2025-02-05 16:24:39 +01:00
|
|
|
* Copyright (C) 2022-2025 Tom Zander <tom@flowee.org>
|
2023-03-11 22:44:27 +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/>.
|
|
|
|
|
*/
|
|
|
|
|
import QtQuick
|
2025-06-18 17:48:29 +02:00
|
|
|
import QtQuick.Controls.Basic as QQC2
|
2023-03-11 22:44:27 +01:00
|
|
|
|
2023-06-21 17:46:17 +02:00
|
|
|
Item {
|
2023-03-11 22:44:27 +01:00
|
|
|
id: root
|
2024-02-12 23:20:36 +01:00
|
|
|
implicitHeight: 70 * 4
|
2024-02-13 14:26:29 +01:00
|
|
|
height: contentHeight
|
2023-06-27 18:57:50 +02:00
|
|
|
|
2026-03-14 21:14:42 +01:00
|
|
|
required property var dataInput
|
2024-02-13 14:26:29 +01:00
|
|
|
/**
|
|
|
|
|
* The keyboard can have a separator in the bottom left position,
|
|
|
|
|
* which is either a dot or a comma based on locale.
|
|
|
|
|
* Or if this property is false, we put the backspace there and
|
|
|
|
|
* reserve the bottom right button for finished()
|
|
|
|
|
*/
|
|
|
|
|
property bool hasSeparator: true
|
|
|
|
|
|
|
|
|
|
/// emitted when the user used the 'Ok' button. @see hasSeparator
|
2026-03-14 21:14:42 +01:00
|
|
|
signal finished
|
2024-02-13 14:26:29 +01:00
|
|
|
|
|
|
|
|
// We export an implicitHeight that is rather small,
|
|
|
|
|
// the parent widget may consider giving this thing a LOT more
|
|
|
|
|
// space, though. Which equally looks bad.
|
|
|
|
|
// So here we have a maximum height we'll actually occupy for
|
|
|
|
|
// usability sake
|
|
|
|
|
property int contentHeight: {
|
|
|
|
|
// we aim to be have buttons no taller than 18mm
|
2026-03-14 21:14:42 +01:00
|
|
|
var realPixelSize = Screen.pixelDensity * 18
|
2024-02-13 14:26:29 +01:00
|
|
|
return Math.min(height, realPixelSize * 4)
|
|
|
|
|
}
|
2023-06-27 18:57:50 +02:00
|
|
|
|
2025-02-05 16:24:39 +01:00
|
|
|
/**
|
|
|
|
|
* The background for a single button.
|
|
|
|
|
* Notice that we expect a property bool pressed and
|
|
|
|
|
* you will have access to the attached property 'index'.
|
|
|
|
|
*/
|
|
|
|
|
property Component buttonBackground: Item {
|
|
|
|
|
id: bg
|
|
|
|
|
property int index: 0
|
|
|
|
|
property bool pressed: false
|
|
|
|
|
Rectangle {
|
|
|
|
|
width: Math.min(parent.width, parent.height) - 6
|
|
|
|
|
height: width
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
radius: bg.pressed ? 20 : height
|
|
|
|
|
|
|
|
|
|
color: {
|
|
|
|
|
if (bg.pressed || index === 11 || index === 9)
|
|
|
|
|
return palette.midlight
|
|
|
|
|
return palette.mid
|
|
|
|
|
}
|
|
|
|
|
opacity: enabled ? 1 : 0
|
|
|
|
|
Behavior on opacity { NumberAnimation { } }
|
|
|
|
|
Behavior on color { ColorAnimation { } }
|
|
|
|
|
Behavior on radius { NumberAnimation { duration: 100 } }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Timer {
|
|
|
|
|
interval: 200
|
|
|
|
|
running: bg.pressed
|
|
|
|
|
onTriggered: bg.pressed = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 11:45:57 +02:00
|
|
|
function flashErrorFeedback() {
|
|
|
|
|
errorFeedback.opacity = 0.7
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 17:46:17 +02:00
|
|
|
Rectangle {
|
|
|
|
|
// when the typed items are not allowd
|
|
|
|
|
// by the back-end, we flash this red area for a very brief time
|
|
|
|
|
// to let the user know.
|
|
|
|
|
// notice we also 'shake' the actual typed text, but if the user is
|
|
|
|
|
// focused on this widget they might miss that.
|
|
|
|
|
// Useful since some currencies don't allow dots/commas, which should
|
|
|
|
|
// be clearly communicated to the user!
|
|
|
|
|
id: errorFeedback
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
radius: 20
|
|
|
|
|
color: mainWindow.errorRedBg
|
|
|
|
|
opacity: 0
|
2023-03-11 22:44:27 +01:00
|
|
|
|
2023-06-21 17:46:17 +02:00
|
|
|
Timer {
|
|
|
|
|
interval: 100
|
|
|
|
|
running: errorFeedback.opacity > 0
|
|
|
|
|
repeat: true
|
|
|
|
|
onTriggered: {
|
|
|
|
|
anim.duration = 400
|
|
|
|
|
errorFeedback.opacity = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Behavior on opacity {
|
|
|
|
|
NumberAnimation {
|
|
|
|
|
id: anim
|
|
|
|
|
duration: 50
|
|
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Flow {
|
|
|
|
|
id: flowLayout
|
2024-02-13 14:26:29 +01:00
|
|
|
|
2023-06-21 17:46:17 +02:00
|
|
|
width: parent.width
|
2024-02-13 14:26:29 +01:00
|
|
|
anchors.bottom: parent.bottom
|
2023-06-21 17:46:17 +02:00
|
|
|
Repeater {
|
|
|
|
|
model: 12
|
|
|
|
|
delegate: Item {
|
|
|
|
|
width: root.width / 3
|
2024-02-13 14:26:29 +01:00
|
|
|
height: root.contentHeight / 4
|
2025-02-05 16:24:39 +01:00
|
|
|
Loader {
|
|
|
|
|
id: background
|
|
|
|
|
sourceComponent: root.buttonBackground
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
onLoaded: item.index = index
|
2024-02-13 14:26:29 +01:00
|
|
|
}
|
2025-02-05 16:24:39 +01:00
|
|
|
|
2023-06-21 17:46:17 +02:00
|
|
|
QQC2.Label {
|
|
|
|
|
id: textLabel
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
font.pixelSize: 28
|
|
|
|
|
text: {
|
|
|
|
|
if (index < 9)
|
2026-03-14 21:14:42 +01:00
|
|
|
return index + 1
|
2024-02-13 14:26:29 +01:00
|
|
|
if (index === 9 && root.hasSeparator)
|
2023-06-21 17:46:17 +02:00
|
|
|
return Qt.locale().decimalPoint
|
|
|
|
|
if (index === 10)
|
|
|
|
|
return "0"
|
2026-03-14 21:14:42 +01:00
|
|
|
return ""
|
2023-06-21 17:46:17 +02:00
|
|
|
}
|
|
|
|
|
// make dim when not enabled.
|
|
|
|
|
color: {
|
|
|
|
|
if (!enabled)
|
2026-03-14 21:14:42 +01:00
|
|
|
return Pay.useDarkSkin ? Qt.darker(palette.buttonText, 2) : Qt.lighter(palette.buttonText, 2)
|
|
|
|
|
return palette.windowText
|
2023-06-21 17:46:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Image {
|
2024-02-13 14:26:29 +01:00
|
|
|
visible: index === 11 || (!root.hasSeparator && index == 9)
|
2023-06-21 17:46:17 +02:00
|
|
|
anchors.centerIn: parent
|
2024-02-13 14:26:29 +01:00
|
|
|
source: {
|
2026-03-14 21:14:42 +01:00
|
|
|
let base = ""
|
2024-02-13 14:26:29 +01:00
|
|
|
if ((root.hasSeparator && index == 11)
|
|
|
|
|
|| (!root.hasSeparator && index == 9))
|
2026-03-14 21:14:42 +01:00
|
|
|
base = "qrc:/backspace"
|
2024-02-13 14:26:29 +01:00
|
|
|
else if (!root.hasSeparator && index == 11)
|
2026-03-14 21:14:42 +01:00
|
|
|
base = "qrc:/confirmIcon"
|
2024-02-13 14:26:29 +01:00
|
|
|
if (base === "")
|
2026-03-14 21:14:42 +01:00
|
|
|
return base
|
|
|
|
|
return base + (Pay.useDarkSkin ? "-light" : "") + ".svg"
|
2024-02-13 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
width: 22
|
|
|
|
|
height: 15
|
2023-06-21 17:46:17 +02:00
|
|
|
opacity: enabled ? 1 : 0.4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
function doSomething() {
|
2026-03-14 21:14:42 +01:00
|
|
|
let editor = dataInput.editor
|
|
|
|
|
let fail = false
|
2023-06-21 17:46:17 +02:00
|
|
|
if (index < 9) // these are digits
|
2026-03-14 21:14:42 +01:00
|
|
|
fail = !editor.insertNumber("" + (index + 1))
|
2024-02-13 14:26:29 +01:00
|
|
|
else if (index === 9 && root.hasSeparator)
|
2023-06-21 17:46:17 +02:00
|
|
|
fail = !editor.addSeparator()
|
|
|
|
|
else if (index === 10)
|
2026-03-14 21:14:42 +01:00
|
|
|
fail = !editor.insertNumber("0")
|
2024-02-13 14:26:29 +01:00
|
|
|
else if (index === 11 && !root.hasSeparator) {
|
|
|
|
|
fail = editor.enteredString === ""
|
|
|
|
|
if (!fail)
|
2026-03-14 21:14:42 +01:00
|
|
|
root.finished()
|
2024-02-13 14:26:29 +01:00
|
|
|
}
|
2023-06-21 17:46:17 +02:00
|
|
|
else
|
2026-03-14 21:14:42 +01:00
|
|
|
fail = !editor.backspacePressed()
|
2023-06-21 17:46:17 +02:00
|
|
|
if (fail) {
|
|
|
|
|
anim.duration = 40
|
2026-03-14 21:14:42 +01:00
|
|
|
root.flashErrorFeedback()
|
|
|
|
|
dataInput.shake()
|
2023-06-21 17:46:17 +02:00
|
|
|
}
|
2024-02-13 14:26:29 +01:00
|
|
|
else {
|
2026-03-14 21:14:42 +01:00
|
|
|
background.item.pressed = true
|
2024-02-13 14:26:29 +01:00
|
|
|
}
|
2023-06-21 17:46:17 +02:00
|
|
|
}
|
2026-03-14 21:14:42 +01:00
|
|
|
onClicked: doSomething()
|
|
|
|
|
onDoubleClicked: doSomething()
|
2023-03-11 22:44:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|