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