No need to set slider orientation. Default is already horizontal
[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
199     }
200
201     Binding {
202         target: cam.evComp
203         property: "value"
204         when: cam.mode == Camera.VideoMode && !root.deviceChangeInProgress
205         value: settings.videoEvComp
206     }
207
208     Binding {
209         target: settings
210         property: "imageEvComp"
211         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
212         value: cam.evComp.value
213     }
214
215     Binding {
216         target: settings
217         property: "videoEvComp"
218         when: cam.mode == Camera.VideoMode && !root.deviceChangeInProgress
219         value: cam.evComp.value
220     }
221
222     Binding {
223         target: cam.whiteBalance
224         property: "value"
225         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
226         value: settings.imageWhiteBalance
227     }
228
229     Binding {
230         target: cam.whiteBalance
231         property: "value"
232         when: cam.mode == Camera.VideoMode && !root.deviceChangeInProgress
233         value: settings.videoWhiteBalance
234     }
235
236     Binding {
237         target: cam.colorTone
238         property: "value"
239         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
240         value: settings.imageColorFilter
241     }
242
243     Binding {
244         target: cam.colorTone
245         property: "value"
246         when: cam.mode == Camera.VideoMode && !root.deviceChangeInProgress
247         value: settings.videoColorFilter
248     }
249
250     Binding {
251         target: cam.iso
252         property: "value"
253         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
254         value: settings.imageIso
255     }
256
257     Binding {
258         target: settings
259         property: "imageIso"
260         when: cam.mode == Camera.ImageMode && !root.deviceChangeInProgress
261         value: cam.iso.value
262     }
263
264     Binding {
265         target: cam.videoMute
266         property: "enabled"
267         value: settings.videoMuted
268     }
269
270     Binding {
271         target: cam.roi
272         property: "enabled"
273         value: settings.faceDetectionEnabled && !focusReticle.pressed && !focusReticle.touchMode && cam.mode == Camera.ImageMode
274     }
275
276     function policyLost() {
277         if (loader.item) {
278             loader.item.policyLost()
279         }
280     }
281
282     function checkBattery() {
283         // We are fine if we are connected to the charger:
284         if (batteryMonitor.charging) {
285             return true
286         }
287
288         // If we have enough battery then we are fine:
289         if (!batteryMonitor.critical) {
290             return true
291         }
292
293         return false
294     }
295
296     function cameraDeviceChanged() {
297         if (loader.item) {
298             loader.item.cameraDeviceChanged()
299         }
300     }
301 }