Changeset View
Changeset View
Standalone View
Standalone View
src/contents/ui/CameraPage.qml
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 74 | else | |||
---|---|---|---|---|---|
75 | camera.captureMode = Camera.CaptureStillImage | 75 | camera.captureMode = Camera.CaptureStillImage | ||
76 | 76 | | |||
77 | console.log("Capture Mode switched") | 77 | console.log("Capture Mode switched") | ||
78 | } | 78 | } | ||
79 | } | 79 | } | ||
80 | mainAction: Kirigami.Action { | 80 | mainAction: Kirigami.Action { | ||
81 | id: captureAction | 81 | id: captureAction | ||
82 | text: { | 82 | text: { | ||
83 | if (camera.captureMode === Camera.CaptureStillImage) | 83 | if (selfTimer.running) | ||
84 | return i18n("Cancel self-timer") | ||||
85 | else if (camera.captureMode === Camera.CaptureStillImage) | ||||
84 | return i18n("Capture photo") | 86 | return i18n("Capture photo") | ||
85 | else if (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus) | 87 | else if (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus) | ||
86 | return i18n("Stop recording video") | 88 | return i18n("Stop recording video") | ||
87 | else if (camera.captureMode === Camera.CaptureVideo) | 89 | else if (camera.captureMode === Camera.CaptureVideo) | ||
88 | return i18n("Start recording video") | 90 | return i18n("Start recording video") | ||
89 | } | 91 | } | ||
90 | icon.color: "transparent" | 92 | icon.color: "transparent" | ||
91 | icon.name: { | 93 | icon.name: { | ||
92 | if (camera.captureMode === Camera.CaptureStillImage) | 94 | if (selfTimer.running) | ||
95 | return "dialog-error-symbolic" | ||||
96 | else if (camera.captureMode === Camera.CaptureStillImage) | ||||
93 | return "camera-photo-symbolic" | 97 | return "camera-photo-symbolic" | ||
94 | else if (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus) | 98 | else if (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus) | ||
95 | return "window-close-symbolic" | 99 | return "window-close-symbolic" | ||
96 | else if (camera.captureMode === Camera.CaptureVideo) | 100 | else if (camera.captureMode === Camera.CaptureVideo) | ||
97 | return "emblem-videos-symbolic" | 101 | return "emblem-videos-symbolic" | ||
98 | } | 102 | } | ||
99 | onTriggered: { | 103 | onTriggered: { | ||
100 | if (camera.captureMode === Camera.CaptureStillImage) { | 104 | if (selfTimer.running) { | ||
101 | camera.imageCapture.capture() | 105 | selfTimer.stop() | ||
102 | showPassiveNotification(i18n("Took a photo")) | | |||
103 | } | 106 | } | ||
104 | else if (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus) { | 107 | else if ((camera.selfTimerDuration === 0) || (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus)) { | ||
105 | camera.videoRecorder.stop() | 108 | selfTimer.onTriggered() | ||
106 | recordingFeedback.visible = false | | |||
107 | showPassiveNotification(i18n("Stopped recording")) | | |||
108 | } | 109 | } | ||
109 | else if (camera.captureMode === Camera.CaptureVideo) { | 110 | else { | ||
110 | camera.videoRecorder.record() | 111 | countdownTimer.remainingSeconds = camera.selfTimerDuration | ||
111 | recordingFeedback.visible = true | 112 | countdownTimer.start() | ||
112 | showPassiveNotification(i18n("Started recording")) | 113 | selfTimer.start() | ||
113 | } | 114 | } | ||
114 | } | 115 | } | ||
115 | enabled: { | 116 | enabled: { | ||
116 | if (camera.captureMode === camera.CaptureStillImage) | 117 | if ((camera.captureMode === camera.CaptureStillImage) && !selfTimer.running) | ||
117 | return camera.imageCapture.ready | 118 | return camera.imageCapture.ready | ||
118 | else | 119 | else | ||
119 | return true | 120 | return true | ||
120 | } | 121 | } | ||
121 | } | 122 | } | ||
122 | rightAction: Kirigami.Action { | 123 | rightAction: Kirigami.Action { | ||
123 | id: switchCameaAction | 124 | id: switchCameaAction | ||
124 | text: i18n("Switch Camera") | 125 | text: i18n("Switch Camera") | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 234 | Rectangle { | |||
247 | 248 | | |||
248 | anchors { | 249 | anchors { | ||
249 | left: parent.left | 250 | left: parent.left | ||
250 | top: parent.top | 251 | top: parent.top | ||
251 | margins: Kirigami.Units.gridUnit * 2 | 252 | margins: Kirigami.Units.gridUnit * 2 | ||
252 | } | 253 | } | ||
253 | } | 254 | } | ||
254 | 255 | | |||
256 | Timer { | ||||
257 | id: selfTimer | ||||
258 | interval: camera.selfTimerDuration * 1000 | ||||
259 | running: false | ||||
260 | repeat: false | ||||
261 | | ||||
262 | onTriggered: { | ||||
263 | running = false | ||||
264 | | ||||
265 | if (camera.captureMode === Camera.CaptureStillImage) { | ||||
266 | camera.imageCapture.capture() | ||||
267 | showPassiveNotification(i18n("Took a photo")) | ||||
268 | } | ||||
269 | else if (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus) { | ||||
270 | camera.videoRecorder.stop() | ||||
271 | recordingFeedback.visible = false | ||||
272 | showPassiveNotification(i18n("Stopped recording")) | ||||
273 | } | ||||
274 | else if (camera.captureMode === Camera.CaptureVideo) { | ||||
275 | camera.videoRecorder.record() | ||||
276 | recordingFeedback.visible = true | ||||
277 | showPassiveNotification(i18n("Started recording")) | ||||
278 | } | ||||
279 | } | ||||
280 | | ||||
281 | onRunningChanged: { | ||||
282 | if (!running) { | ||||
283 | camera.selfTimerRunning = false | ||||
284 | selfTimerAnimation.stop() | ||||
285 | countdownTimer.stop() | ||||
286 | countdownTimer.remainingSeconds = camera.selfTimerDuration | ||||
287 | selfTimerIcon.opacity = 1 | ||||
288 | } | ||||
289 | else { | ||||
290 | camera.selfTimerRunning = true | ||||
291 | } | ||||
292 | } | ||||
293 | } | ||||
294 | | ||||
295 | Timer { // counts the remaining seconds until the selfTimer invokes the capture action | ||||
296 | id: countdownTimer | ||||
297 | interval: 1000 | ||||
298 | running: false | ||||
299 | repeat: true | ||||
300 | property int remainingSeconds: 0 | ||||
301 | | ||||
302 | onTriggered: { | ||||
303 | remainingSeconds-- | ||||
304 | } | ||||
305 | } | ||||
306 | | ||||
307 | RowLayout { | ||||
308 | id: selfTimerInfo | ||||
309 | visible: !(camera.selfTimerDuration === 0) && !((camera.captureMode === Camera.CaptureVideo) && (camera.videoRecorder.recorderStatus === CameraRecorder.RecordingStatus)) | ||||
310 | | ||||
311 | anchors { | ||||
312 | top: parent.top | ||||
313 | horizontalCenter: parent.horizontalCenter | ||||
314 | margins: Kirigami.Units.gridUnit * 1 | ||||
315 | } | ||||
316 | | ||||
317 | Kirigami.Icon { | ||||
318 | id: selfTimerIcon | ||||
319 | source: "alarm-symbolic" | ||||
320 | color: selfTimer.running ? "red" : "white" | ||||
jbbgameich: This could be written shorter
```
selfTimer.running ? "red" : "white"
``` | |||||
321 | Layout.preferredWidth: Kirigami.Units.gridUnit | ||||
322 | Layout.preferredHeight: Kirigami.Units.gridUnit | ||||
323 | Layout.fillWidth: true | ||||
324 | Layout.fillHeight: true | ||||
325 | Layout.alignment: Qt.AlignCenter | ||||
326 | } | ||||
327 | | ||||
328 | Text { | ||||
329 | text: { | ||||
330 | if (selfTimer.running) { | ||||
331 | "%1 s".arg(countdownTimer.remainingSeconds) | ||||
332 | } | ||||
333 | else { | ||||
334 | "%1 s".arg(camera.selfTimerDuration) | ||||
335 | } | ||||
336 | } | ||||
337 | font.pixelSize: Kirigami.Units.gridUnit | ||||
338 | color: { | ||||
339 | if (selfTimer.running) { | ||||
340 | "red" | ||||
341 | } | ||||
342 | else { | ||||
343 | "white" | ||||
344 | } | ||||
345 | } | ||||
346 | } | ||||
347 | | ||||
348 | layer.enabled: selfTimerInfo.enabled | ||||
349 | layer.effect: DropShadow { | ||||
350 | color: Material.dropShadowColor | ||||
351 | samples: 30 | ||||
352 | spread: 0.5 | ||||
353 | } | ||||
354 | } | ||||
355 | | ||||
356 | Rectangle { | ||||
357 | id: selfTimerRectangle | ||||
358 | visible: selfTimer.running | ||||
359 | color: "transparent" | ||||
360 | border.color: "red" | ||||
361 | border.width: Kirigami.Units.gridUnit / 6 | ||||
362 | opacity: 0 | ||||
363 | | ||||
364 | anchors { | ||||
365 | fill: parent | ||||
366 | centerIn: parent | ||||
367 | } | ||||
368 | } | ||||
369 | | ||||
370 | SequentialAnimation { | ||||
371 | id: selfTimerAnimation | ||||
372 | running: selfTimer.running | ||||
373 | loops: Animation.Infinite | ||||
374 | | ||||
375 | ParallelAnimation { | ||||
376 | OpacityAnimator { | ||||
377 | target: selfTimerIcon | ||||
378 | from: 0 | ||||
379 | to: 1 | ||||
380 | duration: 500 | ||||
381 | } | ||||
382 | OpacityAnimator { | ||||
383 | target: selfTimerRectangle | ||||
384 | from: 0 | ||||
385 | to: 1 | ||||
386 | duration: 500 | ||||
387 | } | ||||
388 | } | ||||
389 | | ||||
390 | ParallelAnimation{ | ||||
391 | OpacityAnimator { | ||||
392 | target: selfTimerIcon | ||||
393 | from: 1 | ||||
394 | to: 0 | ||||
395 | duration: 500 | ||||
396 | } | ||||
397 | OpacityAnimator { | ||||
398 | target: selfTimerRectangle | ||||
399 | from: 1 | ||||
400 | to: 0 | ||||
401 | duration: 500 | ||||
402 | } | ||||
403 | } | ||||
404 | } | ||||
405 | | ||||
255 | PreviewArea { | 406 | PreviewArea { | ||
256 | imageCapture: camera.imageCapture | 407 | imageCapture: camera.imageCapture | ||
257 | 408 | | |||
258 | anchors { | 409 | anchors { | ||
259 | right: parent.right | 410 | right: parent.right | ||
260 | bottom: parent.bottom | 411 | bottom: parent.bottom | ||
261 | margins: Kirigami.Units.gridUnit | 412 | margins: Kirigami.Units.gridUnit | ||
262 | } | 413 | } | ||
263 | } | 414 | } | ||
264 | } | 415 | } |
This could be written shorter