blink reticle during focusing and show colors to indicate status of focus
[harmattan/cameraplus] / qml / CameraPage.qml
index 7ea7569..a38bbb5 100644 (file)
@@ -34,96 +34,30 @@ Page {
         property bool needsPipeline: true
         property int policyMode: CameraResources.None
 
-        signal batteryLow
-
-        function updatePolicy() {
-                if (!resourcePolicy.acquire(page.policyMode)) {
-                        cam.stop(force);
-                }
-                else {
-                        handlePipeline();
-                }
-        }
-
-        Component.onCompleted: {
-                if (Qt.application.active && needsPipeline) {
-                        updatePolicy();
-                }
-        }
-
-        onStatusChanged: {
-                if (Qt.application.active && status == PageStatus.Activating) {
-                        updatePolicy();
-                }
-        }
-/*
-        onStatusChanged: {
-                if (status == PageStatus.Active && !page.needsPipeline) {
-                        cam.stop();
-                }
-        }
-*/
+        property Camera cam: null
+        property bool controlsVisible: cam.running && !standby.visible
+        property bool zoomVisible: true
+        property bool modesVisible: true
+        property bool standbyVisible: true
+        property bool focusReticleVisible: true
 
-        onPolicyModeChanged: {
-                if (Qt.application.active) {
-                        updatePolicy();
-                }
-        }
+        anchors.fill: parent
 
-        function handlePipeline() {
-                var acquired = resourcePolicy.acquired;
-                if (!acquired) {
-                        cam.stop(true);
-                        showError(qsTr("Resources lost. Stopping camera."));
-                }
-                else if (!Qt.application.active && !acquired) {
-                        cam.stop(true);
-                        showError(qsTr("Resources lost. Stopping camera."));
-                }
-                else if (!Qt.application.active) {
-                        cam.stop();
-                }
-                else if (acquired && page.needsPipeline && !cam.running) {
-                        if (!cam.start()) {
-                                showError(qsTr("Failed to start camera. Please restart the application."));
-                        }
-                }
-        }
+        property alias previewAnimationRunning: preview.animationRunning
 
-        Connections {
-                target: resourcePolicy
-                onAcquiredChanged: handlePipeline();
-        }
+        signal batteryLow
 
-        Connections {
-                target: Qt.application
-                onActiveChanged: {
-                        if (!Qt.application.active) {
-                                // This is a noop if camera is not
-                                // idle so calling it will not hurt
-                                if (cam.stop()) {
-                                        resourcePolicy.acquire(CameraResources.None);
-                                }
-                        }
-                        else if (page.needsPipeline) {
-                                updatePolicy();
-                        }
+        function updatePolicy() {
+                if (needsPipeline && Qt.application.active && status == PageStatus.Active) {
+                        pipelineManager.reset();
                 }
         }
 
-        Connections {
-                target: cam
-                onIdleChanged: {
-                        if (cam.idle && !Qt.application.active) {
-                                cam.stop();
-                                resourcePolicy.acquire(CameraResources.None);
-                        }
-/*
-                        else if (cam.idle && !page.needsPipeline) {
-                                cam.stop();
-                        }
-*/
-                }
+        FocusReticle {
+                visible: controlsVisible && focusReticleVisible
+                id: focusReticle
+                cafStatus: cam.autoFocus.cafStatus
+                status: cam.autoFocus.status
         }
 
         Rectangle {
@@ -132,19 +66,25 @@ Page {
                 id: standby
                 color: "black"
                 anchors.fill: parent
-                visible: !Qt.application.active || !cam.running || !resourcePolicy.acquired
+                visible: standbyVisible && page.status == PageStatus.Active && pipelineManager.showStandBy
+
                 Image {
+                        id: icon
                         source: "image://theme/icon-l-camera-standby"
                         anchors.centerIn: parent
                 }
-        }
-
-        property Camera cam: null
-        property bool controlsVisible: cam.running && !standby.visible
 
-        anchors.fill: parent
-
-        property alias previewAnimationRunning: preview.animationRunning
+                Label {
+                        anchors.top: icon.bottom
+                        anchors.right: parent.right
+                        anchors.left: parent.left
+                        text: qsTr("Resources lost")
+                        color: "white"
+                        font.pixelSize: 36
+                        horizontalAlignment: Text.AlignHCenter
+                        visible: pipelineManager.state == "policyLost"
+                }
+        }
 
         function setPreview(image) {
                 preview.setPreview(image);
@@ -155,7 +95,7 @@ Page {
                 anchors.right: parent.right
                 anchors.rightMargin: 20
                 anchors.bottomMargin: 20
-                visible: controlsVisible
+                visible: controlsVisible && modesVisible
         }
 
         PreviewImage {
@@ -168,7 +108,7 @@ Page {
                 anchors.top: parent.top
                 anchors.topMargin: 0
                 anchors.horizontalCenter: parent.horizontalCenter
-                visible: controlsVisible
+                visible: controlsVisible && zoomVisible
         }
 
         function checkDiskSpace() {