Warning, /multimedia/haruna/src/qml/MpvVideo.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2020 George Florea Bănuș <georgefb899@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Window
0009 import QtQuick.Controls
0010 
0011 import org.kde.haruna
0012 import org.kde.haruna.settings
0013 import org.kde.kirigami as Kirigami
0014 
0015 MpvItem {
0016     id: root
0017 
0018     property alias mouseY: mouseArea.mouseY
0019 
0020 
0021     property int preMinimizePlaybackState: MpvVideo.PlaybackState.Playing
0022     enum PlaybackState {
0023         Playing,
0024         Paused
0025     }
0026 
0027     onVolumeChanged: {
0028         osd.message(i18nc("@info:tooltip", "Volume: %1", root.volume))
0029     }
0030 
0031     onFileStarted: {
0032         const url = currentUrl.toString()
0033         if (typeof url === "string" && url.startsWith("http")) {
0034             loadingIndicatorParent.visible = true
0035         }
0036     }
0037 
0038     onFileLoaded: {
0039         loadingIndicatorParent.visible = false
0040     }
0041 
0042     onOsdMessage: {
0043         osd.message(text);
0044     }
0045 
0046     onRaise: { app.raiseWindow() }
0047     onPlayNext: { appActions.playNextAction.trigger() }
0048     onPlayPrevious: { appActions.playPreviousAction.trigger() }
0049     onOpenUri: { window.openFile(uri) }
0050 
0051     Timer {
0052         id: hideCursorTimer
0053 
0054         running: window.isFullScreen() && mouseArea.containsMouse
0055         repeat: true
0056         interval: 2000
0057         onTriggered: mouseArea.hideCursor = true
0058     }
0059 
0060     MouseArea {
0061         id: mouseArea
0062 
0063         property bool hideCursor: false
0064 
0065         acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
0066         anchors.fill: parent
0067         hoverEnabled: true
0068         cursorShape: hideCursor && window.isFullScreen() ? Qt.BlankCursor : Qt.ArrowCursor
0069 
0070         onPositionChanged: {
0071             hideCursor = false
0072             hideCursorTimer.restart()
0073 
0074             if (!PlaylistSettings.canToggleWithMouse || playlist.playlistView.count <= 1) {
0075                 return
0076             }
0077             if (PlaylistSettings.position === "right") {
0078                 if (mouseX > width - 50) {
0079                     playlist.state = "visible"
0080                 } else {
0081                     playlist.state = "hidden"
0082                 }
0083             } else {
0084                 if (mouseX < 50) {
0085                     playlist.state = "visible"
0086                 } else {
0087                     playlist.state = "hidden"
0088                 }
0089             }
0090         }
0091 
0092         onWheel: wheel => {
0093             if (wheel.angleDelta.y > 0) {
0094                 if (MouseSettings.scrollUp) {
0095                     appActions[MouseSettings.scrollUp].trigger()
0096                 }
0097             } else if (wheel.angleDelta.y) {
0098                 if (MouseSettings.scrollDown) {
0099                     appActions[MouseSettings.scrollDown].trigger()
0100                 }
0101             }
0102         }
0103 
0104         onPressed: mouse => {
0105             focus = true
0106             if (mouse.button === Qt.LeftButton) {
0107                 if (MouseSettings.left) {
0108                     appActions[MouseSettings.left].trigger()
0109                 }
0110             } else if (mouse.button === Qt.MiddleButton) {
0111                 if (MouseSettings.middle) {
0112                     appActions[MouseSettings.middle].trigger()
0113                 }
0114             } else if (mouse.button === Qt.RightButton) {
0115                 if (MouseSettings.right) {
0116                     appActions[MouseSettings.right].trigger()
0117                 }
0118             }
0119         }
0120 
0121         onDoubleClicked: mouse => {
0122             if (mouse.button === Qt.LeftButton) {
0123                 if (MouseSettings.leftx2) {
0124                     appActions[MouseSettings.leftx2].trigger()
0125                 }
0126             } else if (mouse.button === Qt.MiddleButton) {
0127                 if (MouseSettings.middlex2) {
0128                     appActions[MouseSettings.middlex2].trigger()
0129                 }
0130             } else if (mouse.button === Qt.RightButton) {
0131                 if (MouseSettings.rightx2) {
0132                     appActions[MouseSettings.rightx2].trigger()
0133                 }
0134             }
0135         }
0136     }
0137 
0138     DropArea {
0139         id: dropArea
0140 
0141         anchors.fill: parent
0142         keys: ["text/uri-list"]
0143 
0144         onDropped: drop => {
0145             if (window.acceptedSubtitleTypes.includes(app.mimeType(drop.urls[0]))) {
0146                 command(["sub-add", drop.urls[0], "select"])
0147             }
0148 
0149             if (app.mimeType(drop.urls[0]).startsWith("video/") || app.mimeType(drop.urls[0]).startsWith("audio/")) {
0150                 window.openFile(drop.urls[0], true)
0151             }
0152         }
0153     }
0154 
0155     Rectangle {
0156         id: loadingIndicatorParent
0157 
0158         visible: false
0159         anchors.centerIn: parent
0160         color: Kirigami.Theme.backgroundColor
0161         opacity: 0.6
0162 
0163         Kirigami.Icon {
0164             id: loadingIndicator
0165 
0166             source: "view-refresh"
0167             anchors.centerIn: parent
0168             width: Kirigami.Units.iconSizes.large
0169             height: Kirigami.Units.iconSizes.large
0170 
0171             RotationAnimator {
0172                 target: loadingIndicator
0173                 from: 0
0174                 to: 360
0175                 duration: 1500
0176                 loops: Animation.Infinite
0177                 running: loadingIndicatorParent.visible
0178             }
0179 
0180             Component.onCompleted: {
0181                 parent.width = width + 10
0182                 parent.height = height + 10
0183             }
0184         }
0185     }
0186 }