2023-02-21 23:48:49 +01:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-03-07 05:57:56 +01:00
|
|
|
//
|
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 "../"
|
2021-11-10 01:28:53 +01:00
|
|
|
import "../ui/media"
|
2023-06-02 00:43:38 +02:00
|
|
|
import QtMultimedia
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import im.nheko
|
2019-10-06 01:05:32 +02:00
|
|
|
|
2021-11-11 19:18:45 +01:00
|
|
|
Item {
|
2021-11-10 04:17:00 +01:00
|
|
|
id: content
|
|
|
|
|
2021-07-12 00:24:33 +02:00
|
|
|
required property double proportionalHeight
|
|
|
|
required property int type
|
|
|
|
required property int originalWidth
|
2022-03-21 00:48:27 +01:00
|
|
|
required property int duration
|
2021-07-12 00:24:33 +02:00
|
|
|
required property string thumbnailUrl
|
|
|
|
required property string eventId
|
|
|
|
required property string url
|
|
|
|
required property string body
|
|
|
|
required property string filesize
|
2023-10-09 21:41:00 +02:00
|
|
|
property double divisor: EventDelegateChooser.isReply ? 10 : 4
|
2022-02-14 14:03:17 +01:00
|
|
|
property int tempWidth: originalWidth < 1? 400: originalWidth
|
|
|
|
implicitWidth: type == MtxEvent.VideoMessage ? Math.round(tempWidth*Math.min((timelineView.height/divisor)/(tempWidth*proportionalHeight), 1)) : 500
|
2023-06-04 03:22:57 +02:00
|
|
|
width: Math.min(parent?.width ?? implicitWidth, implicitWidth)
|
2022-02-11 22:02:30 +01:00
|
|
|
height: (type == MtxEvent.VideoMessage ? width*proportionalHeight : 80) + fileInfoLabel.height
|
2023-06-04 03:22:57 +02:00
|
|
|
//implicitHeight: height
|
2021-11-10 04:17:00 +01:00
|
|
|
|
2022-02-14 21:07:03 +01:00
|
|
|
property int metadataWidth
|
|
|
|
property bool fitsMetadata: (parent.width - fileInfoLabel.width) > metadataWidth+4
|
|
|
|
|
2021-11-04 02:43:11 +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?
|
2021-11-04 02:43:11 +01:00
|
|
|
roomm: room
|
2023-06-02 00:43:38 +02:00
|
|
|
audioOutput: AudioOutput {
|
|
|
|
muted: mediaControls.muted
|
|
|
|
volume: mediaControls.desiredVolume
|
|
|
|
}
|
|
|
|
videoOutput: videoOutput
|
2021-07-19 20:11:03 +02:00
|
|
|
}
|
2021-11-09 04:55:16 +01:00
|
|
|
|
2021-07-19 20:11:03 +02:00
|
|
|
Rectangle {
|
|
|
|
id: videoContainer
|
2021-11-11 21:32:38 +01:00
|
|
|
|
2023-06-02 01:29:05 +02:00
|
|
|
color: type == MtxEvent.VideoMessage ? palette.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 {
|
2022-03-19 06:31:43 +01:00
|
|
|
onTapped: Settings.openVideoExternal ? room.openMedia(eventId) : mediaControls.showControls()
|
2021-11-11 21:32:38 +01:00
|
|
|
}
|
2021-11-09 01:18:11 +01:00
|
|
|
|
2021-07-19 20:11:03 +02:00
|
|
|
Image {
|
|
|
|
anchors.fill: parent
|
2023-06-02 01:29:05 +02:00
|
|
|
source: thumbnailUrl ? thumbnailUrl.replace("mxc://", "image://MxcImage/") + "?scale" : "image://colorimage/:/icons/icons/ui/video-file.svg?" + palette.windowText
|
2021-07-19 20:11:03 +02:00
|
|
|
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
|
|
|
|
2021-11-10 04:33:16 +01:00
|
|
|
visible: type == MtxEvent.VideoMessage
|
2021-07-19 20:11:03 +02:00
|
|
|
clip: true
|
|
|
|
anchors.fill: parent
|
|
|
|
fillMode: VideoOutput.PreserveAspectFit
|
2021-11-15 03:35:35 +01:00
|
|
|
orientation: mxcmedia.orientation
|
2021-11-10 04:33:16 +01:00
|
|
|
}
|
2021-11-04 02:43:11 +01:00
|
|
|
|
2021-11-11 19:18:45 +01:00
|
|
|
}
|
|
|
|
|
2023-06-04 03:22:57 +02:00
|
|
|
MediaControls {
|
|
|
|
id: mediaControls
|
|
|
|
|
|
|
|
anchors.left: videoContainer.left
|
|
|
|
anchors.right: videoContainer.right
|
|
|
|
anchors.bottom: videoContainer.bottom
|
|
|
|
playingVideo: type == MtxEvent.VideoMessage
|
|
|
|
positionValue: mxcmedia.position
|
|
|
|
duration: mediaLoaded ? mxcmedia.duration : content.duration
|
|
|
|
mediaLoaded: mxcmedia.loaded
|
|
|
|
mediaState: mxcmedia.playbackState
|
|
|
|
onPositionChanged: mxcmedia.position = position
|
|
|
|
onPlayPauseActivated: mxcmedia.playbackState == MediaPlayer.PlayingState ? mxcmedia.pause() : mxcmedia.play()
|
|
|
|
onLoadActivated: mxcmedia.eventId = eventId
|
|
|
|
}
|
2021-11-11 21:32:38 +01:00
|
|
|
}
|
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
|
|
|
|
|
2023-06-04 03:22:57 +02:00
|
|
|
anchors.top: videoContainer.bottom
|
2021-11-10 04:17:00 +01:00
|
|
|
text: body + " [" + filesize + "]"
|
2021-12-08 23:37:55 +01:00
|
|
|
textFormat: Text.RichText
|
2021-11-10 04:17:00 +01:00
|
|
|
elide: Text.ElideRight
|
2023-06-02 01:29:05 +02:00
|
|
|
color: palette.text
|
2021-11-10 04:17:00 +01:00
|
|
|
|
|
|
|
background: Rectangle {
|
2023-06-02 01:29:05 +02:00
|
|
|
color: palette.base
|
2021-11-10 04:17:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-19 20:11:03 +02:00
|
|
|
|
2021-11-10 04:17:00 +01:00
|
|
|
}
|