Updated copyright year
[harmattan/cameraplus] / qml / VideoPlayerPage.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 1.1
24 import com.nokia.meego 1.1
25 import QtMultimediaKit 1.1
26 import CameraPlus 1.0
27
28 // TODO: error reporting
29
30 CameraPage {
31         id: page
32
33         property bool popTwice: false
34         controlsVisible: false
35         policyMode: CameraResources.None
36         standbyVisible: false
37
38         property alias source: video.source
39
40         function play() {
41                 video.play();
42         }
43
44         MouseArea {
45                 anchors.top: parent.top
46                 anchors.bottom: toolBar.top
47                 anchors.left: parent.left
48                 anchors.right: parent.right
49
50                 onClicked: toolBar.show = !toolBar.show
51         }
52
53         Timer {
54                 id: hideTimer
55                 running: toolBar.show
56                 interval: 3000
57                 onTriggered: toolBar.show = false;
58         }
59
60                 Video {
61                 id: video
62                 anchors.fill: parent
63
64                 function toggle() {
65                         if (!video.paused) {
66                                 video.pause();
67                         }
68                         else {
69                                 page.play();
70                         }
71                 }
72
73                 onStopped: {
74                         source = "";
75                         pageStack.pop(undefined, true);
76
77                         if (page.popTwice) {
78                                 pageStack.pop(undefined);
79                         }
80                 }
81                 }
82
83         Connections {
84                 target: Qt.application
85                 onActiveChanged: {
86                         if (!Qt.application.active) {
87                                 video.stop();
88                         }
89                 }
90         }
91
92         CameraToolBar {
93                 id: toolBar
94
95                 property bool show: true
96
97                 manualBack: true
98                 expanded: true
99                 anchors.bottom: parent.bottom
100                 anchors.bottomMargin: show ? 20 : -1 * (height + 20)
101                 anchors.left: parent.left
102                 anchors.leftMargin: 20
103                 opacity: 0.5
104
105                 Behavior on anchors.bottomMargin {
106                         PropertyAnimation { duration: 200; }
107                 }
108
109                 onClicked: {
110                         page.popTwice = true;
111                         video.stop();
112                 }
113
114                 items: [
115                         ToolIcon { iconId: "icon-m-toolbar-mediacontrol-stop-white"; onClicked: { video.stop(); } },
116                         Slider {
117                                 id: slider
118                                 height: toolBar.height
119                                 anchors.verticalCenter: parent.verticalCenter
120
121                                 platformStyle: SliderStyle {
122                                         handleBackground: ""
123                                         handleBackgroundPressed: ""
124                                 }
125
126                                 minimumValue: 0
127                                 maximumValue: video.duration
128                                 value: video.position
129                                 orientation: Qt.Horizontal
130
131                                 onPressedChanged: {
132                                         if (!slider.pressed) {
133                                                 video.position = slider.value;
134                                         }
135
136                                         hideTimer.restart();
137                                 }
138                         },
139                         ToolIcon {
140                                 id: control
141                                 iconId: !video.paused ? "icon-m-toolbar-mediacontrol-pause-white" : "icon-m-toolbar-mediacontrol-play-white"
142                                 onClicked: {
143                                         video.toggle();
144                                         hideTimer.restart();
145                                 }
146                         }
147                 ]
148         }
149 }