-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathQt5ScannerPage.qml
116 lines (82 loc) · 2.48 KB
/
Qt5ScannerPage.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Window 2.12
import QtMultimedia 5.12
import com.scythestudio.scodes 1.0
/*!
Barcode scanner main page. All QML elements managing from here.
*/
ApplicationWindow {
id: root
visible: true
width: Qt.platform.os == "android"
|| Qt.platform.os == "ios" ? Screen.width : camera.viewfinder.resolution.width
height: Qt.platform.os == "android"
|| Qt.platform.os == "ios" ? Screen.height : camera.viewfinder.resolution.height
Camera {
id: camera
focus {
focusMode: CameraFocus.FocusContinuous
focusPointMode: CameraFocus.FocusPointAuto
}
}
VideoOutput {
id: videoOutput
anchors.fill: parent
source: camera
autoOrientation: true
fillMode: VideoOutput.PreserveAspectCrop
// add barcodeScanner to videoOutput's filters to enable catching barcodes
filters: [barcodeScanner]
onSourceRectChanged: {
barcodeScanner.captureRect = videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(0.25, 0.25, 0.5, 0.5)))
}
Qt5ScannerOverlay {
id: scannerOverlay
anchors.fill: parent
captureRect: videoOutput.mapRectToItem(barcodeScanner.captureRect)
}
// used to get camera focus on touched point
MouseArea {
id: focusTouchArea
anchors.fill: parent
onClicked: {
camera.focus.customFocusPoint = Qt.point(mouse.x / width,
mouse.y / height)
camera.focus.focusMode = CameraFocus.FocusMacro
camera.focus.focusPointMode = CameraFocus.FocusPointCustom
}
}
}
SBarcodeScanner {
id: barcodeScanner
// you can adjust capture rect (scan area) ne changing these Qt.rect() parameters
captureRect: videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(0.25, 0.25, 0.5, 0.5)))
onCapturedChanged: {
active = false
console.log("captured: " + captured)
}
}
Rectangle {
id: resultScreen
anchors.fill: parent
visible: !barcodeScanner.active
Column {
anchors.centerIn: parent
spacing: 20
Text {
id: scanResultText
anchors.horizontalCenter: parent.horizontalCenter
text: barcodeScanner.captured
}
Button {
id: scanButton
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Scan again")
onClicked: {
barcodeScanner.active = true
}
}
}
}
}