minor tweaks
[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: 20
98         anchors.left: parent.left
99         anchors.leftMargin: 20
100         opacity: show ? 0.8 : 0.0
101         visible: opacity > 0
102
103         Behavior on opacity {
104             PropertyAnimation { duration: 200; }
105         }
106
107         tools: CameraToolBarTools {
108             CameraToolIcon {
109                 iconSource: cameraTheme.videoStopIconId
110                 onClicked: video.stop()
111             }
112
113             CameraSlider {
114                 id: slider
115                 height: toolBar.height
116                 anchors.verticalCenter: parent.verticalCenter
117
118                 handleBackground: ""
119                 handleBackgroundPressed: ""
120
121                 minimumValue: 0
122                 maximumValue: video.duration
123                 value: video.position
124                 orientation: Qt.Horizontal
125
126                 onPressedChanged: {
127                     if (!slider.pressed) {
128                         video.position = slider.value
129                     }
130
131                     hideTimer.restart()
132                 }
133             }
134
135             CameraToolIcon {
136                 id: control
137                 iconSource: video.state != VideoPlayer.StatePaused ? cameraTheme.videoPauseIconId : cameraTheme.videoPlayIconId
138                 onClicked: {
139                     video.toggle()
140                     hideTimer.restart()
141                 }
142             }
143         }
144     }
145 }