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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtMultimedia
import QtQuick.Controls
import QtQuick.Layouts
ColumnLayout {
id: top
required property CaptureSession captureSession
readonly property ImageCaptureHelper imageCapture: captureSession.imageCapture
required property CameraHelper camera
required property MediaDevicesHelper mediaDevices
CheckBox {
text: "Camera attached to capture session"
checked: top.captureSession.camera
onClicked: () => {
if (top.captureSession.camera)
top.captureSession.camera = null;
else
top.captureSession.camera = top.camera;
}
}
CameraDeviceSelector {
camera: top.camera
mediaDevices: top.mediaDevices
}
RowLayout {
Label {
text: "Format"
}
Label {
text: "unavailable"
color: "red"
function checkFormatIsAvailable(videoInputs, cameraDevice, format): bool {
// First check if the device is available in QMediaDevices
let foundDevice = videoInputs.find((item) => String(item.id) === String(cameraDevice.id))
if (foundDevice === undefined)
return false
let foundFormat = foundDevice.videoFormats.find((item) =>
top.camera.cameraFormatToString(item) === top.camera.cameraFormatToString(format))
return foundFormat !== undefined
}
function calcOpacity(videoInputs, cameraDevice, format) {
let formatIsAvailable = checkFormatIsAvailable(videoInputs, cameraDevice, format)
if (formatIsAvailable)
return 0.1
else
return 1
}
opacity: calcOpacity(mediaDevices.videoInputs, top.camera.cameraDevice, top.camera.cameraFormat)
}
ComboBox {
implicitContentWidthPolicy: ComboBox.WidestText
model:
top.camera.cameraDevice.videoFormats
.slice()
.sort((a, b) => top.camera.customCameraFormatSortDelegate(a, b))
.map((item) => { return { value: item, text: top.camera.cameraFormatToString(item) } })
textRole: "text"
displayText: top.camera.cameraFormatToString(top.camera.cameraFormat)
currentIndex: model.findIndex(
(item) => item.text === top.camera.cameraFormatToString(top.camera.cameraFormat))
onActivated: index => {
top.camera.cameraFormat = model[index].value
}
}
Button {
text: "Default"
onClicked: top.camera.cameraFormat = undefined
}
}
CheckBox {
text: "Active"
checked: top.camera.active
onToggled: () => {
top.camera.active = checked
checked = Qt.binding(() => top.camera.active)
}
}
ColumnLayout {
enabled: top.camera.minimumZoomFactor < top.camera.maximumZoomFactor
RowLayout {
Label {
text: "Zoom: " + top.camera.zoomFactor.toFixed(1)
font.bold: true
}
Label { text: "min: " + top.camera.minimumZoomFactor.toFixed(1) + " max: " + top.camera.maximumZoomFactor.toFixed(1) }
}
Slider {
Layout.fillWidth: true
from: top.camera.minimumZoomFactor
to: Math.min(top.camera.maximumZoomFactor, 10)
value: top.camera.zoomFactor
onMoved: top.camera.zoomFactor = value
}
Button {
text: "Ramp zoom slowly to max"
onClicked: top.camera.zoomTo(Math.min(top.camera.maximumZoomFactor,
4), 0.1)
}
}
RowLayout {
enabled: top.camera.supportedFocusModes.length > 1
Label {
text: "Focus mode"
font.bold: true
}
ComboBox {
model: top.camera.supportedFocusModes
.map(item => {
return {
"value": item,
"text": top.camera.focusModeToString(item)
}
})
valueRole: "value"
textRole: "text"
displayText: top.camera.focusModeToString(top.camera.focusMode)
currentIndex: model.findIndex(
item => item.value === top.camera.focusMode)
onActivated: index => {
if (top.camera.isFocusModeSupported(currentValue))
top.camera.focusMode = currentValue
else
console.log("Selected unsupported focus mode")
}
}
} // Focus mode
RowLayout {
// Flash mode
enabled: top.camera.supportedFlashModes.length > 1
Label {
text: "Flash mode"
font.bold: true
}
ComboBox {
Layout.alignment: Qt.AlignRight
model: top.camera.supportedFlashModes
.map(item => {
return {
"value": item,
"text": top.camera.flashModeToString(item) } })
textRole: "text"
valueRole: "value"
currentIndex: model.findIndex(item => item.value === top.camera.flashMode)
onActivated: index => {
if (top.camera.isFlashModeSupported(currentValue))
top.camera.flashMode = currentValue
else
console.log("Selected unsupported flash mode")
}
}
} // Flash mode
RowLayout {
enabled: top.camera.supportedTorchModes.length > 1
Label {
text: "Torch mode"
font.bold: true
}
ComboBox {
Layout.alignment: Qt.AlignRight
model:
top.camera.supportedTorchModes
.map(item => { return { "value": item, "text": top.camera.torchModeToString(item) } })
textRole: "text"
valueRole: "value"
onActivated: index => {
if (top.camera.isTorchModeSupported(currentValue))
top.camera.torchMode = currentValue
else
console.log("Selected unsupported torch mode")
}
}
}
ColumnLayout {
enabled: top.camera.supportedFocusModes.includes(Camera.FocusModeManual)
&& top.camera.supportedFeatures & Camera.FocusDistance
Label {
text: "focusDistance " + top.camera.focusDistance.toFixed(1)
}
Slider {
Layout.fillWidth: true
from: 0
to: 1
value: top.camera.focusDistance
onMoved: top.camera.focusDistance = value
}
}
RowLayout {
Label {
text: "Image file format"
}
ComboBox {
implicitContentWidthPolicy: ComboBox.WidestText
model: imageCapture.supportedFormats
.map((item) => { return { displayText: imageCapture.fileFormatToString(item), value: item } })
valueRole: "value"
textRole: "displayText"
currentIndex: model.findIndex(
item => item.value === imageCapture.fileFormat)
displayText: imageCapture.fileFormatToString(imageCapture.fileFormat)
onActivated: index => {
imageCapture.fileFormat = currentValue
currentIndex = model.findIndex(
item => item.value === imageCapture.fileFormat)
}
}
Button {
text: "Default"
onClicked: imageCapture.fileFormat = undefined
}
}
RowLayout {
Label {
text: "Error: "
+ top.camera.errorEnumToString(top.camera.error)
+ " ("
+ top.camera.error
+ ")"
}
}
RowLayout {
Label {
text: "Error string: '" + top.camera.errorString + "'"
}
}
}
|