-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.qml
More file actions
144 lines (124 loc) · 4.16 KB
/
Main.qml
File metadata and controls
144 lines (124 loc) · 4.16 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import SquaredIoTScanner
ApplicationWindow {
id: root
width: 400
height: 600
visible: true
title: "Barcode Scanner Example"
property string scannedCode: ""
property string scannedFormat: ""
ColumnLayout {
anchors.fill: parent
anchors.margins: 20
spacing: 20
Label {
text: "Qt Barcode & QR Code Scanner"
font.pixelSize: 24
font.bold: true
Layout.alignment: Qt.AlignHCenter
}
Rectangle {
id: resultDisplay
Layout.fillWidth: true
Layout.preferredHeight: 200
color: "#f0f0f0"
radius: 10
border.color: "#cccccc"
border.width: 1
ColumnLayout {
anchors.centerIn: parent
spacing: 10
Label {
text: root.scannedCode ? "Scanned Code:" : "No code scanned yet"
font.pixelSize: 16
Layout.alignment: Qt.AlignHCenter
}
Label {
text: root.scannedCode || ""
font.pixelSize: 14
font.bold: true
color: "#2196F3"
Layout.alignment: Qt.AlignHCenter
wrapMode: Text.Wrap
Layout.maximumWidth: resultDisplay.width - 40
}
Label {
text: root.scannedFormat ? `Format: ${root.scannedFormat}` : ""
font.pixelSize: 12
color: "#666666"
Layout.alignment: Qt.AlignHCenter
visible: root.scannedFormat
}
}
}
Button {
text: AndroidBarcodeScanner.isScanning ? "Scanning..." : "Scan Barcode"
Layout.fillWidth: true
Layout.preferredHeight: 60
enabled: !AndroidBarcodeScanner.isScanning
font.pixelSize: 18
onClicked: AndroidBarcodeScanner.startScan()
}
Label {
text: "Supports: QR Code, EAN, Code 128, and more"
font.pixelSize: 12
color: "#666666"
Layout.alignment: Qt.AlignHCenter
}
Item {
Layout.fillHeight: true
}
Label {
id: statusLabel
text: "Status: " + statusLabel.getStatusText()
font.pixelSize: 12
color: statusLabel.getStatusColor()
Layout.alignment: Qt.AlignHCenter
function getStatusText() {
switch (AndroidBarcodeScanner.state) {
case AndroidBarcodeScanner.ScannerState.Idle:
return "Ready"
case AndroidBarcodeScanner.ScannerState.Scanning:
return "Scanning..."
case AndroidBarcodeScanner.ScannerState.Processing:
return "Processing..."
case AndroidBarcodeScanner.ScannerState.Error:
return "Error"
default:
return "Unknown"
}
}
function getStatusColor() {
switch (AndroidBarcodeScanner.state) {
case AndroidBarcodeScanner.ScannerState.Idle:
return "#4CAF50"
case AndroidBarcodeScanner.ScannerState.Scanning:
return "#2196F3"
case AndroidBarcodeScanner.ScannerState.Error:
return "#F44336"
default:
return "#666666"
}
}
}
}
Connections {
target: AndroidBarcodeScanner
function onScanResult(code, format) {
root.scannedCode = code
root.scannedFormat = format
console.log("Scanned:", code, "Format:", format)
}
function onScanCancelled() {
console.log("Scan cancelled by user")
}
function onScanError(error) {
console.error("Scan error:", error)
root.scannedCode = ""
root.scannedFormat = ""
}
}
}