Kill com.nokia.meego importing in the ui.
[harmattan/cameraplus] / qml / VideoOverlay.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_QT_QUICK@
24 import QtCamera 1.0
25 import CameraPlus 1.0
26 import "data.js" as Data
27
28 Item {
29     id: overlay
30     property bool recording: false
31
32     property Camera cam
33     property bool animationRunning: false
34     property int policyMode: recording == true ? CameraResources.Recording : CameraResources.Video
35     property bool controlsVisible: !animationRunning && cam != null && cam.running
36         && dimmer.opacity == 0.0 && !cameraMode.busy
37     property bool pressed: overlay.recording || capture.pressed ||
38         zoomSlider.pressed || modeButton.pressed
39
40     signal previewAvailable(string uri)
41
42     anchors.fill: parent
43
44     VideoMode {
45         id: videoMode
46         camera: cam
47         onPreviewAvailable: overlay.previewAvailable(preview)
48     }
49
50     ZoomSlider {
51         id: zoomSlider
52         camera: cam
53         anchors.top: parent.top
54         anchors.topMargin: 0
55         anchors.horizontalCenter: parent.horizontalCenter
56         visible: controlsVisible
57     }
58
59     ModeButton {
60         id: modeButton
61         anchors.bottom: parent.bottom
62         anchors.right: parent.right
63         anchors.rightMargin: 20
64         anchors.bottomMargin: 20
65         visible: controlsVisible && !overlay.recording
66     }
67
68     ZoomCaptureButton {
69         id: zoomCapture
70         onReleased: overlay.toggleRecording()
71     }
72
73     ZoomCaptureCancel {
74         anchors.fill: parent
75         zoomCapture: zoomCapture
76     }
77
78     CaptureButton {
79         id: capture
80         anchors.right: parent.right
81         anchors.rightMargin: 20
82         anchors.verticalCenter: parent.verticalCenter
83         iconSource: overlay.recording ? "image://theme/icon-m-camera-video-record" : "image://theme/icon-m-camera-video-record"
84         width: 75
85         height: 75
86         opacity: 0.5
87
88         onClicked: overlay.toggleRecording()
89
90         visible: controlsVisible && (!settings.zoomAsShutter && keys.active)
91     }
92
93     CameraToolBar {
94         id: toolBar
95         anchors.bottom: parent.bottom
96         anchors.bottomMargin: 20
97         anchors.left: parent.left
98         anchors.leftMargin: 20
99         opacity: 0.5
100         targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
101         visible: controlsVisible
102         expanded: settings.showToolBar
103         onExpandedChanged: settings.showToolBar = expanded;
104
105         items: [
106             VideoTorchButton {
107                 camera: cam
108             },
109             VideoSceneButton {
110 // TODO: hide when recording
111                 onClicked: toolBar.push(items)
112             },
113             VideoEvCompButton {
114                 onClicked: toolBar.push(items)
115             },
116             VideoWhiteBalanceButton {
117                 onClicked: toolBar.push(items)
118             },
119             VideoColorFilterButton {
120                 onClicked: toolBar.push(items)
121             },
122             VideoMuteButton {
123             }
124         ]
125     }
126
127     Rectangle {
128         anchors.top: parent.top
129         anchors.topMargin: 20
130         anchors.left: parent.left
131         anchors.leftMargin: 20
132         width: 48
133         height: col.height
134         color: "black"
135         border.color: "gray"
136         radius: 20
137         opacity: 0.5
138         visible: controlsVisible
139
140         Column {
141             id: col
142             width: parent.width
143             spacing: 5
144
145             Indicator {
146                 id: resolutionIndicator
147                 source: "image://theme/" + Data.videoIcon(settings.videoResolution)
148             }
149
150             Indicator {
151                 id: wbIndicator
152                 source: visible ? "image://theme/" + Data.wbIcon(settings.videoWhiteBalance) + "-screen" : ""
153                 visible: settings.videoWhiteBalance != WhiteBalance.Auto
154             }
155
156             Indicator {
157                 id: cfIndicator
158                 source: "image://theme/" + Data.cfIcon(settings.videoColorFilter) + "-screen"
159                 visible: settings.videoColorFilter != ColorTone.Normal
160             }
161
162             Indicator {
163                 id: gpsIndicator
164                 visible: settings.useGps
165                 source: "image://theme/icon-m-camera-location"
166
167                 PropertyAnimation on opacity  {
168                     easing.type: Easing.OutSine
169                     loops: Animation.Infinite
170                     from: 0.2
171                     to: 1.0
172                     duration: 1000
173                     running: settings.useGps && !positionSource.position.longitudeValid
174                     alwaysRunToEnd: true
175                 }
176             }
177         }
178     }
179
180     DisplayState {
181         inhibitDim: overlay.recording
182     }
183
184     Connections {
185         target: Qt.application
186         onActiveChanged: {
187             if (!Qt.application.active && overlay.recording) {
188                 overlay.stopRecording()
189             }
190         }
191     }
192
193     Timer {
194         id: recordingDuration
195         property int duration: 0
196         running: overlay.recording
197         interval: 1000
198         repeat: true
199
200         onTriggered: {
201             duration = duration + 1
202
203             if (duration == 3600) {
204                 overlay.stopRecording()
205                 showError(qsTr("Maximum recording time reached."))
206             } else if (!checkDiskSpace()) {
207                 page.stopRecording()
208                 showError(qsTr("Not enough space to continue recording."))
209             }
210
211         }
212     }
213
214     RecordingDurationLabel {
215         visible: overlay.recording
216         duration: recordingDuration.duration
217     }
218
219     function doStartRecording() {
220         if (!overlay.recording) {
221             return
222         }
223
224         if (!pipelineManager.acquired || pipelineManager.hijacked) {
225             showError(qsTr("Failed to acquire needed resources."))
226             overlay.recording = false
227             return
228         }
229
230         metaData.setMetaData()
231
232         if (!mountProtector.lock()) {
233             showError(qsTr("Failed to lock images directory."))
234             overlay.recording = false
235             return
236         }
237
238         var file = fileNaming.videoFileName()
239         var tmpFile = fileNaming.temporaryVideoFileName()
240
241         if (!videoMode.startRecording(file, tmpFile)) {
242             showError(qsTr("Failed to record video. Please restart the camera."))
243             mountProtector.unlock()
244             overlay.recording = false
245             return
246         }
247
248         trackerStore.storeVideo(file);
249     }
250
251     function startRecording() {
252         if (!fileSystem.available) {
253             showError(qsTr("Camera cannot record videos in mass storage mode."))
254         } else if (!checkBattery()) {
255             showError(qsTr("Not enough battery to record video."))
256         } else if (!checkDiskSpace()) {
257             showError(qsTr("Not enough space to record video."))
258         } else {
259             recordingDuration.duration = 0
260             overlay.recording = true
261             doStartRecording()
262         }
263     }
264
265     function stopRecording() {
266         videoMode.stopRecording(true)
267         mountProtector.unlock()
268         overlay.recording = false
269     }
270
271     function toggleRecording() {
272         if (overlay.recording) {
273             overlay.stopRecording()
274         } else {
275             overlay.startRecording()
276         }
277     }
278
279     function cameraError() {
280         overlay.stopRecording()
281     }
282
283     function policyLost() {
284         overlay.stopRecording()
285     }
286
287     function batteryLow() {
288         if (!overlay.recording) {
289             return
290         }
291
292         if (!checkBattery()) {
293             overlay.stopRecording()
294             showError(qsTr("Not enough battery to record video."))
295         }
296     }
297
298 }