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