Added copyright headers and COPYING file.
[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
28 Page {
29         id: page
30
31         property alias standbyWidget: standby
32
33         property bool needsPipeline: true
34         property int policyMode: CameraResources.None
35
36         Component.onCompleted: {
37                 if (Qt.application.active && needsPipeline) {
38                         resourcePolicy.acquire(page.policyMode);
39                 }
40         }
41
42         onStatusChanged: {
43                 if (Qt.application.active && status == PageStatus.Activating) {
44                         resourcePolicy.acquire(page.policyMode);
45                 }
46         }
47 /*
48         onStatusChanged: {
49                 if (status == PageStatus.Active && !page.needsPipeline) {
50                         cam.stop();
51                 }
52         }
53 */
54
55         onPolicyModeChanged: {
56                 if (Qt.application.active) {
57                         resourcePolicy.acquire(page.policyMode);
58                 }
59         }
60
61         function handlePipeline() {
62                 if (!Qt.application.active) {
63                         // TODO: force if we lost resources ?
64                         cam.stop();
65                 }
66                 else if (resourcePolicy.acquired && page.needsPipeline && !cam.running) {
67                         // TODO: error
68                         cam.start();
69                 }
70                 else if (!resourcePolicy.acquired) {
71                         // TODO: force
72                         cam.stop();
73                 }
74         }
75
76         Connections {
77                 target: resourcePolicy
78                 onAcquiredChanged: handlePipeline();
79         }
80
81         Connections {
82                 target: Qt.application
83                 onActiveChanged: {
84                         if (!Qt.application.active) {
85                                 // This is a noop if camera is not
86                                 // idle so calling it will not hurt
87                                 if (cam.stop()) {
88                                         resourcePolicy.acquire(CameraResources.None);
89                                 }
90                         }
91                         else if (page.needsPipeline) {
92                                 resourcePolicy.acquire(page.policyMode);
93                         }
94                 }
95         }
96
97         Connections {
98                 target: cam
99                 onIdleChanged: {
100                         if (cam.idle && !Qt.application.active) {
101                                 cam.stop();
102                                 resourcePolicy.acquire(CameraResources.None);
103                         }
104 /*
105                         else if (cam.idle && !page.needsPipeline) {
106                                 cam.stop();
107                         }
108 */
109                 }
110         }
111
112         Rectangle {
113                 // TODO: color
114                 // TODO: fade out transition
115                 // TODO: there is a toolbar visible on the first startup
116                 id: standby
117                 color: "black"
118                 anchors.fill: parent
119                 visible: !Qt.application.active || !cam.running || !resourcePolicy.acquired
120                 Image {
121                         source: "image://theme/icon-l-camera-standby"
122                         anchors.centerIn: parent
123                 }
124         }
125
126         property Camera cam: null
127         property bool controlsVisible: cam.running && !standby.visible
128
129         anchors.fill: parent
130
131         property alias previewAnimationRunning: preview.animationRunning
132
133         function setPreview(image) {
134                 preview.setPreview(image);
135         }
136
137         ModeButton {
138                 anchors.bottom: parent.bottom
139                 anchors.right: parent.right
140                 anchors.rightMargin: 20
141                 anchors.bottomMargin: 20
142                 visible: controlsVisible
143         }
144
145         PreviewImage {
146                 id: preview
147         }
148
149         ZoomSlider {
150                 id: zoom
151                 camera: cam
152                 anchors.top: parent.top
153                 anchors.topMargin: 0
154                 anchors.horizontalCenter: parent.horizontalCenter
155                 visible: controlsVisible
156         }
157 }