Fixed VideoPlayerPage.qml failure to set cameraConfig
[harmattan/cameraplus] / qml / PostCaptureItem.qml
index 1de94c6..4cc51d1 100644 (file)
@@ -3,7 +3,7 @@
 /*!
  * This file is part of CameraPlus.
  *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-import QtQuick 1.1
-import com.nokia.meego 1.1
+import QtQuick 2.0
 import CameraPlus 1.0
 
-// TODO: pinch zoom
 Item {
-        id: postCaptureItem
-        property bool isVideo: itemData.type.search("nmm#Video") > 0
-        property bool error: false
-        property variant itemData: item
-        property bool isCurrentItem: PathView.isCurrentItem
-        onIsCurrentItemChanged: {
-                if (isCurrentItem) {
-                        page.currentItem = postCaptureItem;
-                }
-        }
+    id: postCaptureItem
+
+    property bool isVideo: itemData.type.search("nmm#Video") > 0
+    property alias error: image.error
+    property variant itemData: item
+    property bool playing: loader.source != ""
+    signal clicked
 
-        function startPlayback() {
-                openFileNow("VideoPlayerPage.qml");
-                pageStack.currentPage.source = itemData.url;
-                pageStack.currentPage.play();
+    function startPlayback() {
+        loader.source = Qt.resolvedUrl("VideoPlayerPage.qml")
+        loader.item.source = itemData.url
+        if (!loader.item.play()) {
+            showError(qsTr("Error playing video. Please try again."))
+            loader.source = ""
         }
+    }
 
-        Label {
-                anchors.fill: parent
-                visible: image.error && page.status == PageStatus.Active
-                text: qsTr("Failed to load preview");
-                verticalAlignment: Text.AlignVCenter
-                horizontalAlignment: Text.AlignHCenter
-                font.pixelSize: 32
+    function stopPlayback() {
+        if (loader.item) {
+            loader.item.stop()
         }
+    }
+
+    Loader {
+        id: loader
+        anchors.fill: parent
+    }
 
-        QuillItem {
-                id: image
-                width: parent.width - 10
-                height: parent.height
-                anchors.centerIn: parent
+    Connections {
+        target: loader.item
+        onFinished: loader.source = ""
+    }
 
-                visible: page.status == PageStatus.Activating || page.status == PageStatus.Active
+// TODO: rotation
+    FullScreenThumbnail {
+        id: image
+        source: itemData.url
+        mimeType: itemData.mimeType
 
-                Component.onCompleted: initialize(itemData.url, itemData.mimetype);
+        width: parent.width - 10
+        height: parent.height
+        anchors.centerIn: parent
+        visible: loader.source == ""
 
-                MouseArea {
-                        id: mouse
-                        anchors.fill: parent
-                        enabled: true
-                        onClicked: toolBar.show = !toolBar.show
-                }
+        MouseArea {
+            id: mouse
+            anchors.fill: parent
+            enabled: true
+            onClicked: postCaptureItem.clicked()
+        }
+
+        Column {
+            anchors.centerIn: parent
+            width: parent.width
+
+            CameraLabel {
+                id: errorLabel
+                width: parent.width
+                visible: image.error
+                text: qsTr("Failed to load preview")
+                verticalAlignment: Text.AlignVCenter
+                horizontalAlignment: Text.AlignHCenter
+                font.pixelSize: 32
+            }
 
-                ToolIcon {
-                        id: playIcon
-                        anchors.centerIn: parent
-                        iconSource: "image://theme/icon-s-music-video-play"
-                        visible: isVideo
-                        onClicked: startPlayback();
-                }
+            CameraToolIcon {
+                id: playIcon
+                anchors.horizontalCenter: parent.horizontalCenter
+                iconSource: "image://theme/icon-s-music-video-play"
+                visible: isVideo
+                onClicked: startPlayback()
+            }
         }
+    }
 }