Added gallery integration
[harmattan/cameraplus] / qml / FocusReticle.qml
index 564c6f2..b698f32 100644 (file)
@@ -25,9 +25,13 @@ import QtCamera 1.0
 import CameraPlus 1.0
 
 // TODO: I've seen the reticle color changing to red while dragging it but failed to reproduce :(
+// TODO: hide all controls when we are focusing
+// TODO: hide all controls when we are dragging
+
 MouseArea {
         property int cafStatus: AutoFocus.None
         property int status: AutoFocus.None
+        property Camera cam: null
         id: mouse
 
         // A 100x100 central "rectangle"
@@ -35,14 +39,29 @@ MouseArea {
 
         property alias touchMode: reticle.touchMode
 
-        x: cam.renderArea.x
-        y: cam.renderArea.y
-        width: cam.renderArea.width
-        height: cam.renderArea.height
-
-        // Changing mode (which implies changing pages) will not reset ROI thus we do it here
-        Component.onCompleted: cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
+        x: cam ? cam.renderArea.x : 0
+        y: cam ? cam.renderArea.y : 0
+        width: cam ? cam.renderArea.width : 0
+        height: cam ? cam.renderArea.height : 0
+
+        Connections {
+                target: settings
+                // Changing mode (which implies changing pages) will not reset ROI
+                // thus we do it here
+                onModeChanged: {
+                        moveToCenter();
+                        cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
+                }
+        }
 
+        Connections {
+                target: cam
+                onRunningChanged: {
+                        if (cam.running) {
+                                setRegionOfInterest();
+                        }
+                }
+        }
 /*
         // This is for debugging
         Rectangle {
@@ -91,6 +110,11 @@ MouseArea {
                 }
         }
 
+        function moveToCenter() {
+                reticle.anchors.centerIn = reticle.parent;
+                reticle.touchMode = false;
+        }
+
         function moveReticle(x, y) {
                 var xPos = x - ((reticle.width * 1) / 2);
                 var yPos = y - ((reticle.height * 1) / 2);
@@ -98,19 +122,25 @@ MouseArea {
                 yPos = Math.min(Math.max(yPos, drag.minimumY), drag.maximumY);
                 reticle.x = xPos;
                 reticle.y = yPos;
+                reticle.anchors.centerIn = undefined;
+                reticle.touchMode = true;
         }
 
         function moveToCenterIfNeeded(x, y) {
                 if (x >= centerRect.x && y >= centerRect.y &&
                     x <= centerRect.x + centerRect.width &&
                     y <= centerRect.y + centerRect.height) {
-                        reticle.x = reticle.center.x
-                        reticle.y = reticle.center.y
+                        moveToCenter();
+                }
+                else {
+                        reticle.anchors.centerIn = undefined;
+                        reticle.touchMode = true;
                 }
         }
 
         function setRegionOfInterest() {
                 if (!reticle.touchMode) {
+//                        console.log("resetting ROI");
                         cam.autoFocus.setRegionOfInterest(Qt.rect(0, 0, 0, 0));
                         return;
                 }
@@ -134,6 +164,7 @@ MouseArea {
                 y = y / cam.videoResolution.height;
                 height = height / cam.videoResolution.height;
 
+//                console.log("Setting ROI to: " + x + " " + y);
                 cam.autoFocus.setRegionOfInterest(Qt.rect(x, y, width, height));
         }
 
@@ -143,22 +174,35 @@ MouseArea {
         }
 
         onPressed: {
+                reticle.anchors.centerIn = undefined;
                 moveReticle(mouse.x, mouse.y);
         }
 
         FocusRectangle {
                 id: reticle
                 property variant center: Qt.point((mouse.width - width) / 2, (mouse.height - height) / 2);
-                property bool touchMode: !(reticle.x == center.x && reticle.y == center.y)
+                property bool touchMode: false
 
                 scale: mouse.pressed ? 0.6 : touchMode ? 0.8 : 1.0
 
                 width: 250
                 height: 150
-                x: center.x
-                y: center.y
+
+                anchors.centerIn: parent
 
                 color: predictColor(cafStatus, status);
+
+                Behavior on x {
+                        PropertyAnimation { duration: 100; }
+                }
+
+                Behavior on y {
+                        PropertyAnimation { duration: 100; }
+                }
+
+                Behavior on scale {
+                        PropertyAnimation { duration: 100; }
+                }
         }
 
         Timer {