2023-06-09 18:27:13 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2023-03-14 02:52:16 +00:00
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
2024-07-12 09:46:43 +00:00
|
|
|
import StatusQ.Components 0.1
|
2023-03-14 02:52:16 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2023-03-30 17:57:18 +00:00
|
|
|
import StatusQ.Controls.Validators 0.1
|
2023-03-14 02:52:16 +00:00
|
|
|
import StatusQ.Core 0.1
|
2024-07-12 09:46:43 +00:00
|
|
|
import StatusQ.Core.Backpressure 0.1
|
2023-03-14 02:52:16 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-06-09 18:27:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
NOTE: I'm doing some crazy workarounds here. Tested on MacOS.
|
|
|
|
What I wanted to achieve:
|
|
|
|
|
|
|
|
1. User only gets a OS "allow camera access" popup
|
|
|
|
when a page with QR code scanner is opened.
|
|
|
|
2. Mimize UI freezes, or at least make it obvious
|
|
|
|
that something is going on.
|
|
|
|
|
|
|
|
Camera component uses main UI thread to request OS for available devices.
|
|
|
|
Therefore, we can't simply use Loader with `asyncronous` flag.
|
|
|
|
Neiter we can set `loading: qrCodeScanner.status === Loader.Loading` to this button.
|
|
|
|
|
|
|
|
To achieve desired points, I manually set `loading` property of the button
|
|
|
|
and delay the camera loading for 250ms. UI quickly shows loading indicator,
|
|
|
|
then it will freeze until the camera is loaded.
|
|
|
|
|
|
|
|
I think this can only be improved by moving the OS requests to another thread from C++.
|
|
|
|
|
|
|
|
We also don't yet have ability to auto-detect if the camera access was already enabled.
|
|
|
|
So we show `Enable camera` button everytime.
|
|
|
|
*/
|
2023-03-14 02:52:16 +00:00
|
|
|
|
2023-03-30 17:57:18 +00:00
|
|
|
Column {
|
2023-03-14 02:52:16 +00:00
|
|
|
id: root
|
|
|
|
|
2023-03-30 17:57:18 +00:00
|
|
|
property list<StatusValidator> validators
|
|
|
|
|
2023-03-14 02:52:16 +00:00
|
|
|
signal connectionStringFound(connectionString: string)
|
|
|
|
|
2023-03-30 17:57:18 +00:00
|
|
|
spacing: 12
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2023-03-14 02:52:16 +00:00
|
|
|
|
2023-06-09 18:27:13 +00:00
|
|
|
readonly property int radius: 16
|
2023-03-30 17:57:18 +00:00
|
|
|
property string errorMessage
|
|
|
|
property string lastTag
|
|
|
|
property int counter: 0
|
|
|
|
|
2023-06-09 18:27:13 +00:00
|
|
|
property bool showCamera: false
|
|
|
|
|
2023-03-30 17:57:18 +00:00
|
|
|
function validateConnectionString(connectionString) {
|
|
|
|
for (let i in root.validators) {
|
|
|
|
const validator = root.validators[i]
|
|
|
|
if (!validator.validate(connectionString)) {
|
|
|
|
d.errorMessage = validator.errorMessage
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.errorMessage = ""
|
|
|
|
root.connectionStringFound(connectionString)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-14 02:52:16 +00:00
|
|
|
|
2023-06-09 18:27:13 +00:00
|
|
|
Loader {
|
|
|
|
id: cameraLoader
|
|
|
|
active: true
|
2023-03-30 17:57:18 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
width: 330
|
|
|
|
height: 330
|
2023-06-09 18:27:13 +00:00
|
|
|
|
|
|
|
sourceComponent: d.showCamera ? cameraComponent : btnComponent
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: btnComponent
|
|
|
|
|
2023-10-03 18:40:20 +00:00
|
|
|
ShapeRectangle {
|
2023-06-09 18:27:13 +00:00
|
|
|
anchors.fill: parent
|
2023-10-03 18:40:20 +00:00
|
|
|
path.fillColor: Theme.palette.baseColor4
|
2023-06-09 18:27:13 +00:00
|
|
|
radius: d.radius
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: 20
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr('Enable access to your camera')
|
|
|
|
leftPadding: 48
|
|
|
|
rightPadding: 48
|
|
|
|
font.pixelSize: 15
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: qsTr("To scan a QR, Status needs\naccess to your webcam")
|
|
|
|
leftPadding: 48
|
|
|
|
rightPadding: 48
|
|
|
|
font.pixelSize: 15
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
color: Theme.palette.directColor4
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: button
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
text: qsTr("Enable camera access")
|
|
|
|
onClicked: {
|
|
|
|
loading = true
|
|
|
|
Backpressure.debounce(this, 250, () => {
|
|
|
|
button.loading = false
|
|
|
|
d.showCamera = true
|
|
|
|
})()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
}
|
2023-03-30 17:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 18:27:13 +00:00
|
|
|
Component {
|
|
|
|
id: cameraComponent
|
|
|
|
StatusQrCodeScanner {
|
|
|
|
anchors.fill: parent
|
|
|
|
onLastTagChanged: {
|
|
|
|
d.validateConnectionString(lastTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:57:18 +00:00
|
|
|
Item {
|
|
|
|
width: parent.width
|
2023-10-03 18:40:20 +00:00
|
|
|
height: 8
|
2023-03-30 17:57:18 +00:00
|
|
|
}
|
2023-03-14 02:52:16 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
2023-06-09 18:27:13 +00:00
|
|
|
visible: d.showCamera && cameraLoader.item.currentTag ? true : false
|
2023-03-30 17:57:18 +00:00
|
|
|
width: parent.width
|
2023-06-09 18:27:13 +00:00
|
|
|
height: visible ? implicitHeight : 0
|
2023-03-30 17:57:18 +00:00
|
|
|
wrapMode: Text.WordWrap
|
2023-03-14 02:52:16 +00:00
|
|
|
color: Theme.palette.dangerColor1
|
2023-03-30 17:57:18 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
text: d.errorMessage
|
|
|
|
}
|
|
|
|
|
2023-10-03 18:40:20 +00:00
|
|
|
StatusBaseText {
|
|
|
|
visible: !d.showCamera
|
|
|
|
width: parent.width
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
text: qsTr("Ensure both devices are on the same network")
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:57:18 +00:00
|
|
|
StatusBaseText {
|
2023-06-09 18:27:13 +00:00
|
|
|
visible: d.showCamera && cameraLoader.item.camera ? true : false
|
2023-03-30 17:57:18 +00:00
|
|
|
width: parent.width
|
2023-06-09 18:27:13 +00:00
|
|
|
height: visible ? implicitHeight : 0
|
2023-03-30 17:57:18 +00:00
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
color: Theme.palette.baseColor1
|
2023-10-03 18:40:20 +00:00
|
|
|
font.pixelSize: Theme.tertiaryTextFontSize
|
2023-03-30 17:57:18 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
text: qsTr("Ensure that the QR code is in focus to scan")
|
2023-03-14 02:52:16 +00:00
|
|
|
}
|
|
|
|
}
|