Warning, /multimedia/plasmatube/src/ui/videoplayer/VideoPlayerParent.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020-2022 Devin Lin <devin@kde.org>
0002 // SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
0003 // SPDX-License-Identifier: GPL-3.0-or-later
0004 
0005 import QtQuick
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.plasmatube
0010 
0011 Flickable {
0012     id: root
0013     boundsBehavior: Flickable.StopAtBounds
0014     contentHeight: applicationWindow().height * 2
0015     interactive: Kirigami.Settings.hasTransientTouchInput
0016 
0017     property bool maximized: false
0018     property real contentToPlayerSpacing: 0
0019 
0020     property alias previewSource: videoPlayer.previewSource
0021 
0022     readonly property bool isVideoLoaded: PlasmaTube.videoController.currentVideo.isLoaded
0023     readonly property real miniPlayerHeight: Kirigami.Units.gridUnit * 3 + Kirigami.Units.gridUnit / 6
0024 
0025     function open() {
0026         toOpen.restart();
0027         maximized = true;
0028     }
0029 
0030     function close() {
0031         toClose.restart();
0032         maximized = false;
0033     }
0034 
0035     function resetToBoundsOnFlick() {
0036         if (!atYBeginning || !atYEnd) {
0037             if (root.verticalVelocity > 0) {
0038                 toOpen.restart();
0039             } else if (root.verticalVelocity < 0) {
0040                 toClose.restart();
0041             } else { // i.e. when verticalVelocity === 0
0042                 if (contentY > contentHeight / 4) {
0043                     toOpen.restart();
0044                 } else  {
0045                     toClose.restart();
0046                 }
0047             }
0048         }
0049     }
0050 
0051     function resetToBoundsOnResize() {
0052         if (maximized) {
0053             contentY = contentHeight / 2;
0054         } else {
0055             contentY = 0;
0056         }
0057     }
0058 
0059     NumberAnimation on contentY {
0060         id: toOpen
0061         from: contentY
0062         to: contentHeight / 2
0063         duration: Kirigami.Units.longDuration * 2
0064         easing.type: Easing.OutCubic
0065         running: false
0066         onFinished: {
0067             videoPlayer.forceActiveFocus(Qt.PopupFocusReason);
0068             console.log("Setting active focus...");
0069         }
0070     }
0071     NumberAnimation on contentY {
0072         id: toClose
0073         from: contentY
0074         to: 0
0075         duration: Kirigami.Units.longDuration * 2
0076         easing.type: Easing.OutCubic
0077         running: false
0078     }
0079 
0080     // snap to end
0081     MouseArea {
0082         anchors.fill: contentZone
0083         propagateComposedEvents: true
0084         onPressed: {
0085             toOpen.stop();
0086             toClose.stop();
0087             propagateComposedEvents = true;
0088         }
0089         onReleased: root.resetToBoundsOnFlick()
0090     }
0091 
0092     onMovementStarted: {
0093         toOpen.stop();
0094         toClose.stop();
0095     }
0096     onFlickStarted: resetToBoundsOnFlick()
0097     onMovementEnded: resetToBoundsOnFlick()
0098 
0099     Connections {
0100         target: applicationWindow()
0101 
0102         function onHeightChanged() {
0103             resetToBoundsOnResize()
0104         }
0105     }
0106 
0107     ColumnLayout {
0108         id: contentZone
0109         spacing: 0
0110         height: applicationWindow().height * 2
0111         anchors.bottom: parent.bottom
0112         anchors.left: parent.left
0113         anchors.right: parent.right
0114 
0115         Item {
0116             Layout.fillWidth: true
0117             implicitHeight: applicationWindow().height
0118 
0119             Rectangle {
0120                 anchors.left: parent.left
0121                 anchors.right: parent.right
0122                 anchors.bottom: parent.bottom
0123                 height: root.contentToPlayerSpacing
0124                 color: Kirigami.Theme.backgroundColor
0125             }
0126 
0127             Kirigami.Separator {
0128                 anchors.left: parent.left
0129                 anchors.right: parent.right
0130                 anchors.bottom: minimizedPlayer.top
0131             }
0132 
0133             MinimizedVideoPlayer {
0134                 id: minimizedPlayer
0135                 visible: root.isVideoLoaded
0136                 height: root.miniPlayerHeight
0137                 anchors.left: parent.left
0138                 anchors.right: parent.right
0139                 anchors.bottom: parent.bottom
0140                 anchors.bottomMargin: root.contentToPlayerSpacing
0141 
0142                 previewSource: root.previewSource
0143                 videoName: videoPlayer.videoName
0144                 channelName: videoPlayer.channelName
0145 
0146                 onToggleRequested: PlasmaTube.videoController.togglePlaying()
0147                 onStopRequested: PlasmaTube.videoController.stop()
0148                 onOpenRequested: root.open()
0149                 onNextRequested: PlasmaTube.videoController.next()
0150             }
0151         }
0152 
0153         VideoPlayer {
0154             id: videoPlayer
0155             Layout.fillWidth: true
0156             Layout.fillHeight: true
0157 
0158             onRequestClosePlayer: root.close();
0159         }
0160     }
0161 }