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