matrixion/qml/delegates/PlayableMediaMessage.qml

100 lines
3.3 KiB
QML
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 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 "../ui/media"
2022-04-11 04:37:15 +03:00
import QtMultimedia
import QtQuick 2.15
import QtQuick.Controls 2.15
2021-11-11 08:16:25 +03:00
import QtQuick.Layouts 1.15
import im.nheko
2021-11-11 21:18:45 +03:00
Item {
2021-11-10 06:17:00 +03:00
id: content
2022-04-16 03:13:01 +03:00
required property string body
property double divisor: isReply ? 4 : 2
2022-03-21 02:48:27 +03:00
required property int duration
required property string eventId
required property string filesize
2022-04-16 03:13:01 +03:00
property bool fitsMetadata: (parent.width - fileInfoLabel.width) > metadataWidth + 4
2022-02-14 23:07:03 +03:00
property int metadataWidth
2022-04-16 03:13:01 +03:00
required property int originalWidth
required property double proportionalHeight
property int tempWidth: originalWidth < 1 ? 400 : originalWidth
required property string thumbnailUrl
required property int type
required property string url
height: (type == MtxEvent.VideoMessage ? width * proportionalHeight : 80) + fileInfoLabel.height
implicitHeight: height
implicitWidth: type == MtxEvent.VideoMessage ? Math.round(tempWidth * Math.min((timelineView.height / divisor) / (tempWidth * proportionalHeight), 1)) : 500
width: Math.min(parent.width, implicitWidth)
2022-02-14 23:07:03 +03:00
MxcMedia {
id: mxcmedia
roomm: room
2022-04-16 03:13:01 +03:00
videoOutput: videoOutput
2022-04-11 04:37:15 +03:00
audioOutput: AudioOutput {
muted: mediaControls.muted
volume: mediaControls.desiredVolume
}
2021-07-19 21:11:03 +03:00
}
Rectangle {
id: videoContainer
2022-04-11 05:18:16 +03:00
color: type == MtxEvent.VideoMessage ? timelineRoot.palette.window : "transparent"
2021-11-11 21:18:45 +03:00
height: parent.height - fileInfoLabel.height
2022-04-16 03:13:01 +03:00
width: parent.width
2021-11-11 21:18:45 +03:00
2021-11-11 23:32:38 +03:00
TapHandler {
onTapped: Settings.openVideoExternal ? room.openMedia(eventId) : mediaControls.showControls()
2021-11-11 23:32:38 +03:00
}
2021-07-19 21:11:03 +03:00
Image {
anchors.fill: parent
asynchronous: true
fillMode: Image.PreserveAspectFit
2022-04-16 03:13:01 +03:00
source: thumbnailUrl ? thumbnailUrl.replace("mxc://", "image://MxcImage/") + "?scale" : ""
2021-11-10 06:17:00 +03:00
2021-07-19 21:11:03 +03:00
VideoOutput {
id: videoOutput
anchors.fill: parent
2022-04-16 03:13:01 +03:00
clip: true
2021-07-19 21:11:03 +03:00
fillMode: VideoOutput.PreserveAspectFit
2022-04-11 04:37:15 +03:00
//flushMode: VideoOutput.FirstFrame
orientation: mxcmedia.orientation
2022-04-16 03:13:01 +03:00
visible: type == MtxEvent.VideoMessage
}
2021-11-11 21:18:45 +03:00
}
}
2021-11-11 23:32:38 +03:00
MediaControls {
id: mediaControls
2022-04-16 03:13:01 +03:00
anchors.bottom: fileInfoLabel.top
2021-11-11 23:32:38 +03:00
anchors.left: content.left
anchors.right: content.right
2022-03-21 02:48:27 +03:00
duration: mediaLoaded ? mxcmedia.duration : content.duration
2021-11-11 23:32:38 +03:00
mediaLoaded: mxcmedia.loaded
mediaState: mxcmedia.state
2022-04-16 03:13:01 +03:00
playingVideo: type == MtxEvent.VideoMessage
positionValue: mxcmedia.position
2021-11-11 23:32:38 +03:00
onLoadActivated: mxcmedia.eventId = eventId
2022-04-16 03:13:01 +03:00
onPlayPauseActivated: mxcmedia.state == MediaPlayer.PlayingState ? mxcmedia.pause() : mxcmedia.play()
onPositionChanged: mxcmedia.position = position
2021-11-11 23:32:38 +03:00
}
2021-11-10 06:17:00 +03:00
2021-11-10 07:52:59 +03:00
// information about file name and file size
2021-11-10 06:17:00 +03:00
Label {
id: fileInfoLabel
2021-11-11 21:18:45 +03:00
anchors.bottom: content.bottom
2022-04-16 03:13:01 +03:00
color: timelineRoot.palette.text
elide: Text.ElideRight
2021-11-10 06:17:00 +03:00
text: body + " [" + filesize + "]"
textFormat: Text.RichText
2021-11-10 06:17:00 +03:00
background: Rectangle {
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.base
2021-11-10 06:17:00 +03:00
}
}
}