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