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