kasts/src/qml/PlayerControls.qml

165 lines
7.1 KiB
QML
Raw Normal View History

2021-03-25 17:14:51 +01:00
/**
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.14
import QtQuick.Controls 2.14 as Controls
import QtQuick.Layouts 1.14
import QtMultimedia 5.15
import org.kde.kirigami 2.14 as Kirigami
import org.kde.alligator 1.0
Kirigami.Page {
id: playercontrols
title: audio.entry.title
clip: true
Layout.margins: 0
2021-03-25 22:25:39 +01:00
Component.onCompleted: audio.playerOpen = true
Component.onDestruction: audio.playerOpen = false
2021-03-25 17:14:51 +01:00
ColumnLayout {
anchors.fill: parent
2021-04-08 22:53:33 +02:00
Controls.SwipeView {
id: swipeView
currentIndex: 0
2021-03-25 17:14:51 +01:00
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
2021-04-08 22:53:33 +02:00
Layout.preferredWidth: parent.width
Layout.preferredHeight: parent.height - media.height - indicator.height
Layout.margins: 0
Item {
Image {
asynchronous: true
source: audio.entry.image === "" ? "logo.png" : "file://"+Fetcher.image(audio.entry.image)
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
//Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
width: Math.min(parent.width, Kirigami.Units.iconSizes.enormous * 3)
height: Math.min(parent.height, Kirigami.Units.iconSizes.enormous * 3)
}
}
EntryPage { entry: audio.entry }
}
Controls.PageIndicator {
id: indicator
count:swipeView.count
currentIndex: swipeView.currentIndex
Layout.alignment: Qt.AlignHCenter
2021-03-25 17:14:51 +01:00
}
Item {
id: media
implicitHeight: mediaControls.height
Layout.fillWidth: true
Layout.margins: 0
ColumnLayout {
id: mediaControls
2021-04-08 22:53:33 +02:00
//implicitHeight: controls.height
2021-03-25 17:14:51 +01:00
anchors.left: parent.left
anchors.right: parent.right
Controls.Slider {
Layout.fillWidth: true
from: 0
to: audio.duration
value: audio.position
onMoved: audio.seek(value)
}
2021-03-25 17:14:51 +01:00
RowLayout {
id: controls
2021-04-08 22:53:33 +02:00
Layout.leftMargin: 0
Layout.rightMargin: 0
Layout.fillWidth: true
2021-03-25 17:14:51 +01:00
Controls.Label {
2021-04-08 22:53:33 +02:00
//anchor.left: parent.left
2021-03-25 17:14:51 +01:00
text: (Math.floor(audio.position/3600000) < 10 ? "0" : "") + Math.floor(audio.position/3600000) + ":" + (Math.floor(audio.position/60000) % 60 < 10 ? "0" : "") + Math.floor(audio.position/60000) % 60 + ":" + (Math.floor(audio.position/1000) % 60 < 10 ? "0" : "") + Math.floor(audio.position/1000) % 60
}
Item {
2021-03-25 17:14:51 +01:00
Layout.fillWidth: true
}
2021-04-08 22:53:33 +02:00
Item {
Layout.preferredHeight: endLabel.implicitHeight + Kirigami.Units.gridUnit
Layout.preferredWidth: endLabel.implicitWidth + Kirigami.Units.gridUnit
Controls.Label {
id: endLabel
property int toggle: 0
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
text: (toggle === 0) ? ((Math.floor(audio.duration/3600000) < 10 ? "0" : "") + Math.floor(audio.duration/3600000) + ":" + (Math.floor(audio.duration/60000) % 60 < 10 ? "0" : "") + Math.floor(audio.duration/60000) % 60 + ":" + (Math.floor(audio.duration/1000) % 60 < 10 ? "0" : "") + Math.floor(audio.duration/1000) % 60) : ((Math.floor((audio.duration-audio.position)/3600000) < 10 ? "-0" : "-") + Math.floor((audio.duration-audio.position)/3600000) + ":" + (Math.floor((audio.duration-audio.position)/60000) % 60 < 10 ? "0" : "") + Math.floor((audio.duration-audio.position)/60000) % 60 + ":" + (Math.floor((audio.duration-audio.position)/1000) % 60 < 10 ? "0" : "") + Math.floor((audio.duration-audio.position)/1000) % 60)
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onClicked: (endLabel.toggle === 0) ? endLabel.toggle=1 : endLabel.toggle=0
}
2021-03-25 17:14:51 +01:00
}
}
RowLayout {
Layout.maximumWidth: Number.POSITIVE_INFINITY //TODO ?
Layout.fillWidth: true
2021-04-08 22:53:33 +02:00
Layout.topMargin: Kirigami.Units.gridUnit * 2
property int buttonsize: Kirigami.Units.gridUnit * 2
2021-03-25 17:14:51 +01:00
Controls.Button {
text: audio.playbackRate + "x"
onClicked: {
if(audio.playbackRate === 2.5)
audio.playbackRate = 1
else
audio.playbackRate = audio.playbackRate + 0.25
}
flat: true
Layout.alignment: Qt.AlignHCenter
implicitWidth: playButton.width
implicitHeight: playButton.height
}
Controls.Button {
icon.name: "media-seek-backward"
icon.height: parent.buttonsize
icon.width: parent.buttonsize
2021-03-25 17:14:51 +01:00
flat: true
Layout.alignment: Qt.AlignHCenter
onClicked: audio.seek(audio.position - 10000)
}
Controls.Button {
id: playButton
icon.name: audio.playbackState === Audio.PlayingState ? "media-playback-pause" : "media-playback-start"
icon.height: parent.buttonsize
icon.width: parent.buttonsize
2021-03-25 17:14:51 +01:00
flat: true
onClicked: audio.playbackState === Audio.PlayingState ? audio.pause() : audio.play()
Layout.alignment: Qt.AlignHCenter
}
Controls.Button {
icon.name: "media-seek-forward"
icon.height: parent.buttonsize
icon.width: parent.buttonsize
2021-03-25 17:14:51 +01:00
flat: true
Layout.alignment: Qt.AlignHCenter
onClicked: audio.seek(audio.position + 10000)
}
Controls.Button {
icon.name: "media-skip-forward"
icon.height: parent.buttonsize
icon.width: parent.buttonsize
2021-03-25 17:14:51 +01:00
flat: true
Layout.alignment: Qt.AlignHCenter
onClicked: console.log("TODO")
}
}
}
}
}
}