Reworked and fixed pipeline error handling.
[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
34
35         orientationLock: PageOrientation.LockLandscape
36
37         function cameraError() {
38                 mountProtector.unlock();
39         }
40
41         function captureImage() {
42                 if (!checkBattery()) {
43                         showError(qsTr("Not enough battery to capture images."));
44                         return;
45                 }
46
47                 if (!checkDiskSpace()) {
48                         showError(qsTr("Not enough space to capture images."));
49                         return;
50                 }
51
52                 if (!fileSystem.available) {
53                         showError(qsTr("Camera cannot capture images in mass storage mode."));
54                         return;
55                 }
56
57                 if (!mountProtector.lock()) {
58                         showError(qsTr("Failed to lock images directory."));
59                         return;
60                 }
61
62                 metaData.setMetaData();
63
64                 var fileName = fileNaming.imageFileName();
65                 if (!imageMode.capture(fileName)) {
66                         showError(qsTr("Failed to capture image. Please restart the camera."));
67                         return;
68                 }
69
70                 trackerStore.storeImage(fileName);
71         }
72
73         CaptureButton {
74                 id: capture
75                 anchors.right: parent.right
76                 anchors.rightMargin: 20
77                 anchors.verticalCenter: parent.verticalCenter
78                 iconSource: "image://theme/icon-m-camera-shutter"
79                 width: 75
80                 height: 75
81                 opacity: 0.5
82                 onClicked: captureImage();
83                 visible: imageMode.canCapture && !cameraMode.animationRunning && !previewAnimationRunning && cam.running
84
85                 onExited: {
86                         if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
87                                 // Release outside the button:
88                                 cam.autoFocus.stopAutoFocus();
89                         }
90                 }
91
92                 Timer {
93                         interval: 200
94                         running: capture.pressed
95                         repeat: false
96                         onTriggered: {
97                                 if (cam.autoFocus.cafStatus != AutoFocus.Success) {
98                                         cam.autoFocus.startAutoFocus();
99                                 }
100                         }
101                 }
102         }
103
104         ImageMode {
105                 id: imageMode
106                 camera: cam
107                 onPreviewAvailable: {
108                         page.setPreview(preview);
109                         cam.autoFocus.stopAutoFocus();
110                 }
111
112                 onSaved: mountProtector.unlock();
113         }
114
115         FlashButton {
116                 id: flash
117                 visible: controlsVisible
118                 anchors.top: parent.top
119                 anchors.left: parent.left
120                 anchors.topMargin: 20
121                 anchors.leftMargin: 20
122         }
123
124         ImageSceneButton {
125                 id: scene
126                 visible: controlsVisible
127                 anchors.top: flash.bottom
128                 anchors.left: parent.left
129                 anchors.topMargin: 10
130                 anchors.leftMargin: 20
131         }
132
133         ImageEvCompButton {
134                 id: evComp
135                 visible: controlsVisible
136                 anchors.top: scene.bottom
137                 anchors.left: parent.left
138                 anchors.topMargin: 10
139                 anchors.leftMargin: 20
140         }
141
142         MouseArea {
143                 id: indicators
144                 anchors.bottom: parent.bottom
145                 anchors.bottomMargin: 20
146                 anchors.left: parent.left
147                 anchors.leftMargin: 20
148                 width: 48
149                 height: col.height
150                 onClicked: openFile("ImageSettingsPage.qml");
151                 visible: controlsVisible
152
153                 BorderImage {
154                         id: image
155                         anchors.fill: parent
156                         smooth: true
157                         source: indicators.pressed ? "image://theme/meegotouch-camera-settings-indicators-background-pressed" : "image://theme/meegotouch-camera-settings-indicators-background"
158                 }
159
160                 Column {
161                         id: col
162                         width: parent.width
163                         spacing: 5
164
165                         Indicator {
166                                 id: resolutionIndicator
167                                 source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution);
168                         }
169
170                         Indicator {
171                                 id: wbIndicator
172                                 source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
173                                 visible: settings.imageWhiteBalance != WhiteBalance.Auto
174                         }
175
176                         Indicator {
177                                 id: cfIndicator
178                                 source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
179                                 visible: settings.imageColorFilter != ColorTone.Normal
180                         }
181
182                         Indicator {
183                                 id: isoIndicator
184                                 visible: settings.imageIso != 0
185                                 source: "image://theme/" + Data.isoIcon(settings.imageIso);
186                         }
187
188                         Indicator {
189                                 id: gpsIndicator
190                                 visible: settings.useGps
191                                 source: "image://theme/icon-m-camera-location"
192
193                                 PropertyAnimation on opacity  {
194                                         easing.type: Easing.OutSine
195                                         loops: Animation.Infinite
196                                         from: 0.2
197                                         to: 1.0
198                                         duration: 1000
199                                         running: settings.useGps && !positionSource.position.longitudeValid
200                                         alwaysRunToEnd: true
201                                 }
202                         }
203                 }
204         }
205
206         Button {
207                 id: cameraRoll
208                 anchors.top: parent.top
209                 anchors.right: parent.right
210                 anchors.topMargin: 20
211                 anchors.rightMargin: 20
212                 width: 56
213                 height: 56
214
215                 opacity: 0.5
216                 iconSource: "image://theme/icon-m-camera-roll"
217                 onClicked: openFile("PostCapturePage.qml");
218                 visible: controlsVisible
219         }
220 }