Add missing capability.cpp
[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: cam.autoFocus.stopAutoFocus()
46
47         onPreviewAvailable: overlay.previewAvailable(preview)
48
49         onSaved: mountProtector.unlock()
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         onClicked: captureImage()
80         visible: controlsVisible && (!settings.zoomAsShutter && keys.active)
81
82         onExited: {
83             if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
84                 // Release outside the button:
85                 cam.autoFocus.stopAutoFocus()
86             }
87         }
88     }
89
90     Timer {
91         id: autoFocusTimer
92         interval: 200
93         running: capture.pressed || zoomCapture.zoomPressed
94         repeat: false
95         onTriggered: {
96             if (cam.autoFocus.cafStatus != AutoFocus.Success) {
97                 cam.autoFocus.startAutoFocus()
98             }
99         }
100     }
101
102     ZoomCaptureButton {
103         id: zoomCapture
104         onReleased: parent.captureImage()
105     }
106
107     ZoomCaptureCancel {
108         anchors.fill: parent
109         zoomCapture: zoomCapture
110         onCanceled: {
111             if (!autoFocusTimer.running) {
112                 cam.autoFocus.stopAutoFocus()
113             }
114         }
115     }
116
117     CameraToolBar {
118         id: toolBar
119         anchors.bottom: parent.bottom
120         anchors.bottomMargin: 20
121         anchors.left: parent.left
122         anchors.leftMargin: 20
123         opacity: 0.5
124         targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
125         visible: controlsVisible
126         expanded: settings.showToolBar
127         onExpandedChanged: settings.showToolBar = expanded
128         tools: CameraToolBarTools {
129             FlashButton {
130                 onClicked: toolBar.push(tools)
131             }
132
133             ImageSceneButton {
134                 onClicked: toolBar.push(tools)
135             }
136
137             ImageEvCompButton {
138                 onClicked: toolBar.push(tools)
139             }
140
141             ImageWhiteBalanceButton {
142                 onClicked: toolBar.push(tools)
143             }
144
145             ImageColorFilterButton {
146                 onClicked: toolBar.push(tools)
147             }
148
149             ImageIsoButton {
150                 onClicked: toolBar.push(tools)
151             }
152         }
153     }
154
155     Rectangle {
156         id: indicators
157         anchors.top: parent.top
158         anchors.topMargin: 20
159         anchors.left: parent.left
160         anchors.leftMargin: 20
161         width: 48
162         height: col.height
163         color: "black"
164         border.color: "gray"
165         radius: 20
166         opacity: 0.5
167         visible: controlsVisible
168
169         Column {
170             id: col
171             width: parent.width
172             spacing: 5
173
174             Indicator {
175                 id: flashIndicator
176                 visible: !toolBar.expanded
177                 source: cameraTheme.flashIcon(settings.imageFlashMode)
178             }
179
180             CameraLabel {
181                 anchors.left: parent.left
182                 anchors.right: parent.right
183                 anchors.leftMargin: 5
184                 anchors.rightMargin: 5
185                 anchors.topMargin: 5
186                 anchors.bottomMargin: 5
187                 property string mp: imageSettings.currentResolutionMegapixel == "" ? "?" : imageSettings.currentResolutionMegapixel
188                 text: qsTr("%1M").arg(mp)
189                 font.bold: true
190                 verticalAlignment: Text.AlignVCenter
191                 horizontalAlignment: Text.AlignHCenter
192             }
193
194             Indicator {
195                 id: wbIndicator
196                 source: visible ? cameraTheme.whiteBalanceIcon(settings.imageWhiteBalance) : ""
197                 visible: settings.imageWhiteBalance != WhiteBalance.Auto && !toolBar.expanded
198             }
199
200             Indicator {
201                 id: cfIndicator
202                 source: visible ? cameraTheme.colorFilterIcon(settings.imageColorFilter) : ""
203                 visible: settings.imageColorFilter != ColorTone.Normal && !toolBar.expanded
204             }
205
206             Indicator {
207                 id: isoIndicator
208                 visible: settings.imageIso != 0 && !toolBar.expanded
209                 source: visible ? cameraTheme.isoIcon(settings.imageIso) : ""
210             }
211
212             Indicator {
213                 id: sceneIndicator
214                 visible: settings.imageSceneMode != Scene.Auto && !toolBar.expanded
215                 source: visible ? cameraTheme.imageSceneModeIcon(settings.imageSceneMode) : ""
216             }
217
218             Indicator {
219                 id: gpsIndicator
220                 visible: settings.useGps
221                 source: cameraTheme.gpsIndicatorIcon
222
223                 PropertyAnimation on opacity  {
224                     easing.type: Easing.OutSine
225                     loops: Animation.Infinite
226                     from: 0.2
227                     to: 1.0
228                     duration: 1000
229                     running: settings.useGps && !positionSource.position.longitudeValid
230                     alwaysRunToEnd: true
231                 }
232             }
233
234             Indicator {
235                 id: faceDetectionIndicator
236                 visible: settings.faceDetectionEnabled
237                 source: cameraTheme.faceDetectionIndicatorIcon
238             }
239
240         }
241     }
242
243     function cameraError() {
244         mountProtector.unlock()
245     }
246
247     function policyLost() {
248         // Nothing
249     }
250
251     function batteryLow() {
252         // Nothing
253     }
254
255     function captureImage() {
256         if (!imageMode.canCapture) {
257             showError(qsTr("Camera is already capturing an image."))
258             cam.autoFocus.stopAutoFocus()
259         } else if (!checkBattery()) {
260             showError(qsTr("Not enough battery to capture images."))
261             cam.autoFocus.stopAutoFocus()
262         } else if (!fileSystem.available) {
263             showError(qsTr("Camera cannot capture images in mass storage mode."))
264             cam.autoFocus.stopAutoFocus()
265         } else if (!checkDiskSpace()) {
266             showError(qsTr("Not enough space to capture images."))
267             cam.autoFocus.stopAutoFocus()
268         } else if (!mountProtector.lock()) {
269             showError(qsTr("Failed to lock images directory."))
270             cam.autoFocus.stopAutoFocus()
271         } else {
272             metaData.setMetaData()
273
274             var fileName = fileNaming.imageFileName()
275             if (!imageMode.capture(fileName)) {
276                 showError(qsTr("Failed to capture image. Please restart the camera."))
277                 mountProtector.unlock()
278                 cam.autoFocus.stopAutoFocus()
279             } else {
280                 trackerStore.storeImage(fileName)
281             }
282         }
283     }
284
285 }