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