2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import QtMultimedia 5.0
19 import Ubuntu.Components 1.3
23 property var sourceData
24 property string context: ""
25 property list<Action> actions
26 property Item rootItem: QuickUtils.rootItem(root)
27 property var maximumEmbeddedHeight
29 property alias header: headerContent.item
30 property alias content: contentLoader.item
31 property alias footer: footerContent.item
32 property alias fullscreen: priv.fullscreen
36 onFullscreenChanged: {
37 if (!fullscreen) rotationAction.checked = false;
40 readonly property color backgroundColor: "#1B1B1B"
41 readonly property color iconColor: "#F3F3E7"
45 color: root.backgroundColor
51 automaticOrientation: fullscreen
59 when: !rotationAction.checked
63 when: rotationAction.checked
71 PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: false }
72 PropertyAction { target: orientationHelper; property: "orientationAngle"; value: 90 }
73 PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: false }
79 PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: false }
80 PropertyAction { target: orientationHelper; property: "orientationAngle"; value: 0 }
81 PropertyAction { target: orientationHelper; property: "automaticOrientation"; value: fullscreen }
93 return videoComponent;
102 objectName: "videoPlayer"
104 width: orientationHelper.width
105 height: orientationHelper.height
106 maximumEmbeddedHeight: root.maximumEmbeddedHeight
107 fixedHeight: fullscreen
108 orientation: orientationState.state === "landscape" ? Qt.LandscapeOrientation : Qt.PortraitOrientation
110 playButtonBackgroundColor: root.backgroundColor
111 playButtonIconColor: root.iconColor
114 var screenshotData = root.sourceData["screenshot"];
115 if (screenshotData) return screenshotData;
117 var source = root.sourceData["source"];
119 if (source.toString().indexOf("file://") === 0) {
120 return "image://thumbnailer/" + source.toString().substr(7);
126 mediaPlayer: footer ? footer.mediaPlayer : null
129 if (mediaPlayer.availability !== MediaPlayer.Available) return;
131 if (mediaPlayer.playbackState === MediaPlayer.StoppedState) {
133 } else if (controlHideTimer.running) {
134 if (mediaPlayer.playbackState === MediaPlayer.PlayingState) {
140 controlHideTimer.restart();
143 onPositionChanged: controlHideTimer.restart();
155 topMargin: -headerContent.height
167 color: root.backgroundColor
169 visible: headerContent.status === Loader.Ready
172 active: root.fullscreen
173 sourceComponent: headerComponent
178 MediaServicesHeader {
179 iconColor: root.iconColor
181 rotationAction.checked = false;
187 // If we interact with the bar, reset the hide timer.
191 mouse.accepted = false
192 if (controlHideTimer.running) controlHideTimer.restart()
202 bottom: parent.bottom
203 bottomMargin: -footerContent.height
211 return videoControlsComponent;
222 color: root.backgroundColor
224 visible: footerContent.status === Loader.Ready
228 id: videoControlsComponent
229 VideoPlayerControls {
231 objectName: "videoControls"
233 viewAction: rotationAction.enabled ? rotationAction : fullscreenAction
234 userActions: root.actions
235 iconColor: root.iconColor
236 backgroundColor: root.backgroundColor
238 mediaPlayer.source: {
239 if (!root.sourceData) return "";
241 var source = root.sourceData["source"];
242 if (source.toString().indexOf("video://") === 0) {
243 return source.toString().substr(6);
247 mediaPlayer.onPlaybackStateChanged: {
248 controlHideTimer.restart();
253 property: "forceControlsShown"
255 value: (fullscreen && mediaPlayer.playbackState === MediaPlayer.StoppedState) ||
256 mediaPlayer.playbackState === MediaPlayer.PausedState ||
260 onInteractingChanged: {
261 controlHideTimer.restart();
267 value: controls.mediaPlayer.metaData.title !== undefined ?
268 controls.mediaPlayer.metaData.title :
269 controls.mediaPlayer.source.toString().replace(/^.*[\\\/]/, '')
275 // If we interact with the bar, reset the hide timer.
280 mouse.accepted = false
281 if (controlHideTimer.running) controlHideTimer.restart()
289 name: "controlsShown"
290 when: priv.forceControlsShown || priv.controlTimerActive
292 target: footerContent
293 anchors.bottomMargin: 0
297 target: headerContent
307 SequentialAnimation {
308 PropertyAction { target: root; property: "clip"; value: true }
309 PropertyAction { property: "visible" }
311 properties: "anchors.bottomMargin,anchors.topMargin"
312 duration: UbuntuAnimation.FastDuration
314 PropertyAction { target: root; property: "clip"; value: false }
318 from: "controlsShown"
319 SequentialAnimation {
320 PropertyAction { target: root; property: "clip"; value: true }
322 properties: "anchors.bottomMargin,anchors.topMargin"
323 duration: UbuntuAnimation.FastDuration
325 PropertyAction { property: "visible" }
326 PropertyAction { target: root; property: "clip"; value: false }
336 when: !priv.fullscreen
337 PropertyChanges { target: root; implicitHeight: content ? content.implicitHeight : 0; }
341 when: priv.fullscreen
342 ParentChange { target: root; parent: rootItem; x: 0; y: 0; width: parent.width; }
343 PropertyChanges { target: root; implicitHeight: root.parent ? root.parent.height : 0; }
344 PropertyChanges { target: fullscreenAction; iconName: "view-restore"; }
348 transitions: Transition {
350 UbuntuNumberAnimation { properties: "x,y,width,implicitHeight"; duration: UbuntuAnimation.FastDuration }
358 property bool fullscreen: false
359 property alias controlTimerActive: controlHideTimer.running
360 property bool forceControlsShown: false
365 objectName: "controlHideTimer"
372 enabled: rotationAction.enabled === false
373 iconName: "view-fullscreen"
375 onTriggered: priv.fullscreen = !priv.fullscreen
380 enabled: root.fullscreen === true
381 iconName: "view-rotate"
383 property bool checked: false
384 onTriggered: checked = !checked