Use Component as the type for initialPage in harmattan CameraWindow
[harmattan/cameraplus] / qml / MainPage.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 // TODO: flash not ready (battery low or flash not ready message)
28 // TODO: Sounds
29 // TODO: N950 conf
30
31 CameraPage {
32     id: root
33
34     property bool deviceChangeInProgress: false
35     property bool inCaptureMode: mainView.currentIndex == 1
36     property Item dimmer: camDimmer
37
38     CameraTheme {
39         id: cameraTheme
40     }
41
42     VisualItemModel {
43         id: mainModel
44
45         SettingsView {
46             camera: viewfinder.camera
47             width: mainView.width
48             height: mainView.height
49         }
50
51         CameraView {
52             id: viewfinder
53             width: mainView.width
54             height: mainView.height
55         }
56
57         PostCaptureView {
58             camera: viewfinder.camera
59             width: mainView.width
60             height: mainView.height
61         }
62     }
63
64     ListView {
65         id: mainView
66         LayoutMirroring.enabled: false
67         anchors.fill: parent
68         orientation: ListView.Horizontal
69         model: mainModel
70         snapMode: ListView.SnapOneItem
71         highlightRangeMode: ListView.StrictlyEnforceRange
72         boundsBehavior: Flickable.StopAtBounds
73         currentIndex: 1
74         interactive: !currentItem.pressed
75     }
76
77     Component.onCompleted: {
78         platformSettings.init()        
79         root.resetCamera(settings.device, settings.mode)
80     }
81
82     PlatformSettings {
83         id: platformSettings
84     }
85
86     Settings {
87         id: settings
88         onDeviceAboutToChange: {
89             root.deviceChangeInProgress = true
90         }
91
92         onDeviceChanged: {
93             viewfinder.cameraDeviceChanged()
94
95             // Reset pipeline manager error
96             pipelineManager.error = false
97
98             if (root.resetCamera(settings.device, settings.mode)) {
99                 root.deviceChangeInProgress = false
100                 pipelineManager.startCamera()
101             }
102         }
103
104         onImageAspectRatioChanged: {
105             if (!root.deviceChangeInProgress) {
106                 imageSettings.setImageResolution()
107             }
108         }
109
110         onImageResolutionChanged: {
111             if (!root.deviceChangeInProgress) {
112                 imageSettings.setImageResolution()
113             }
114         }
115
116         onVideoResolutionChanged: {
117             if (!root.deviceChangeInProgress) {
118                 videoSettings.setVideoResolution()
119             }
120         }
121
122         onVideoAspectRatioChanged: {
123             if (!root.deviceChangeInProgress) {
124                 videoSettings.setVideoResolution()
125             }
126         }
127     }
128
129     PipelineManager {
130         id: pipelineManager
131         camera: viewfinder.camera
132         currentItem: mainView.currentItem
133     }
134
135     function resetCamera(deviceId, mode) {
136         if (!viewfinder.camera.reset(deviceId, mode)) {
137             showError(qsTr("Failed to set camera device and mode. Please restart the application."))
138             return false
139         }
140
141         if (mode == Camera.ImageMode) {
142             imageSettings.setImageResolution()
143         }
144         else if (mode == Camera.VideoMode) {
145             videoSettings.setVideoResolution()
146         }
147
148         return true
149     }
150
151     function showError(msg) {
152         error.text = msg
153         error.show()
154     }
155
156     PlatformQuirks {
157         id: platformQuirks
158     }
159
160     DisplayState {
161         id: displayState
162         inhibitDim: mainView.currentItem != null ? mainView.currentItem.inhibitDim : false
163     }
164
165     CameraPositionSource {
166         id: positionSource
167         active: (viewfinder.camera.running || platformQuirks.forceOn) && settings.useGps && displayState.isOn
168         onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude)
169     }
170
171     MetaData {
172         id: metaData
173         camera: viewfinder.camera
174         manufacturer: deviceInfo.manufacturer
175         model: deviceInfo.model
176         country: geocode.country
177         city: geocode.city
178         suburb: geocode.suburb
179         longitude: positionSource.longitude
180         longitudeValid: positionSource.longitudeValid && settings.useGps
181         latitude: positionSource.latitude
182         latitudeValid: positionSource.latitudeValid && settings.useGps
183         elevation: positionSource.altitude
184         elevationValid: positionSource.altitudeValid && settings.useGps
185         orientation: orientation.orientation
186         artist: settings.creatorName
187         captureDirection: compass.direction
188         captureDirectionValid: compass.directionValid
189         horizontalError: positionSource.horizontalAccuracy
190         horizontalErrorValid: positionSource.horizontalAccuracyValid && settings.useGps
191         dateTimeEnabled: true
192     }
193
194     CameraOrientation {
195         id: orientation
196         active: viewfinder.camera.running || (mainView.currentIndex == 2 && Qt.application.active)
197     }
198
199     CameraCompass {
200         id: compass
201         active: viewfinder.camera.running
202     }
203
204     ReverseGeocode {
205         id: geocode
206         active: (viewfinder.camera.running || platformQuirks.forceOn) && settings.useGps && settings.useGeotags && displayState.isOn
207     }
208
209     DeviceInfo {
210         id: deviceInfo
211     }
212
213     FSMonitor {
214         id: fileSystem
215     }
216
217     CameraInfoBanner {
218         id: error
219     }
220
221     FileNaming {
222         id: fileNaming
223         imageSuffix: viewfinder.camera.imageSuffix
224         videoSuffix: viewfinder.camera.videoSuffix
225         imagePath: platformSettings.imagePath
226         videoPath: platformSettings.videoPath
227         temporaryVideoPath: platformSettings.temporaryVideoPath
228         settings: settings
229     }
230
231     MountProtector {
232         id: mountProtector
233     }
234
235     TrackerStore {
236         id: trackerStore
237         active: viewfinder.camera.running
238         manufacturer: deviceInfo.manufacturer
239         model: deviceInfo.model
240     }
241
242     ImageSettings {
243         id: imageSettings
244         camera: viewfinder.camera
245
246         function setImageResolution() {
247             if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
248                 showError(qsTr("Failed to set required resolution"))
249             }
250         }
251     }
252
253     VideoSettings {
254         id: videoSettings
255         camera: viewfinder.camera
256
257         function setVideoResolution() {
258             if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
259                 showError(qsTr("Failed to set required resolution"))
260             }
261         }
262     }
263
264     ModeController {
265         id: cameraMode
266         cam: viewfinder.camera
267         dimmer: root.dimmer
268     }
269
270     Rectangle {
271         property bool dimmed: false
272         id: camDimmer
273         z: 1
274         anchors.fill: parent
275         opacity: dimmed ? 1.0 : 0.0
276         color: "black"
277         Behavior on opacity {
278             PropertyAnimation { duration: 150 }
279         }
280     }
281
282     DeviceKeys {
283         id: keys
284         active: Qt.application.active && pipelineManager.scaleAcquired && root.inCaptureMode && !mainView.moving
285         repeat: !settings.zoomAsShutter
286     }
287
288     Timer {
289         id: proximityTimer
290         running: proximitySensor.close
291         repeat: false
292         interval: 500
293         onTriggered: {
294             if (proximitySensor.close) {
295                 proximitySensor.sensorClosed = true
296             }
297         }
298     }
299
300     CameraProximitySensor {
301         id: proximitySensor
302         property bool sensorClosed: false
303
304         active: Qt.application.active && viewfinder.camera.running && settings.proximityAsShutter && root.inCaptureMode && !mainView.moving
305         onCloseChanged: {
306             if (!close) {
307                 sensorClosed = false
308             }
309         }
310     }
311
312     Standby {
313         policyLost: pipelineManager.state == "policyLost"
314         show: !Qt.application.active || pipelineManager.showStandBy ||
315             (inCaptureMode && !viewfinder.camera.running)
316     }
317 }