Activated the option to disable capture previews
[harmattan/cameraplus] / qml / ImageOverlay.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 Item {
28     id: overlay
29
30     property Camera cam
31     property bool animationRunning: false
32     property int policyMode: CameraResources.Image
33     property bool pressed: capture.pressed || zoomSlider.pressed || modeButton.pressed
34     property bool controlsVisible: imageMode.canCapture && cam.running && !animationRunning
35         && dimmer.opacity == 0.0 && !cameraMode.busy
36     property bool inhibitDim: false
37
38     signal previewAvailable(string uri)
39
40     anchors.fill: parent
41
42     ImageMode {
43         id: imageMode
44         camera: cam
45
46         onCaptureEnded: stopAutoFocus()
47
48         enablePreview: settings.enablePreview
49
50         onPreviewAvailable: overlay.previewAvailable(preview)
51
52         onSaved: mountProtector.unlock(fileNaming.imagePath)
53     }
54
55     ZoomSlider {
56         id: zoomSlider
57         camera: cam
58         anchors.top: parent.top
59         anchors.topMargin: 0
60         anchors.horizontalCenter: parent.horizontalCenter
61         visible: controlsVisible
62     }
63
64     ModeButton {
65         id: modeButton
66         anchors.bottom: parent.bottom
67         anchors.right: parent.right
68         anchors.rightMargin: 20
69         anchors.bottomMargin: 20
70         visible: controlsVisible
71     }
72
73     CaptureButton {
74         id: capture
75         anchors.right: parent.right
76         anchors.rightMargin: 20
77         anchors.verticalCenter: parent.verticalCenter
78         iconSource: cameraTheme.captureButtonImageIconId
79         width: 75
80         height: 75
81         opacity: 0.5
82         visible: controlsVisible
83
84         onExited: {
85             if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
86                 // Release outside the button:
87                 captureControl.canceled = true
88             }
89         }
90     }
91
92     Timer {
93         id: autoFocusTimer
94         interval: 200
95         running: captureControl.state == "capturing"
96         repeat: false
97         onTriggered: {
98             if (cam.autoFocus.cafStatus != AutoFocus.Success) {
99                 startAutoFocus()
100             }
101         }
102     }
103
104     ZoomCaptureButton {
105         id: zoomCapture
106     }
107
108     CaptureControl {
109         id: captureControl
110         capturePressed: capture.pressed
111         zoomPressed: zoomCapture.zoomPressed
112         proximityClosed: proximitySensor.sensorClosed
113         onStartCapture: captureImage()
114         onCancelCapture: stopAutoFocus()
115     }
116
117     CaptureCancel {
118         anchors.fill: parent
119         enabled: captureControl.showCancelBanner
120         onPressed:  captureControl.canceled = true
121     }
122
123     CameraToolBar {
124         id: toolBar
125         anchors.bottom: parent.bottom
126         anchors.bottomMargin: 20
127         anchors.left: parent.left
128         anchors.leftMargin: 20
129         opacity: 0.5
130         targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
131         visible: controlsVisible
132         expanded: settings.showToolBar
133         onExpandedChanged: settings.showToolBar = expanded
134         tools: CameraToolBarTools {
135             FlashButton {
136                 onClicked: toolBar.push(tools)
137                 visible: overlay.cam ? !overlay.cam.quirks.hasQuirk(Quirks.NoFlash) : false
138             }
139
140             ImageSceneButton {
141                 onClicked: toolBar.push(tools)
142             }
143
144             ImageEvCompButton {
145                 onClicked: toolBar.push(tools)
146             }
147
148             ImageWhiteBalanceButton {
149                 onClicked: toolBar.push(tools)
150             }
151
152             ImageColorFilterButton {
153                 onClicked: toolBar.push(tools)
154             }
155
156             ImageIsoButton {
157                 onClicked: toolBar.push(tools)
158             }
159         }
160     }
161
162     Rectangle {
163         id: indicators
164         anchors.top: parent.top
165         anchors.topMargin: 20
166         anchors.left: parent.left
167         anchors.leftMargin: 20
168         width: 48
169         height: col.height
170         color: "black"
171         border.color: "gray"
172         radius: 20
173         opacity: 0.5
174         visible: controlsVisible
175
176         Column {
177             id: col
178             width: parent.width
179             spacing: 5
180
181             Indicator {
182                 id: flashIndicator
183                 visible: !toolBar.expanded && !overlay.cam.quirks.hasQuirk(Quirks.NoFlash)
184                 source: cameraTheme.flashIcon(settings.imageFlashMode)
185             }
186
187             CameraLabel {
188                 anchors.left: parent.left
189                 anchors.right: parent.right
190                 anchors.leftMargin: 5
191                 anchors.rightMargin: 5
192                 anchors.topMargin: 5
193                 anchors.bottomMargin: 5
194                 text: imageSettings.currentResolution ? qsTr("%1M").arg(imageSettings.currentResolution.megaPixels) : qsTr("?M")
195                 font.bold: true
196                 verticalAlignment: Text.AlignVCenter
197                 horizontalAlignment: Text.AlignHCenter
198             }
199
200             Indicator {
201                 id: wbIndicator
202                 source: visible ? cameraTheme.whiteBalanceIcon(settings.imageWhiteBalance) : ""
203                 visible: settings.imageWhiteBalance != WhiteBalance.Auto && !toolBar.expanded
204             }
205
206             Indicator {
207                 id: cfIndicator
208                 source: visible ? cameraTheme.colorFilterIcon(settings.imageColorFilter) : ""
209                 visible: settings.imageColorFilter != ColorTone.Normal && !toolBar.expanded
210             }
211
212             Indicator {
213                 id: isoIndicator
214                 visible: settings.imageIso != 0 && !toolBar.expanded
215                 source: visible ? cameraTheme.isoIcon(settings.imageIso) : ""
216             }
217
218             Indicator {
219                 id: sceneIndicator
220                 visible: settings.imageSceneMode != Scene.Auto && !toolBar.expanded
221                 source: visible ? cameraTheme.imageSceneModeIcon(settings.imageSceneMode) : ""
222             }
223
224             Indicator {
225                 id: gpsIndicator
226                 visible: settings.useGps
227                 source: cameraTheme.gpsIndicatorIcon
228
229                 PropertyAnimation on opacity  {
230                     easing.type: Easing.OutSine
231                     loops: Animation.Infinite
232                     from: 0.2
233                     to: 1.0
234                     duration: 1000
235                     running: settings.useGps && !positionSource.position.longitudeValid
236                     alwaysRunToEnd: true
237                 }
238             }
239
240             Indicator {
241                 id: faceDetectionIndicator
242                 visible: settings.faceDetectionEnabled
243                 source: cameraTheme.faceDetectionIndicatorIcon
244             }
245
246         }
247     }
248
249     function cameraError() {
250         mountProtector.unlock(fileNaming.imagePath)
251     }
252
253     function policyLost() {
254         // Nothing
255     }
256
257     function batteryLow() {
258         // Nothing
259     }
260
261     function captureImage() {
262         if (!imageMode.canCapture) {
263             showError(qsTr("Camera is already capturing an image."))
264             stopAutoFocus()
265         } else if (!checkBattery()) {
266             showError(qsTr("Not enough battery to capture images."))
267             stopAutoFocus()
268         } else if (!fileSystem.available) {
269             showError(qsTr("Camera cannot capture images in mass storage mode."))
270             stopAutoFocus()
271         } else if (!fileSystem.hasFreeSpace(fileNaming.imagePath)) {
272             showError(qsTr("Not enough space to capture images."))
273             stopAutoFocus()
274         } else if (!mountProtector.lock(fileNaming.imagePath)) {
275             showError(qsTr("Failed to lock images directory."))
276             stopAutoFocus()
277         } else {
278             metaData.setMetaData()
279
280             var fileName = fileNaming.imageFileName()
281             if (!imageMode.capture(fileName)) {
282                 showError(qsTr("Failed to capture image. Please restart the camera."))
283                 mountProtector.unlock(fileNaming.imagePath)
284                 stopAutoFocus()
285             } else {
286                 trackerStore.storeImage(fileName)
287             }
288         }
289     }
290
291     function startAutoFocus() {
292         if (!overlay.cam.quirks.hasQuirk(Quirks.NoAutoFocus)) {
293             cam.autoFocus.startAutoFocus()
294         }
295     }
296
297     function stopAutoFocus() {
298         if (!overlay.cam.quirks.hasQuirk(Quirks.NoAutoFocus)) {
299             if (!autoFocusTimer.running) {
300                 cam.autoFocus.stopAutoFocus()
301             }
302         }
303     }
304
305     function resetToolBar() {
306         if (toolBar.depth() > 1) {
307             toolBar.pop()
308         }
309     }
310
311     function cameraDeviceChanged() {
312         resetToolBar()
313     }
314 }