@@ -2,6 +2,7 @@ import QtQuick
22
33import QtMultimedia
44import QZXing
5+ import com.scythestudio.scodes 1.0
56
67Item {
78 id: root
@@ -13,28 +14,27 @@ Item {
1314 readonly property real sourceRatio: videoOutput .sourceRect .width
1415 / videoOutput .sourceRect .height
1516
16- readonly property int failsCount: d .failsCount
17- readonly property int tagsCount: d .tagsCount
18- readonly property int decodeTime: d .decodeTime
1917 readonly property string lastTag: d .lastTag
20- readonly property string currentTag: d .currentTag
2118
2219 readonly property alias contentRect: videoOutput .contentRect
2320
21+ required property int captureRectWidth
22+ required property int captureRectHeight
23+
2424 readonly property var availableCameras: {
2525 return mediaDevices .videoInputs .map (d => ({
2626 deviceId: d .id .toString (),
2727 displayName: d .description
2828 }))
2929 }
3030
31- readonly property bool cameraAvailable: camera .active
32- readonly property string cameraError: camera .errorString
31+ readonly property bool cameraAvailable: barcodeScanner . camera .active
32+ readonly property string cameraError: barcodeScanner . camera .errorString
3333
3434 signal tagFound (string tag)
3535
3636 function setCameraDevice (deviceId : string ) {
37- camera .cameraDevice = mediaDevices .videoInputs .find (
37+ barcodeScanner . camera .cameraDevice = mediaDevices .videoInputs .find (
3838 d => d .id .toString () === deviceId)
3939 }
4040
@@ -45,59 +45,39 @@ Item {
4545 QtObject {
4646 id: d
4747
48- property int failsCount: 0
49- property int tagsCount: 0
50- property int decodeTime: 0
5148 property string lastTag
52- property string currentTag
5349 }
5450
55- Camera {
56- id: camera
5751
58- active : true
59- focusMode : Camera . FocusModeAutoNear
52+ SBarcodeScanner {
53+ id : barcodeScanner
6054
61- Component .onDestruction : camera .active = false
62- }
55+ forwardVideoSink: videoOutput .videoSink
56+ scanning: true
57+
58+ captureRect: contentZoneHighlight
6359
64- CaptureSession {
65- camera: camera
66- videoOutput: videoOutput
60+ onCapturedChanged : (tag ) => {
61+ d .lastTag = tag
62+ root .tagFound (tag)
63+ }
6764 }
6865
6966 VideoOutput {
7067 id: videoOutput
7168
7269 anchors .fill : parent
73- fillMode: VideoOutput .PreserveAspectCrop
74- }
7570
76- QZXingFilter {
77- id: zxingFilter
78- videoSink: videoOutput .videoSink
79- orientation: videoOutput .orientation
80-
81- captureRect: videoOutput .sourceRect
82-
83- decoder {
84- enabledDecoders: QZXing .DecoderFormat_EAN_13 | QZXing .DecoderFormat_CODE_39 | QZXing .DecoderFormat_QR_CODE
85- onTagFound : (tag ) => {
86- d .currentTag = tag
87- d .lastTag = tag
88- root .tagFound (tag)
89- }
90- tryHarder: false
91- }
71+ width: root .width
9272
93- onDecodingFinished : ( succeeded , decodeTime ) => {
94- if (succeeded) {
95- ++ d . tagsCount
96- } else {
97- ++ d . failsCount
98- d . currentTag = " "
99- }
100- d . decodeTime = decodeTime
101- }
73+ focus : visible
74+ fillMode : VideoOutput . PreserveAspectCrop
75+ }
76+ Rectangle {
77+ id : captureRect
78+ width : root . captureRectWidth
79+ height : root . captureRectHeight
80+ anchors . centerIn : parent
81+ visible : false
10282 }
10383}
0 commit comments