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