Don't disable GPS when we are obscured by location-ui or conndlgs
[harmattan/cameraplus] / qml / ImageOverlay.qml
index fe01b37..ec1ee83 100644 (file)
@@ -23,7 +23,6 @@
 import QtQuick 2.0
 import QtCamera 1.0
 import CameraPlus 1.0
-import "data.js" as Data
 
 Item {
     id: overlay
@@ -34,6 +33,7 @@ Item {
     property bool pressed: capture.pressed || zoomSlider.pressed || modeButton.pressed
     property bool controlsVisible: imageMode.canCapture && cam.running && !animationRunning
         && dimmer.opacity == 0.0 && !cameraMode.busy
+    property bool inhibitDim: false
 
     signal previewAvailable(string uri)
 
@@ -42,12 +42,12 @@ Item {
     ImageMode {
         id: imageMode
         camera: cam
-        onPreviewAvailable: {
-            overlay.previewAvailable(preview)
-            cam.autoFocus.stopAutoFocus()
-        }
 
-        onSaved: mountProtector.unlock()
+        onCaptureEnded: stopAutoFocus()
+
+        onPreviewAvailable: overlay.previewAvailable(preview)
+
+        onSaved: mountProtector.unlock(fileNaming.imagePath)
     }
 
     ZoomSlider {
@@ -73,17 +73,16 @@ Item {
         anchors.right: parent.right
         anchors.rightMargin: 20
         anchors.verticalCenter: parent.verticalCenter
-        iconId: cameraTheme.captureButtonImageIconId
+        iconSource: cameraTheme.captureButtonImageIconId
         width: 75
         height: 75
         opacity: 0.5
-        onClicked: captureImage()
-        visible: controlsVisible && (!settings.zoomAsShutter && keys.active)
+        visible: controlsVisible
 
         onExited: {
             if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
                 // Release outside the button:
-                cam.autoFocus.stopAutoFocus()
+                captureControl.canceled = true
             }
         }
     }
@@ -91,28 +90,32 @@ Item {
     Timer {
         id: autoFocusTimer
         interval: 200
-        running: capture.pressed || zoomCapture.zoomPressed
+        running: captureControl.state == "capturing"
         repeat: false
         onTriggered: {
             if (cam.autoFocus.cafStatus != AutoFocus.Success) {
-                cam.autoFocus.startAutoFocus()
+                startAutoFocus()
             }
         }
     }
 
     ZoomCaptureButton {
         id: zoomCapture
-        onReleased: parent.captureImage()
     }
 
-    ZoomCaptureCancel {
+    CaptureControl {
+        id: captureControl
+        capturePressed: capture.pressed
+        zoomPressed: zoomCapture.zoomPressed
+        proximityClosed: proximitySensor.close
+        onStartCapture: captureImage()
+        onCancelCapture: stopAutoFocus()
+    }
+
+    CaptureCancel {
         anchors.fill: parent
-        zoomCapture: zoomCapture
-        onCanceled: {
-            if (!autoFocusTimer.running) {
-                cam.autoFocus.stopAutoFocus()
-            }
-        }
+        enabled: captureControl.showCancelBanner
+        onPressed:  captureControl.canceled = true
     }
 
     CameraToolBar {
@@ -126,26 +129,32 @@ Item {
         visible: controlsVisible
         expanded: settings.showToolBar
         onExpandedChanged: settings.showToolBar = expanded
-        items: [
+        tools: CameraToolBarTools {
             FlashButton {
-                onClicked: toolBar.push(items)
-            },
+                onClicked: toolBar.push(tools)
+                visible: !overlay.cam.quirks.hasQuirk(Quirks.NoFlash)
+            }
+
             ImageSceneButton {
-                onClicked: toolBar.push(items)
-            },
+                onClicked: toolBar.push(tools)
+            }
+
             ImageEvCompButton {
-                onClicked: toolBar.push(items)
-            },
+                onClicked: toolBar.push(tools)
+            }
+
             ImageWhiteBalanceButton {
-                onClicked: toolBar.push(items)
-            },
+                onClicked: toolBar.push(tools)
+            }
+
             ImageColorFilterButton {
-                onClicked: toolBar.push(items)
-            },
+                onClicked: toolBar.push(tools)
+            }
+
             ImageIsoButton {
-                onClicked: toolBar.push(items)
+                onClicked: toolBar.push(tools)
             }
-        ]
+        }
     }
 
     Rectangle {
@@ -168,26 +177,46 @@ Item {
             spacing: 5
 
             Indicator {
-                id: resolutionIndicator
-                source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution)
+                id: flashIndicator
+                visible: !toolBar.expanded && !overlay.cam.quirks.hasQuirk(Quirks.NoFlash)
+                source: cameraTheme.flashIcon(settings.imageFlashMode)
+            }
+
+            CameraLabel {
+                anchors.left: parent.left
+                anchors.right: parent.right
+                anchors.leftMargin: 5
+                anchors.rightMargin: 5
+                anchors.topMargin: 5
+                anchors.bottomMargin: 5
+                text: imageSettings.currentResolution ? qsTr("%1M").arg(imageSettings.currentResolution.megaPixels) : qsTr("?M")
+                font.bold: true
+                verticalAlignment: Text.AlignVCenter
+                horizontalAlignment: Text.AlignHCenter
             }
 
             Indicator {
                 id: wbIndicator
-                source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
-                visible: settings.imageWhiteBalance != WhiteBalance.Auto
+                source: visible ? cameraTheme.whiteBalanceIcon(settings.imageWhiteBalance) : ""
+                visible: settings.imageWhiteBalance != WhiteBalance.Auto && !toolBar.expanded
             }
 
             Indicator {
                 id: cfIndicator
-                source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
-                visible: settings.imageColorFilter != ColorTone.Normal
+                source: visible ? cameraTheme.colorFilterIcon(settings.imageColorFilter) : ""
+                visible: settings.imageColorFilter != ColorTone.Normal && !toolBar.expanded
             }
 
             Indicator {
                 id: isoIndicator
-                visible: settings.imageIso != 0
-                source: "image://theme/" + Data.isoIcon(settings.imageIso)
+                visible: settings.imageIso != 0 && !toolBar.expanded
+                source: visible ? cameraTheme.isoIcon(settings.imageIso) : ""
+            }
+
+            Indicator {
+                id: sceneIndicator
+                visible: settings.imageSceneMode != Scene.Auto && !toolBar.expanded
+                source: visible ? cameraTheme.imageSceneModeIcon(settings.imageSceneMode) : ""
             }
 
             Indicator {
@@ -216,7 +245,7 @@ Item {
     }
 
     function cameraError() {
-        mountProtector.unlock()
+        mountProtector.unlock(fileNaming.imagePath)
     }
 
     function policyLost() {
@@ -230,25 +259,54 @@ Item {
     function captureImage() {
         if (!imageMode.canCapture) {
             showError(qsTr("Camera is already capturing an image."))
+            stopAutoFocus()
         } else if (!checkBattery()) {
             showError(qsTr("Not enough battery to capture images."))
+            stopAutoFocus()
         } else if (!fileSystem.available) {
             showError(qsTr("Camera cannot capture images in mass storage mode."))
-        } else if (!checkDiskSpace()) {
+            stopAutoFocus()
+        } else if (!fileSystem.hasFreeSpace(fileNaming.imagePath)) {
             showError(qsTr("Not enough space to capture images."))
-        } else if (!mountProtector.lock()) {
+            stopAutoFocus()
+        } else if (!mountProtector.lock(fileNaming.imagePath)) {
             showError(qsTr("Failed to lock images directory."))
+            stopAutoFocus()
         } else {
             metaData.setMetaData()
 
             var fileName = fileNaming.imageFileName()
             if (!imageMode.capture(fileName)) {
                 showError(qsTr("Failed to capture image. Please restart the camera."))
-                mountProtector.unlock()
+                mountProtector.unlock(fileNaming.imagePath)
+                stopAutoFocus()
             } else {
                 trackerStore.storeImage(fileName)
             }
         }
     }
 
+    function startAutoFocus() {
+        if (!overlay.cam.quirks.hasQuirk(Quirks.NoAutoFocus)) {
+            cam.autoFocus.startAutoFocus()
+        }
+    }
+
+    function stopAutoFocus() {
+        if (!overlay.cam.quirks.hasQuirk(Quirks.NoAutoFocus)) {
+            if (!autoFocusTimer.running) {
+                cam.autoFocus.stopAutoFocus()
+            }
+        }
+    }
+
+    function resetToolBar() {
+        if (toolBar.depth() > 1) {
+            toolBar.pop()
+        }
+    }
+
+    function cameraDeviceChanged() {
+        resetToolBar()
+    }
 }