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