Warning, /maui/booth/src/views/CameraPage.qml is written in an unsupported language. File is not indexed.
0001 // Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
0002 // Copyright 2018-2020 Nitrux Latinoamericana S.C.
0003 //
0004 // SPDX-License-Identifier: GPL-3.0-or-later
0005
0006 import QtQml 2.14
0007 import QtQuick 2.14
0008 import QtQuick.Controls 2.15
0009 import QtMultimedia 5.15
0010
0011 import org.mauikit.controls 1.3 as Maui
0012
0013 import org.mauikit.filebrowsing 1.3 as FB
0014
0015 import org.kde.prison.scanner 1.0 as Prison
0016
0017 import "../widgets"
0018
0019 Pane
0020 {
0021 id: cameraPage
0022 padding: 0
0023 property bool manualMode: false
0024 property alias camera : _camera
0025 state: "PhotoCapture"
0026
0027 background: Rectangle
0028 {
0029 color: "black"
0030 }
0031
0032 states: [
0033 State {
0034 name: "PhotoCapture"
0035 StateChangeScript {
0036 script: {
0037 camera.captureMode = Camera.CaptureStillImage
0038 camera.start()
0039 }
0040 }
0041 },
0042 State {
0043 name: "PhotoPreview"
0044 },
0045 State {
0046 name: "VideoCapture"
0047 StateChangeScript {
0048 script: {
0049 camera.captureMode = Camera.CaptureVideo
0050 camera.start()
0051 }
0052 }
0053 },
0054 State {
0055 name: "VideoPreview"
0056 StateChangeScript {
0057 script: {
0058 camera.stop()
0059 }
0060 }
0061 }
0062 ]
0063
0064 Prison.VideoScanner
0065 {
0066 id: scanner
0067 // formats: Prison.Format.QRCode | Prison.Format.Aztec
0068 onResultChanged: {
0069 if (result.hasText) {
0070 console.log(result.text, result.format);
0071 } else if (result.hasBinaryData) {
0072 console.log("<binary content>", result.format);
0073 } else {
0074 console.log("no barcode found");
0075 }
0076 }
0077 }
0078
0079
0080 contentItem: PinchArea
0081 {
0082 pinch.minimumScale: 0
0083 pinch.maximumScale: camera.maximumDigitalZoom
0084 enabled: camera.maximumDigitalZoom > 1 && Maui.Handy.isTouch
0085
0086 onPinchUpdated:
0087 {
0088 console.log("PINCH ZOOMING", pinch.previousScale)
0089 camera.setDigitalZoom(Math.round(pinch.previousScale + pinch.scale))
0090 pinch.accepted = true
0091 }
0092
0093 VideoOutput
0094 {
0095 id: viewfinder
0096 visible: cameraPage.state == "PhotoCapture" || cameraPage.state == "VideoCapture"
0097 anchors.fill: parent
0098
0099 autoOrientation: true
0100
0101 filters: settings.readQR ? [scanner] : []
0102
0103 source: Camera
0104 {
0105 id: _camera
0106 captureMode: Camera.CaptureStillImage
0107
0108 // flash.mode: Camera.FlashRedEyeReduction
0109 // imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
0110
0111 exposure {
0112 exposureCompensation: -1.0
0113 exposureMode: Camera.ExposurePortrait
0114 }
0115
0116 focus {
0117 focusMode: Camera.FocusPointAuto
0118 // focusPointMode: Camera.FocusPointCustom
0119 customFocusPoint: Qt.point(0.2, 0.2) // Focus relative to top-left corner
0120 }
0121
0122 imageCapture {
0123 onImageCaptured:
0124 {
0125 _previewImage.source = preview
0126 // stillControls.previewAvailable = true
0127 // cameraPage.state = "PhotoPreview"
0128 }
0129 }
0130
0131 videoRecorder {
0132 resolution: "640x480"
0133 frameRate: 30
0134 }
0135 }
0136
0137 Repeater
0138 {
0139 model: _camera.focus.focusZones
0140
0141 Rectangle
0142 {
0143 border
0144 {
0145 width: 2
0146 color: status == Camera.FocusAreaFocused ? "green" : "white"
0147 }
0148
0149 color: "transparent"
0150
0151 // Map from the relative, normalized frame coordinates
0152 property variant mappedRect: viewfinder.mapNormalizedRectToItem(area);
0153
0154 x: mappedRect.x
0155 y: mappedRect.y
0156 width: mappedRect.width
0157 height: mappedRect.height
0158 }
0159 }
0160
0161
0162 Maui.Chip
0163 {
0164 text: _camera.digitalZoom+"x"
0165 visible: _camera.digitalZoom >1
0166 anchors.right: parent.right
0167 anchors.bottom: parent.bottom
0168 anchors.margins: Maui.Style.space.big
0169 }
0170
0171 Item
0172 {
0173 height: 100
0174 width: 100
0175
0176 anchors.left: parent.left
0177 anchors.bottom: parent.bottom
0178 anchors.margins: Maui.Style.space.big
0179
0180 Image
0181 {
0182 id: _previewImage
0183 anchors.fill: parent
0184 sourceSize.width: width
0185 sourceSize.height: height
0186
0187 fillMode: Image.PreserveAspectFit
0188 }
0189 }
0190 }
0191
0192 Item
0193 {
0194 anchors.fill: parent
0195
0196 Label
0197 {
0198 text: {
0199 if (camera.lockStatus == Camera.Unlocked)
0200 "Focus";
0201 else if (camera.lockStatus == Camera.Searching)
0202 "Focusing"
0203 else
0204 "Unlock"
0205 }
0206 }
0207
0208 TapHandler
0209 {
0210 onTapped:
0211 {
0212 var mappedPoint = viewfinder.mapPointToSourceNormalized(eventPoint.scenePosition);
0213
0214 var point = Qt.point(eventPoint.scenePosition.x/viewfinder.contentRect.width, mappedPoint.y/viewfinder.contentRect.height)
0215
0216 console.log("TAPPED POINT", point.x, point.y)
0217 camera.focus.customFocusPoint = mappedPoint
0218
0219 if (camera.lockStatus == Camera.Unlocked)
0220 {
0221 camera.searchAndLock();
0222 }
0223 else
0224 {
0225 camera.unlock();
0226 camera.searchAndLock();
0227 }
0228 }
0229
0230 onDoubleTapped:
0231 {
0232 var mappedPoint = viewfinder.mapPointToSourceNormalized(eventPoint.scenePosition);
0233
0234 var point = Qt.point(eventPoint.scenePosition.x/viewfinder.contentRect.width, mappedPoint.y/viewfinder.contentRect.height)
0235
0236 console.log("TAPPED POINT", point.x, point.y)
0237 camera.focus.customFocusPoint = mappedPoint
0238
0239 camera.searchAndLock();
0240 }
0241 }
0242 }
0243
0244 Rectangle
0245 {
0246 color: "#80ff0000"
0247 x: viewfinder.mapRectToItem(scanner.result.boundingRect).x
0248 y: viewfinder.mapRectToItem(scanner.result.boundingRect).y
0249 width: viewfinder.mapRectToItem(scanner.result.boundingRect).width
0250 height: viewfinder.mapRectToItem(scanner.result.boundingRect).height
0251
0252 Maui.Chip
0253 {
0254 z: parent.z + 9999
0255 anchors.top: parent.bottom
0256 anchors.left: parent.left
0257
0258 text: scanner.result.text
0259
0260 onClicked:
0261 {
0262 console.log("Trying to open URL")
0263 Qt.openUrlExternally(scanner.result.text)
0264 }
0265 }
0266 }
0267
0268 }
0269
0270
0271 // PhotoPreview
0272 // {
0273 // id : photoPreview
0274 // anchors.fill : parent
0275 // onClosed: cameraPage.state = "PhotoCapture"
0276 // visible: cameraPage.state == "PhotoPreview"
0277 // focus: visible
0278 // }
0279
0280 // VideoPreview
0281 // {
0282 // id : videoPreview
0283 // anchors.fill : parent
0284 // onClosed: cameraPage.state = "VideoCapture"
0285 // visible: cameraPage.state == "VideoPreview"
0286 // focus: visible
0287
0288 // //don't load recorded video if preview is invisible
0289 // source: visible ? camera.videoRecorder.actualLocation : ""
0290 // }
0291
0292
0293 // PhotoCaptureControls
0294 // {
0295 // id: stillControls
0296 // anchors.fill: parent
0297 // camera: camera
0298 // visible: cameraPage.state == "PhotoCapture"
0299 // onPreviewSelected: cameraPage.state = "PhotoPreview"
0300 // }
0301
0302 // VideoCaptureControls
0303 // {
0304 // id: videoControls
0305 // anchors.fill: parent
0306 // camera: camera
0307 // visible: cameraPage.state == "VideoCapture"
0308 // onPreviewSelected: cameraPage.state = "VideoPreview"
0309 // }
0310
0311 function flipCamera()
0312 {
0313
0314 }
0315
0316 function capture()
0317 {
0318 if(cameraPage.state === "PhotoCapture" && camera.imageCapture.ready)
0319 {
0320 cameraPage.camera.imageCapture.capture()
0321 }
0322
0323 if(cameraPage.state === "VideoCapture" && _cameraPage.camera.videoRecorder.recorderStatus == CameraRecorder.LoadedStatus)
0324 {
0325
0326 cameraPage.camera.videoRecorder.record()
0327 }
0328 }
0329
0330 Component.onCompleted:
0331 {
0332 cameraPage.state = "PhotoCapture"
0333 }
0334 }
0335