Added auto focus starting and stopping.
[harmattan/cameraplus] / qml / ImagePage.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 1.1
24 import com.nokia.meego 1.1
25 import QtCamera 1.0
26 import CameraPlus 1.0
27 import "data.js" as Data
28
29 CameraPage {
30         id: page
31
32         policyMode: CameraResources.Image
33         controlsVisible: capture.visible && cam.running && !standbyWidget.visible
34
35         orientationLock: PageOrientation.LockLandscape
36
37         function captureImage() {
38                 if (!checkBattery()) {
39                         showError(qsTr("Not enough battery to capture images."));
40                         return;
41                 }
42
43                 if (!checkDiskSpace()) {
44                         showError(qsTr("Not enough space to capture images."));
45                         return;
46                 }
47
48                 if (!fileSystem.available) {
49                         showError(qsTr("Camera cannot capture images in mass storage mode."));
50                         return;
51                 }
52
53                 if (!mountProtector.lock()) {
54                         showError(qsTr("Failed to lock images directory."));
55                         return;
56                 }
57
58                 metaData.setMetaData();
59
60                 var fileName = fileNaming.imageFileName();
61                 if (!imageMode.capture(fileName)) {
62                         showError(qsTr("Failed to capture image. Please restart the camera."));
63                         return;
64                 }
65
66                 trackerStore.storeImage(fileName);
67         }
68
69         CaptureButton {
70                 id: capture
71                 anchors.right: parent.right
72                 anchors.rightMargin: 20
73                 anchors.verticalCenter: parent.verticalCenter
74                 iconSource: "image://theme/icon-m-camera-shutter"
75                 width: 75
76                 height: 75
77                 opacity: 0.5
78                 onClicked: captureImage();
79                 visible: imageMode.canCapture && !cameraMode.animationRunning && !previewAnimationRunning && cam.running
80
81                 onExited: {
82                         if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
83                                 // Release outside the button:
84                                 cam.autoFocus.stopAutoFocus();
85                         }
86                 }
87
88                 Timer {
89                         interval: 200
90                         running: capture.pressed
91                         repeat: false
92                         onTriggered: cam.autoFocus.startAutoFocus();
93                 }
94         }
95
96         ImageMode {
97                 id: imageMode
98                 camera: cam
99                 onPreviewAvailable: { page.setPreview(preview); cam.autoFocus.stopAutoFocus(); }
100                 onSaved: mountProtector.unlock();
101         }
102
103         FlashButton {
104                 id: flash
105                 visible: controlsVisible
106                 anchors.top: parent.top
107                 anchors.left: parent.left
108                 anchors.topMargin: 20
109                 anchors.leftMargin: 20
110         }
111
112         ImageSceneButton {
113                 id: scene
114                 visible: controlsVisible
115                 anchors.top: flash.bottom
116                 anchors.left: parent.left
117                 anchors.topMargin: 10
118                 anchors.leftMargin: 20
119         }
120
121         ImageEvCompButton {
122                 id: evComp
123                 visible: controlsVisible
124                 anchors.top: scene.bottom
125                 anchors.left: parent.left
126                 anchors.topMargin: 10
127                 anchors.leftMargin: 20
128         }
129
130         MouseArea {
131                 id: indicators
132                 anchors.bottom: parent.bottom
133                 anchors.bottomMargin: 20
134                 anchors.left: parent.left
135                 anchors.leftMargin: 20
136                 width: 48
137                 height: col.height
138                 onClicked: openFile("ImageSettingsPage.qml");
139                 visible: controlsVisible
140
141                 BorderImage {
142                         id: image
143                         anchors.fill: parent
144                         smooth: true
145                         source: indicators.pressed ? "image://theme/meegotouch-camera-settings-indicators-background-pressed" : "image://theme/meegotouch-camera-settings-indicators-background"
146                 }
147
148                 Column {
149                         id: col
150                         width: parent.width
151                         spacing: 5
152
153                         Indicator {
154                                 id: resolutionIndicator
155                                 source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution);
156                         }
157
158                         Indicator {
159                                 id: wbIndicator
160                                 source: "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen"
161                                 visible: settings.imageWhiteBalance != WhiteBalance.Auto
162                         }
163
164                         Indicator {
165                                 id: cfIndicator
166                                 source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
167                                 visible: settings.imageColorFilter != ColorTone.Normal
168                         }
169
170                         Indicator {
171                                 id: isoIndicator
172                                 visible: settings.imageIso != 0
173                                 source: "image://theme/" + Data.isoIcon(settings.imageIso);
174                         }
175
176                         Indicator {
177                                 id: gpsIndicator
178                                 visible: settings.useGps
179                                 source: "image://theme/icon-m-camera-location"
180
181                                 PropertyAnimation on opacity  {
182                                         easing.type: Easing.OutSine
183                                         loops: Animation.Infinite
184                                         from: 0.2
185                                         to: 1.0
186                                         duration: 1000
187                                         running: settings.useGps && !positionSource.position.longitudeValid
188                                         alwaysRunToEnd: true
189                                 }
190                         }
191                 }
192         }
193
194         Button {
195                 id: cameraRoll
196                 anchors.top: parent.top
197                 anchors.right: parent.right
198                 anchors.topMargin: 20
199                 anchors.rightMargin: 20
200                 width: 56
201                 height: 56
202
203                 opacity: 0.5
204                 iconSource: "image://theme/icon-m-camera-roll"
205                 onClicked: openFile("PostCapturePage.qml");
206                 visible: controlsVisible
207         }
208 }