2021-11-10 06:17:00 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2021-11-10 06:17:00 +03:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2021-11-11 08:16:25 +03:00
|
|
|
import "../"
|
2021-11-11 21:18:45 +03:00
|
|
|
import "../../"
|
2022-04-19 02:41:41 +03:00
|
|
|
import QtMultimedia
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Layouts
|
2022-04-15 03:58:44 +03:00
|
|
|
import im.nheko
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
Rectangle {
|
2021-11-10 06:17:00 +03:00
|
|
|
id: control
|
|
|
|
|
|
|
|
property alias desiredVolume: volumeSlider.desiredVolume
|
2022-04-16 03:13:01 +03:00
|
|
|
property var duration
|
|
|
|
property bool mediaLoaded: false
|
|
|
|
property var mediaState
|
2021-11-11 21:18:45 +03:00
|
|
|
property bool muted: false
|
2021-11-11 08:16:25 +03:00
|
|
|
property bool playingVideo: false
|
2021-11-10 06:17:00 +03:00
|
|
|
property var position
|
2022-04-16 03:13:01 +03:00
|
|
|
property var positionValue: 0
|
2021-11-11 21:56:51 +03:00
|
|
|
property bool shouldShowControls: !playingVideo || playerMouseArea.shouldShowControls || volumeSlider.state == "shown"
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2022-04-16 03:13:01 +03:00
|
|
|
signal loadActivated
|
|
|
|
signal playPauseActivated
|
2021-11-11 21:56:51 +03:00
|
|
|
|
2021-11-10 06:17:00 +03:00
|
|
|
function durationToString(duration) {
|
|
|
|
function maybeZeroPrepend(time) {
|
|
|
|
return (time < 10) ? "0" + time.toString() : time.toString();
|
|
|
|
}
|
|
|
|
var totalSeconds = Math.floor(duration / 1000);
|
|
|
|
var seconds = totalSeconds % 60;
|
|
|
|
var minutes = (Math.floor(totalSeconds / 60)) % 60;
|
|
|
|
var hours = (Math.floor(totalSeconds / (60 * 24))) % 24;
|
|
|
|
// Always show minutes and don't prepend zero into the leftmost element
|
|
|
|
var ss = maybeZeroPrepend(seconds);
|
|
|
|
var mm = (hours > 0) ? maybeZeroPrepend(minutes) : minutes.toString();
|
|
|
|
var hh = hours.toString();
|
|
|
|
if (hours < 1)
|
|
|
|
return mm + ":" + ss;
|
|
|
|
return hh + ":" + mm + ":" + ss;
|
|
|
|
}
|
2022-04-16 03:13:01 +03:00
|
|
|
function showControls() {
|
|
|
|
controlHideTimer.restart();
|
|
|
|
}
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 23:32:38 +03:00
|
|
|
color: {
|
2022-04-11 05:18:16 +03:00
|
|
|
var wc = timelineRoot.palette.alternateBase;
|
2021-11-11 23:32:38 +03:00
|
|
|
return Qt.rgba(wc.r, wc.g, wc.b, 0.5);
|
|
|
|
}
|
|
|
|
height: controlLayout.implicitHeight
|
2022-04-16 03:13:01 +03:00
|
|
|
opacity: control.shouldShowControls ? 1 : 0
|
|
|
|
|
|
|
|
// Fade controls in/out
|
|
|
|
Behavior on opacity {
|
|
|
|
OpacityAnimator {
|
|
|
|
duration: 100
|
|
|
|
}
|
|
|
|
}
|
2021-11-11 23:32:38 +03:00
|
|
|
|
2021-11-11 21:56:51 +03:00
|
|
|
HoverHandler {
|
2021-11-10 06:17:00 +03:00
|
|
|
id: playerMouseArea
|
|
|
|
|
2021-11-11 21:56:51 +03:00
|
|
|
property bool shouldShowControls: hovered || controlHideTimer.running || control.mediaState != MediaPlayer.PlayingState
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 23:32:38 +03:00
|
|
|
onHoveredChanged: showControls()
|
2021-11-10 06:17:00 +03:00
|
|
|
}
|
2021-11-11 08:16:25 +03:00
|
|
|
ColumnLayout {
|
|
|
|
id: controlLayout
|
2021-11-10 06:17:00 +03:00
|
|
|
anchors.bottom: control.bottom
|
|
|
|
anchors.left: control.left
|
|
|
|
anchors.right: control.right
|
2022-04-16 03:13:01 +03:00
|
|
|
enabled: control.shouldShowControls
|
|
|
|
spacing: 0
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 08:16:25 +03:00
|
|
|
NhekoSlider {
|
|
|
|
Layout.fillWidth: true
|
2021-11-11 21:18:45 +03:00
|
|
|
Layout.leftMargin: Nheko.paddingSmall
|
|
|
|
Layout.rightMargin: Nheko.paddingSmall
|
2022-04-16 03:13:01 +03:00
|
|
|
alwaysShowSlider: false
|
2021-11-11 21:18:45 +03:00
|
|
|
enabled: control.mediaLoaded
|
2021-11-11 08:16:25 +03:00
|
|
|
from: 0
|
|
|
|
to: control.duration
|
2022-04-16 03:13:01 +03:00
|
|
|
value: control.positionValue
|
2021-11-11 08:16:25 +03:00
|
|
|
|
2022-04-16 03:13:01 +03:00
|
|
|
onMoved: control.position = value
|
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
RowLayout {
|
2022-04-16 03:13:01 +03:00
|
|
|
Layout.fillWidth: true
|
2021-11-11 21:18:45 +03:00
|
|
|
Layout.margins: Nheko.paddingSmall
|
|
|
|
spacing: Nheko.paddingSmall
|
|
|
|
|
|
|
|
// Cache/Play/pause button
|
|
|
|
ImageButton {
|
|
|
|
id: playbackStateImage
|
2021-11-11 23:32:38 +03:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
2021-11-11 21:18:45 +03:00
|
|
|
Layout.preferredHeight: 24
|
|
|
|
Layout.preferredWidth: 24
|
2022-04-16 03:13:01 +03:00
|
|
|
buttonTextColor: timelineRoot.palette.text
|
2021-11-11 21:18:45 +03:00
|
|
|
image: {
|
|
|
|
if (control.mediaLoaded) {
|
|
|
|
if (control.mediaState == MediaPlayer.PlayingState)
|
2021-11-14 04:23:10 +03:00
|
|
|
return ":/icons/icons/ui/pause-symbol.svg";
|
2021-11-11 21:18:45 +03:00
|
|
|
else
|
2021-11-14 04:23:10 +03:00
|
|
|
return ":/icons/icons/ui/play-sign.svg";
|
2021-11-11 21:18:45 +03:00
|
|
|
} else {
|
2021-11-14 04:23:10 +03:00
|
|
|
return ":/icons/icons/ui/download.svg";
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
}
|
2022-04-16 03:13:01 +03:00
|
|
|
|
2021-11-11 23:32:38 +03:00
|
|
|
onClicked: control.mediaLoaded ? control.playPauseActivated() : control.loadActivated()
|
2021-11-11 08:16:25 +03:00
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
ImageButton {
|
|
|
|
id: volumeButton
|
2021-11-11 23:32:38 +03:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
2021-11-11 21:18:45 +03:00
|
|
|
Layout.preferredHeight: 24
|
|
|
|
Layout.preferredWidth: 24
|
2022-04-16 03:13:01 +03:00
|
|
|
buttonTextColor: timelineRoot.palette.text
|
2021-11-11 21:18:45 +03:00
|
|
|
image: {
|
2021-11-11 23:32:38 +03:00
|
|
|
if (control.muted || control.desiredVolume <= 0)
|
2021-11-14 04:23:10 +03:00
|
|
|
return ":/icons/icons/ui/volume-off-indicator.svg";
|
2021-11-11 23:32:38 +03:00
|
|
|
else
|
2021-11-14 04:23:10 +03:00
|
|
|
return ":/icons/icons/ui/volume-up.svg";
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
2022-04-16 03:13:01 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
onClicked: control.muted = !control.muted
|
|
|
|
}
|
|
|
|
NhekoSlider {
|
2021-11-11 23:32:38 +03:00
|
|
|
id: volumeSlider
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 23:32:38 +03:00
|
|
|
property real desiredVolume: QtMultimedia.convertVolume(volumeSlider.value, QtMultimedia.LogarithmicVolumeScale, QtMultimedia.LinearVolumeScale)
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
Layout.preferredWidth: 0
|
|
|
|
opacity: 0
|
|
|
|
orientation: Qt.Horizontal
|
2022-04-16 03:13:01 +03:00
|
|
|
state: ""
|
2021-11-11 21:18:45 +03:00
|
|
|
value: 1
|
2022-04-16 03:13:01 +03:00
|
|
|
|
|
|
|
states: State {
|
|
|
|
name: "shown"
|
|
|
|
when: Settings.mobileMode || volumeButton.hovered || volumeSlider.hovered || volumeSlider.pressed
|
|
|
|
|
|
|
|
PropertyChanges {
|
|
|
|
Layout.preferredWidth: 100
|
|
|
|
target: volumeSlider
|
|
|
|
}
|
|
|
|
PropertyChanges {
|
|
|
|
opacity: 1
|
|
|
|
target: volumeSlider
|
|
|
|
}
|
2021-11-11 08:16:25 +03:00
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: ""
|
|
|
|
to: "shown"
|
|
|
|
|
|
|
|
SequentialAnimation {
|
2021-11-11 23:32:38 +03:00
|
|
|
PauseAnimation {
|
|
|
|
duration: 50
|
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
NumberAnimation {
|
|
|
|
duration: 100
|
2021-11-11 23:32:38 +03:00
|
|
|
easing.type: Easing.InQuad
|
2022-04-16 03:13:01 +03:00
|
|
|
properties: "opacity"
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 150
|
2022-04-16 03:13:01 +03:00
|
|
|
properties: "Layout.preferredWidth"
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Transition {
|
|
|
|
from: "shown"
|
|
|
|
to: ""
|
|
|
|
|
|
|
|
SequentialAnimation {
|
2021-11-11 23:32:38 +03:00
|
|
|
PauseAnimation {
|
|
|
|
duration: 100
|
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
ParallelAnimation {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 100
|
|
|
|
easing.type: Easing.InQuad
|
2022-04-16 03:13:01 +03:00
|
|
|
properties: "opacity"
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 150
|
2022-04-16 03:13:01 +03:00
|
|
|
properties: "Layout.preferredWidth"
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2021-11-11 23:32:38 +03:00
|
|
|
|
2022-04-16 03:13:01 +03:00
|
|
|
onDesiredVolumeChanged: {
|
|
|
|
control.muted = !(desiredVolume > 0);
|
2021-11-11 23:32:38 +03:00
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
Label {
|
|
|
|
Layout.alignment: Qt.AlignRight
|
2022-04-11 05:18:16 +03:00
|
|
|
color: timelineRoot.palette.text
|
2022-04-16 03:13:01 +03:00
|
|
|
text: (!control.mediaLoaded ? "-- " : durationToString(control.positionValue)) + " / " + durationToString(control.duration)
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
2021-11-10 06:17:00 +03:00
|
|
|
}
|
|
|
|
}
|
2021-11-11 21:56:51 +03:00
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
|
2021-11-10 06:17:00 +03:00
|
|
|
// For hiding controls on stationary cursor
|
|
|
|
Timer {
|
|
|
|
id: controlHideTimer
|
|
|
|
interval: 1500 //ms
|
|
|
|
repeat: false
|
|
|
|
}
|
|
|
|
}
|