Switch toolbar animation to opacity
[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 url itemUrl: url
30     property string itemTitle: title
31     property string itemMimeType: mimeType
32     property string itemCreated: created
33     property string itemFileName: fileName
34
35     property bool isVideo: itemMimeType.search("video/") >= 0
36     property alias error: image.error
37     property bool playing: loader.source != ""
38     signal clicked
39     clip: true
40
41     function startPlayback() {
42         loader.source = Qt.resolvedUrl("VideoPlayerPage.qml")
43         loader.item.source = itemUrl
44         if (!loader.item.play()) {
45             showError(qsTr("Error playing video. Please try again."))
46             loader.source = ""
47         }
48     }
49
50     function stopPlayback() {
51         if (loader.item) {
52             loader.item.stop()
53         }
54     }
55
56     Loader {
57         id: loader
58         anchors.fill: parent
59     }
60
61     Connections {
62         target: loader.item
63         onFinished: loader.source = ""
64     }
65
66     FullScreenThumbnail {
67         id: image
68         source: itemUrl
69         mimeType: itemMimeType
70         rotation: calculateRotation(orientation.orientation)
71         width: isPortrait ? parent.height : parent.width - 10
72         height: isPortrait ? parent.width - 10 : parent.height
73         anchors.centerIn: parent
74         visible: loader.source == ""
75         property bool isPortrait: rotation == -90
76
77         Behavior on width {
78             PropertyAnimation { duration: 100 }
79         }
80
81         Behavior on height {
82             PropertyAnimation { duration: 100 }
83         }
84
85         Behavior on rotation {
86             PropertyAnimation { duration: 100 }
87         }
88
89         function calculateRotation(orientation) {
90             switch (orientation) {
91                 case CameraOrientation.InvertedLandscape:
92                 case CameraOrientation.Landscape:
93                     return 0
94                 case CameraOrientation.InvertedPortrait:
95                 case CameraOrientation.Portrait:
96                     return -90
97                 default:
98                     return 0
99             }
100         }
101
102         MouseArea {
103             id: mouse
104             anchors.fill: parent
105             enabled: true
106             onClicked: postCaptureItem.clicked()
107         }
108
109         Column {
110             anchors.centerIn: parent
111             width: parent.width
112
113             CameraLabel {
114                 id: errorLabel
115                 width: parent.width
116                 visible: image.error
117                 text: qsTr("Failed to load preview")
118                 verticalAlignment: Text.AlignVCenter
119                 horizontalAlignment: Text.AlignHCenter
120                 font.pixelSize: 32
121             }
122
123             CameraToolIcon {
124                 id: playIcon
125                 anchors.horizontalCenter: parent.horizontalCenter
126                 iconSource: cameraTheme.videoPlayIconId
127                 visible: isVideo
128                 onClicked: startPlayback()
129             }
130         }
131     }
132 }