Warning, /pim/vakzination/src/qml/ScanBarcodePage.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtCore
0007 import QtQuick 2.15
0008 import QtQuick.Layouts 1.15
0009 import QtQuick.Controls 2.15 as QQC2
0010 import QtMultimedia
0011 import org.kde.kirigami 2.17 as Kirigami
0012 import org.kde.prison.scanner 1.0 as Prison
0013 import org.kde.vakzination 1.0
0014 
0015 Kirigami.Page {
0016     id: root
0017     title: i18n("Scan QR code")
0018 
0019     leftPadding: 0
0020     rightPadding: 0
0021     topPadding: 0
0022     bottomPadding: 0
0023 
0024     actions: [
0025         Kirigami.Action {
0026             icon.name: checked ? "flashlight-off" : "flashlight-on"
0027             text: i18n("Light")
0028             checkable: true
0029             checked: camera.torchMode == Camera.TorchOn
0030             visible: camera.isTorchModeSupported
0031             onTriggered: camera.torchMode = (camera.torchMode == Camera.TorchOn ? Camera.TorchOff : Camera.TorchOn)
0032         }
0033     ]
0034 
0035     CameraPermission {
0036         id: permission
0037         onStatusChanged: {
0038             if (status == Qt.PermissionStatus.Granted) {
0039                 camera.start();
0040             }
0041         }
0042     }
0043 
0044     VideoOutput {
0045         id: viewFinder
0046         anchors.fill: parent
0047         fillMode: VideoOutput.PreserveAspectCrop
0048     }
0049 
0050     Prison.VideoScanner {
0051         id: scanner
0052         formats: Prison.Format.QRCode | Prison.Format.Aztec | Prison.Format.DataMatrix | Prison.Format.PDF417
0053         videoSink: viewFinder.videoSink
0054         onResultContentChanged: {
0055             if (result.hasText && CertificatesModel.importCertificateFromText(result.text)) {
0056                 applicationWindow().pageStack.goBack();
0057             }
0058             if (result.hasBinaryData && CertificatesModel.importCertificateFromData(result.binaryData)) {
0059                 applicationWindow().pageStack.goBack();
0060             }
0061         }
0062     }
0063 
0064     CaptureSession {
0065         id: captureSession
0066         camera: Camera {
0067             id: camera
0068             active: true
0069         }
0070         videoOutput: viewFinder
0071     }
0072 
0073     Rectangle {
0074         border {
0075             color: Kirigami.Theme.focusColor
0076             width: 2
0077         }
0078         color: Qt.rgba(Kirigami.Theme.focusColor.r, Kirigami.Theme.focusColor.g, Kirigami.Theme.focusColor.b, 0.2);
0079         radius: Kirigami.Units.smallSpacing
0080 
0081         x: viewFinder.contentRect.x + scanner.result.boundingRect.x / viewFinder.sourceRect.width * viewFinder.contentRect.width
0082         y: viewFinder.contentRect.y + scanner.result.boundingRect.y / viewFinder.sourceRect.height * viewFinder.contentRect.height
0083         width: scanner.result.boundingRect.width / viewFinder.sourceRect.width * viewFinder.contentRect.width
0084         height: scanner.result.boundingRect.height / viewFinder.sourceRect.height * viewFinder.contentRect.height
0085     }
0086 
0087     Kirigami.PlaceholderMessage {
0088         anchors.fill: parent
0089         text: i18n("No camera available.")
0090         visible: camera.error != Camera.NoError
0091     }
0092 
0093     Component.onCompleted: {
0094         if (permission.status == Qt.PermissionStatus.Undetermined)
0095             permission.request()
0096     }
0097 }