Added an option to disable preview for images and videos (inactive)
[harmattan/cameraplus] / qml / CameraView.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 2.0
24 import QtCamera 1.0
25 import CameraPlus 1.0
26
27 Viewfinder {
28     id: viewfinder
29     property bool pressed: focusReticle.locked || preview.animationRunning
30         || (loader.item ? loader.item.pressed : false)
31     property int policyMode: loader.item ? loader.item.policyMode : CameraResources.None
32     property bool inhibitDim: loader.item ? loader.item.inhibitDim : false
33
34     camera: cam
35     cameraConfig: cam.cameraConfig
36     renderingEnabled: mainView.currentItem == viewfinder
37
38     Component.onDestruction: cam.stop()
39
40     GridLines {
41         x: viewfinder.renderArea.x
42         y: viewfinder.renderArea.y
43         width: viewfinder.renderArea.width
44         height: viewfinder.renderArea.height
45         visible: settings.gridEnabled
46     }
47
48     PhoneProfile {
49         id: phoneProfile
50     }
51
52     Camera {
53         id: cam
54         sounds: Sounds {
55             id: sounds
56             mute: !settings.soundEnabled || phoneProfile.isSilent
57             volume: volumeControl.fullVolume ? Sounds.VolumeHigh : Sounds.VolumeLow
58             imageCaptureStart: platformSettings.imageCaptureStartedSound
59             imageCaptureEnd: platformSettings.imageCaptureEndedSound
60             videoRecordingStart: platformSettings.videoRecordingStartedSound
61             videoRecordingEnd: platformSettings.videoRecordingEndedSound
62             autoFocusAcquired: platformSettings.autoFocusAcquiredSound
63         }
64
65         onFocusChanged: focus.value = Focus.ContinuousNormal
66         onRoiChanged: roi.normalize = false
67
68         onRunningChanged: {
69             if (!cam.running) {
70                 mountProtector.unlockAll()
71             }
72         }
73
74         onError: {
75             if (pipelineManager.error) {
76                 // Ignore any subsequent errors.
77                 // Killing pulseaudio while recording will lead to an
78                 // infinite supply of errors which will break the UI
79                 // if we show a banner for each.
80                 return
81             }
82
83             pipelineManager.error = true
84             if (loader.item) {
85                 loader.item.cameraError()
86             }
87
88             console.log("Camera error (" + code + "): " + message + " " + debug)
89             showError(qsTr("Camera error. Please restart the application."))
90             // We cannot stop camera here. Seems there is a race condition somewhere
91             // which leads to a freeze if we do so.
92         }
93
94     }
95
96     SoundVolumeControl {
97         id: volumeControl
98     }
99
100     BatteryInfo {
101         id: batteryMonitor
102         active: cam.running
103
104         function check() {
105             if (!checkBattery()) {
106                 loader.item.batteryLow()
107             }
108         }
109
110         onChargingChanged: {
111             batteryMonitor.check()
112         }
113
114         onCriticalChanged: {
115             batteryMonitor.check()
116         }
117     }
118
119     PreviewImage {
120         id: preview
121     }
122
123     FocusReticle {
124         id: focusReticle
125         cam: cam
126         videoResolution: viewfinder.videoResolution
127         renderArea: viewfinder.renderArea
128
129         visible: loader.item != null && loader.item.controlsVisible &&
130             cam.autoFocus.canFocus(cam.scene.value)
131         cafStatus: cam ? cam.autoFocus.cafStatus : -1
132         status: cam ? cam.autoFocus.status : -1
133     }
134
135     Loader {
136         id: loader
137         property string src: cam.mode == Camera.VideoMode ? "VideoOverlay.qml" : "ImageOverlay.qml"
138         anchors.fill: parent
139         source: Qt.resolvedUrl(src)
140     }
141
142     Connections {
143         target: loader.item
144         onPreviewAvailable: {
145             if (settings.enablePreview) {
146                 preview.setPreview(uri)
147             }
148         }
149     }
150
151     Binding {
152         target: loader.item
153         property: "cam"
154         value: cam
155         when: loader.item != null
156     }
157
158     Binding {
159         target: loader.item
160         property: "animationRunning"
161         value: preview.animationRunning
162         when: loader.item != null
163     }
164
165     /* Camera bindings */
166     Binding {
167         target: cam.flash
168         property: "value"
169         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
170         value: settings.imageFlashMode
171     }
172
173     Binding {
174         target: settings
175         property: "imageFlashMode"
176         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
177         value: cam.flash.value
178     }
179
180     Binding {
181         target: cam.scene
182         property: "value"
183         when: cam.mode == Camera.VideoMode && !root.deviceChangeInProgress
184         value: settings.videoSceneMode
185     }
186
187     Binding {
188         target: cam.scene
189         property: "value"
190         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
191         value: settings.imageSceneMode
192     }
193
194     Binding {
195         target: cam.evComp
196         property: "value"
197         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
198         value: settings.imageEvComp