Added more icon IDs
[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         tools: CameraToolBarTools {
130             FlashButton {
131                 onClicked: toolBar.push(tools)
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                 source: "image://theme/" + Data.flashIcon(settings.imageFlashMode) + "-screen"
178             }
179
180             Indicator {
181                 id: resolutionIndicator
182                 property string imageAspectRatio: settings.device == 1 ? settings.secondaryImageAspectRatio : settings.primaryImageAspectRatio
183                 property string imageResolution: settings.device == 1 ? settings.secondaryImageResolution : settings.primaryImageResolution
184                 source: "image://theme/" + cameraTheme.imageIcon(imageAspectRatio, imageResolution, settings.device)
185             }
186
187             Indicator {
188                 id: wbIndicator
189                 source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
190                 visible: settings.imageWhiteBalance != WhiteBalance.Auto
191             }
192
193             Indicator {
194                 id: cfIndicator
195                 source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
196                 visible: settings.imageColorFilter != ColorTone.Normal
197             }
198
199             Indicator {
200                 id: isoIndicator
201                 visible: settings.imageIso != 0
202                 source: "image://theme/" + Data.isoIcon(settings.imageIso)
203             }
204
205             Indicator {
206                 id: gpsIndicator
207                 visible: settings.useGps
208                 source: cameraTheme.gpsIndicatorIcon
209
210                 PropertyAnimation on opacity  {
211                     easing.type: Easing.OutSine
212                     loops: Animation.Infinite
213                     from: 0.2
214                     to: 1.0
215                     duration: 1000
216                     running: settings.useGps && !positionSource.position.longitudeValid
217                     alwaysRunToEnd: true
218                 }
219             }
220
221             Indicator {
222                 id: faceDetectionIndicator
223                 visible: settings.faceDetectionEnabled
224                 source: cameraTheme.faceDetectionIndicatorIcon
225             }
226
227         }
228     }
229
230     function cameraError() {
231         mountProtector.unlock()
232     }
233
234     function policyLost() {
235         // Nothing
236     }
237
238     function batteryLow() {
239         // Nothing
240     }
241
242     function captureImage() {
243         if (!imageMode.canCapture) {
244             showError(qsTr("Camera is already capturing an image."))
245         } else if (!checkBattery()) {
246             showError(qsTr("Not enough battery to capture images."))
247         } else if (!fileSystem.available) {
248             showError(qsTr("Camera cannot capture images in mass storage mode."))
249         } else if (!checkDiskSpace()) {
250             showError(qsTr("Not enough space to capture images."))
251         } else if (!mountProtector.lock()) {
252             showError(qsTr("Failed to lock images directory."))
253         } else {
254             metaData.setMetaData()
255
256             var fileName = fileNaming.imageFileName()
257             if (!imageMode.capture(fileName)) {
258                 showError(qsTr("Failed to capture image. Please restart the camera."))
259                 mountProtector.unlock()
260             } else {
261                 trackerStore.storeImage(fileName)
262             }
263         }
264     }
265
266 }