4 * This file is part of CameraPlus.
6 * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
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.
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.
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
24 import com.nokia.meego 1.1
25 import com.nokia.extras 1.1
28 import QtMobility.location 1.2
30 // TODO: flash not ready (battery low or flash not ready message)
35 property alias dimmer: camDimmer
44 enabled: pageStack.busy
47 Component.onCompleted: {
48 theme.inverted = true;
49 // TODO: hardcoding device id
50 root.resetCamera(0, settings.mode);
53 function showError(msg) {
58 function resetCamera(deviceId, mode) {
59 if (!cam.reset(deviceId, mode)) {
60 showError(qsTr("Failed to set camera device and mode. Please restart the application."));
65 // NOTE: The source will not reset the position when we lose the signal.
66 // This shouldn't be a big problem as we are course enough.
67 // If we ever need street level updates then this will be an issue.
69 active: settings.useGps
70 // TODO: we cannot bind to cam.running because camera will stop
71 // when the connection dialog pops up and we end up with an infinite loop
72 // active: cam.running && settings.useGps
73 onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude);
79 manufacturer: deviceInfo.manufacturer
80 model: deviceInfo.model
81 country: geocode.country
83 suburb: geocode.suburb
84 longitude: positionSource.position.coordinate.longitude
85 longitudeValid: positionSource.position.longitudeValid && settings.useGps
86 latitude: positionSource.position.coordinate.latitude
87 latitudeValid: positionSource.position.latitudeValid && settings.useGps
88 elevation: positionSource.position.coordinate.altitude
89 elevationValid: positionSource.position.altitudeValid && settings.useGps
90 orientation: orientation.orientation
91 artist: settings.creatorName
92 captureDirection: compass.direction
93 captureDirectionValid: compass.directionValid
94 horizontalError: positionSource.position.horizontalAccuracy
95 horizontalErrorValid: positionSource.position.horizontalAccuracyValid && settings.useGps
111 active: cam.running && settings.useGps && settings.useGeotags
137 imageSuffix: cam.imageSuffix
138 videoSuffix: cam.videoSuffix
143 path: fileNaming.path
151 if (!checkBattery()) {
152 pageStack.currentPage.batteryLow();
157 batteryMonitor.check();
161 batteryMonitor.check();
165 function replacePage(file) {
166 pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
169 function openFile(file) {
170 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
173 function openFileNow(file) {
174 pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
177 function checkBattery() {
178 // We are fine if we are connected to the charger:
179 if (batteryMonitor.charging) {
183 // If we have enough battery then we are fine:
184 if (!batteryMonitor.critical) {
194 function setImageResolution() {
195 if (!imageSettings.setResolution(settings.imageAspectRatio, settings.imageResolution)) {
196 showError(qsTr("Failed to set required resolution"));
202 imageSettings.setImageResolution();
211 function setVideoResolution() {
212 if (!videoSettings.setResolution(settings.videoAspectRatio, settings.videoResolution)) {
213 showError(qsTr("Failed to set required resolution"));
219 videoSettings.setVideoResolution();
227 onImageAspectRatioChanged: {
228 imageSettings.setImageResolution();
231 onImageResolutionChanged: {
232 imageSettings.setImageResolution();
235 onVideoResolutionChanged: {
236 videoSettings.setVideoResolution();
244 onRoiChanged: roi.normalize = false;
249 width: cam.renderArea.width
250 height: cam.renderArea.height
251 visible: settings.gridEnabled
257 visible: pageStack.currentPage && pageStack.currentPage.controlsVisible && pageStack.currentPage.focusReticleVisible && cam && cam.autoFocus.canFocus(cam.scene.value);
258 cafStatus: cam ? cam.autoFocus.cafStatus : -1
259 status: cam ? cam.autoFocus.status : -1
263 if (pipelineManager.error) {
264 // Ignore any subsequent errors.
265 // Killing pulseaudio while recording will lead to an
266 // infinite supply of errors which will break the UI
267 // if we show a banner for each.
271 pipelineManager.error = true;
272 pageStack.currentPage.cameraError();
273 console.log("Camera error (" + code + "): " + message + " " + debug);
274 showError(qsTr("Camera error. Please restart the application."));
276 // We cannot stop camera here. Seems there is a race condition somewhere
277 // which leads to a freeze if we do so.
282 mountProtector.unlock();
286 Component.onDestruction: cam.stop();
288 // We need to show viewfinder below pages.
292 property bool dimmed: false
296 opacity: dimmed ? 1.0 : 0.0
298 Behavior on opacity {
299 PropertyAnimation { duration: 150 }
303 notifications: Sounds {
305 mute: !settings.soundEnabled
313 when: cam.mode == Camera.ImageMode
314 value: settings.imageFlashMode
319 property: "imageFlashMode"
320 when: cam.mode == Camera.ImageMode
321 value: cam.flash.value
327 when: cam.mode == Camera.VideoMode
328 value: settings.videoSceneMode
334 when: cam.mode == Camera.ImageMode
335 value: settings.imageSceneMode
341 when: cam.mode == Camera.ImageMode
342 value: settings.imageEvComp
348 when: cam.mode == Camera.VideoMode
349 value: settings.videoEvComp
354 property: "imageEvComp"
355 when: cam.mode == Camera.ImageMode
356 value: cam.evComp.value
361 property: "videoEvComp"
362 when: cam.mode == Camera.VideoMode
363 value: cam.evComp.value
367 target: cam.whiteBalance
369 when: cam.mode == Camera.ImageMode
370 value: settings.imageWhiteBalance
374 target: cam.whiteBalance
376 when: cam.mode == Camera.VideoMode
377 value: settings.videoWhiteBalance
381 target: cam.colorTone
383 when: cam.mode == Camera.ImageMode
384 value: settings.imageColorFilter
388 target: cam.colorTone
390 when: cam.mode == Camera.VideoMode
391 value: settings.videoColorFilter
397 when: cam.mode == Camera.ImageMode
398 value: settings.imageIso
404 when: cam.mode == Camera.ImageMode
409 target: cam.videoMute
411 value: settings.videoMuted
417 value: settings.faceDetectionEnabled && !focusReticle.pressed && !focusReticle.touchMode && cam.mode == Camera.ImageMode
424 manufacturer: deviceInfo.manufacturer
425 model: deviceInfo.model
437 if (cam.mode == Camera.VideoMode) {
438 replacePage("VideoPage.qml");
441 replacePage("ImagePage.qml");
447 policyLost: pipelineManager.state == "policyLost"
448 show: !pageStack.currentPage || (pageStack.currentPage.activationData.standbyVisible && pageStack.currentPage.status == PageStatus.Active && pipelineManager.showStandBy)
453 active: Qt.application.active && pipelineManager.scaleAcquired
454 repeat: !settings.zoomAsShutter