Add opacity animation to settings and post capture views
[harmattan/cameraplus] / qml / MainPage.qml
index 90ab26e..95cba6b 100644 (file)
@@ -25,11 +25,16 @@ import QtCamera 1.0
 import CameraPlus 1.0
 
 // TODO: flash not ready (battery low or flash not ready message)
-// TODO: front camera night mode
+// TODO: Sounds
+// TODO: N950 conf
 
 CameraPage {
     id: root
 
+    property bool deviceChangeInProgress: false
+    property bool inCaptureMode: mainView.currentIndex == 1
+    property Item dimmer: camDimmer
+
     CameraTheme {
         id: cameraTheme
     }
@@ -37,10 +42,19 @@ CameraPage {
     VisualItemModel {
         id: mainModel
 
-        SettingsView {
-            camera: viewfinder.camera
+        Loader {
+            id: settingsLoader
             width: mainView.width
             height: mainView.height
+
+            property bool pressed: false
+            property bool inhibitDim: false
+            property int policyMode: settings.mode == Camera.VideoMode ? CameraResources.Video : CameraResources.Image
+            opacity: item ? 1.0 : 0
+
+            Behavior on opacity {
+                NumberAnimation {duration: 200}
+            }
         }
 
         CameraView {
@@ -49,10 +63,19 @@ CameraPage {
             height: mainView.height
         }
 
-        PostCaptureView {
-            camera: viewfinder.camera
+        Loader {
+            id: postCaptureLoader
+            property bool pressed: item ? item.pressed : false
+            property bool inhibitDim: item ? item.inhibitDim : false
+            property int policyMode: item ? item.policyMode : settings.mode == Camera.VideoMode ? CameraResources.Video : CameraResources.Image
+
             width: mainView.width
             height: mainView.height
+            opacity: item ? 1.0 : 0
+
+            Behavior on opacity {
+                NumberAnimation {duration: 200}
+            }
         }
     }
 
@@ -67,6 +90,16 @@ CameraPage {
         boundsBehavior: Flickable.StopAtBounds
         currentIndex: 1
         interactive: !currentItem.pressed
+        onContentXChanged: {
+            if (contentX == 0) {
+                settingsLoader.source = Qt.resolvedUrl("SettingsView.qml")
+            } else if (contentX == width) {
+                settingsLoader.source = ""
+                postCaptureLoader.source = ""
+            } else if (contentX == width * 2) {
+                postCaptureLoader.source = Qt.resolvedUrl("PostCaptureView.qml")
+            }
+        }
     }
 
     Component.onCompleted: {
@@ -80,6 +113,10 @@ CameraPage {
 
     Settings {
         id: settings
+        onDeviceAboutToChange: {
+            root.deviceChangeInProgress = true
+        }
+
         onDeviceChanged: {
             viewfinder.cameraDeviceChanged()
 
@@ -87,9 +124,34 @@ CameraPage {
             pipelineManager.error = false
 
             if (root.resetCamera(settings.device, settings.mode)) {
+                root.deviceChangeInProgress = false
                 pipelineManager.startCamera()
             }
         }
+
+        onImageAspectRatioChanged: {
+            if (!root.deviceChangeInProgress) {
+                imageSettings.setImageResolution()
+            }
+        }
+
+        onImageResolutionChanged: {
+            if (!root.deviceChangeInProgress) {
+                imageSettings.setImageResolution()
+            }
+        }
+
+        onVideoResolutionChanged: {
+            if (!root.deviceChangeInProgress) {
+                videoSettings.setVideoResolution()
+            }
+        }
+
+        onVideoAspectRatioChanged: {
+            if (!root.deviceChangeInProgress) {
+                videoSettings.setVideoResolution()
+            }
+        }
     }
 
     PipelineManager {
@@ -104,6 +166,13 @@ CameraPage {
             return false
         }
 
+        if (mode == Camera.ImageMode) {
+            imageSettings.setImageResolution()
+        }
+        else if (mode == Camera.VideoMode) {
+            videoSettings.setVideoResolution()
+        }
+
         return true
     }
 
@@ -112,13 +181,18 @@ CameraPage {
         error.show()
     }
 
-    property alias dimmer: camDimmer
+    PlatformQuirks {
+        id: platformQuirks
+    }
+
+    DisplayState {
+        id: displayState
+        inhibitDim: mainView.currentItem != null ? mainView.currentItem.inhibitDim : false
+    }
+
     CameraPositionSource {
         id: positionSource
-        active: settings.useGps
-        // TODO: we cannot bind to cam.running because camera will stop
-        // when the connection dialog pops up and we end up with an infinite loop
-        // active: cam.running && settings.useGps
+        active: (viewfinder.camera.running || platformQuirks.forceOn) && settings.useGps && displayState.isOn
         onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude)
     }
 
@@ -157,7 +231,7 @@ CameraPage {
 
     ReverseGeocode {
         id: geocode
-        active: viewfinder.camera.running && settings.useGps && settings.useGeotags
+        active: (viewfinder.camera.running || platformQuirks.forceOn) && settings.useGps && settings.useGeotags && displayState.isOn
     }
 
     DeviceInfo {
@@ -179,6 +253,7 @@ CameraPage {
         imagePath: platformSettings.imagePath
         videoPath: platformSettings.videoPath
         temporaryVideoPath: platformSettings.temporaryVideoPath
+        settings: settings
     }
 
     MountProtector {
@@ -201,12 +276,6 @@ CameraPage {
                 showError(qsTr("Failed to set required resolution"))
             }
         }
-
-        onReadyChanged: {
-            if (ready) {
-                imageSettings.setImageResolution()
-            }
-        }
     }
 
     VideoSettings {
@@ -218,28 +287,6 @@ CameraPage {
                 showError(qsTr("Failed to set required resolution"))
             }
         }
-
-        onReadyChanged: {
-            if (ready) {
-                videoSettings.setVideoResolution()
-            }
-        }
-    }
-
-    Connections {
-        target: settings
-
-        onImageAspectRatioChanged: {
-            imageSettings.setImageResolution()
-        }
-
-        onImageResolutionChanged: {
-            imageSettings.setImageResolution()
-        }
-
-        onVideoResolutionChanged: {
-            videoSettings.setVideoResolution()
-        }
     }
 
     ModeController {
@@ -262,13 +309,37 @@ CameraPage {
 
     DeviceKeys {
         id: keys
-        active: Qt.application.active && pipelineManager.scaleAcquired
+        active: Qt.application.active && pipelineManager.scaleAcquired && root.inCaptureMode && !mainView.moving
         repeat: !settings.zoomAsShutter
     }
 
+    Timer {
+        id: proximityTimer
+        running: proximitySensor.close
+        repeat: false
+        interval: 500
+        onTriggered: {
+            if (proximitySensor.close) {
+                proximitySensor.sensorClosed = true
+            }
+        }
+    }
+
+    CameraProximitySensor {
+        id: proximitySensor
+        property bool sensorClosed: false
+
+        active: Qt.application.active && viewfinder.camera.running && settings.proximityAsShutter && root.inCaptureMode && !mainView.moving
+        onCloseChanged: {
+            if (!close) {
+                sensorClosed = false
+            }
+        }
+    }
+
     Standby {
         policyLost: pipelineManager.state == "policyLost"
         show: !Qt.application.active || pipelineManager.showStandBy ||
-            (mainView.currentIndex == 1 && !viewfinder.camera.running)
+            (inCaptureMode && !viewfinder.camera.running)
     }
 }