nheko/resources/qml/delegates/PlayableMediaMessage.qml

221 lines
6.3 KiB
QML
Raw Normal View History

2021-03-05 00:35:15 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
2021-03-05 00:35:15 +01:00
// SPDX-License-Identifier: GPL-3.0-or-later
2021-03-27 01:17:58 +01:00
import "../"
import QtMultimedia 5.15
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.2
import im.nheko 1.0
2019-10-05 23:11:20 +02:00
Rectangle {
2020-10-08 21:11:21 +02:00
id: bg
2019-10-05 23:11:20 +02:00
required property double proportionalHeight
required property int type
required property int originalWidth
required property string thumbnailUrl
required property string eventId
required property string url
required property string body
required property string filesize
2020-10-08 21:11:21 +02:00
radius: 10
2021-05-13 08:23:56 +02:00
color: Nheko.colors.alternateBase
2020-10-08 21:11:21 +02:00
height: Math.round(content.height + 24)
width: parent ? parent.width : undefined
ListView.onPooled: height = 4
ListView.onReused: height = Math.round(content.height + 24)
2020-10-08 21:11:21 +02:00
Column {
id: content
width: parent.width - 24
anchors.centerIn: parent
Rectangle {
id: videoContainer
property double tempWidth: Math.min(parent ? parent.width : undefined, originalWidth < 1 ? 400 : originalWidth)
property double tempHeight: tempWidth * proportionalHeight
property double divisor: isReply ? 4 : 2
property bool tooHigh: tempHeight > timelineView.height / divisor
2020-10-08 21:11:21 +02:00
visible: type == MtxEvent.VideoMessage
height: tooHigh ? timelineView.height / divisor : tempHeight
width: tooHigh ? (timelineView.height / divisor) / proportionalHeight : tempWidth
2020-10-08 21:11:21 +02:00
Image {
anchors.fill: parent
source: thumbnailUrl.replace("mxc://", "image://MxcImage/")
2020-10-08 21:11:21 +02:00
asynchronous: true
fillMode: Image.PreserveAspectFit
VideoOutput {
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectFit
flushMode: VideoOutput.FirstFrame
source: mxcmedia
2020-10-08 21:11:21 +02:00
}
}
}
RowLayout {
width: parent.width
Text {
id: positionText
text: "--:--:--"
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
Slider {
id: progress
//indeterminate: true
function updatePositionTexts() {
function formatTime(date) {
var hh = date.getUTCHours();
var mm = date.getUTCMinutes();
var ss = date.getSeconds();
if (hh < 10)
hh = "0" + hh;
if (mm < 10)
mm = "0" + mm;
if (ss < 10)
ss = "0" + ss;
return hh + ":" + mm + ":" + ss;
}
positionText.text = formatTime(new Date(mxcmedia.position));
durationText.text = formatTime(new Date(mxcmedia.duration));
2020-10-08 21:11:21 +02:00
}
Layout.fillWidth: true
value: mxcmedia.position
2020-10-08 21:11:21 +02:00
from: 0
to: mxcmedia.duration
onMoved: mxcmedia.position = value
2020-10-08 21:11:21 +02:00
onValueChanged: updatePositionTexts()
2021-05-13 08:23:56 +02:00
palette: Nheko.colors
2020-10-08 21:11:21 +02:00
}
Text {
id: durationText
text: "--:--:--"
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
}
RowLayout {
width: parent.width
spacing: 15
2021-03-27 01:17:58 +01:00
ImageButton {
2020-10-08 21:11:21 +02:00
id: button
2021-04-09 14:12:37 +02:00
Layout.alignment: Qt.AlignVCenter
2021-05-13 08:23:56 +02:00
//color: Nheko.colors.window
2021-03-27 01:17:58 +01:00
//radius: 22
height: 32
width: 32
z: 3
image: ":/icons/icons/ui/arrow-pointing-down.png"
onClicked: {
switch (button.state) {
case "":
mxcmedia.eventId = eventId;
2021-03-27 01:17:58 +01:00
break;
case "stopped":
mxcmedia.play();
2021-03-27 01:17:58 +01:00
console.log("play");
button.state = "playing";
break;
case "playing":
mxcmedia.pause();
2021-03-27 01:17:58 +01:00
console.log("pause");
button.state = "stopped";
break;
}
}
2020-10-08 21:11:21 +02:00
states: [
State {
name: "stopped"
PropertyChanges {
2021-03-27 01:17:58 +01:00
target: button
image: ":/icons/icons/ui/play-sign.png"
2020-10-08 21:11:21 +02:00
}
},
State {
name: "playing"
PropertyChanges {
2021-03-27 01:17:58 +01:00
target: button
image: ":/icons/icons/ui/pause-symbol.png"
2020-10-08 21:11:21 +02:00
}
}
]
2021-02-14 01:28:28 +01:00
CursorShape {
anchors.fill: parent
2020-10-08 21:11:21 +02:00
cursorShape: Qt.PointingHandCursor
}
MxcMedia {
id: mxcmedia
2020-10-08 21:11:21 +02:00
roomm: room
2020-10-08 21:11:21 +02:00
onError: console.log(errorString)
onMediaStatusChanged: {
if (status == MxcMedia.LoadedMedia) {
2020-10-08 21:11:21 +02:00
progress.updatePositionTexts();
button.state = "stopped";
}
2020-10-08 21:11:21 +02:00
}
onStateChanged: {
2021-08-29 05:20:23 +02:00
if (state == MxcMedia.StoppedState)
2020-10-08 21:11:21 +02:00
button.state = "stopped";
2021-08-29 05:20:23 +02:00
2020-10-08 21:11:21 +02:00
}
}
}
ColumnLayout {
id: col
Text {
Layout.fillWidth: true
text: body
2020-10-08 21:11:21 +02:00
elide: Text.ElideRight
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
Text {
Layout.fillWidth: true
text: filesize
2020-10-08 21:11:21 +02:00
textFormat: Text.PlainText
elide: Text.ElideRight
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
}
}
}
}