Reworked mode animation.
[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.busy && dimmer.opacity == 0.0 && !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         Rectangle {
116                 id: indicators
117                 anchors.top: parent.top
118                 anchors.topMargin: 20
119                 anchors.left: parent.left
120                 anchors.leftMargin: 20
121                 width: 48
122                 height: col.height
123                 color: "black"
124                 border.color: "gray"
125                 radius: 20
126                 opacity: 0.5
127                 visible: controlsVisible
128
129                 Column {
130                         id: col
131                         width: parent.width
132                         spacing: 5
133
134                         Indicator {
135                                 id: resolutionIndicator
136                                 source: "image://theme/" + Data.imageIcon(settings.imageAspectRatio, settings.imageResolution);
137                         }
138
139                         Indicator {
140                                 id: wbIndicator
141                                 source: visible ? "image://theme/" + Data.wbIcon(settings.imageWhiteBalance) + "-screen" : ""
142                                 visible: settings.imageWhiteBalance != WhiteBalance.Auto
143                         }
144
145                         Indicator {
146                                 id: cfIndicator
147                                 source: "image://theme/" + Data.cfIcon(settings.imageColorFilter) + "-screen"
148                                 visible: settings.imageColorFilter != ColorTone.Normal
149                         }
150
151                         Indicator {
152                                 id: isoIndicator
153                                 visible: settings.imageIso != 0
154                                 source: "image://theme/" + Data.isoIcon(settings.imageIso);
155                         }
156
157                         Indicator {
158                                 id: gpsIndicator
159                                 visible: settings.useGps
160                                 source: "image://theme/icon-m-camera-location"
161
162                                 PropertyAnimation on opacity  {
163                                         easing.type: Easing.OutSine
164                                         loops: Animation.Infinite
165                                         from: 0.2
166                                         to: 1.0
167                                         duration: 1000
168                                         running: settings.useGps && !positionSource.position.longitudeValid
169                                         alwaysRunToEnd: true
170                                 }
171                         }
172                 }
173         }
174
175         Button {
176                 id: cameraRoll
177                 anchors.top: parent.top
178                 anchors.right: parent.right
179                 anchors.topMargin: 20
180                 anchors.rightMargin: 20
181                 width: 56
182                 height: 56
183
184                 opacity: 0.5
185                 iconSource: "image://theme/icon-m-camera-roll"
186                 onClicked: openFile("PostCapturePage.qml");
187                 visible: controlsVisible
188         }
189
190         CameraToolBar {
191                 id: toolBar
192                 anchors.bottom: parent.bottom
193                 anchors.bottomMargin: 20
194                 anchors.left: parent.left
195                 anchors.leftMargin: 20
196                 opacity: 0.5
197                 targetWidth: parent.width - (anchors.leftMargin * 2) - (66 * 1.5)
198                 visible: controlsVisible
199                 expanded: settings.showToolBar
200                 onExpandedChanged: settings.showToolBar = expanded;
201
202                 items: [
203                 FlashButton {
204                         onClicked: toolBar.push(items);
205                 },
206                 ImageSceneButton {
207                         onClicked: toolBar.push(items);
208                 },
209                 ImageEvCompButton {
210                         onClicked: toolBar.push(items);
211                 },
212                 ImageWhiteBalanceButton {
213                         onClicked: toolBar.push(items);
214                 },
215                 ImageColorFilterButton {
216                         onClicked: toolBar.push(items);
217                 },
218                 ToolIcon {
219                         iconSource: "image://theme/icon-m-toolbar-view-menu-white"
220                         onClicked: openFile("ImageSettingsPage.qml");
221                 }
222                 ]
223         }
224 }