Added copyright headers and COPYING file.
[harmattan/cameraplus] / qml / VideoPage.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 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 // TODO: video recording indicators.
30 // TODO: stop recording when battery low
31 // TODO: stop recording when disk is low
32 CameraPage {
33         id: page
34
35         policyMode: CameraResources.Video
36
37         controlsVisible: videoControlsVisible && !videoMode.recording
38         property bool videoControlsVisible: recording.visible && cam.running && !standbyWidget.visible
39
40         orientationLock: PageOrientation.LockLandscape
41
42         DisplayState {
43                 inhibitDim: videoMode.recording
44         }
45
46         Button {
47                 id: recording
48                 anchors.right: parent.right
49                 anchors.rightMargin: 20
50                 anchors.verticalCenter: parent.verticalCenter
51                 iconSource: "image://theme/icon-m-camera-video-record"
52                 width: 75
53                 height: 75
54                 opacity: 0.5
55
56                 onClicked: {
57                         if (!fileSystem.available) {
58                                 showError(qsTr("Camera cannot record videos in mass storage mode."));
59                                 return;
60                         }
61
62                         // We only toggle the mode to video recording so
63                         // policy can acquire the needed resources
64
65                         if (policyMode == CameraResources.Video) {
66                                 policyMode = CameraResources.Recording;
67                         }
68                         else if (videoMode.recording) {
69                                 // We just ask to stop video.
70                                 videoMode.stopRecording();
71                         }
72                 }
73
74                 Connections {
75                         target: videoMode
76                         onRecordingChanged: {
77                                 if (!videoMode.recording) {
78                                         policyMode = CameraResources.Video;
79                                 }
80                         }
81                 }
82
83                 Connections {
84                         target: resourcePolicy
85                         onAcquiredChanged: {
86                                 if (resourcePolicy.acquired && policyMode == CameraResources.Recording) {
87                                         metaData.setMetaData();
88                                         if (!videoMode.startRecording(fileNaming.videoFileName())) {
89                                                 showError(qsTr("Failed to record video. Please restart the camera."));
90                                                 policyMode = CameraResources.Video
91 }
92                                 }
93                         }
94                 }
95
96                 visible: (videoMode.recording || videoMode.canCapture) && !cameraMode.animationRunning && !previewAnimationRunning && !standbyWidget.visible
97         }
98
99         Connections {
100                 target: Qt.application
101                 onActiveChanged: {
102                         if (!Qt.application.active && videoMode.recording) {
103                                 videoMode.stopRecording();
104                         }
105                 }
106         }
107
108         VideoMode {
109                 id: videoMode
110                 camera: cam
111                 onPreviewAvailable: {
112                         if (!standbyWidget.visible) {
113                                 page.setPreview(preview);
114                         }
115                 }
116         }
117
118         VideoTorchButton {
119                 id: torch
120                 visible: videoControlsVisible
121                 anchors.top: parent.top
122                 anchors.left: parent.left
123                 anchors.topMargin: 20
124                 anchors.leftMargin: 20
125                 opacity: 0.5
126         }
127
128         VideoSceneButton {
129                 id: scene
130                 visible: controlsVisible
131                 anchors.top: torch.bottom
132                 anchors.left: parent.left
133                 anchors.topMargin: 10
134                 anchors.leftMargin: 20
135         }
136
137         EvCompButton {
138                 id: evComp
139                 visible: videoControlsVisible
140                 anchors.top: scene.bottom
141                 anchors.left: parent.left
142                 anchors.topMargin: 10
143                 anchors.leftMargin: 20
144         }
145
146         MouseArea {
147                 id: indicators
148                 anchors.bottom: parent.bottom
149                 anchors.bottomMargin: 20
150                 anchors.left: parent.left
151                 anchors.leftMargin: 20
152                 width: 48
153                 height: col.height
154                 onClicked: openFile("VideoSettingsPage.qml");
155                 visible: controlsVisible
156
157                 BorderImage {
158                         id: image
159                         anchors.fill: parent
160                         smooth: true
161                         source: indicators.pressed ? "image://theme/meegotouch-camera-settings-indicators-background-pressed" : "image://theme/meegotouch-camera-settings-indicators-background"
162                 }
163
164                 Column {
165                         id: col
166                         width: parent.width
167                         spacing: 5
168
169                         Indicator {
170                                 id: resolutionIndicator
171                                 // TODO:
172                         }
173
174                         Indicator {
175                                 id: wbIndicator
176                                 source: "image://theme/" + Data.wbIcon(settings.videoWhiteBalance) + "-screen"
177                                 visible: settings.videoWhiteBalance != WhiteBalance.Auto
178                         }
179
180                         Indicator {
181                                 id: cfIndicator
182                                 source: "image://theme/" + Data.cfIcon(settings.videoColorFilter) + "-screen"
183                                 visible: settings.videoColorFilter != ColorTone.Normal
184                         }
185
186                         Indicator {
187                                 id: gpsIndicator
188                                 visible: settings.useGps
189                                 source: "image://theme/icon-m-camera-location"
190
191                                 PropertyAnimation on opacity  {
192                                         easing.type: Easing.OutSine
193                                         loops: Animation.Infinite
194                                         from: 0.2
195                                         to: 1.0
196                                         duration: 1000
197                                         running: settings.useGps && !positionSource.position.longitudeValid
198                                         alwaysRunToEnd: true
199                                 }
200                         }
201                 }
202         }
203
204         Button {
205                 id: cameraRoll
206                 anchors.top: parent.top
207                 anchors.right: parent.right
208                 anchors.topMargin: 20
209                 anchors.rightMargin: 20
210                 width: 56
211                 height: 56
212
213                 opacity: 0.5
214                 iconSource: "image://theme/icon-m-camera-roll"
215                 onClicked: openFile("PostCapturePage.qml");
216                 visible: controlsVisible && !videoMode.recording
217         }
218 }