Added ROI an face detection
[harmattan/cameraplus] / qml / ImagePage.qml
index 8b1cbca..53c012b 100644 (file)
@@ -1,4 +1,25 @@
 // -*- qml -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 import QtQuick 1.1
 import com.nokia.meego 1.1
 import QtCamera 1.0
@@ -9,9 +30,47 @@ CameraPage {
         id: page
 
         policyMode: CameraResources.Image
-        controlsVisible: capture.visible && cam.running && !standbyWidget.visible
+        controlsVisible: capture.visible
 
-        Button {
+        orientationLock: PageOrientation.LockLandscape
+
+        function cameraError() {
+                mountProtector.unlock();
+        }
+
+        function captureImage() {
+                if (!checkBattery()) {
+                        showError(qsTr("Not enough battery to capture images."));
+                        return;
+                }
+
+                if (!fileSystem.available) {
+                        showError(qsTr("Camera cannot capture images in mass storage mode."));
+                        return;
+                }
+
+                if (!checkDiskSpace()) {
+                        showError(qsTr("Not enough space to capture images."));
+                        return;
+                }
+
+                if (!mountProtector.lock()) {
+                        showError(qsTr("Failed to lock images directory."));
+                        return;
+                }
+
+                metaData.setMetaData();
+
+                var fileName = fileNaming.imageFileName();
+                if (!imageMode.capture(fileName)) {
+                        showError(qsTr("Failed to capture image. Please restart the camera."));
+                        return;
+                }
+
+                trackerStore.storeImage(fileName);
+        }
+
+        CaptureButton {
                 id: capture
                 anchors.right: parent.right
                 anchors.rightMargin: 20
@@ -20,112 +79,103 @@ CameraPage {
                 width: 75
                 height: 75
                 opacity: 0.5
-                onClicked: {
-                        if (!fileSystem.available) {
-                                showError(qsTr("Camera cannot capture images in mass storage mode."));
-                                return;
-                        }
+                onClicked: captureImage();
+                visible: imageMode.canCapture && !cameraMode.busy && dimmer.opacity == 0.0 && !previewAnimationRunning && cam.running
 
-                        metaData.setMetaData();
-
-                        if (!imageMode.capture(fileNaming.imageFileName())) {
-                                showError(qsTr("Failed to capture image. Please restart the camera."));
+                onExited: {
+                        if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
+                                // Release outside the button:
+                                cam.autoFocus.stopAutoFocus();
                         }
                 }
 
-                visible: imageMode.canCapture && !cameraMode.animationRunning && !previewAnimationRunning && cam.running
+                Timer {
+                        interval: 200
+                        running: capture.pressed
+                        repeat: false
+                        onTriggered: {
+                                if (cam.autoFocus.cafStatus != AutoFocus.Success) {
+                                        cam.autoFocus.startAutoFocus();
+                                }
+                        }
+                }
         }
 
         ImageMode {
                 id: imageMode
                 camera: cam
-                onPreviewAvailable: page.setPreview(preview);
+                onPreviewAvailable: {
+                        page.setPreview(preview);
+                        cam.autoFocus.stopAutoFocus();
+                }
+
+                onSaved: mountProtector.unlock();
         }
 
-        FlashButton {
-                id: flash
-                visible: controlsVisible
+        Rectangle {
+                id: indicators
                 anchors.top: parent.top
-                anchors.left: parent.left
                 anchors.topMargin: 20
-                anchors.leftMargin: 20
-        }
-
-        ImageSceneButton {
-                id: scene
-                visible: controlsVisible
-                anchors.top: flash.bottom
                 anchors.left: parent.left
-                anchors.topMargin: 10
                 anchors.leftMargin: 20
-        }
-
-        EvCompButton {
-                id: evComp
+                width: 48
+                height: col.height
+                color: "black"
+                border.color: "gray"
+                radius: 20
+                opacity: 0.5
                 visible: controlsVisible
-                anchors.top: scene.bottom
-                anchors.left: parent.left
-                anchors.topMargin: 10
-                anchors.leftMargin: 20
-        }
 
-        Indicators {
-                visible: controlsVisible
-                anchors.bottom: parent.bottom
-                anchors.bottomMargin: 20
-                anchors.left: parent.left
-                anchors.leftMargin: 20
+                Column {
+                        id: col
+                        width: parent.width
+                        spacing: 5
 
-                onClicked: openFile("ImageSettingsPage.qml");
+                        Indicator {
+                                id: resolutionIndicator
+                                source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution);
+                        }
 
-//                Label {
-                // TODO:
-                        // resolution
-//                }
+                        Indicator {
+                                id: wbIndicator
+                                source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
+                                visible: settings.imageWhiteBalance != WhiteBalance.Auto
+                        }
 
-                Indicator {
-                        id: wbIndicator
-                        source: "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen"
-                        width: parent.width
-                        height: width
-                        visible: settings.imageWhiteBalance != WhiteBalance.Auto
-                }
+                        Indicator {
+                                id: cfIndicator
+                                source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
+                                visible: settings.imageColorFilter != ColorTone.Normal
+                        }
 
-                Indicator {
-                        id: cfIndicator
-                        anchors.top: wbIndicator.bottom
-                        source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
-                        width: parent.width
-                        height: width
-                        visible: settings.imageColorFilter != ColorTone.Normal
-                }
+                        Indicator {
+                                id: isoIndicator
+                                visible: settings.imageIso != 0
+                                source: "image://theme/" + Data.isoIcon(settings.imageIso);
+                        }
 
-                Indicator {
-                        id: isoIndicator
-                        width: parent.width
-                        height: width
-                        visible: settings.imageIso != 0
-                        source: "image://theme/" + Data.isoIcon(settings.imageIso);
-                        anchors.top: cfIndicator.bottom
-                }
+                        Indicator {
+                                id: gpsIndicator
+                                visible: settings.useGps
+                                source: "image://theme/icon-m-camera-location"
+
+                                PropertyAnimation on opacity  {
+                                        easing.type: Easing.OutSine
+                                        loops: Animation.Infinite
+                                        from: 0.2
+                                        to: 1.0
+                                        duration: 1000
+                                        running: settings.useGps && !positionSource.position.longitudeValid
+                                        alwaysRunToEnd: true
+                                }
+                        }
 
-                Indicator {
-                        id: gpsIndicator
-                        width: parent.width
-                        height: width
-                        anchors.top: isoIndicator.bottom
-                        visible: settings.useGps
-                        source: "image://theme/icon-m-camera-location"
-
-                        PropertyAnimation on opacity  {
-                                easing.type: Easing.OutSine
-                                loops: Animation.Infinite
-                                from: 0.2
-                                to: 1.0
-                                duration: 1000
-                                running: settings.useGps && !positionSource.position.longitudeValid
-                                alwaysRunToEnd: true
+                        Indicator {
+                                id: faceDetectionIndicator
+                                visible: settings.faceDetectionEnabled
+                                source: "image://theme/icon-m-camera-face-detection-screen"
                         }
+
                 }
         }
 
@@ -143,4 +193,46 @@ CameraPage {
                 onClicked: openFile("PostCapturePage.qml");
                 visible: controlsVisible
         }
+
+        CameraToolBar {
+                id: toolBar
+                anchors.bottom: parent.bottom
+                anchors.bottomMargin: 20
+                anchors.left: parent.left
+                anchors.leftMargin: 20
+                opacity: 0.5
+                targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
+                visible: controlsVisible
+                expanded: settings.showToolBar
+                onExpandedChanged: settings.showToolBar = expanded;
+
+                items: [
+                FlashButton {
+                        onClicked: toolBar.push(items);
+                },
+                ImageSceneButton {
+                        onClicked: toolBar.push(items);
+                },
+                ImageEvCompButton {
+                        onClicked: toolBar.push(items);
+                },
+                ImageWhiteBalanceButton {
+                        onClicked: toolBar.push(items);
+                },
+                ImageColorFilterButton {
+                        onClicked: toolBar.push(items);
+                },
+                ImageIsoButton {
+                        onClicked: toolBar.push(items);
+                },
+                ToolIcon {
+                        iconSource: "image://theme/icon-m-toolbar-view-menu-white"
+                        onClicked: imageSettingsDialog.open();
+                }
+                ]
+        }
+
+        ImageSettingsDialog {
+                id: imageSettingsDialog
+        }
 }