Don't reuse file names
[harmattan/cameraplus] / qml / PostCaptureItem.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012-2013 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 2.0
24 import CameraPlus 1.0
25
26 Item {
27     id: postCaptureItem
28
29     property bool isVideo: itemData.type.search("nmm#Video") > 0
30     property alias error: image.error
31     property variant itemData: item
32     property bool playing: loader.source != ""
33     signal clicked
34     clip: true
35
36     function startPlayback() {
37         loader.source = Qt.resolvedUrl("VideoPlayerPage.qml")
38         loader.item.source = itemData.url
39         if (!loader.item.play()) {
40             showError(qsTr("Error playing video. Please try again."))
41             loader.source = ""
42         }
43     }
44
45     function stopPlayback() {
46         if (loader.item) {
47             loader.item.stop()
48         }
49     }
50
51     Loader {
52         id: loader
53         anchors.fill: parent
54     }
55
56     Connections {
57         target: loader.item
58         onFinished: loader.source = ""
59     }
60
61     FullScreenThumbnail {
62         id: image
63         source: itemData.url
64         mimeType: itemData.mimeType
65         rotation: calculateRotation(orientation.orientation)
66         width: isPortrait ? parent.height : parent.width - 10
67         height: isPortrait ? parent.width - 10 : parent.height
68         anchors.centerIn: parent
69         visible: loader.source == ""
70         property bool isPortrait: rotation == -90
71
72         Behavior on width {
73             PropertyAnimation { duration: 100 }
74         }
75
76         Behavior on height {
77             PropertyAnimation { duration: 100 }
78         }
79
80         Behavior on rotation {
81             PropertyAnimation { duration: 100 }
82         }
83
84         function calculateRotation(orientation) {
85             switch (orientation) {
86                 case CameraOrientation.InvertedLandscape:
87                 case CameraOrientation.Landscape:
88                     return 0
89                 case CameraOrientation.InvertedPortrait:
90                 case CameraOrientation.Portrait:
91                     return -90
92                 default:
93                     return 0
94             }
95         }
96
97         MouseArea {
98             id: mouse
99             anchors.fill: parent
100             enabled: true
101             onClicked: postCaptureItem.clicked()
102         }
103
104         Column {
105             anchors.centerIn: parent
106             width: parent.width
107
108             CameraLabel {
109                 id: errorLabel
110                 width: parent.width
111                 visible: image.error
112                 text: qsTr("Failed to load preview")
113                 verticalAlignment: Text.AlignVCenter
114                 horizontalAlignment: Text.AlignHCenter
115                 font.pixelSize: 32
116             }
117
118             CameraToolIcon {
119                 id: playIcon
120                 anchors.horizontalCenter: parent.horizontalCenter
121                 iconSource: cameraTheme.videoPlayIconId
122                 visible: isVideo
123                 onClicked: startPlayback()
124             }
125         }
126     }
127 }