Added ImageSettings::currentResolution and methods to find ImageResolution and set it
[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         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                 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                 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                 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                 visible: cam.device == 0
132             }
133
134             ImageSceneButton {
135                 onClicked: toolBar.push(tools)
136             }
137
138             ImageEvCompButton {
139                 onClicked: toolBar.push(tools)
140             }
141
142             ImageWhiteBalanceButton {
143                 onClicked: toolBar.push(tools)
144             }
145
146             ImageColorFilterButton {
147                 onClicked: toolBar.push(tools)
148             }
149
150             ImageIsoButton {
151                 onClicked: toolBar.push(tools)
152             }
153         }
154     }
155
156     Rectangle {
157         id: indicators
158         anchors.top: parent.top
159         anchors.topMargin: 20
160         anchors.left: parent.left
161         anchors.leftMargin: 20
162         width: 48
163         height: col.height
164         color: "black"
165         border.color: "gray"
166         radius: 20
167         opacity: 0.5
168         visible: controlsVisible
169
170         Column {
171             id: col
172             width: parent.width
173             spacing: 5
174
175             Indicator {
176                 id: flashIndicator
177                 visible: !toolBar.expanded && cam.device == 0
178                 source: cameraTheme.flashIcon(settings.imageFlashMode)
179             }
180
181             CameraLabel {
182                 anchors.left: parent.left
183                 anchors.right: parent.right
184                 anchors.leftMargin: 5
185                 anchors.rightMargin: 5
186                 anchors.topMargin: 5
187                 anchors.bottomMargin: 5
188                 text: imageSettings.currentResolution ? qsTr("%1M").arg(imageSettings.currentResolution.megaPixels) : qsTr("?M")
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(fileNaming.imagePath)
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             stopAutoFocus()
259         } else if (!checkBattery()) {
260             showError(qsTr("Not enough battery to capture images."))
261             stopAutoFocus()
262         } else if (!fileSystem.available) {
263             showError(qsTr("Camera cannot capture images in mass storage mode."))
264             stopAutoFocus()
265         } else if (!fileSystem.hasFreeSpace(fileNaming.imagePath)) {
266             showError(qsTr("Not enough space to capture images."))
267             stopAutoFocus()
268         } else if (!mountProtector.lock(fileNaming.imagePath)) {
269             showError(qsTr("Failed to lock images directory."))
270             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(fileNaming.imagePath)
278                 stopAutoFocus()
279             } else {
280                 trackerStore.storeImage(fileName)
281             }
282         }
283     }
284
285     function startAutoFocus() {
286         if (cam.device == 0) {
287             cam.autoFocus.startAutoFocus()
288         }
289     }
290
291     function stopAutoFocus() {
292         if (cam.device == 0) {
293             cam.autoFocus.stopAutoFocus()
294         }
295     }
296
297 }