Debian Codegraph @

qml/Viewfinder/ViewFinderOverlay.qml

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.12
18 import QtQuick.Window 2.2
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21 import QtMultimedia 5.9
22 import QtPositioning 5.2
23 import QtSensors 5.0
24 import CameraApp 0.1
25 import Qt.labs.settings 1.0
26 import QtGraphicalEffects 1.0
27
28 import "../components"
29
30 Item {
31 id: viewFinderOverlay
32
33 property Camera camera
34 property bool touchAcquired: bottomEdge.pressed || zoomPinchArea.active
35 property real revealProgress: noSpaceHint.visible ? 1.0 : bottomEdge.progress
36 property var controls: controls
37 property var settings: settings
38 property bool readyForCapture
39 property int sensorOrientation
40 // Sometimes the value is FlashVideoLight, sometimes it's FlashTorch
41 property int videoFlashOnValue: Camera.FlashVideoLight
42
43 // Screen's aspect ratio in both major orientations
44 readonly property string screenAspectRatio: sizeToAspectRatio(Qt.size(Screen.width, Screen.height))
45 readonly property string screenAspectRatio2: sizeToAspectRatio(Qt.size(Screen.height, Screen.width))
46
47 function showFocusRing(x, y) {
48 focusRing.center = Qt.point(x, y);
49 focusRing.show();
50 }
51
52 Settings {
53 id: settings
54
55 property int flashMode: Camera.FlashAuto
56 property bool gpsEnabled: false
57 property bool hasEXIF: false // Should it even be enabled by default?
58 property bool hdrEnabled: false
59 property bool videoFlashOn: false
60 property int videoQuality: 0 // 0 - Normal, 1 - High
61 // Left for compatibility
62 property int videoFlashMode: -1
63 property int selfTimerDelay: 0
64 property int encodingQuality: 2 // QMultimedia.NormalQuality
65 property bool gridEnabled: false
66 property bool preferRemovableStorage: false
67 property bool playShutterSound: true
68 property bool shutterVibration: false
69 property var photoResolutions
70 property var videoResolutions
71 // Left for compatibility
72 property string videoResolution: ""
73 property bool dateStampImages: false
74 property string dateStampFormat: Qt.locale().dateFormat(Locale.ShortFormat)
75 property color dateStampColor: LomiriColors.orange;
76 property real dateStampOpacity: 1.0;
77 property int dateStampAlign : Qt.AlignBottom | Qt.AlignRight;
78
79 Component.onCompleted: {
80 if (!photoResolutions) photoResolutions = {}
81
82 if (!videoResolutions) {
83 videoResolutions = {}
84 if (videoResolution)
85 // Migrate old value into default camera
86 setVideoResolution(videoResolution);
87 }
88
89 if (videoFlashMode != -1) {
90 videoFlashOn = (videoFlashMode != Camera.FlashOff);
91 videoFlashMode = -1;
92 }
93 }
94
95 onPhotoResolutionsChanged: updateViewfinderResolution();
96 onVideoResolutionsChanged: updateViewfinderResolution();
97
98 onGpsEnabledChanged: if(gpsEnabled&&!hasEXIF)hasEXIF = true;
99 onHasEXIFChanged: if(gpsEnabled&&!hasEXIF)gpsEnabled = false;
100 onFlashModeChanged: if (flashMode != Camera.FlashOff) hdrEnabled = false;
101 onHdrEnabledChanged: if (hdrEnabled) flashMode = Camera.FlashOff
102 }
103
104 Binding {
105 target: camera.flash
106 property: "mode"
107 value: settings.flashMode
108 when: camera.captureMode == Camera.CaptureStillImage
109 }
110
111 Binding {
112 target: camera.flash
113 property: "mode"
114 value: settings.videoFlashOn && viewFinderView.inView ? videoFlashOnValue : Camera.FlashOff
115 when: camera.captureMode == Camera.CaptureVideo
116 }
117
118 Binding {
119 target: camera.advanced
120 property: "hasEXIF"
121 value: settings.hasEXIF
122 }
123
124 Binding {
125 target: camera.advanced
126 property: "hdrEnabled"
127 value: settings.hdrEnabled
128 }
129
130 Binding {
131 target: camera.advanced
132 property: "encodingQuality"
133 value: settings.encodingQuality
134 // This makes sure that the correct image quality is initiated
135 when: camera.cameraStatus == Camera.ActiveStatus
136 }
137
138 Binding {
139 target: camera.videoRecorder
140 property: "videoBitRate"
141 value: getVideoBitrate()
142 // This makes sure that the correct video bitrate is initiated
143 when: camera.cameraStatus == Camera.ActiveStatus
144 }
145
146 Binding {
147 target: camera.videoRecorder
148 property: "resolution"
149 value: settings.videoResolutions[camera.deviceId] || Qt.size(-1, -1)
150 // This makes sure that the correct video resolution is initiated
151 when: camera.cameraStatus == Camera.LoadedStatus || camera.cameraStatus == Camera.ActiveStatus
152 }
153
154 Binding {
155 target: camera.imageCapture
156 property: "resolution"
157 value: settings.photoResolutions[camera.deviceId] || Qt.size(-1, -1)
158 }
159
160 // FIXME: where's the proper location for this?
161 function updateViewfinderResolution() {
162 var EPSILON = 0.02;
163 var supportedViewfinderResolutions = camera.supportedViewfinderResolutions();
164
165 if (supportedViewfinderResolutions.length === 0) {
166 console.log("updateViewfinderResolution: viewfinder resolutions is not known yet.");
167 return;
168 }
169
170 var targetResolution = stringToSize(
171 camera.captureMode === Camera.CaptureStillImage
172 ? settings.photoResolutions[camera.deviceId]
173 : settings.videoResolutions[camera.deviceId]
174 );
175
176 if (!targetResolution) {
177 // Resolution has not been selected yet.
178 return;
179 }
180
181 var targetAspectRatio = targetResolution.width / targetResolution.height;
182 var selectedResolution;
183
184 // Select the highest resolution with matching aspect ratio.
185 for (var i = 0; i < supportedViewfinderResolutions.length; i++) {
186 var currentResolution = supportedViewfinderResolutions[i];
187 var currentAspectRatio = currentResolution.width / currentResolution.height;
188
189 if (Math.abs(targetAspectRatio - currentAspectRatio) > EPSILON)
190 continue;
191
192 if (!selectedResolution ||
193 currentResolution.width > selectedResolution.width) {
194 selectedResolution = currentResolution;
195 }
196 }
197
198 if (!selectedResolution) {
199 // This is strange. Not sure why this would happen.
200 console.log("updateViewfinderResolution: cannot find suitable viewfinder resolution. Use the default one.");
201 selectedResolution = supportedViewfinderResolutions[0];
202 }
203
204 console.log("updateViewfinderResolution: For target resolution " +
205 sizeToString(targetResolution) + ", select " +
206 sizeToString(selectedResolution) + " for viewfinder resolution.");
207
208 camera.viewfinder.resolution =
209 Qt.size(selectedResolution.width, selectedResolution.height);
210 }
211
212 function updateVideoFlashOnValue() {
213 if (camera.captureMode != Camera.CaptureVideo) {
214 // The value can be probed only in video mode.
215 return;
216 }
217
218 var supportedModes = camera.flash.supportedModes;
219 for (var i = 0; i < supportedModes.length; i++) {
220 if (supportedModes[i] === Camera.FlashVideoLight ||
221 supportedModes[i] === Camera.FlashTorch) {
222 videoFlashOnValue = supportedModes[i];
223 return;
224 }
225 }
226 }
227
228 Connections {
229 target: camera.imageCapture
230 onImageCaptured: {
231 if(settings.shutterVibration) {
232 Haptics.play({intensity:0.25,duration:LomiriAnimation.SnapDuration/3});
233 }
234 }
235 }
236
237 Connections {
238 target: camera.flash
239 onSupportedModesChanged: { updateVideoFlashOnValue(); }
240 }
241
242 Connections {
243 target: camera
244 onCaptureModeChanged: {
245 updateViewfinderResolution();
246 }
247
248 onCameraStatusChanged: {
249 // Supported viewfinder resolution is guaranteed to be known at
250 // ActiveStatus, if not earlier.
251 if (camera.cameraStatus == Camera.LoadedStatus
252 || camera.cameraStatus == Camera.ActiveStatus) {
253 updateViewfinderResolution();
254 }
255 }
256 }
257
258 function triggerShoot() {
259 if (shootButton.enabled) {
260 if (camera.captureMode == Camera.CaptureVideo && camera.videoRecorder.recorderState == CameraRecorder.RecordingState) {
261 camera.videoRecorder.stop();
262 } else {
263 if (settings.selfTimerDelay > 0) {
264 controls.timedShoot(settings.selfTimerDelay);
265 } else {
266 controls.shoot();
267 }
268 }
269 }
270 }
271
272 function resolutionToLabel(resolution, full=true) {
273 // takes in a resolution string (e.g. "1920x1080") and returns a nicer
274 // form of it for display in the UI: "1080p"
275 const label = resolution.split("x").pop() + "p";
276
277 if (full) {
278 // Include the aspect ratio in full format
279 const aspectRatio = sizeToAspectRatio(stringToSize(resolution));
280 let finalAspectRatio = aspectRatio
281
282 // Label those that are equal to screen's aspect ratio as "Full"
283 // except 16:9 since it's common
284 if ((aspectRatio === viewFinderOverlay.screenAspectRatio
285 || aspectRatio === viewFinderOverlay.screenAspectRatio2
286 )
287 && aspectRatio !== "16:9") {
288 finalAspectRatio = i18n.tr("Full")
289 }
290
291 return "%1 (%2)".arg(label).arg(finalAspectRatio);
292 }
293
294 return "%1".arg(label);
295 }
296
297 function sizeToString(size) {
298 return size.width + "x" + size.height;
299 }
300
301 function stringToSize(resolution) {
302 var r = resolution ? resolution.split("x") : null;
303 return Qt.size(r[0], r[1]);
304 }
305
306 function sizeToAspectRatio(size) {
307 var ratio = Math.max(size.width, size.height) / Math.min(size.width, size.height);
308 var maxDenominator = 12;
309 var epsilon;
310 var numerator;
311 var denominator;
312 var bestDenominator;
313 var bestEpsilon = 10000;
314 for (denominator = 2; denominator <= maxDenominator; denominator++) {
315 numerator = ratio * denominator;
316 epsilon = Math.abs(Math.round(numerator) - numerator);
317 if (epsilon < bestEpsilon) {
318 bestEpsilon = epsilon;
319 bestDenominator = denominator;
320 }
321 }
322 numerator = Math.round(ratio * bestDenominator);
323
324 // Further simplify square aspect ratio to 1:1
325 if (numerator === bestDenominator) {
326 numerator = 1;
327 bestDenominator = 1;
328 }
329
330 return "%1:%2".arg(numerator).arg(bestDenominator);
331 }
332
333 function sizeToMegapixels(size) {
334 var megapixels = (size.width * size.height) / 1000000;
335 return parseFloat(megapixels.toFixed(1))
336 }
337
338 function trimNumberToFit(numberStr, digits) {
339 return (""+numberStr).substr(0,digits).replace(/\.$/,"");
340 }
341
342 function updateVideoResolutionOptions() {
343 // Clear and refill videoResolutionOptionsModel with available resolutions
344 // Try to only display well known resolutions: 2160p, 1440p, 1080p, 720p and 480p
345 videoResolutionOptionsModel.clear();
346 var supported = camera.advanced.videoSupportedResolutions;
347 var wellKnown = ["2160", "1440", "1080", "720", "480"];
348
349 var supportedFiltered = supported.filter(function (resolution) {
350 return wellKnown.findIndex(
351 value => {
352 const _pattern = "x" + value + "$"
353 const _regex = new RegExp(_pattern, "g")
354 return resolution.match(_regex)
355 }
356 ) !== -1;
357 });
358
359 if (supportedFiltered.length === 0)
360 supportedFiltered = supported.slice();
361
362 // Sort resolutions from low to high, but then insert them into model
363 // in reverse order (so that highest resolution appear first).
364 supportedFiltered.sort(function(a, b) {
365 return a.split("x")[1] - b.split("x")[1];
366 });
367
368 for (var i=0; i<supportedFiltered.length; i++) {
369 var resolution = supportedFiltered[i];
370 var option = {"icon": "",
371 "label": resolutionToLabel(resolution),
372 "value": resolution};
373 videoResolutionOptionsModel.insert(0, option);
374 }
375
376 // If resolution setting chosen is not supported select the highest available resolution
377 if (supportedFiltered.length > 0
378 && supportedFiltered.indexOf(settings.videoResolutions[camera.deviceId]) === -1) {
379 setVideoResolution(supportedFiltered[supportedFiltered.length - 1]);
380 }
381 }
382
383 function updatePhotoResolutionOptions() {
384 // Clear and refill photoResolutionOptionsModel with available resolutions
385 photoResolutionOptionsModel.clear();
386
387
388 //Change to Size object and sort the resolutions by megapixel ( in reverse order so it goes from top high to bottom low )
389 var sortedResolutions = [];
390 for(var i in camera.advanced.imageSupportedResolutions) {
391 sortedResolutions.push( stringToSize(camera.advanced.imageSupportedResolutions[i]) );
392 }
393 sortedResolutions.sort(function(a, b) { return sizeToMegapixels(b) - sizeToMegapixels(a) });
394
395 for(var i in sortedResolutions) {
396 var res = sortedResolutions[i];
397 photoResolutionOptionsModel.insert(i,{"icon": "",
398 "label": "%1 (%2MP)".arg(sizeToAspectRatio(res))
399 .arg(sizeToMegapixels(res)),
400 "value": sizeToString(res)});
401 }
402
403 // If resolution setting is not supported select the resolution automatically
404 var photoResolution = settings.photoResolutions[camera.deviceId];
405 if (!isPhotoResolutionAnOption(photoResolution)) {
406 setPhotoResolution(getAutomaticPhotoResolution());
407 }
408
409 }
410
411 // Get the appropriate video bitrate based on the current quality setting
412 function getVideoBitrate() {
413 const quality = settings.videoQuality
414 const resoSize = camera.videoRecorder.resolution
415
416 if (quality === 1) { // High Quality
417 switch(true) {
418 case resoSize.height >= 2160:
419 return 48000000 // 48 Mbps
420 case resoSize.height >= 1440:
421 return 35000000 // 35 Mbps
422 case resoSize.height >= 1080:
423 return 17000000 // 17 Mbps
424 case resoSize.height >= 720:
425 return 10000000 // 10 Mbps
426 case resoSize.height >= 480:
427 return 6000000 // 6 Mbps
428 default:
429 return 5000000 // 5 Mbps
430 }
431 } else {
432 switch(true) {
433 case resoSize.height >= 2160:
434 return 35000000 // 35 Mbps
435 case resoSize.height >= 1440:
436 return 16000000 // 16 Mbps
437 case resoSize.height >= 1080:
438 return 8000000 // 8 Mbps
439 case resoSize.height >= 720:
440 return 5000000 // 5 Mbps
441 case resoSize.height >= 480:
442 return 2500000 // 2.5 Mbps
443 default:
444 return 2000000 // 2 Mbps
445 }
446 }
447 }
448
449 function setPhotoResolution(resolution) {
450 var size = stringToSize(resolution);
451 if (size.width > 0 && size.height > 0
452 && resolution != settings.photoResolutions[camera.deviceId]) {
453 settings.photoResolutions[camera.deviceId] = resolution;
454 // FIXME: resetting the value of the property 'photoResolutions' is
455 // necessary to ensure that a change notification signal is emitted
456 settings.photoResolutions = settings.photoResolutions;
457 }
458 }
459
460 function setVideoResolution(resolution) {
461 if (resolution !== settings.videoResolutions[camera.deviceId]) {
462 settings.videoResolutions[camera.deviceId] = resolution;
463 // FIXME: resetting the value of the property 'videoResolutions' is
464 // necessary to ensure that a change notification signal is emitted
465 settings.videoResolutions = settings.videoResolutions;
466 }
467 }
468
469 function getAutomaticPhotoResolution() {
470 var fittingResolution = sizeToString(camera.advanced.fittingResolution);
471 var maximumResolution = sizeToString(camera.advanced.maximumResolution);
472 if (isPhotoResolutionAnOption(fittingResolution)) {
473 return fittingResolution;
474 } else {
475 return maximumResolution;
476 }
477 }
478
479 function isPhotoResolutionAnOption(resolution) {
480 for (var i=0; i<photoResolutionOptionsModel.count; i++) {
481 var option = photoResolutionOptionsModel.get(i);
482 if (option.value == resolution) {
483 return true;
484 }
485 }
486 return false;
487 }
488
489 Connections {
490 target: camera.advanced
491 onVideoSupportedResolutionsChanged: updateVideoResolutionOptions();
492 onImageSupportedResolutionsChanged: updatePhotoResolutionOptions();
493 onFittingResolutionChanged: updatePhotoResolutionOptions();
494 onMaximumResolutionChanged: updatePhotoResolutionOptions();
495 }
496
497 Connections {
498 target: camera
499 onDeviceIdChanged: {
500 // Clear viewfinder resolution settings as it might not be supported
501 // by the new device.
502 camera.viewfinder.resolution = Qt.size(-1, -1);
503 }
504 }
505
506 function optionsOverlayClose() {
507 print("optionsOverlayClose")
508 if (optionsOverlayLoader.item.valueSelectorOpened) {
509 optionsOverlayLoader.item.closeValueSelector();
510 } else {
511 bottomEdge.close();
512 }
513 }
514
515 MouseArea {
516 id: bottomEdgeClose
517 anchors.fill: parent
518 onClicked: optionsOverlayClose()
519 enabled: !camera.timedCaptureInProgress
520 }
521
522 OrientationHelper {
523 id: bottomEdgeOrientation
524 transitionEnabled: bottomEdge.opened
525
526 Panel {
527 id: bottomEdge
528 anchors {
529 right: parent.right
530 left: parent.left
531 bottom: parent.bottom
532 }
533 height: optionsOverlayLoader.height
534 onOpenedChanged: optionsOverlayLoader.item.closeValueSelector()
535 enabled: camera.videoRecorder.recorderState == CameraRecorder.StoppedState
536 && !camera.photoCaptureInProgress && !camera.timedCaptureInProgress
537 opacity: enabled ? 1.0 : 0.3
538 property bool ready: optionsOverlayLoader.status == Loader.Ready
539
540 /* At startup, opened is false and 'bottomEdge.height' is 0 until
541 optionsOverlayLoader has finished loading. When that happens
542 'bottomEdge.height' becomes non 0 and 'bottomEdge.position' which
543 depends on bottomEdge.height eventually reaches the value
544 'bottomEdge.height'. Unfortunately during that short period 'progress'
545 has an incorrect value and unfortunate consequences/bugs occur.
546 That makes it important to only compute progress when 'opened' is true.
547
548 Ref.: https://bugs.launchpad.net/ubuntu/+source/camera-app/+bug/1472903
549 */
550 property real progress: bottomEdge.height ? (bottomEdge.height - bottomEdge.position) / bottomEdge.height : 0
551 property list<ListModel> options: [
552 ListModel {
553 id: gpsOptionsModel
554
555 property string settingsProperty: "gpsEnabled"
556 property string icon: "location"
557 property string label: ""
558 property bool isToggle: true
559 property int selectedIndex: bottomEdge.indexForValue(gpsOptionsModel, settings.gpsEnabled)
560 property bool available: true
561 property bool visible: true
562 property bool showInIndicators: true
563 property bool colorize: !positionSource.isPrecise
564
565 ListElement {
566 icon: ""
567 label: QT_TR_NOOP("On")
568 value: true
569 }
570 ListElement {
571 icon: ""
572 label: QT_TR_NOOP("Off")
573 value: false
574 }
575 },
576 ListModel {
577 id: flashOptionsModel
578
579 property string settingsProperty: "flashMode"
580 property string icon: ""
581 property string label: ""
582 property bool isToggle: false
583 property int selectedIndex: bottomEdge.indexForValue(flashOptionsModel, settings.flashMode)
584 property bool available: camera.advanced.hasFlash
585 property bool visible: camera.captureMode == Camera.CaptureStillImage
586 property bool showInIndicators: true
587
588 ListElement {
589 icon: "flash-on"
590 label: QT_TR_NOOP("On")
591 value: Camera.FlashOn
592 }
593 ListElement {
594 icon: "flash-auto"
595 label: QT_TR_NOOP("Auto")
596 value: Camera.FlashAuto
597 }
598 ListElement {
599 icon: "flash-off"
600 label: QT_TR_NOOP("Off")
601 value: Camera.FlashOff
602 }
603 },
604 ListModel {
605 id: videoFlashOptionsModel
606
607 property string settingsProperty: "videoFlashOn"
608 property string icon: ""
609 property string label: ""
610 property bool isToggle: false
611 property int selectedIndex: bottomEdge.indexForValue(videoFlashOptionsModel, settings.videoFlashOn)
612 property bool available: camera.advanced.hasFlash
613 property bool visible: camera.captureMode == Camera.CaptureVideo
614 property bool showInIndicators: true
615
616 ListElement {
617 icon: "torch-on"
618 label: QT_TR_NOOP("On")
619 value: true
620 }
621 ListElement {
622 icon: "torch-off"
623 label: QT_TR_NOOP("Off")
624 value: false
625 }
626 },
627 ListModel {
628 id: hdrOptionsModel
629
630 property string settingsProperty: "hdrEnabled"
631 property string icon: ""
632 property string label: i18n.tr("HDR")
633 property bool isToggle: true
634 property int selectedIndex: bottomEdge.indexForValue(hdrOptionsModel, settings.hdrEnabled)
635 property bool available: camera.advanced.hasHdr
636 property bool visible: camera.captureMode === Camera.CaptureStillImage
637 property bool showInIndicators: true
638
639 ListElement {
640 icon: ""
641 label: QT_TR_NOOP("On")
642 value: true
643 }
644 ListElement {
645 icon: ""
646 label: QT_TR_NOOP("Off")
647 value: false
648 }
649 },
650 ListModel {
651 id: selfTimerOptionsModel
652
653 property string settingsProperty: "selfTimerDelay"
654 property string icon: ""
655 property string iconSource: "../../assets/self_timer.svg"
656 property string label: ""
657 property bool isToggle: true
658 property int selectedIndex: bottomEdge.indexForValue(selfTimerOptionsModel, settings.selfTimerDelay)
659 property bool available: true
660 property bool visible: true
661 property bool showInIndicators: true
662
663 ListElement {
664 icon: ""
665 label: QT_TR_NOOP("Off")
666 value: 0
667 }
668 ListElement {
669 icon: ""
670 label: QT_TR_NOOP("5 seconds")
671 value: 5
672 }
673 ListElement {
674 icon: ""
675 label: QT_TR_NOOP("15 seconds")
676 value: 15
677 }
678 },
679 ListModel {
680 id: encodingQualityOptionsModel
681
682 property string settingsProperty: "encodingQuality"
683 property string icon: "stock_image"
684 property string label: ""
685 property bool isToggle: false
686 property int selectedIndex: bottomEdge.indexForValue(encodingQualityOptionsModel, settings.encodingQuality)
687 property bool available: true
688 property bool visible: camera.captureMode == Camera.CaptureStillImage
689 property bool showInIndicators: false
690
691 ListElement {
692 icon: ""
693 label: QT_TR_NOOP("Fine Quality")
694 value: 4 // QMultimedia.VeryHighQuality
695 }
696 ListElement {
697 icon: ""
698 label: QT_TR_NOOP("High Quality")
699 value: 3 // QMultimedia.HighQuality
700 }
701 ListElement {
702 icon: ""
703 label: QT_TR_NOOP("Normal Quality")
704 value: 2 // QMultimedia.NormalQuality
705 }
706 ListElement {
707 icon: ""
708 label: QT_TR_NOOP("Basic Quality")
709 value: 1 // QMultimedia.LowQuality
710 }
711 },
712 ListModel {
713 id: videoQualityOptionsModel
714 property string settingsProperty: "videoQuality"
715 property string icon: "stock_video"
716 property string label: ""
717 property bool isToggle: false
718 property int selectedIndex: bottomEdge.indexForValue(videoQualityOptionsModel, settings.videoQuality)
719 property bool available: true
720 property bool visible: camera.captureMode == Camera.CaptureVideo
721 property bool showInIndicators: false
722 ListElement {
723 icon: ""
724 label: QT_TR_NOOP("High Quality")
725 value: 1
726 }
727 ListElement {
728 icon: ""
729 label: QT_TR_NOOP("Normal Quality")
730 value: 0
731 }
732 },
733 ListModel {
734 id: videoResolutionOptionsModel
735
736 function setSettingProperty(value) {
737 setVideoResolution(value);
738 }
739
740 property string icon: ""
741 property string label: resolutionToLabel(settings.videoResolutions[camera.deviceId], false)
742 property bool isToggle: false
743 property int selectedIndex: bottomEdge.indexForValue(videoResolutionOptionsModel,
744 settings.videoResolutions[camera.deviceId])
745 property bool available: true
746 property bool visible: camera.captureMode == Camera.CaptureVideo
747 property bool showInIndicators: false
748 },
749 ListModel {
750 id: gridOptionsModel
751
752 property string settingsProperty: "gridEnabled"
753 property string icon: ""
754 property string iconSource: "../../assets/grid_lines.svg"
755 property string label: ""
756 property bool isToggle: true
757 property int selectedIndex: bottomEdge.indexForValue(gridOptionsModel, settings.gridEnabled)
758 property bool available: true
759 property bool visible: true
760
761 ListElement {
762 icon: ""
763 label: QT_TR_NOOP("On")
764 value: true
765 }
766 ListElement {
767 icon: ""
768 label: QT_TR_NOOP("Off")
769 value: false
770 }
771 },
772 ListModel {
773 id: removableStorageOptionsModel
774
775 property string settingsProperty: "preferRemovableStorage"
776 property string icon: ""
777 // TRANSLATORS: this will be displayed on an small button so for it to fit it should be less then 3 characters long.
778 property string label: i18n.tr("SD")
779 property bool isToggle: true
780 property int selectedIndex: bottomEdge.indexForValue(removableStorageOptionsModel, settings.preferRemovableStorage)
781 property bool available: StorageLocations.removableStoragePresent
782 property bool visible: available
783
784 ListElement {
785 icon: ""
786 label: QT_TR_NOOP("Save to SD Card")
787 value: true
788 }
789 ListElement {
790 icon: ""
791 label: QT_TR_NOOP("Save internally")
792 value: false
793 }
794 },
795 ListModel {
796 id: shutterSoundOptionsModel
797
798 function setSettingProperty(value) {
799 settings.shutterVibration = value & 0x1;
800 settings.playShutterSound = value & 0x2;
801 }
802
803 property string settingsProperty: "playShutterSound"
804 property string icon: ""
805 property string label: ""
806 property bool isToggle: true
807 property int selectedIndex: bottomEdge.indexForValue(shutterSoundOptionsModel, 2 * settings.playShutterSound + settings.shutterVibration)
808 property bool available: true
809 property bool visible: camera.captureMode === Camera.CaptureStillImage
810 property bool showInIndicators: false
811
812 ListElement {
813 icon: "audio-volume-high"
814 label: QT_TR_NOOP("On")
815 value: 2
816 }
817 ListElement {
818 iconSource: "../../assets/vibrate.png"
819 label: QT_TR_NOOP("Vibrate")
820 value: 1
821 }
822 ListElement {
823 icon: "audio-volume-muted"
824 label: QT_TR_NOOP("Off")
825 value: 0
826 }
827 },
828 ListModel {
829 id: photoResolutionOptionsModel
830
831 function setSettingProperty(value) {
832 setPhotoResolution(value);
833 }
834
835 property string icon: ""
836 property string label: "%1MP".arg(trimNumberToFit(sizeToMegapixels(stringToSize(settings.photoResolutions[camera.deviceId])),3))
837 property bool isToggle: false
838 property int selectedIndex: bottomEdge.indexForValue(photoResolutionOptionsModel, settings.photoResolutions[camera.deviceId])
839 property bool available: true
840 property bool visible: camera.captureMode == Camera.CaptureStillImage
841 property bool showInIndicators: false
842 },
843 ListModel {
844 id: photoEXIFSettingsModel
845
846 function setSettingProperty(value) {
847 settings.hasEXIF = value;
848 }
849
850 property string settingsProperty: "hasEXIF"
851 property string icon: ""
852 property string label: ""
853 property bool isToggle: true
854 property int selectedIndex: bottomEdge.indexForValue(photoEXIFSettingsModel, settings.hasEXIF)
855 property bool available: true
856 property bool visible: camera.captureMode === Camera.CaptureStillImage
857 property bool showInIndicators: false
858
859 ListElement {
860 icon: "private-browsing-exit"
861 label: QT_TR_NOOP("Save device info")
862 value: true
863 }
864 ListElement {
865 icon: "private-browsing"
866 label: QT_TR_NOOP("No device info")
867 value: false
868 }
869 }
870 ]
871
872 /* FIXME: StorageLocations.removableStoragePresent is not updated dynamically.
873 Workaround that by reading it when the bottom edge is opened/closed.
874 */
875 Connections {
876 target: bottomEdge
877 onOpenedChanged: StorageLocations.updateRemovableStorageInfo()
878 }
879
880 function indexForValue(model, value) {
881 var i;
882 var element;
883 for (i=0; i<model.count; i++) {
884 element = model.get(i);
885 if (element.value === value) {
886 return i;
887 }
888 }
889
890 return -1;
891 }
892
893 BottomEdgeIndicators {
894 id: bottomEdgeIndicators
895 options: bottomEdge.options
896 anchors {
897 horizontalCenter: parent.horizontalCenter
898 bottom: parent.top
899 }
900 opacity: bottomEdge.pressed || bottomEdge.opened ? 0.0 : 1.0
901 Behavior on opacity { LomiriNumberAnimation {} }
902 }
903
904 Loader {
905 id: optionsOverlayLoader
906 anchors {
907 left: parent.left
908 right: parent.right
909 top: parent.top
910 }
911 asynchronous: true
912 sourceComponent: Component {
913 OptionsOverlay {
914 options: bottomEdge.options
915 }
916 }
917 }
918
919 triggerSize: units.gu(3)
920
921 Item {
922 /* Use the 'trigger' feature of Panel so that tapping on the Panel
923 can be acted upon */
924 id: clickReceiver
925 anchors.fill: parent
926 anchors.topMargin: -bottomEdge.triggerSize
927
928 function trigger() {
929 if (bottomEdge.opened) {
930 optionsOverlayClose();
931 } else {
932 bottomEdge.open();
933 }
934 }
935 }
936 }
937 }
938
939 OrientationSensor {
940 id: orientationSensor
941 active: true
942 }
943
944 Item {
945 id: controls
946
947 anchors {
948 left: parent.left
949 right: parent.right
950 }
951 height: parent.height
952 y: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation) == 0 ? bottomEdge.position - bottomEdge.height : 0
953 opacity: 1 - bottomEdge.progress
954 visible: opacity != 0.0
955 enabled: !bottomEdge.progress
956
957 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.FastDuration}}
958
959 function timedShoot(secs) {
960 camera.timedCaptureInProgress = true;
961 timedShootFeedback.start();
962 shootingTimer.remainingSecs = secs;
963 shootingTimer.start();
964 }
965
966 function cancelTimedShoot() {
967 if (camera.timedCaptureInProgress) {
968 camera.timedCaptureInProgress = false;
969 shootingTimer.stop();
970 timedShootFeedback.stop();
971 }
972 }
973
974 function shoot() {
975 // Note that orientation now means the clockwise rotation of the image.
976 var orientation = 0;
977 if (orientationSensor.reading != null) {
978 switch (orientationSensor.reading.orientation) {
979 case OrientationReading.TopUp:
980 orientation = 0;
981 break;
982 case OrientationReading.TopDown:
983 orientation = 180;
984 break;
985 case OrientationReading.LeftUp:
986 orientation = 270;
987 break;
988 case OrientationReading.RightUp:
989 orientation = 90;
990 break;
991 default:
992 /* Workaround for OrientationSensor not setting a valid value until
993 the device is rotated.
994 Ref.: https://bugs.launchpad.net/qtubuntu-sensors/+bug/1429865
995
996 Note that the value returned by Screen.angleBetween is valid if
997 the orientation lock is not engaged.
998 Ref.: https://bugs.launchpad.net/camera-app/+bug/1422762
999 */
1000 orientation = Screen.angleBetween(Screen.primaryOrientation, Screen.orientation);
1001 break;
1002 }
1003 }
1004
1005 if (camera.position === Camera.FrontFace) {
1006 // Clockwise device becomes counter-clockwise camera
1007 orientation = 360 - orientation;
1008 }
1009
1010 // account for the orientation of the sensor
1011 orientation += viewFinderOverlay.sensorOrientation;
1012
1013 // Ensure that the orientation is positive and within range.
1014 orientation = (orientation + 360) % 360;
1015
1016 if (camera.captureMode == Camera.CaptureVideo) {
1017 if (main.contentExportMode) {
1018 camera.videoRecorder.outputLocation = StorageLocations.temporaryLocation;
1019 } else if (StorageLocations.removableStoragePresent && settings.preferRemovableStorage) {
1020 camera.videoRecorder.outputLocation = StorageLocations.removableStorageVideosLocation;
1021 } else {
1022 camera.videoRecorder.outputLocation = StorageLocations.videosLocation;
1023 }
1024
1025 if (camera.videoRecorder.recorderState == CameraRecorder.StoppedState) {
1026 camera.videoRecorder.setMetadata("Orientation", orientation);
1027 camera.videoRecorder.setMetadata("Date", new Date());
1028 camera.videoRecorder.record();
1029 }
1030 } else {
1031 if (!main.contentExportMode) {
1032 shootFeedback.start();
1033 }
1034 camera.photoCaptureInProgress = true;
1035 camera.imageCapture.setMetadata("Orientation", orientation);
1036 camera.imageCapture.setMetadata("Date", new Date());
1037 var position = positionSource.position;
1038 if (settings.hasEXIF && settings.gpsEnabled && positionSource.isPrecise) {
1039 camera.imageCapture.setMetadata("GPSLatitude", position.coordinate.latitude);
1040 camera.imageCapture.setMetadata("GPSLongitude", position.coordinate.longitude);
1041 camera.imageCapture.setMetadata("GPSTimeStamp", position.timestamp);
1042 camera.imageCapture.setMetadata("GPSProcessingMethod", "GPS");
1043 if (position.altitudeValid) {
1044 camera.imageCapture.setMetadata("GPSAltitude", position.coordinate.altitude);
1045 }
1046 }
1047
1048 if (main.contentExportMode) {
1049 camera.imageCapture.captureToLocation(StorageLocations.temporaryLocation);
1050 } else if (StorageLocations.removableStoragePresent && settings.preferRemovableStorage) {
1051 camera.imageCapture.captureToLocation(StorageLocations.removableStoragePicturesLocation);
1052 } else {
1053 camera.imageCapture.captureToLocation(StorageLocations.picturesLocation);
1054 }
1055 }
1056 }
1057
1058 function switchCamera() {
1059 camera.switchInProgress = true;
1060 // viewFinderGrab.sourceItem = viewFinder;
1061 viewFinderGrab.x = viewFinder.x;
1062 viewFinderGrab.y = viewFinder.y;
1063 viewFinderGrab.width = viewFinder.width;
1064 viewFinderGrab.height = viewFinder.height;
1065 viewFinderGrab.visible = true;
1066 viewFinderGrab.scheduleUpdate();
1067 }
1068
1069 function completeSwitch() {
1070 viewFinderSwitcherAnimation.restart();
1071 camera.switchInProgress = false;
1072 zoomControl.value = camera.currentZoom;
1073 }
1074
1075 function changeRecordMode() {
1076 if (camera.captureMode == Camera.CaptureVideo) camera.videoRecorder.stop()
1077 camera.captureMode = (camera.captureMode == Camera.CaptureVideo) ? Camera.CaptureStillImage : Camera.CaptureVideo
1078 zoomControl.value = camera.currentZoom
1079 }
1080
1081 Connections {
1082 target: Qt.application
1083 onActiveChanged: if (active) zoomControl.value = camera.currentZoom
1084 }
1085
1086 Timer {
1087 id: shootingTimer
1088 repeat: true
1089 triggeredOnStart: true
1090
1091 property int remainingSecs: 0
1092
1093 onTriggered: {
1094 if (remainingSecs == 0) {
1095 running = false;
1096 camera.timedCaptureInProgress = false;
1097 controls.shoot();
1098 timedShootFeedback.stop();
1099 } else {
1100 timedShootFeedback.showRemainingSecs(remainingSecs);
1101 remainingSecs--;
1102 }
1103 }
1104 }
1105
1106 PositionSource {
1107 id: positionSource
1108 updateInterval: 1000
1109 active: settings.gpsEnabled
1110 property bool isPrecise: valid
1111 && position.latitudeValid
1112 && position.longitudeValid
1113 && (!position.horizontalAccuracyValid ||
1114 position.horizontalAccuracy <= 100)
1115 }
1116
1117 Connections {
1118 target: camera.imageCapture
1119 onReadyChanged: {
1120 if (camera.imageCapture.ready) {
1121 if (camera.switchInProgress) {
1122 controls.completeSwitch();
1123 }
1124 }
1125 }
1126 }
1127
1128 CircleButton {
1129 id: recordModeButton
1130 objectName: "recordModeButton"
1131
1132 anchors {
1133 right: shootButton.left
1134 rightMargin: units.gu(7.5)
1135 bottom: parent.bottom
1136 bottomMargin: units.gu(6)
1137 }
1138
1139 automaticOrientation: false
1140 customRotation: main.staticRotationAngle
1141 iconName: (camera.captureMode == Camera.CaptureStillImage) ? "camcorder" : "camera-symbolic"
1142 onClicked: controls.changeRecordMode()
1143 enabled: camera.videoRecorder.recorderState == CameraRecorder.StoppedState && !main.contentExportMode
1144 && !camera.photoCaptureInProgress && !camera.timedCaptureInProgress
1145 }
1146
1147 ShootButton {
1148 id: shootButton
1149
1150 anchors {
1151 bottom: parent.bottom
1152 // account for the bottom shadow in the asset
1153 bottomMargin: units.gu(5) - units.dp(6)
1154 horizontalCenter: parent.horizontalCenter
1155 }
1156
1157 enabled: (
1158 (camera.captureMode == Camera.CaptureVideo
1159 && camera.videoRecorder.recorderStatus == CameraRecorder.RecordingStatus) ||
1160 (viewFinderOverlay.readyForCapture && !storageMonitor.diskSpaceCriticallyLow
1161 && !camera.timedCaptureInProgress)
1162 )
1163 state: (camera.captureMode == Camera.CaptureVideo) ?
1164 ((camera.videoRecorder.recorderState == CameraRecorder.StoppedState) ? "record_off" : "record_on") :
1165 "camera"
1166 onClicked: {
1167 viewFinderOverlay.triggerShoot();
1168 }
1169 rotation: main.staticRotationAngle
1170 Behavior on rotation {
1171 RotationAnimator {
1172 duration: LomiriAnimation.BriskDuration
1173 easing: LomiriAnimation.StandardEasing
1174 direction: RotationAnimator.Shortest
1175 }
1176 }
1177 }
1178
1179 CircleButton {
1180 id: swapButton
1181 objectName: "swapButton"
1182
1183 anchors {
1184 left: shootButton.right
1185 leftMargin: units.gu(7.5)
1186 bottom: parent.bottom
1187 bottomMargin: units.gu(6)
1188 }
1189
1190 automaticOrientation: false
1191 customRotation: main.staticRotationAngle
1192 enabled: !camera.switchInProgress && camera.videoRecorder.recorderState == CameraRecorder.StoppedState
1193 && !camera.photoCaptureInProgress && !camera.timedCaptureInProgress
1194 iconName: "camera-flip"
1195 onClicked: controls.switchCamera()
1196 }
1197
1198
1199 PinchArea {
1200 id: zoomPinchArea
1201 anchors {
1202 top: parent.top
1203 topMargin: bottomEdgeIndicators.height
1204 bottom: shootButton.top
1205 bottomMargin: bottomEdgeIndicators.height
1206 left: parent.left
1207 leftMargin: bottomEdgeIndicators.height
1208 right: parent.right
1209 rightMargin: bottomEdgeIndicators.height
1210 }
1211
1212 property real initialZoom
1213 property real minimumScale: 0.3
1214 property real maximumScale: 3.0
1215 property bool active: false
1216
1217 enabled: !camera.photoCaptureInProgress && !camera.timedCaptureInProgress
1218 onPinchStarted: {
1219 active = true;
1220 initialZoom = zoomControl.value;
1221 zoomControl.show();
1222 }
1223 onPinchUpdated: {
1224 zoomControl.show();
1225 var scaleFactor = MathUtils.projectValue(pinch.scale, 1.0, maximumScale, 0.0, zoomControl.maximumValue);
1226 zoomControl.value = MathUtils.clamp(initialZoom + scaleFactor, zoomControl.minimumValue, zoomControl.maximumValue);
1227 }
1228 onPinchFinished: {
1229 active = false;
1230 }
1231
1232
1233 MouseArea {
1234 id: manualFocusMouseArea
1235 anchors.fill: parent
1236 objectName: "manualFocusMouseArea"
1237 enabled: camera.focus.isFocusPointModeSupported(Camera.FocusPointCustom) &&
1238 !camera.photoCaptureInProgress && !camera.timedCaptureInProgress
1239 onClicked: {
1240 // mouse.x/y is relative to this item. Convert to be relative to the overlay,
1241 // which in turn is relative to viewFinderView, where camera's VideoOutput resides.
1242 var mappedPoint = mapToItem(viewFinderOverlay, mouse.x, mouse.y);
1243 camera.manualFocus(mappedPoint.x, mappedPoint.y);
1244 mouse.accepted = false;
1245 }
1246 }
1247 }
1248
1249 ZoomControl {
1250 id: zoomControl
1251
1252 anchors {
1253 bottom: shootButton.top
1254 bottomMargin: units.gu(2)
1255 left: parent.left
1256 right: parent.right
1257 leftMargin: recordModeButton.x
1258 rightMargin: parent.width - (swapButton.x + swapButton.width)
1259 }
1260 maximumValue: camera.maximumZoom
1261
1262 Binding { target: camera; property: "currentZoom"; value: zoomControl.value }
1263 }
1264
1265 StopWatch {
1266 id: stopWatch
1267
1268 anchors {
1269 top: parent.top
1270 topMargin: units.gu(6)
1271 horizontalCenter: parent.horizontalCenter
1272 }
1273 opacity: camera.videoRecorder.recorderState == CameraRecorder.StoppedState ? 0.0 : 1.0
1274 Behavior on opacity { LomiriNumberAnimation {} }
1275 visible: opacity != 0
1276 time: camera.videoRecorder.duration / 1000
1277 rotation: main.staticRotationAngle
1278 }
1279
1280 FocusRing {
1281 id: focusRing
1282 }
1283
1284 CircleButton {
1285 id: exportBackButton
1286 objectName: "exportBackButton"
1287
1288 anchors {
1289 top: parent.top
1290 topMargin: units.gu(4)
1291 left: recordModeButton.left
1292 }
1293
1294 iconName: visible ? "go-previous" : ""
1295 visible: main.contentExportMode
1296 enabled: main.contentExportMode
1297 onClicked: main.cancelExport()
1298 }
1299 }
1300
1301 ProcessingFeedback {
1302 anchors {
1303 top: parent.top
1304 topMargin: units.gu(2)
1305 left: parent.left
1306 leftMargin: units.gu(2)
1307 }
1308 processing: camera.photoCaptureInProgress
1309 }
1310
1311 StorageMonitor {
1312 id: storageMonitor
1313 location: (StorageLocations.removableStoragePresent && settings.preferRemovableStorage) ?
1314 StorageLocations.removableStorageLocation : StorageLocations.videosLocation
1315 onDiskSpaceLowChanged: if (storageMonitor.diskSpaceLow && !storageMonitor.diskSpaceCriticallyLow) {
1316 PopupUtils.open(freeSpaceLowDialogComponent);
1317 }
1318 onDiskSpaceCriticallyLowChanged: if (storageMonitor.diskSpaceCriticallyLow) {
1319 camera.videoRecorder.stop();
1320 }
1321 onIsWriteableChanged: if (!isWriteable && !diskSpaceLow && !main.contentExportMode) {
1322 PopupUtils.open(readOnlyMediaDialogComponent);
1323 }
1324 }
1325
1326 NoSpaceHint {
1327 id: noSpaceHint
1328 objectName: "noSpace"
1329 anchors.fill: parent
1330 visible: storageMonitor.diskSpaceCriticallyLow
1331 }
1332
1333 Component {
1334 id: freeSpaceLowDialogComponent
1335 Dialog {
1336 id: freeSpaceLowDialog
1337 objectName: "lowSpaceDialog"
1338 title: i18n.tr("Low storage space")
1339 text: i18n.tr("You are running out of storage space. To continue without interruptions, free up storage space now.")
1340 Button {
1341 text: i18n.tr("Cancel")
1342 onClicked: PopupUtils.close(freeSpaceLowDialog)
1343 }
1344 }
1345 }
1346
1347 Component {
1348 id: readOnlyMediaDialogComponent
1349 Dialog {
1350 id: readOnlyMediaDialog
1351 objectName: "readOnlyMediaDialog"
1352 title: i18n.tr("External storage not writeable")
1353 text: i18n.tr("It does not seem possible to write to your external storage media. Trying to eject and insert it again might solve the issue, or you might need to format it.")
1354 Button {
1355 text: i18n.tr("Cancel")
1356 onClicked: PopupUtils.close(readOnlyMediaDialog)
1357 }
1358 }
1359 }
1360
1361 Connections {
1362 id: permissionErrorMonitor
1363 property var currentPermissionsDialog: null
1364 target: camera
1365 onError: {
1366 if (errorCode == Camera.ServiceMissingError) {
1367 if (currentPermissionsDialog == null) {
1368 currentPermissionsDialog = PopupUtils.open(noPermissionsDialogComponent);
1369 }
1370 camera.failedToConnect = true;
1371 }
1372 }
1373 onCameraStateChanged: {
1374 if (camera.cameraState != Camera.UnloadedState) {
1375 if (currentPermissionsDialog != null) {
1376 PopupUtils.close(currentPermissionsDialog);
1377 currentPermissionsDialog = null;
1378 }
1379 camera.failedToConnect = false;
1380 } else {
1381 camera.photoCaptureInProgress = false;
1382 }
1383 }
1384 }
1385
1386 Component {
1387 id: noPermissionsDialogComponent
1388 Dialog {
1389 id: noPermissionsDialog
1390 objectName: "noPermissionsDialog"
1391 title: i18n.tr("Cannot access camera")
1392 text: i18n.tr("Camera app doesn't have permission to access the camera hardware or another error occurred.\n\nIf granting permission does not resolve this problem, reboot your device.")
1393 Button {
1394 text: i18n.tr("Edit Permissions")
1395 color: theme.palette.normal.focus
1396 onClicked: {
1397 Qt.openUrlExternally("settings:///system/security-privacy?service=camera");
1398 PopupUtils.close(noPermissionsDialog);
1399 permissionErrorMonitor.currentPermissionsDialog = null;
1400 }
1401 }
1402 Button {
1403 text: i18n.tr("Cancel")
1404 onClicked: {
1405 PopupUtils.close(noPermissionsDialog);
1406 permissionErrorMonitor.currentPermissionsDialog = null;
1407 }
1408 }
1409 }
1410 }
1411
1412 FastBlur {
1413 id: viewFinderSwitcherBlurred
1414 anchors.fill: parent
1415 property real finalRadius: 67
1416 property real finalOpacity: 1.0
1417 radius: photoRollHint.visible ? finalRadius : viewFinderOverlay.revealProgress * finalRadius
1418 opacity: photoRollHint.visible ? finalOpacity : (1.0 - viewFinderOverlay.revealProgress) * finalOpacity + finalOpacity
1419 source: viewFinderSwitcher !== null ? viewFinderSwitcher : null
1420 z:-1
1421 visible: appSettings.blurEffects && radius !== 0
1422 transparentBorder:false
1423 Behavior on radius { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration} }
1424 }
1425
1426 Rectangle {
1427 id: viewFinderOverlayTint
1428 anchors.fill:parent
1429 property real finalOpacity: 0.25
1430 property real tintOpacity : viewFinderOverlay.revealProgress * finalOpacity
1431 visible: viewFinderOverlay.revealProgress > 0
1432 opacity:tintOpacity
1433 color: LomiriColors.jet
1434 z:-1
1435 }
1436 }