2021-11-10 06:17:00 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// 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 "../../"
|
2021-11-10 06:17:00 +03:00
|
|
|
import QtMultimedia 5.15
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
2021-11-11 08:16:25 +03:00
|
|
|
import QtQuick.Layouts 1.15
|
2021-11-10 06:17:00 +03:00
|
|
|
import im.nheko 1.0
|
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
Rectangle {
|
2021-11-10 06:17:00 +03:00
|
|
|
id: control
|
|
|
|
|
|
|
|
property alias desiredVolume: volumeSlider.desiredVolume
|
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 mediaState
|
|
|
|
property bool mediaLoaded: false
|
|
|
|
property var duration
|
|
|
|
property var positionValue: 0
|
|
|
|
property var position
|
2021-11-11 21:56:51 +03:00
|
|
|
property bool shouldShowControls: !playingVideo || playerMouseArea.shouldShowControls || volumeSlider.state == "shown"
|
2021-11-11 21:18:45 +03:00
|
|
|
color: {
|
|
|
|
var wc = Nheko.colors.alternateBase;
|
|
|
|
return Qt.rgba(wc.r, wc.g, wc.b, 0.5);
|
|
|
|
}
|
2021-11-11 21:56:51 +03:00
|
|
|
opacity: control.shouldShowControls ? 1 : 0
|
2021-11-11 21:18:45 +03:00
|
|
|
height: controlLayout.implicitHeight
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
signal playPauseActivated()
|
|
|
|
signal loadActivated()
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:56:51 +03:00
|
|
|
function showControls() {
|
|
|
|
controlHideTimer.restart();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 21:56:51 +03:00
|
|
|
onHoveredChanged: showControls();
|
2021-11-10 06:17:00 +03:00
|
|
|
}
|
|
|
|
|
2021-11-11 08:16:25 +03:00
|
|
|
ColumnLayout {
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 08:16:25 +03:00
|
|
|
id: controlLayout
|
2021-11-11 21:56:51 +03:00
|
|
|
enabled: control.shouldShowControls
|
2021-11-11 08:16:25 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
spacing: 0
|
2021-11-10 06:17:00 +03:00
|
|
|
anchors.bottom: control.bottom
|
|
|
|
anchors.left: control.left
|
|
|
|
anchors.right: control.right
|
|
|
|
|
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
|
|
|
|
|
|
|
|
enabled: control.mediaLoaded
|
|
|
|
|
2021-11-11 08:16:25 +03:00
|
|
|
value: control.positionValue
|
|
|
|
onMoved: control.position = value
|
|
|
|
from: 0
|
|
|
|
to: control.duration
|
|
|
|
alwaysShowSlider: false
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
RowLayout {
|
|
|
|
Layout.margins: Nheko.paddingSmall
|
|
|
|
spacing: Nheko.paddingSmall
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
// Cache/Play/pause button
|
|
|
|
ImageButton {
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
id: playbackStateImage
|
|
|
|
|
|
|
|
buttonTextColor: Nheko.colors.text
|
|
|
|
Layout.preferredHeight: 24
|
|
|
|
Layout.preferredWidth: 24
|
|
|
|
|
|
|
|
image: {
|
|
|
|
if (control.mediaLoaded) {
|
|
|
|
if (control.mediaState == MediaPlayer.PlayingState)
|
|
|
|
return ":/icons/icons/ui/pause-symbol.png";
|
|
|
|
else
|
|
|
|
return ":/icons/icons/ui/play-sign.png";
|
|
|
|
} else {
|
|
|
|
return ":/icons/icons/ui/arrow-pointing-down.png";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: control.mediaLoaded ? control.playPauseActivated() : control.loadActivated();
|
|
|
|
|
2021-11-11 08:16:25 +03:00
|
|
|
}
|
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
ImageButton {
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
id: volumeButton
|
2021-11-11 08:16:25 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
buttonTextColor: Nheko.colors.text
|
|
|
|
Layout.preferredHeight: 24
|
|
|
|
Layout.preferredWidth: 24
|
2021-11-11 08:16:25 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
image: {
|
|
|
|
if (control.muted || control.desiredVolume <= 0) {
|
|
|
|
return ":/icons/icons/ui/volume-off-indicator.png";
|
|
|
|
} else {
|
|
|
|
return ":/icons/icons/ui/volume-up.png";
|
2021-11-10 07:52:59 +03:00
|
|
|
}
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
onClicked: control.muted = !control.muted
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
2021-11-11 08:16:25 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
NhekoSlider {
|
|
|
|
state: ""
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
states: State {
|
|
|
|
name: "shown"
|
|
|
|
when: Settings.mobileMode || volumeButton.hovered || volumeSlider.hovered || volumeSlider.pressed
|
|
|
|
PropertyChanges {target: volumeSlider; Layout.preferredWidth: 100}
|
|
|
|
PropertyChanges {target: volumeSlider; opacity: 1}
|
2021-11-11 08:16:25 +03:00
|
|
|
}
|
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
|
|
|
|
id: volumeSlider
|
|
|
|
orientation: Qt.Horizontal
|
|
|
|
property real desiredVolume: QtMultimedia.convertVolume(volumeSlider.value, QtMultimedia.LogarithmicVolumeScale, QtMultimedia.LinearVolumeScale)
|
|
|
|
value: 1
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
onDesiredVolumeChanged: {
|
|
|
|
control.muted = !(desiredVolume > 0);
|
2021-11-11 08:16:25 +03:00
|
|
|
}
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
transitions: [
|
|
|
|
Transition {
|
|
|
|
from: ""
|
|
|
|
to: "shown"
|
|
|
|
|
|
|
|
SequentialAnimation {
|
|
|
|
PauseAnimation { duration: 50 }
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 100
|
|
|
|
properties: "opacity"
|
|
|
|
easing.type: Easing.InQuad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberAnimation {
|
|
|
|
properties: "Layout.preferredWidth"
|
|
|
|
duration: 150
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Transition {
|
|
|
|
from: "shown"
|
|
|
|
to: ""
|
|
|
|
|
|
|
|
SequentialAnimation {
|
|
|
|
PauseAnimation { duration: 100 }
|
|
|
|
|
|
|
|
ParallelAnimation {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 100
|
|
|
|
properties: "opacity"
|
|
|
|
easing.type: Easing.InQuad
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberAnimation {
|
|
|
|
properties: "Layout.preferredWidth"
|
|
|
|
duration: 150
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
Layout.alignment: Qt.AlignRight
|
|
|
|
|
|
|
|
text: (!control.mediaLoaded) ? "-- / --" : (durationToString(control.positionValue) + " / " + durationToString(control.duration))
|
|
|
|
color: Nheko.colors.text
|
|
|
|
}
|
|
|
|
|
|
|
|
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-11 21:56:51 +03:00
|
|
|
// Fade controls in/out
|
|
|
|
Behavior on opacity {
|
|
|
|
OpacityAnimator {
|
|
|
|
duration: 100
|
2021-11-10 06:17:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// For hiding controls on stationary cursor
|
|
|
|
Timer {
|
|
|
|
id: controlHideTimer
|
|
|
|
|
|
|
|
interval: 1500 //ms
|
|
|
|
repeat: false
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|