0df33c6d39f53324d74f7bf544a3bc7c133d50b1
[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         property Item settingsDialog: null
38
39         function cameraError() {
40                 mountProtector.unlock();
41         }
42
43         function captureImage() {
44                 if (!checkBattery()) {
45                         showError(qsTr("Not enough battery to capture images."));
46                         return;
47                 }
48
49                 if (!fileSystem.available) {
50                         showError(qsTr("Camera cannot capture images in mass storage mode."));
51                         return;
52                 }
53
54                 if (!checkDiskSpace()) {
55                         showError(qsTr("Not enough space to capture images."));
56                         return;
57                 }
58
59                 if (!mountProtector.lock()) {
60                         showError(qsTr("Failed to lock images directory."));
61                         return;
62                 }
63
64                 metaData.setMetaData();
65
66                 var fileName = fileNaming.imageFileName();
67                 if (!imageMode.capture(fileName)) {
68                         showError(qsTr("Failed to capture image. Please restart the camera."));
69                         return;
70                 }
71
72                 trackerStore.storeImage(fileName);
73         }
74
75         CaptureButton {
76                 id: capture
77                 anchors.right: parent.right
78                 anchors.rightMargin: 20
79                 anchors.verticalCenter: parent.verticalCenter
80                 iconSource: "image://theme/icon-m-camera-shutter"
81                 width: 75
82                 height: 75
83                 opacity: 0.5
84                 onClicked: captureImage();
85                 visible: imageMode.canCapture && !cameraMode.busy && dimmer.opacity == 0.0 && !previewAnimationRunning && cam.running
86
87                 onExited: {
88                         if (mouseX <= 0 || mouseY <= 0 || mouseX > width || mouseY > height) {
89                                 // Release outside the button:
90                                 cam.autoFocus.stopAutoFocus();
91                         }
92                 }
93
94                 Timer {
95                         interval: 200
96                         running: capture.pressed
97                         repeat: false
98                         onTriggered: {
99                                 if (cam.autoFocus.cafStatus != AutoFocus.Success) {
100                                         cam.autoFocus.startAutoFocus();
101                                 }
102                         }
103                 }
104         }
105
106         ImageMode {
107                 id: imageMode
108                 camera: cam
109                 onPreviewAvailable: {
110                         page.setPreview(preview);
111                         cam.autoFocus.stopAutoFocus();
112                 }
113
114                 onSaved: mountProtector.unlock();
115         }
116
117         Rectangle {
118                 id: indicators
119                 anchors.top: parent.top
120                 anchors.topMargin: 20
121                 anchors.left: parent.left
122                 anchors.leftMargin: 20
123                 width: 48
124                 height: col.height
125                 color: "black"
126                 border.color: "gray"
127                 radius: 20
128                 opacity: 0.5
129                 visible: controlsVisible
130
131                 Column {
132                         id: col
133                         width: parent.width
134                         spacing: 5
135
136                         Indicator {
137                                 id: resolutionIndicator
138                                 source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution);
139                         }
140
141                         Indicator {
142                                 id: wbIndicator
143                                 source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
144                                 visible: settings.imageWhiteBalance != WhiteBalance.Auto
145                         }
146
147                         Indicator {
148                                 id: cfIndicator
149                                 source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
150                                 visible: settings.imageColorFilter != ColorTone.Normal
151                         }
152
153                         Indicator {
154                                 id: isoIndicator
155                                 visible: settings.imageIso != 0
156                                 source: "image://theme/" + Data.isoIcon(settings.imageIso);
157                         }
158
159                         Indicator {
160                                 id: gpsIndicator
161                                 visible: settings.useGps
162                                 source: "image://theme/icon-m-camera-location"
163
164                                 PropertyAnimation on opacity  {
165                                         easing.type: Easing.OutSine
166                                         loops: Animation.Infinite
167                                         from: 0.2
168                                         to: 1.0
169                                         duration: 1000
170                                         running: settings.useGps && !positionSource.position.longitudeValid
171                                         alwaysRunToEnd: true
172                                 }
173                         }
174
175                         Indicator {
176                                 id: faceDetectionIndicator
177                                 visible: settings.faceDetectionEnabled
178                                 source: "image://theme/icon-m-camera-face-detection-screen"
179                         }
180
181                 }
182         }
183
184         Button {
185                 id: cameraRoll
186                 anchors.top: parent.top
187                 anchors.right: parent.right
188                 anchors.topMargin: 20
189                 anchors.rightMargin: 20
190                 width: 56
191                 height: 56
192
193                 opacity: 0.5
194                 iconSource: "image://theme/icon-m-camera-roll"
195                 onClicked: openFile("PostCapturePage.qml");
196                 visible: controlsVisible
197         }
198
199         CameraToolBar {
200                 id: toolBar
201                 anchors.bottom: parent.bottom
202                 anchors.bottomMargin: 20
203                 anchors.left: parent.left
204                 anchors.leftMargin: 20
205                 opacity: 0.5
206                 targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
207                 visible: controlsVisible
208                 expanded: settings.showToolBar
209                 onExpandedChanged: settings.showToolBar = expanded;
210
211                 items: [
212                 FlashButton {
213                         onClicked: toolBar.push(items);
214                 },
215                 ImageSceneButton {
216                         onClicked: toolBar.push(items);
217                 },
218                 ImageEvCompButton {
219                         onClicked: toolBar.push(items);
220                 },
221                 ImageWhiteBalanceButton {
222                         onClicked: toolBar.push(items);
223                 },
224                 ImageColorFilterButton {
225                         onClicked: toolBar.push(items);
226                 },
227                 ImageIsoButton {
228                         onClicked: toolBar.push(items);
229                 },
230                 ToolIcon {
231                         iconSource: "image://theme/icon-m-toolbar-view-menu-white"
232                         onClicked: openSettings();
233                 }
234                 ]
235         }
236
237         function openSettings() {
238                 var roiEnabled = cam.roi.enabled;
239                 cam.roi.enabled = false;
240
241                 if (!settingsDialog) {
242                         settingsDialog = imageSettingsDialog.createObject(page);
243                 }
244
245                 settingsDialog.open();
246
247                 cam.roi.enabled = roiEnabled;
248         }
249
250         Component {
251                 id: imageSettingsDialog
252
253                 ImageSettingsDialog { }
254         }
255 }