| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import "../ui/media" |
| 6 |
import QtMultimedia |
| 7 |
import QtQuick |
| 8 |
import QtQuick.Controls |
| 9 |
import im.nheko |
| 10 |
|
| 11 |
Item { |
| 12 |
id: content |
| 13 |
|
| 14 |
required property double proportionalHeight |
| 15 |
required property int type |
| 16 |
required property int originalWidth |
| 17 |
required property int duration |
| 18 |
required property string thumbnailUrl |
| 19 |
required property string eventId |
| 20 |
required property string url |
| 21 |
required property string body |
| 22 |
required property string filesize |
| 23 |
property double divisor: EventDelegateChooser.isReply ? 10 : 4 |
| 24 |
property int tempWidth: originalWidth < 1? 400: originalWidth |
| 25 |
implicitWidth: type == MtxEvent.VideoMessage ? Math.round(tempWidth*Math.min((timelineView.height/divisor)/(tempWidth*proportionalHeight), 1)) : 500 |
| 26 |
width: Math.min(parent?.width ?? implicitWidth, implicitWidth) |
| 27 |
height: (type == MtxEvent.VideoMessage ? width*proportionalHeight : mediaControls.height) + fileInfoLabel.height |
| 28 |
//implicitHeight: height |
| 29 |
|
| 30 |
property int metadataWidth |
| 31 |
property bool fitsMetadata: parent != null ? ((parent.width - fileInfoLabel.width) > metadataWidth+4) : false |
| 32 |
|
| 33 |
Component.onCompleted: mxcmedia.startDownload(true) |
| 34 |
|
| 35 |
MxcMedia { |
| 36 |
id: mxcmedia |
| 37 |
|
| 38 |
// TODO: Show error in overlay or so? |
| 39 |
roomm: room |
| 40 |
eventId: content.eventId |
| 41 |
videoOutput: videoOutput |
| 42 |
|
| 43 |
muted: mediaControls.muted |
| 44 |
volume: mediaControls.desiredVolume |
| 45 |
} |
| 46 |
|
| 47 |
Rectangle { |
| 48 |
id: videoContainer |
| 49 |
|
| 50 |
color: content.type == MtxEvent.VideoMessage ? palette.window : "transparent" |
| 51 |
width: parent.width |
| 52 |
height: parent.height - fileInfoLabel.height |
| 53 |
|
| 54 |
TapHandler { |
| 55 |
onTapped: Settings.openVideoExternal ? room.openMedia(eventId) : mediaControls.showControls() |
| 56 |
} |
| 57 |
|
| 58 |
Image { |
| 59 |
anchors.fill: parent |
| 60 |
visible: content.type == MtxEvent.VideoMessage |
| 61 |
source: content.thumbnailUrl ? thumbnailUrl.replace("mxc://", "image://MxcImage/") + "?scale" : "image://colorimage/:/icons/icons/ui/video-file.svg?" + palette.windowText |
| 62 |
asynchronous: true |
| 63 |
fillMode: Image.PreserveAspectFit |
| 64 |
|
| 65 |
VideoOutput { |
| 66 |
id: videoOutput |
| 67 |
|
| 68 |
visible: content.type == MtxEvent.VideoMessage |
| 69 |
clip: true |
| 70 |
anchors.fill: parent |
| 71 |
fillMode: VideoOutput.PreserveAspectFit |
| 72 |
orientation: mxcmedia.orientation |
| 73 |
} |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
MediaControls { |
| 78 |
id: mediaControls |
| 79 |
|
| 80 |
anchors.left: videoContainer.left |
| 81 |
anchors.right: videoContainer.right |
| 82 |
anchors.bottom: videoContainer.bottom |
| 83 |
playingVideo: content.type == MtxEvent.VideoMessage |
| 84 |
positionValue: mxcmedia.position |
| 85 |
duration: mediaLoaded ? mxcmedia.duration : content.duration |
| 86 |
mediaLoaded: mxcmedia.loaded |
| 87 |
mediaState: mxcmedia.playbackState |
| 88 |
onPositionChanged: mxcmedia.position = position |
| 89 |
onPlayPauseActivated: mxcmedia.playbackState == MediaPlayer.PlayingState ? mxcmedia.pause() : mxcmedia.play() |
| 90 |
onLoadActivated: mxcmedia.startDownload() |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
// information about file name and file size |
| 95 |
Label { |
| 96 |
id: fileInfoLabel |
| 97 |
|
| 98 |
anchors.top: videoContainer.bottom |
| 99 |
text: content.body + " [" + filesize + "]" |
| 100 |
textFormat: Text.RichText |
| 101 |
elide: Text.ElideRight |
| 102 |
color: palette.text |
| 103 |
|
| 104 |
background: Rectangle { |
| 105 |
color: palette.base |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
} |