We manually set the the camera mode upon startup to avoid binding the value.
[harmattan/cameraplus] / qml / main.qml
1 // -*- qml -*-
2 import QtQuick 1.1
3 import com.nokia.meego 1.1
4 import QtCamera 1.0
5 import CameraPlus 1.0
6
7 PageStackWindow {
8         id: root
9
10         property alias dimmer: camDimmer
11
12         showStatusBar: false
13
14         Component.onCompleted: {
15                 theme.inverted = true;
16                 if (settings.mode == 0) {
17                         openFile("ImagePage.qml");
18                 }
19                 else {
20                         openFile("VideoPage.qml");
21                 }
22         }
23
24         Settings {
25                 id: settings
26         }
27
28         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
29         function replacePage(file) {
30                 var component = Qt.createComponent(file)
31
32                 if (component.status == Component.Ready) {
33                         pageStack.replace(component, {cam: cam}, true);
34                 }
35                 else {
36                         console.log("Error loading component:", component.errorString());
37                 }
38         }
39
40         function openFile(file) {
41                 var component = Qt.createComponent(file)
42
43                 if (component.status == Component.Ready) {
44                         pageStack.push(component, {cam: cam});
45                 }
46                 else {
47                         console.log("Error loading component:", component.errorString());
48                 }
49         }
50
51         platformStyle: PageStackWindowStyle {
52                 // TODO: Hack
53                 background: " "
54                 portraitBackground: " "
55                 landscapeBackground: " "
56         }
57
58         Camera {
59                 onDeviceIdChanged: cam.start();
60
61                 id: cam
62                 anchors.fill: parent
63
64                 // TODO: hardcoding
65                 Component.onCompleted: { cam.deviceId = 0; mode = settings.mode; }
66
67                 // TODO: Hack
68                 z: -1
69
70                 Rectangle {
71                         id: camDimmer
72                         z: 1
73                         anchors.fill: parent
74                         opacity: 0
75                         color: "black"
76                 }
77         }
78
79         ModeController {
80                 id: cameraMode
81                 cam: cam
82                 dimmer: root.dimmer
83         }
84
85         Connections {
86                 target: cam
87                 onModeChanged: {
88                         if (cam.mode == Camera.VideoMode) {
89                                 replacePage("VideoPage.qml");
90                         }
91                         else {
92                                 replacePage("ImagePage.qml");
93                         }
94                 }
95         }
96 }