Drop unneeded CameraOverlay.qml
[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_QT_QUICK@
24 import QtCamera 1.0
25 import CameraPlus 1.0
26
27 // TODO: reset reticle and roi when we stop camera or change mode
28 Camera {
29     id: cam
30
31     property bool pressed: focusReticle.locked || (loader.item ? loader.item.pressed : false)
32     property int policyMode: loader.item ? loader.item.policyMode : CameraResources.None
33
34     renderingEnabled: mainView.currentItem == cam
35
36     function policyLost() {
37         if (loader.item) {
38             loader.item.policyLost()
39         }
40     }
41
42     function checkBattery() {
43         // We are fine if we are connected to the charger:
44         if (batteryMonitor.charging) {
45             return true
46         }
47
48         // If we have enough battery then we are fine:
49         if (!batteryMonitor.critical) {
50             return true
51         }
52
53         return false
54     }
55
56     Component.onDestruction: cam.stop()
57
58     onRunningChanged: {
59         if (!cam.running) {
60             mountProtector.unlock()
61         }
62     }
63
64     notifications: Sounds {
65         id: sounds
66         mute: !settings.soundEnabled
67     }
68
69     BatteryInfo {
70         id: batteryMonitor
71         active: cam.running
72
73         function check() {
74             if (!checkBattery()) {
75                 loader.item.batteryLow()
76             }
77         }
78
79         onChargingChanged: {
80             batteryMonitor.check()
81         }
82
83         onCriticalChanged: {
84             batteryMonitor.check()
85         }
86     }
87
88     PreviewImage {
89         id: preview
90     }
91
92     Connections {
93         target: loader.item
94         onPreviewAvailable: preview.setPreview(uri)
95     }
96
97     Binding {
98         target: loader.item
99         property: "cam"
100         value: cam
101         when: loader.item != null
102     }
103
104     Binding {
105         target: loader.item
106         property: "animationRunning"
107         value: preview.animationRunning
108         when: loader.item != null
109     }
110
111     onRoiChanged: roi.normalize = false
112
113     GridLines {
114         x: cam.renderArea.x
115         y: cam.renderArea.y
116         width: cam.renderArea.width
117         height: cam.renderArea.height
118         visible: settings.gridEnabled
119     }
120
121     FocusReticle {
122         id: focusReticle
123         cam: cam
124         visible: loader.item != null && loader.item.controlsVisible &&
125             cam.autoFocus.canFocus(cam.scene.value)
126         cafStatus: cam ? cam.autoFocus.cafStatus : -1
127         status: cam ? cam.autoFocus.status : -1
128     }
129
130     Loader {
131         id: loader
132         property string src: mode == Camera.VideoMode ? "VideoOverlay.qml" : "ImageOverlay.qml"
133         anchors.fill: parent
134         source: Qt.resolvedUrl(src)
135     }
136
137     Binding {
138         target: cam.flash
139         property: "value"
140         when: cam.mode == Camera.ImageMode
141         value: settings.imageFlashMode
142     }
143
144     Binding {
145         target: settings
146         property: "imageFlashMode"
147         when: cam.mode == Camera.ImageMode
148         value: cam.flash.value
149     }
150
151     Binding {
152         target: cam.scene
153         property: "value"
154         when: cam.mode == Camera.VideoMode
155         value: settings.videoSceneMode
156     }
157
158     Binding {
159         target: cam.scene
160         property: "value"
161         when: cam.mode == Camera.ImageMode
162         value: settings.imageSceneMode
163     }
164
165     Binding {
166         target: cam.evComp
167         property: "value"
168         when: cam.mode == Camera.ImageMode
169         value: settings.imageEvComp
170     }
171
172     Binding {
173         target: cam.evComp
174         property: "value"
175         when: cam.mode == Camera.VideoMode
176         value: settings.videoEvComp
177     }
178
179     Binding {
180         target: settings
181         property: "imageEvComp"
182         when: cam.mode == Camera.ImageMode
183         value: cam.evComp.value
184     }
185
186     Binding {
187         target: settings
188         property: "videoEvComp"
189         when: cam.mode == Camera.VideoMode
190         value: cam.evComp.value
191     }
192
193     Binding {
194         target: cam.whiteBalance
195         property: "value"
196         when: cam.mode == Camera.ImageMode
197         value: settings.imageWhiteBalance
198     }
199
200     Binding {
201         target: cam.whiteBalance
202         property: "value"
203         when: cam.mode == Camera.VideoMode
204         value: settings.videoWhiteBalance
205     }
206
207     Binding {
208         target: cam.colorTone
209         property: "value"
210         when: cam.mode == Camera.ImageMode
211         value: settings.imageColorFilter
212     }
213
214     Binding {
215         target: cam.colorTone
216         property: "value"
217         when: cam.mode == Camera.VideoMode
218         value: settings.videoColorFilter
219     }
220
221     Binding {
222         target: cam.iso
223         property: "value"
224         when: cam.mode == Camera.ImageMode
225         value: settings.imageIso
226     }
227
228     Binding {
229         target: settings
230         property: "imageIso"
231         when: cam.mode == Camera.ImageMode
232         value: cam.iso.value
233     }
234
235     Binding {
236         target: cam.videoMute
237         property: "enabled"
238         value: settings.videoMuted
239     }
240
241     Binding {
242         target: cam.roi
243         property: "enabled"
244         value: settings.faceDetectionEnabled && !focusReticle.pressed && !focusReticle.touchMode && cam.mode == Camera.ImageMode
245     }
246
247     onError: {
248         if (pipelineManager.error) {
249             // Ignore any subsequent errors.
250             // Killing pulseaudio while recording will lead to an
251             // infinite supply of errors which will break the UI
252             // if we show a banner for each.
253             return
254         }
255
256         pipelineManager.error = true
257         if (loader.item) {
258             loader.item.cameraError()
259         }
260
261         console.log("Camera error (" + code + "): " + message + " " + debug)
262         showError(qsTr("Camera error. Please restart the application."))
263         // We cannot stop camera here. Seems there is a race condition somewhere
264         // which leads to a freeze if we do so.
265     }
266
267 }