cdd3a7afe340df043442d1323958bf68336cac06
[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
6 PageStackWindow {
7         id: root
8
9         property alias dimmer: camDimmer
10
11         showStatusBar: false
12         Component.onCompleted: theme.inverted = true;
13
14         // Stolen from https://qt.gitorious.org/qt-components/qt-components/blobs/master/examples/meego/QmlComponentGallery/qml/ListPage.qml
15         function replacePage(file) {
16                 var component = Qt.createComponent(file)
17
18                 if (component.status == Component.Ready) {
19                         pageStack.replace(component, {cam: cam}, true);
20                 }
21                 else {
22                         console.log("Error loading component:", component.errorString());
23                 }
24         }
25
26         function openFile(file) {
27                 var component = Qt.createComponent(file)
28
29                 if (component.status == Component.Ready) {
30                         pageStack.push(component);
31                 }
32                 else {
33                         console.log("Error loading component:", component.errorString());
34                 }
35         }
36
37         platformStyle: PageStackWindowStyle {
38                 // TODO: Hack
39                 background: " "
40                 portraitBackground: " "
41                 landscapeBackground: " "
42         }
43
44         Camera {
45                 onDeviceIdChanged: cam.start();
46
47                 id: cam
48                 anchors.fill: parent
49
50                 // TODO: hardcoding
51                 Component.onCompleted: { cam.deviceId = 0; }
52
53                 // TODO: Hack
54                 z: -1
55
56                 Rectangle {
57                         id: camDimmer
58                         z: 1
59                         anchors.fill: parent
60                         opacity: 0
61                         color: "black"
62                 }
63         }
64
65         ModeController {
66                 id: cameraMode
67                 cam: cam
68                 dimmer: root.dimmer
69         }
70
71         Connections {
72                 target: cam
73                 onModeChanged: {
74                         if (cam.mode == Camera.VideoMode) {
75                                 replacePage("VideoPage.qml");
76                         }
77                         else {
78                                 replacePage("ImagePage.qml");
79                         }
80                 }
81         }
82
83         // TODO: hardcoding
84         initialPage: ImagePage { cam: cam }
85 }