matrixion/resources/qml/delegates/PlayableMediaMessage.qml

221 lines
6.3 KiB
QML
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2021-03-27 03:17:58 +03: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-06 00:11:20 +03:00
Rectangle {
2020-10-08 22:11:21 +03:00
id: bg
2019-10-06 00:11:20 +03: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 22:11:21 +03:00
radius: 10
2021-05-13 09:23:56 +03:00
color: Nheko.colors.alternateBase
2020-10-08 22:11:21 +03: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 22:11:21 +03: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 22:11:21 +03:00
visible: type == MtxEvent.VideoMessage
height: tooHigh ? timelineView.height / divisor : tempHeight
width: tooHigh ? (timelineView.height / divisor) / proportionalHeight : tempWidth
2020-10-08 22:11:21 +03:00
Image {
anchors.fill: parent
source: thumbnailUrl.replace("mxc://", "image://MxcImage/")
2020-10-08 22:11:21 +03:00
asynchronous: true
fillMode: Image.PreserveAspectFit
VideoOutput {
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectFit
flushMode: VideoOutput.FirstFrame
source: mxcmedia
2020-10-08 22:11:21 +03:00
}
}
}
RowLayout {
width: parent.width
Text {
id: positionText
text: "--:--:--"
2021-05-13 09:23:56 +03:00
color: Nheko.colors.text
2020-10-08 22:11:21 +03: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 22:11:21 +03:00
}
Layout.fillWidth: true
value: mxcmedia.position
2020-10-08 22:11:21 +03:00
from: 0
to: mxcmedia.duration
onMoved: mxcmedia.position = value
2020-10-08 22:11:21 +03:00
onValueChanged: updatePositionTexts()
2021-05-13 09:23:56 +03:00
palette: Nheko.colors
2020-10-08 22:11:21 +03:00
}
Text {
id: durationText
text: "--:--:--"
2021-05-13 09:23:56 +03:00
color: Nheko.colors.text
2020-10-08 22:11:21 +03:00
}
}
RowLayout {
width: parent.width
spacing: 15
2021-03-27 03:17:58 +03:00
ImageButton {
2020-10-08 22:11:21 +03:00
id: button
2021-04-09 15:12:37 +03:00
Layout.alignment: Qt.AlignVCenter
2021-05-13 09:23:56 +03:00
//color: Nheko.colors.window
2021-03-27 03:17:58 +03: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 03:17:58 +03:00
break;
case "stopped":
mxcmedia.play();
2021-03-27 03:17:58 +03:00
console.log("play");
button.state = "playing";
break;
case "playing":
mxcmedia.pause();
2021-03-27 03:17:58 +03:00
console.log("pause");
button.state = "stopped";
break;
}
}
2020-10-08 22:11:21 +03:00
states: [
State {
name: "stopped"
PropertyChanges {
2021-03-27 03:17:58 +03:00
target: button
image: ":/icons/icons/ui/play-sign.png"
2020-10-08 22:11:21 +03:00
}
},
State {
name: "playing"
PropertyChanges {
2021-03-27 03:17:58 +03:00
target: button
image: ":/icons/icons/ui/pause-symbol.png"
2020-10-08 22:11:21 +03:00
}
}
]
2021-02-14 03:28:28 +03:00
CursorShape {
anchors.fill: parent
2020-10-08 22:11:21 +03:00
cursorShape: Qt.PointingHandCursor
}
MxcMedia {
id: mxcmedia
2020-10-08 22:11:21 +03:00
roomm: room
2020-10-08 22:11:21 +03:00
onError: console.log(errorString)
onMediaStatusChanged: {
if (status == MxcMedia.LoadedMedia) {
2020-10-08 22:11:21 +03:00
progress.updatePositionTexts();
button.state = "stopped";
}
2020-10-08 22:11:21 +03:00
}
onStateChanged: {
if (state == MxcMedia.StoppedState) {
2020-10-08 22:11:21 +03:00
button.state = "stopped";
}
}
}
}
ColumnLayout {
id: col
Text {
Layout.fillWidth: true
text: body
2020-10-08 22:11:21 +03:00
elide: Text.ElideRight
2021-05-13 09:23:56 +03:00
color: Nheko.colors.text
2020-10-08 22:11:21 +03:00
}
Text {
Layout.fillWidth: true
text: filesize
2020-10-08 22:11:21 +03:00
textFormat: Text.PlainText
elide: Text.ElideRight
2021-05-13 09:23:56 +03:00
color: Nheko.colors.text
2020-10-08 22:11:21 +03:00
}
}
}
}
}