Don't disable all interactions when standby is visible
[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
29 CameraPage {
30     id: root
31
32     property bool deviceChangeInProgress: false
33     property bool inCaptureMode: mainView.currentIndex == 1
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             if (!root.deviceChangeInProgress) {
103                 imageSettings.setImageResolution()
104             }
105         }
106
107         onImageResolutionChanged: {
108             if (!root.deviceChangeInProgress) {
109                 imageSettings.setImageResolution()
110             }
111         }
112
113         onVideoResolutionChanged: {
114             if (!root.deviceChangeInProgress) {
115                 videoSettings.setVideoResolution()
116             }
117         }
118
119         onVideoAspectRatioChanged: {
120             if (!root.deviceChangeInProgress) {
121                 videoSettings.setVideoResolution()
122             }
123         }
124     }
125
126     PipelineManager {
127         id: pipelineManager
128         camera: viewfinder.camera
129         currentItem: mainView.currentItem
130     }
131
132     function resetCamera(deviceId, mode) {
133         if (!viewfinder.camera.reset(deviceId, mode)) {
134             showError(qsTr("Failed to set camera device and mode. Please restart the application."))
135             return false
136         }
137
138         if (mode == Camera.ImageMode) {
139             imageSettings.setImageResolution()
140         }
141         else if (mode == Camera.VideoMode) {
142             videoSettings.setVideoResolution()
143         }
144
145         return true
146     }
147
148     function showError(msg) {
149         error.text = msg
150         error.show()
151     }
152
153     property alias dimmer: camDimmer
154     CameraPositionSource {
155         id: positionSource
156         active: settings.useGps
157         // TODO: we cannot bind to cam.running because camera will stop
158         // when the connection dialog pops up and we end up with an infinite loop
159         // active: cam.running && settings.useGps
160         onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude)
161     }
162
163     MetaData {
164         id: metaData
165         camera: viewfinder.camera
166         manufacturer: deviceInfo.manufacturer
167         model: deviceInfo.model
168         country: geocode.country
169         city: geocode.city
170         suburb: geocode.suburb
171         longitude: positionSource.longitude
172         longitudeValid: positionSource.longitudeValid && settings.useGps
173         latitude: positionSource.latitude
174         latitudeValid: positionSource.latitudeValid && settings.useGps
175         elevation: positionSource.altitude
176         elevationValid: positionSource.altitudeValid && settings.useGps
177         orientation: orientation.orientation
178         artist: settings.creatorName
179         captureDirection: compass.direction
180         captureDirectionValid: compass.directionValid
181         horizontalError: positionSource.horizontalAccuracy
182         horizontalErrorValid: positionSource.horizontalAccuracyValid && settings.useGps
183         dateTimeEnabled: true
184     }
185
186     CameraOrientation {
187         id: orientation
188         active: viewfinder.camera.running || (mainView.currentIndex == 2 && Qt.application.active)
189     }
190
191     CameraCompass {
192         id: compass
193         active: viewfinder.camera.running
194     }
195
196     ReverseGeocode {
197         id: geocode
198         active: viewfinder.camera.running && settings.useGps && settings.useGeotags
199     }
200
201     DeviceInfo {
202         id: deviceInfo
203     }
204
205     FSMonitor {
206         id: fileSystem
207     }
208
209     CameraInfoBanner {
210         id: error
211     }
212
213     FileNaming {
214         id: fileNaming
215         imageSuffix: viewfinder.camera.imageSuffix
216         videoSuffix: viewfinder.camera.videoSuffix
217         imagePath: platformSettings.imagePath
218         videoPath: platformSettings.videoPath
219         temporaryVideoPath: platformSettings.temporaryVideoPath
220         settings: settings
221     }
222
223     MountProtector {
224         id: mountProtector
225     }
226
227     TrackerStore {
228         id: trackerStore
229         active: viewfinder.camera.running
230         manufacturer: deviceInfo.manufacturer
231         model: deviceInfo.model
232     }
233
234     ImageSettings {
235         id: imageSettings
236         camera: viewfinder.camera
237
238         function setImageResolution() {
239             if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
240                 showError(qsTr("Failed to set required resolution"))
241             }
242         }
243     }
244
245     VideoSettings {
246         id: videoSettings
247         camera: viewfinder.camera
248
249         function setVideoResolution() {
250             if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
251                 showError(qsTr("Failed to set required resolution"))
252             }
253         }
254     }
255
256     ModeController {
257         id: cameraMode
258         cam: viewfinder.camera
259         dimmer: root.dimmer
260     }
261
262     Rectangle {
263         property bool dimmed: false
264         id: camDimmer
265         z: 1
266         anchors.fill: parent
267         opacity: dimmed ? 1.0 : 0.0
268         color: "black"
269         Behavior on opacity {
270             PropertyAnimation { duration: 150 }
271         }
272     }
273
274     DeviceKeys {
275         id: keys
276         active: Qt.application.active && pipelineManager.scaleAcquired && root.inCaptureMode && !mainView.moving
277         repeat: !settings.zoomAsShutter
278     }
279
280     CameraProximitySensor {
281         id: proximitySensor
282         active: Qt.application.active && viewfinder.camera.running && settings.proximityAsShutter && root.inCaptureMode && !mainView.moving
283     }
284
285     Standby {
286         policyLost: pipelineManager.state == "policyLost"
287         show: !Qt.application.active || pipelineManager.showStandBy ||
288             (inCaptureMode && !viewfinder.camera.running)
289     }
290 }