Reworked mode animation.
authorMohammed Sameer <msameer@foolab.org>
Mon, 31 Dec 2012 01:59:53 +0000 (03:59 +0200)
committerMohammed Sameer <msameer@foolab.org>
Mon, 31 Dec 2012 01:59:53 +0000 (03:59 +0200)
Use a series of property change notifications and bindings to derive the animation/

The PauseAnimation {} is needed because the dimmer doesn't fully dim without it :(

qml/CameraPage.qml
qml/ImagePage.qml
qml/ModeController.qml
qml/RecordingPage.qml
qml/VideoPage.qml
qml/main.qml

index 4c871ae..0b16370 100644 (file)
@@ -33,6 +33,8 @@ Page {
         property int policyMode: CameraResources.None
 
         property Camera cam: null
+        property Item dimmer: null
+
         property bool controlsVisible: cam.running && !standby.visible
         property bool zoomVisible: true
         property bool modesVisible: true
@@ -109,6 +111,7 @@ Page {
         }
 
         BatteryInfo {
+                // TODO: replace this
                 id: batteryMonitor
                 monitorChargingStateChanges: cam.running
                 monitorBatteryStatusChanges: cam.running
index 5fa8783..121429f 100644 (file)
@@ -80,7 +80,7 @@ CameraPage {
                 height: 75
                 opacity: 0.5
                 onClicked: captureImage();
-                visible: imageMode.canCapture && !cameraMode.animationRunning && !previewAnimationRunning && cam.running
+                visible: imageMode.canCapture && !cameraMode.busy && dimmer.opacity == 0.0 && !previewAnimationRunning && cam.running
 
                 onExited: {
                         if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
index b764eec..952431a 100644 (file)
@@ -26,40 +26,32 @@ import QtCamera 1.0
 
 Item {
         id: controller
-        property int mode: settings.mode
         property Camera cam: null
         property Item dimmer: null
-        property alias animationRunning: animation.running
+        property bool busy: cam.mode != settings.mode
 
-        SequentialAnimation {
-                id: animation
-                property int mode: Camera.UnknownMode
-
-                function setMode() {
-                        root.resetCamera(cam.deviceId, mode);
-                }
-
-                NumberAnimation { target: dimmer; property: "opacity"; from: 0; to: 1; duration: 150; alwaysRunToEnd: true }
-
-                PauseAnimation { duration: 50 }
-
-                ParallelAnimation {
-                        ScriptAction { script: animation.setMode(); }
-                        PauseAnimation { duration: 200 }
+        onBusyChanged: {
+                if (busy) {
+                        controller.dimmer.dimmed = true;
                 }
-
-                PauseAnimation { duration: 50 }
-
-                NumberAnimation { target: dimmer; property: "opacity"; from: 1; to: 0; duration: 150; alwaysRunToEnd: true }
         }
 
-        onModeChanged: {
-                if (!cam || cam.mode == mode) {
-                        return;
+        Connections {
+                target: controller.cam
+                onModeChanged: {
+                        controller.dimmer.dimmed = false;
                 }
+        }
 
-                animation.mode = mode;
+        PauseAnimation {
+                id: pause
+                duration: 50
+                running: controller.dimmer.opacity == 1.0 && controller.busy
 
-                animation.start();
+                onRunningChanged: {
+                        if (!running && controller.busy) {
+                                root.resetCamera(cam.deviceId, settings.mode);
+                        }
+                }
         }
 }
index d21314a..231c354 100644 (file)
@@ -36,7 +36,7 @@ CameraPage {
 
         policyMode: CameraResources.Recording
 
-        controlsVisible: cam.running && videoMode.recording && !cameraMode.animationRunning && !previewAnimationRunning && !error
+        controlsVisible: cam.running && videoMode.recording && !error
 
         orientationLock: PageOrientation.LockLandscape
 
index 58d456b..dbb3d44 100644 (file)
@@ -31,7 +31,7 @@ CameraPage {
 
         policyMode: CameraResources.Video
 
-        controlsVisible: cam.running && !videoMode.recording && videoMode.canCapture && !cameraMode.animationRunning && !previewAnimationRunning
+        controlsVisible: cam.running && !videoMode.recording && videoMode.canCapture && !cameraMode.busy && dimmer.opacity == 0.0 && !previewAnimationRunning
         orientationLock: PageOrientation.LockLandscape
 
         function startRecording() {
index b1253ba..01fbfa2 100644 (file)
@@ -143,15 +143,15 @@ PageStackWindow {
         }
 
         function replacePage(file) {
-                pageStack.replace(Qt.resolvedUrl(file), {cam: cam}, true);
+                pageStack.replace(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
         }
 
         function openFile(file) {
-                pageStack.push(Qt.resolvedUrl(file), {cam: cam});
+                pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer});
         }
 
         function openFileNow(file) {
-                pageStack.push(Qt.resolvedUrl(file), {cam: cam}, true);
+                pageStack.push(Qt.resolvedUrl(file), {cam: cam, dimmer: root.dimmer}, true);
         }
 
         platformStyle: PageStackWindowStyle {
@@ -259,11 +259,15 @@ PageStackWindow {
                 z: -1
 
                 Rectangle {
+                        property bool dimmed: false
                         id: camDimmer
                         z: 1
                         anchors.fill: parent
-                        opacity: 0
+                        opacity: dimmed ? 1.0 : 0.0
                         color: "black"
+                        Behavior on opacity {
+                                PropertyAnimation { duration: 150 }
+                        }
                 }
 
                 notifications: Sounds {