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