Debian Codegraph @

src/qml/player/Controls.qml

raw
1 /*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Ugo Riboni <[email protected]>
6 * MichaƂ Sawicz <[email protected]>
7 * Renato Araujo Oliveira Filho <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 import QtQuick 2.4
22 import QtQuick.Window 2.2
23 import QtMultimedia 5.0
24 import Lomiri.Components 1.3
25
26 Item {
27 id: controls
28
29 readonly property string orientation: controls.width >= units.gu(60) ? "LANDSCAPE" : "PORTRAIT"
30 property variant video: null
31 property int maximumHeight: 0
32 property alias sceneSelectorHeight: _sceneSelector.height
33 property alias sceneSelectorVisible: _sceneSelector.visible
34 property int heightOffset: 0
35 property variant playerStatus: MediaPlayer.NoMedia
36
37 property alias finalSeekPosition: _timeline.finalSeekPosition
38 property alias openFileEnabled: _openFileButton.enabled
39
40 signal fullscreenClicked
41 signal playbackClicked
42 signal settingsClicked
43 signal openFileClicked
44 signal shareClicked
45 signal seekRequested(int time)
46 signal startSeek
47 signal endSeek
48
49 focus: true
50 height: sceneSelectorVisible ? maximumHeight - heightOffset : _toolbar.height
51
52 function removeExt(uri) {
53 return uri.toString().substring(0, uri.toString().lastIndexOf("."))
54 }
55
56 ListModel {
57 id: _sceneSelectorModel
58 }
59
60 Rectangle {
61 id: _bgColor
62
63 color: "black"
64 opacity: 0.8
65 anchors.fill: parent
66 }
67
68 SceneSelector {
69 id: _sceneSelector
70
71 property bool show: false
72
73 property bool parentActive: _controls.active
74
75 function selectSceneAt(time) {
76 // SKIP it for now, we need to fix hybris bug #1231147
77 return
78 }
79
80 objectName: "Controls.SceneSelector"
81 opacity: 0
82 visible: opacity > 0
83 // SKIP it for now, we need to fix hybris bug #1231147
84 //model: _sceneSelectorModel
85 anchors {
86 left: parent.left
87 right: parent.right
88 top: parent.top
89 }
90
91 onSceneSelected: controls.seekRequested(start)
92 onParentActiveChanged: {
93 if (!parentActive) {
94 show = false
95 }
96 }
97
98 ParallelAnimation {
99 id: _showAnimation
100
101 // SKIP it for now, we need to fix hybris bug #1231147
102 running: false //_sceneSelector.show
103 NumberAnimation { target: _sceneSelector; property: "opacity"; to: 1; duration: 175 }
104 NumberAnimation { target: controls; property: "heightOffset"; to: 0; duration: 175 }
105 }
106
107 ParallelAnimation {
108 id: _hideAnimation
109
110 // SKIP it for now, we need to fix hybris bug #1231147
111 running: false //!_sceneSelector.show
112 NumberAnimation { target: _sceneSelector; property: "opacity"; to: 0; duration: 175 }
113 NumberAnimation { target: controls; property: "heightOffset"; to: units.gu(2); duration: 175 }
114 }
115 }
116
117 HLine {
118 id: _divLine
119 anchors {
120 left: _toolbar.left
121 right: _toolbar.right
122 top: parent.top
123 }
124 }
125 Column {
126 id: _toolbar
127
128 anchors {
129 bottom: parent.bottom
130 left: parent.left
131 right: parent.right
132 }
133 height: childrenRect.height
134
135 Item {
136 id: timelinePlaceHolderPortrait
137
138 anchors {
139 left: parent.left
140 right: parent.right
141 }
142 height: controls.orientation === "PORTRAIT" ? units.gu(5) : 0
143 }
144
145 Row {
146 id: controlsRow
147 anchors {
148 left: parent.left
149 right: parent.right
150 margins: units.gu(2)
151 }
152 height: units.gu(5)
153
154 IconButton {
155 id: _fullScreenButton
156
157 iconSource: Window.visibility === Window.FullScreen ? "image://theme/view-restore" : "image://theme/view-fullscreen"
158 iconSize: units.gu(3)
159 anchors.verticalCenter: parent.verticalCenter
160 width: visible ? units.gu(8) : 0
161 height: units.gu(4)
162 onClicked: controls.fullscreenClicked()
163 leftAlignment: true
164 }
165
166 VLine {
167 }
168
169 IconButton {
170 id: playbackButton
171 objectName: "Controls.PlayBackButton"
172
173 property string icon
174
175 iconSource: icon ? "image://theme/media-playback-%1".arg(icon) : ""
176 iconSize: units.gu(3)
177 anchors.verticalCenter: parent.verticalCenter
178 width: controls.orientation === "LANDSCAPE" ? units.gu(10) :
179 controlsRow.width -
180 _fullScreenButton.width -
181 _timeLabel.width -
182 _shareButton.width -
183 _openFileButton.width -
184 _quitButton.width
185
186 height: units.gu(4)
187 onClicked: controls.playbackClicked()
188 }
189
190 VLine {
191 }
192
193 Item {
194 id: timelinePlaceHolderLandscape
195
196 anchors {
197 top: parent.top
198 bottom: parent.bottom
199 }
200
201 width: controls.orientation === "LANDSCAPE" ? controlsRow.width -
202 _fullScreenButton.width -
203 playbackButton.width -
204 _timeLabel.width -
205 _shareButton.width -
206 _openFileButton.width -
207 _quitButton.width : 0
208
209 TimeLine {
210 id: _timeline
211
212 property bool seeking: false
213
214 anchors {
215 left: parent.left
216 right: parent.right
217 margins: units.gu(2)
218 verticalCenter: parent.verticalCenter
219 }
220 height: units.gu(4)
221 parent: controls.orientation === "PORTRAIT" ? timelinePlaceHolderPortrait : timelinePlaceHolderLandscape
222 minimumValue: 0
223 maximumValue: video && video.duration > 0 ? video.duration / 1000 : 0 // overridden by video Connections onPositionChanged
224 playerStatus: controls.playerStatus
225
226 // pause the video during the seek
227 onPressedChanged: {
228 if (!pressed && seeking) {
229 endSeek()
230 seeking = false
231 }
232 }
233
234 // Live value is the real slider value. Ex: User dragging the slider
235 onLiveValueChanged: {
236 if (video) {
237 var changed = Math.abs(liveValue - videoPosition)
238 if (changed > 1) {
239 if (!seeking) {
240 startSeek()
241 seeking = true
242 }
243 seekRequested(liveValue * 1000)
244 _sceneSelector.selectSceneAt(liveValue * 1000)
245 }
246 }
247 }
248
249 onValueChanged: _sceneSelector.selectSceneAt(video.position)
250 onClicked: {
251 if (insideThumb) {
252 _sceneSelector.show = !_sceneSelector.show
253 } else {
254 _sceneSelector.show = true
255 }
256 }
257 }
258 }
259
260 VLine {
261 visible: controls.orientation === "LANDSCAPE"
262 }
263
264 TimeLabel {
265 id: _timeLabel
266
267 remainingTime: _timeline.remainingTime
268 currentTime: _timeline.currentTime
269
270 anchors {
271 top: parent.top
272 bottom: parent.bottom
273 }
274 width: controls.orientation === "LANDSCAPE" ? units.gu(10) : units.gu(8)
275 }
276
277 VLine {
278 visible: _shareButton.visible
279 }
280
281 IconButton {
282 id: _shareButton
283
284 /* Disable share button for now until we get some feedback from designers */
285 visible: false
286 iconSource: "artwork/icon_share.png"
287 iconSize: units.gu(3)
288 anchors {
289 top: parent.top
290 bottom: parent.bottom
291 }
292 width: visible ? units.gu(7) : 0
293 onClicked: controls.shareClicked()
294 }
295
296 VLine {
297 visible: _openFileButton.visible
298 }
299
300 IconButton {
301 id: _openFileButton
302
303 visible: enabled
304 iconSource: "image://theme/document-open"
305 iconSize: units.gu(3)
306 anchors {
307 top: parent.top
308 bottom: parent.bottom
309 }
310 width: visible ? units.gu(7) : 0
311 enabled: false
312 opacity: enabled ? 1.0 : 0.2
313 onClicked: openFileClicked()
314 }
315
316 VLine {}
317
318 IconButton {
319 id: _quitButton
320
321 iconSource: "image://theme/close"
322 iconSize: units.gu(3)
323 anchors {
324 top: parent.top
325 bottom: parent.bottom
326 }
327 width: units.gu(7)
328 onClicked: Qt.quit()
329 }
330 }
331 }
332
333 Connections {
334 target: video
335 onDurationChanged: {
336 _sceneSelector.currentIndex = -1
337 _sceneSelectorModel.clear()
338 var frameSize = video.duration / 10;
339 for (var i = 0; i < 10; ++i) {
340 var pos = Math.floor(i * frameSize);
341 if (pos <= video.duration) {
342 _sceneSelectorModel.append({"thumbnail": "image://video/" + video.source + "/" + pos,
343 "start" : pos,
344 "duration" : frameSize})
345 }
346 }
347 }
348
349 onPositionChanged: {
350 // To get position to be smooth and accurate during seeking, do
351 // not use the reported value for position from media-hub but instead
352 // use the value that the user move the scrubber to. This makes seeking
353 // silky smooth. Report correctly on normal advance, or EOS.
354 if (!_timeline.seeking || controls.playerStatus == MediaPlayer.EndOfMedia) {
355 _timeline.videoPosition = video ? video.position / 1000 : 0
356 }
357
358 // work around for durationChanged not emitted in some situation
359 // making the timeline maximum negative
360 console.log('onPositionChanged', position, video.duration, _timeline.maximumValue)
361 if (_timeline.maximumValue <= 0) {
362 _timeline.maximumValue = video.duration / 1000
363 }
364 }
365 }
366
367 states: [
368 State {
369 name: "stopped"
370 PropertyChanges { target: playbackButton; icon: "start" }
371 },
372
373 State {
374 name: "playing"
375 PropertyChanges { target: playbackButton; icon: "pause" }
376 },
377
378 State {
379 name: "paused"
380 PropertyChanges { target: playbackButton; icon: "start" }
381 }
382 ]
383 }