ca91e235ce7ccf90eab827248327b0240d441efb
[harmattan/cameraplus] / qml / CameraPage.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 QtMobility.systeminfo 1.2
28
29 Page {
30         id: page
31
32         property alias standbyWidget: standby
33
34         property bool needsPipeline: true
35         property int policyMode: CameraResources.None
36
37         property Camera cam: null
38         property bool controlsVisible: cam.running && !standby.visible
39         property bool zoomVisible: true
40         property bool modesVisible: true
41         property bool standbyVisible: true
42         property bool focusReticleVisible: true
43
44         anchors.fill: parent
45
46         property alias previewAnimationRunning: preview.animationRunning
47
48         signal batteryLow
49
50         function updatePolicy() {
51                 if (needsPipeline && Qt.application.active && status == PageStatus.Active) {
52                         pipelineManager.reset();
53                 }
54         }
55
56         FocusReticle {
57                 visible: controlsVisible && focusReticleVisible
58                 id: focusReticle
59                 autoFocusStatus: cam.autoFocus.cafStatus
60         }
61
62         Rectangle {
63                 // TODO: fade out transition
64                 // TODO: there is a toolbar visible on the first startup
65                 id: standby
66                 color: "black"
67                 anchors.fill: parent
68                 visible: standbyVisible && page.status == PageStatus.Active && pipelineManager.showStandBy
69
70                 Image {
71                         id: icon
72                         source: "image://theme/icon-l-camera-standby"
73                         anchors.centerIn: parent
74                 }
75
76                 Label {
77                         anchors.top: icon.bottom
78                         anchors.right: parent.right
79                         anchors.left: parent.left
80                         text: qsTr("Resources lost")
81                         color: "white"
82                         font.pixelSize: 36
83                         horizontalAlignment: Text.AlignHCenter
84                         visible: pipelineManager.state == "policyLost"
85                 }
86         }
87
88         function setPreview(image) {
89                 preview.setPreview(image);
90         }
91
92         ModeButton {
93                 anchors.bottom: parent.bottom
94                 anchors.right: parent.right
95                 anchors.rightMargin: 20
96                 anchors.bottomMargin: 20
97                 visible: controlsVisible && modesVisible
98         }
99
100         PreviewImage {
101                 id: preview
102         }
103
104         ZoomSlider {
105                 id: zoom
106                 camera: cam
107                 anchors.top: parent.top
108                 anchors.topMargin: 0
109                 anchors.horizontalCenter: parent.horizontalCenter
110                 visible: controlsVisible && zoomVisible
111         }
112
113         function checkDiskSpace() {
114                 return fileSystem.hasFreeSpace(fileNaming.path);
115         }
116
117         function checkBattery() {
118                 // We are fine if we are connected to the charger:
119                 if (batteryMonitor.chargingState == BatteryInfo.Charging) {
120                         return true;
121                 }
122
123                 // If we have enough battery then we are fine:
124                 if (batteryMonitor.batteryStatus > BatteryInfo.BatteryCritical) {
125                         return true;
126                 }
127
128                 return false;
129         }
130
131         BatteryInfo {
132                 id: batteryMonitor
133                 monitorChargingStateChanges: cam.running
134                 monitorBatteryStatusChanges: cam.running
135
136                 onChargingStateChanged: {
137                         if (!checkBattery()) {
138                                 parent.batteryLow();
139                         }
140                 }
141
142                 onBatteryStatusChanged:  {
143                         if (!checkBattery()) {
144                                 parent.batteryLow();
145                         }
146                 }
147         }
148 }