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