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