68200302c7f71b41596d0467ab42884bfde0815d
[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 CameraPlus 1.0
26 import QtCamera 1.0
27 import QtCameraExtras 1.0
28
29 Item {
30     id: page
31
32     signal finished
33     property alias source: video.source
34
35     function play() {
36         return video.play()
37     }
38
39     function stop() {
40         return video.stop()
41     }
42
43     MouseArea {
44         anchors.top: parent.top
45         anchors.bottom: toolBar.top
46         anchors.left: parent.left
47         anchors.right: parent.right
48
49         onClicked: toolBar.show = !toolBar.show
50     }
51
52     Timer {
53         id: hideTimer
54         running: toolBar.show
55         interval: 3000
56         onTriggered: toolBar.show = false
57     }
58
59     VideoPlayer {
60         id: video
61         anchors.fill: parent
62         cameraConfig: cam.cameraConfig
63
64         onError: showError(qsTr("Error playing video. Please try again or restart the application"))
65
66         function toggle() {
67             if (!video.paused) {
68                 video.pause()
69             } else {
70                 page.play()
71             }
72         }
73
74         onStateChanged: {
75             if (state == VideoPlayer.StateStopped) {
76                 page.finished()
77             }
78         }
79     }
80
81     Connections {
82         target: Qt.application
83         onActiveChanged: {
84             if (!Qt.application.active) {
85                 video.stop()
86             }
87         }
88     }
89
90     CameraToolBar {
91         id: toolBar
92
93         property bool show: true
94
95         hideBack: true
96         expanded: true
97         anchors.bottom: parent.bottom
98         anchors.bottomMargin: show ? 20 : -1 * (height + 20)
99         anchors.left: parent.left
100         anchors.leftMargin: 20
101         opacity: 0.5
102
103         Behavior on anchors.bottomMargin {
104             PropertyAnimation { duration: 200; }
105         }
106
107         items: [
108             ToolIcon {
109                 iconId: "icon-m-toolbar-mediacontrol-stop-white"
110                 onClicked: video.stop()
111             },
112             Slider {
113                 id: slider
114                 height: toolBar.height
115                 anchors.verticalCenter: parent.verticalCenter
116
117                 platformStyle: SliderStyle {
118                     handleBackground: ""
119                     handleBackgroundPressed: ""
120                 }
121
122                 minimumValue: 0
123                 maximumValue: video.duration
124                 value: video.position
125                 orientation: Qt.Horizontal
126
127                 onPressedChanged: {
128                     if (!slider.pressed) {
129                         video.position = slider.value
130                     }
131
132                     hideTimer.restart()
133                 }
134             },
135             ToolIcon {
136                 id: control
137                 iconId: !video.paused ? "icon-m-toolbar-mediacontrol-pause-white"
138                     : "icon-m-toolbar-mediacontrol-play-white"
139                 onClicked: {
140                     video.toggle()
141                     hideTimer.restart()
142                 }
143             }
144         ]
145     }
146 }