nheko/resources/qml/delegates/PlayableMediaMessage.qml

110 lines
3.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 "../ui/media"
import QtMultimedia 5.15
import QtQuick 2.15
import QtQuick.Controls 2.15
2021-11-11 06:16:25 +01:00
import QtQuick.Layouts 1.15
import im.nheko 1.0
2021-11-11 19:18:45 +01:00
Item {
2021-11-10 04:17:00 +01:00
id: content
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
2021-11-11 21:32:38 +01:00
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 > timelineRoot.height / divisor
2021-11-11 21:32:38 +01:00
height: (type == MtxEvent.VideoMessage ? tooHigh ? timelineRoot.height / divisor : tempHeight : 80) + fileInfoLabel.height
width: type == MtxEvent.VideoMessage ? tooHigh ? (timelineRoot.height / divisor) / proportionalHeight : tempWidth : 250
2021-11-10 04:17:00 +01:00
MxcMedia {
id: mxcmedia
2021-11-10 04:17:00 +01:00
2021-07-19 20:11:03 +02:00
// TODO: Show error in overlay or so?
onError: console.log(error)
roomm: room
2021-11-10 04:17:00 +01:00
// desiredVolume is a float from 0.0 -> 1.0, MediaPlayer volume is an int from 0 to 100
// this value automatically gets clamped for us between these two values.
volume: mediaControls.desiredVolume * 100
muted: mediaControls.muted
2021-07-19 20:11:03 +02:00
}
2021-07-19 20:11:03 +02:00
Rectangle {
id: videoContainer
2021-11-11 21:32:38 +01:00
2021-11-10 05:52:59 +01:00
color: type == MtxEvent.VideoMessage ? Nheko.colors.window : "transparent"
2021-11-11 19:18:45 +01:00
width: parent.width
height: parent.height - fileInfoLabel.height
2021-11-11 21:32:38 +01:00
TapHandler {
onTapped: mediaControls.showControls()
}
2021-11-09 01:18:11 +01:00
2021-07-19 20:11:03 +02:00
Image {
anchors.fill: parent
source: thumbnailUrl.replace("mxc://", "image://MxcImage/")
asynchronous: true
fillMode: Image.PreserveAspectFit
2021-11-10 04:17:00 +01:00
2021-07-19 20:11:03 +02:00
VideoOutput {
id: videoOutput
2021-11-10 05:52:59 +01:00
visible: type == MtxEvent.VideoMessage
2021-07-19 20:11:03 +02:00
clip: true
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectFit
source: mxcmedia
flushMode: VideoOutput.FirstFrame
orientation: mxcmedia.orientation
}
2021-11-11 19:18:45 +01:00
}
}
2021-11-11 21:32:38 +01:00
MediaControls {
id: mediaControls
anchors.left: content.left
anchors.right: content.right
anchors.bottom: fileInfoLabel.top
playingVideo: type == MtxEvent.VideoMessage
positionValue: mxcmedia.position
duration: mxcmedia.duration
mediaLoaded: mxcmedia.loaded
mediaState: mxcmedia.state
onPositionChanged: mxcmedia.position = position
onPlayPauseActivated: mxcmedia.state == MediaPlayer.PlayingState ? mxcmedia.pause() : mxcmedia.play()
onLoadActivated: mxcmedia.eventId = eventId
}
2021-11-10 04:17:00 +01:00
2021-11-10 05:52:59 +01:00
// information about file name and file size
2021-11-10 04:17:00 +01:00
Label {
id: fileInfoLabel
2021-11-11 19:18:45 +01:00
anchors.bottom: content.bottom
2021-11-10 04:17:00 +01:00
text: body + " [" + filesize + "]"
textFormat: Text.PlainText
elide: Text.ElideRight
color: Nheko.colors.text
background: Rectangle {
color: Nheko.colors.base
}
}
2021-07-19 20:11:03 +02:00
2021-11-10 04:17:00 +01:00
}