Files
pay/guis/mobile/QRScannerOverlay.qml
T

255 lines
7.9 KiB
QML
Raw Permalink Normal View History

2022-12-07 14:36:51 +01:00
/*
* This file is part of the Flowee project
2023-06-15 19:15:02 +02:00
* Copyright (C) 2022-2023 Tom Zander <tom@flowee.org>
2022-12-07 14:36:51 +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-12-03 13:44:21 +01:00
import QtQuick
import QtQuick.Controls as QQC2
2022-12-14 14:21:56 +01:00
import QtQuick.Shapes
2022-12-03 13:44:21 +01:00
import QtMultimedia
import "../Flowee" as Flowee
2022-12-14 14:21:56 +01:00
FocusScope {
2022-12-03 13:44:21 +01:00
id: root
2022-12-14 14:21:56 +01:00
visible: CameraController.visible
enabled: visible
onVisibleChanged: if (visible) root.forceActiveFocus();
2022-12-14 14:21:56 +01:00
Keys.onPressed: (event)=> {
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) {
2022-12-14 14:21:56 +01:00
event.accepted = true;
CameraController.abort();
}
}
Rectangle {
id: background
anchors.fill: parent
2023-02-21 16:40:46 +01:00
color: palette.window
2022-12-14 14:21:56 +01:00
}
2023-06-11 18:10:39 +02:00
MouseArea {
anchors.fill: parent
// eat all clicks
}
2022-12-14 14:21:56 +01:00
2022-12-03 13:44:21 +01:00
// We put the 'Camera' in a loader to avoid Android permissions to be popped up until the
// feature is actually requisted by the user.
Loader {
sourceComponent: videoFeedPanel
active: CameraController.loadCamera
anchors.fill: parent
}
2022-12-14 14:21:56 +01:00
// The 'progress' icon.
Shape {
id: cutout
anchors.fill: parent.fill
smooth: true
opacity: 0.5
property int x1: root.width / 2 - 100
property int y1: root.height / 2 - 100
property int y2: y1 + 200
property int x2: x1 + 200
property int radius: 30
ShapePath {
fillColor: "black"
strokeWidth: 0
strokeColor: "transparent"
startX: 0; startY: 0
PathLine { x: width; y: 0 }
PathLine { x: width; y: height }
PathLine { x: 0; y: height }
PathLine { x: 0; y: height / 2 }
// move to the center part.
PathLine { x: cutout.x1; y: height / 2 }
PathLine { x: cutout.x1; y: cutout.y1 + cutout.radius }
PathArc {
x: cutout.x1 + cutout.radius
y: cutout.y1
radiusX: cutout.radius
radiusY: cutout.radius
}
PathLine { x: cutout.x2 - cutout.radius; y: cutout.y1 }
PathArc {
x: cutout.x2
y: cutout.y1 + cutout.radius
radiusX: cutout.radius
radiusY: cutout.radius
}
PathLine { x: cutout.x2; y: cutout.y2 - cutout.radius}
PathArc {
x: cutout.x2 - cutout.radius
y: cutout.y2
radiusX: cutout.radius
radiusY: cutout.radius
}
PathLine { x: cutout.x1 + cutout.radius; y: cutout.y2 }
PathArc {
x: cutout.x1
y: cutout.y2 - cutout.radius
radiusX: cutout.radius
radiusY: cutout.radius
}
PathLine { x: cutout.x1; y: height / 2}
PathLine { x: 0; y: height / 2 }
PathLine { x: 0; y: 0 }
}
}
2023-06-11 17:52:54 +02:00
Rectangle {
2023-06-15 19:15:02 +02:00
id: pasteFrame
2023-06-11 17:52:54 +02:00
x: 50
anchors.bottom: parent.bottom
anchors.bottomMargin: 50
visible: CameraController.supportsPaste
2023-06-15 19:15:02 +02:00
radius: 6
2023-06-11 17:52:54 +02:00
width: pasteButton.width
height: pasteButton.height
color: palette.base
Flowee.ImageButton {
id: pasteButton
source: "qrc:/edit-clipboard" + (Pay.useDarkSkin ? "-light.svg" : ".svg");
text: qsTr("Paste")
onClicked: pasteFeedback.visible = !CameraController.importScanFromClipboard();
}
Rectangle {
id: pasteFeedback
color: palette.toolTipBase
border.color: palette.toolTipText
border.width: 2
width: errorLabel.width + 10
height: errorLabel.height + 10
radius: 5
anchors.top : pasteButton.bottom
visible: false
Flowee.Label {
id: errorLabel
anchors.centerIn: parent
text: qsTr("Failed")
color: palette.toolTipText
}
Timer {
interval: 4000
running: parent.visible
onTriggered: parent.visible = false
}
}
}
2023-06-15 19:15:02 +02:00
Rectangle {
id: flashFrame
anchors.top: pasteFrame.top
anchors.right: parent.right
anchors.rightMargin: 50
radius: 6
visible: false
width: flashButton.width
height: flashButton.height
color: palette.base
Flowee.ImageButton {
id: flashButton
source: "qrc:/flash" + (Pay.useDarkSkin ? "-light.svg" : ".svg");
opacity: CameraController.torchEnabled ? 0.3 : 1
onClicked: CameraController.torchEnabled = !CameraController.torchEnabled
}
}
2023-06-11 17:52:54 +02:00
2023-08-27 20:39:46 +02:00
Rectangle {
width: parent.width
height: Math.max(closeIcon.height, instaLabel.height) + 20
color: mainWindow.floweeBlue
Flowee.CloseIcon {
id: closeIcon
anchors.right: parent.right
anchors.rightMargin: 10
y: 10
onClicked: CameraController.abort();
}
Flowee.Label {
id: instaLabel
anchors.left: parent.left
anchors.top: parent.top
anchors.right: closeIcon.left
anchors.margins: 10
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
color: "white"
text: {
let cur = portfolio.current;
if (cur === null || !cur.allowInstaPay)
return "";
let fiatName = Fiat.currencyName;
let limit = cur.fiatInstaPayLimit(fiatName);
if (limit === 0)
return "";
var answer = qsTr("Instant Pay limit is %1").arg(Fiat.formattedPrice(limit));
if (!portfolio.singleAccountSetup)
answer += "\n" + qsTr("Selected wallet: '%1'").arg(cur.name);
return answer;
}
}
}
// ------ components below this, which are not instantiated by default -----
2022-12-03 13:44:21 +01:00
Component {
id: videoFeedPanel
2022-12-14 14:21:56 +01:00
Item {
2022-12-03 13:44:21 +01:00
Component.onCompleted: {
CameraController.camera = camera
CameraController.videoSink = videoOutput.videoSink
}
Connections {
target: CameraController
function onCameraActiveChanged() {
if (CameraController.cameraActive) {
camera.start();
2023-06-15 19:15:02 +02:00
flashFrame.visible = camera.isTorchModeSupported(Camera.TorchOn)
2022-12-14 14:21:56 +01:00
} else if (Qt.platform.os !== "linux") {
// at least on Linux stopping a camera and turning it on again fails with
// "Camera is in use"
camera.stop();
2022-12-03 13:44:21 +01:00
}
}
}
2022-12-07 14:36:51 +01:00
Camera {
2022-12-03 13:44:21 +01:00
id: camera
active: false
2022-12-03 13:44:21 +01:00
}
CaptureSession {
camera: camera
videoOutput: videoOutput
}
VideoOutput {
id: videoOutput
2023-06-11 17:52:54 +02:00
fillMode: VideoOutput.PreserveAspectCrop
2022-12-03 13:44:21 +01:00
width: parent.width
2022-12-07 14:36:51 +01:00
height: parent.height
}
2022-12-03 13:44:21 +01:00
}
}
}