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