Move PreviewImage underneath FocusReticle
[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 (!video.paused) {
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         items: [
107             CameraToolIcon {
108                 iconId: "icon-m-toolbar-mediacontrol-stop-white"
109                 onClicked: video.stop()
110             },
111             CameraSlider {
112                 id: slider
113                 height: toolBar.height
114                 anchors.verticalCenter: parent.verticalCenter
115
116                 handleBackground: ""
117                 handleBackgroundPressed: ""
118
119                 minimumValue: 0
120                 maximumValue: video.duration
121                 value: video.position
122                 orientation: Qt.Horizontal
123
124                 onPressedChanged: {
125                     if (!slider.pressed) {
126                         video.position = slider.value
127                     }
128
129                     hideTimer.restart()
130                 }
131             },
132             CameraToolIcon {
133                 id: control
134                 iconId: !video.paused ? "icon-m-toolbar-mediacontrol-pause-white"
135                     : "icon-m-toolbar-mediacontrol-play-white"
136                 onClicked: {
137                     video.toggle()
138                     hideTimer.restart()
139                 }
140             }
141         ]
142     }
143 }