fe01b37ab8b3f56b8fa922ac7fe4a4c105e8bb67
[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 import "data.js" as Data
27
28 Item {
29     id: overlay
30
31     property Camera cam
32     property bool animationRunning: false
33     property int policyMode: CameraResources.Image
34     property bool pressed: capture.pressed || zoomSlider.pressed || modeButton.pressed
35     property bool controlsVisible: imageMode.canCapture && cam.running && !animationRunning
36         && dimmer.opacity == 0.0 && !cameraMode.busy
37
38     signal previewAvailable(string uri)
39
40     anchors.fill: parent
41
42     ImageMode {
43         id: imageMode
44         camera: cam
45         onPreviewAvailable: {
46             overlay.previewAvailable(preview)
47             cam.autoFocus.stopAutoFocus()
48         }
49
50         onSaved: mountProtector.unlock()
51     }
52
53     ZoomSlider {
54         id: zoomSlider
55         camera: cam
56         anchors.top: parent.top
57         anchors.topMargin: 0
58         anchors.horizontalCenter: parent.horizontalCenter
59         visible: controlsVisible
60     }
61
62     ModeButton {
63         id: modeButton
64         anchors.bottom: parent.bottom
65         anchors.right: parent.right
66         anchors.rightMargin: 20
67         anchors.bottomMargin: 20
68         visible: controlsVisible
69     }
70
71     CaptureButton {
72         id: capture
73         anchors.right: parent.right
74         anchors.rightMargin: 20
75         anchors.verticalCenter: parent.verticalCenter
76         iconId: cameraTheme.captureButtonImageIconId
77         width: 75
78         height: 75
79         opacity: 0.5
80         onClicked: captureImage()
81         visible: controlsVisible && (!settings.zoomAsShutter && keys.active)
82
83         onExited: {
84             if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
85                 // Release outside the button:
86                 cam.autoFocus.stopAutoFocus()
87             }
88         }
89     }
90
91     Timer {
92         id: autoFocusTimer
93         interval: 200
94         running: capture.pressed || zoomCapture.zoomPressed
95         repeat: false
96         onTriggered: {
97             if (cam.autoFocus.cafStatus != AutoFocus.Success) {
98                 cam.autoFocus.startAutoFocus()
99             }
100         }
101     }
102
103     ZoomCaptureButton {
104         id: zoomCapture
105         onReleased: parent.captureImage()
106     }
107
108     ZoomCaptureCancel {
109         anchors.fill: parent
110         zoomCapture: zoomCapture
111         onCanceled: {
112             if (!autoFocusTimer.running) {
113                 cam.autoFocus.stopAutoFocus()
114             }
115         }
116     }
117
118     CameraToolBar {
119         id: toolBar
120         anchors.bottom: parent.bottom
121         anchors.bottomMargin: 20
122         anchors.left: parent.left
123         anchors.leftMargin: 20
124         opacity: 0.5
125         targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
126         visible: controlsVisible
127         expanded: settings.showToolBar
128         onExpandedChanged: settings.showToolBar = expanded
129         items: [
130             FlashButton {
131                 onClicked: toolBar.push(items)
132             },
133             ImageSceneButton {
134                 onClicked: toolBar.push(items)
135             },
136             ImageEvCompButton {
137                 onClicked: toolBar.push(items)
138             },
139             ImageWhiteBalanceButton {
140                 onClicked: toolBar.push(items)
141             },
142             ImageColorFilterButton {
143                 onClicked: toolBar.push(items)
144             },
145             ImageIsoButton {
146                 onClicked: toolBar.push(items)
147             }
148         ]
149     }
150
151     Rectangle {
152         id: indicators
153         anchors.top: parent.top
154         anchors.topMargin: 20
155         anchors.left: parent.left
156         anchors.leftMargin: 20
157         width: 48
158         height: col.height
159         color: "black"
160         border.color: "gray"
161         radius: 20
162         opacity: 0.5
163         visible: controlsVisible
164
165         Column {
166             id: col
167             width: parent.width
168             spacing: 5
169
170             Indicator {
171                 id: resolutionIndicator
172                 source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution)
173             }
174
175             Indicator {
176                 id: wbIndicator
177                 source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
178                 visible: settings.imageWhiteBalance != WhiteBalance.Auto
179             }
180
181             Indicator {
182                 id: cfIndicator
183                 source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
184                 visible: settings.imageColorFilter != ColorTone.Normal
185             }
186
187             Indicator {
188                 id: isoIndicator
189                 visible: settings.imageIso != 0
190                 source: "image://theme/" + Data.isoIcon(settings.imageIso)
191             }
192
193             Indicator {
194                 id: gpsIndicator
195                 visible: settings.useGps
196                 source: cameraTheme.gpsIndicatorIcon
197
198                 PropertyAnimation on opacity  {
199                     easing.type: Easing.OutSine
200                     loops: Animation.Infinite
201                     from: 0.2
202                     to: 1.0
203                     duration: 1000
204                     running: settings.useGps && !positionSource.position.longitudeValid
205                     alwaysRunToEnd: true
206                 }
207             }
208
209             Indicator {
210                 id: faceDetectionIndicator
211                 visible: settings.faceDetectionEnabled
212                 source: cameraTheme.faceDetectionIndicatorIcon
213             }
214
215         }
216     }
217
218     function cameraError() {
219         mountProtector.unlock()
220     }
221
222     function policyLost() {
223         // Nothing
224     }
225
226     function batteryLow() {
227         // Nothing
228     }
229
230     function captureImage() {
231         if (!imageMode.canCapture) {
232             showError(qsTr("Camera is already capturing an image."))
233         } else if (!checkBattery()) {
234             showError(qsTr("Not enough battery to capture images."))
235         } else if (!fileSystem.available) {
236             showError(qsTr("Camera cannot capture images in mass storage mode."))
237         } else if (!checkDiskSpace()) {
238             showError(qsTr("Not enough space to capture images."))
239         } else if (!mountProtector.lock()) {
240             showError(qsTr("Failed to lock images directory."))
241         } else {
242             metaData.setMetaData()
243
244             var fileName = fileNaming.imageFileName()
245             if (!imageMode.capture(fileName)) {
246                 showError(qsTr("Failed to capture image. Please restart the camera."))
247                 mountProtector.unlock()
248             } else {
249                 trackerStore.storeImage(fileName)
250             }
251         }
252     }
253
254 }