Switch toolbar animation to opacity
[harmattan/cameraplus] / qml / FocusReticle.qml
index dd22a7e..f4f4c8c 100644 (file)
@@ -20,7 +20,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-import QtQuick 1.1
+import QtQuick 2.0
 import QtCamera 1.0
 import CameraPlus 1.0
 
@@ -29,15 +29,20 @@ import CameraPlus 1.0
 
 MouseArea {
     id: mouse
-    x: cam ? cam.renderArea.x : 0
-    y: cam ? cam.renderArea.y : 0
-    width: cam ? cam.renderArea.width : 0
-    height: cam ? cam.renderArea.height : 0
+    x: renderArea.x
+    y: renderArea.y
+    width: renderArea.width
+    height: renderArea.height
     drag.minimumX: 0
     drag.minimumY: 0
     drag.maximumX: width - reticle.width
     drag.maximumY: height - reticle.height
 
+    property variant videoResolution
+    property variant renderArea
+
+    property bool locked: false
+
     property int cafStatus: AutoFocus.None
     property int status: AutoFocus.None
     property Camera cam
@@ -54,9 +59,32 @@ MouseArea {
     property variant allRoiRects
     property bool roiMode: allRoiRects != null && allRoiRects.length > 0 && !touchMode && !pressed
 
-    onPressed: calculateTouchPoint(mouse.x, mouse.y)
-    onReleased: calculateTouchPoint(mouse.x, mouse.y)
+    enabled: !cam.quirks.hasQuirk(Quirks.NoTouchFocus)
+
+    property variant __initialPos
+    onPressed: {
+
+        if (mouse.x >= reticle.x &&
+            mouse.y >= reticle.y &&
+            mouse.x <= reticle.x + reticle.width &&
+            mouse.y <= reticle.y + reticle.height) {
+            locked = true
+        }
+
+        __initialPos = touchPoint
+        calculateTouchPoint(mouse.x, mouse.y)
+    }
+
+    onReleased: {
+        calculateTouchPoint(mouse.x, mouse.y)
+        locked = false
+    }
+
     onPositionChanged: calculateTouchPoint(mouse.x, mouse.y)
+    onCanceled: {
+        calculateTouchPoint(__initialPos.x, __initialPos.y)
+        locked = false
+    }
 
     function resetReticle() {
         calculateTouchPoint(centerRect.x, centerRect.y)
@@ -71,22 +99,25 @@ MouseArea {
             return
         } else if (!touchMode && !roiMode) {
             // console.log("resetting ROI")
-            cam.roi.resetRegionOfInterest()
+            if (cam.roi) {
+                cam.roi.resetRegionOfInterest()
+            }
+
             return
         }
 
         // TODO: rework this and move to unnormalized coordinates
         // in terms of video resolution:
-        var rx = (cam.videoResolution.width * reticle.x) / mouse.width
-        var rwidth = (cam.videoResolution.width * reticle.width) / mouse.width
-        var ry = (cam.videoResolution.height * reticle.y) / mouse.height
-        var rheight = (cam.videoResolution.height * reticle.height) / mouse.height
+        var rx = (videoResolution.width * reticle.x) / mouse.width
+        var rwidth = (videoResolution.width * reticle.width) / mouse.width
+        var ry = (videoResolution.height * reticle.y) / mouse.height
+        var rheight = (videoResolution.height * reticle.height) / mouse.height
 
         // Translate to normalized coordinates (1x1 square) as expected by our C++ backend
-        rx = rx / cam.videoResolution.width
-        rwidth = rwidth / cam.videoResolution.width
-        ry = ry / cam.videoResolution.height
-        rheight = rheight / cam.videoResolution.height
+        rx = rx / videoResolution.width
+        rwidth = rwidth / videoResolution.width
+        ry = ry / videoResolution.height
+        rheight = rheight / videoResolution.height
 
         // console.log("Setting ROI to: " + rx + "x" + ry)
         cam.roi.setRegionOfInterest(Qt.rect(rx, ry, rwidth, rheight))