Files
purple-electrumwallet/electrum/gui/qml/components/controls/QRScan.qml
T

167 lines
3.9 KiB
QML
Raw Normal View History

2023-07-17 10:49:06 +02:00
import QtQuick
import QtQuick.Controls
2023-07-14 13:51:08 +02:00
import QtMultimedia
2023-07-19 14:13:10 +02:00
import QtQml
2021-04-05 12:24:45 +02:00
2022-03-30 18:01:16 +02:00
import org.electrum 1.0
2021-04-05 12:24:45 +02:00
Item {
2022-03-29 16:36:20 +02:00
id: scanner
property bool active: false
property string url
property string scanData
2023-04-24 13:19:40 +02:00
property string hint
2022-03-29 16:36:20 +02:00
signal found
2021-04-05 12:24:45 +02:00
function restart() {
2023-07-19 14:13:10 +02:00
console.log('qrscan.restart')
scanData = ''
qr.reset()
start()
}
function start() {
console.log('qrscan.start')
loader.item.startTimer.start()
}
2023-07-19 14:13:10 +02:00
function stop() {
console.log('qrscan.stop')
scanner.active = false
}
Item {
id: points
z: 100
2021-04-05 12:24:45 +02:00
anchors.fill: parent
2023-07-19 14:13:10 +02:00
}
2022-03-29 16:36:20 +02:00
2023-07-19 14:13:10 +02:00
Loader {
id: loader
anchors.fill: parent
sourceComponent: scancomp
onStatusChanged: {
if (loader.status == Loader.Ready) {
console.log('camera loaded')
} else if (loader.status == Loader.Error) {
console.log('camera load error')
2023-04-24 13:19:40 +02:00
}
}
2021-04-05 12:24:45 +02:00
}
2023-07-19 14:13:10 +02:00
Component {
id: scancomp
Item {
property alias vo: _vo
property alias ic: _ic
property alias startTimer: _startTimer
2022-03-29 16:36:20 +02:00
2023-07-19 14:13:10 +02:00
VideoOutput {
id: _vo
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectCrop
Rectangle {
width: parent.width
height: (parent.height - parent.width) / 2
anchors.top: parent.top
color: Qt.rgba(0,0,0,0.5)
}
Rectangle {
width: parent.width
height: (parent.height - parent.width) / 2
anchors.bottom: parent.bottom
color: Qt.rgba(0,0,0,0.5)
}
InfoTextArea {
visible: scanner.hint
background.opacity: 0.5
iconStyle: InfoTextArea.IconStyle.None
anchors {
top: parent.top
topMargin: constants.paddingXLarge
left: parent.left
leftMargin: constants.paddingXXLarge
right: parent.right
rightMargin: constants.paddingXXLarge
}
text: scanner.hint
}
Component.onCompleted: {
startTimer.start()
}
}
ImageCapture {
id: _ic
}
MediaDevices {
id: mediaDevices
}
Camera {
id: camera
cameraDevice: mediaDevices.defaultVideoInput
active: scanner.active
focusMode: Camera.FocusModeAutoNear
customFocusPoint: Qt.point(0.5, 0.5)
onErrorOccurred: {
console.log('camera error: ' + errorString)
}
}
CaptureSession {
videoOutput: _vo
imageCapture: _ic
camera: camera
}
Timer {
id: _startTimer
interval: 500
repeat: false
onTriggered: scanner.active = true
}
}
2022-03-29 16:36:20 +02:00
}
Component {
id: r
Rectangle {
property int cx
property int cy
width: 15
height: 15
x: cx - width/2
y: cy - height/2
radius: 5
visible: scanner._pointsVisible
}
}
Connections {
2022-03-30 18:01:16 +02:00
target: qr
2022-03-29 16:36:20 +02:00
function onDataChanged() {
2023-07-19 14:13:10 +02:00
console.log('QR DATA: ' + qr.data)
2022-03-29 16:36:20 +02:00
scanner.active = false
2022-03-30 18:01:16 +02:00
scanner.scanData = qr.data
2023-07-19 14:13:10 +02:00
scanner.found()
2022-03-29 16:36:20 +02:00
}
}
2022-03-30 18:01:16 +02:00
QRParser {
id: qr
2023-07-19 14:13:10 +02:00
videoSink: loader.item.vo.videoSink
2022-03-30 18:01:16 +02:00
}
2021-04-05 12:24:45 +02:00
}