2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2021-03-07 07:57:56 +03:00
|
|
|
//
|
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 "../"
|
2021-11-10 03:28:53 +03:00
|
|
|
import "../ui/media"
|
2021-08-28 01:38:33 +03:00
|
|
|
import QtMultimedia 5.15
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
2021-11-11 08:16:25 +03:00
|
|
|
import QtQuick.Layouts 1.15
|
2019-11-30 03:43:39 +03:00
|
|
|
import im.nheko 1.0
|
2019-10-06 02:05:32 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
Item {
|
2021-11-10 06:17:00 +03:00
|
|
|
id: content
|
|
|
|
|
2021-07-12 01:24:33 +03:00
|
|
|
required property double proportionalHeight
|
|
|
|
required property int type
|
|
|
|
required property int originalWidth
|
2022-03-21 02:48:27 +03:00
|
|
|
required property int duration
|
2021-07-12 01:24:33 +03:00
|
|
|
required property string thumbnailUrl
|
|
|
|
required property string eventId
|
|
|
|
required property string url
|
|
|
|
required property string body
|
|
|
|
required property string filesize
|
2021-11-11 23:32:38 +03:00
|
|
|
property double divisor: isReply ? 4 : 2
|
2022-02-14 16:03:17 +03:00
|
|
|
property int tempWidth: originalWidth < 1? 400: originalWidth
|
2022-03-22 22:33:14 +03:00
|
|
|
implicitWidth: type == MtxEvent.VideoMessage ? Math.round(tempWidth*Math.min((timelineView.fullHeight/divisor)/(tempWidth*proportionalHeight), 1)) : 500
|
2022-02-14 23:07:03 +03:00
|
|
|
width: Math.min(parent.width, implicitWidth)
|
2022-02-12 00:02:30 +03:00
|
|
|
height: (type == MtxEvent.VideoMessage ? width*proportionalHeight : 80) + fileInfoLabel.height
|
2022-02-09 23:36:04 +03:00
|
|
|
implicitHeight: height
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2022-02-14 23:07:03 +03:00
|
|
|
property int metadataWidth
|
|
|
|
property bool fitsMetadata: (parent.width - fileInfoLabel.width) > metadataWidth+4
|
|
|
|
|
2021-11-04 04:43:11 +03:00
|
|
|
MxcMedia {
|
|
|
|
id: mxcmedia
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-07-19 21:11:03 +03:00
|
|
|
// TODO: Show error in overlay or so?
|
2021-11-04 04:43:11 +03:00
|
|
|
onError: console.log(error)
|
|
|
|
roomm: room
|
2021-11-10 06:17:00 +03: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 21:11:03 +03:00
|
|
|
}
|
2021-11-09 06:55:16 +03:00
|
|
|
|
2021-07-19 21:11:03 +03:00
|
|
|
Rectangle {
|
|
|
|
id: videoContainer
|
2021-11-11 23:32:38 +03:00
|
|
|
|
2021-11-10 07:52:59 +03:00
|
|
|
color: type == MtxEvent.VideoMessage ? Nheko.colors.window : "transparent"
|
2021-11-11 21:18:45 +03:00
|
|
|
width: parent.width
|
|
|
|
height: parent.height - fileInfoLabel.height
|
|
|
|
|
2021-11-11 23:32:38 +03:00
|
|
|
TapHandler {
|
2022-03-19 08:31:43 +03:00
|
|
|
onTapped: Settings.openVideoExternal ? room.openMedia(eventId) : mediaControls.showControls()
|
2021-11-11 23:32:38 +03:00
|
|
|
}
|
2021-11-09 03:18:11 +03:00
|
|
|
|
2021-07-19 21:11:03 +03:00
|
|
|
Image {
|
|
|
|
anchors.fill: parent
|
2022-03-21 07:05:29 +03:00
|
|
|
source: thumbnailUrl ? thumbnailUrl.replace("mxc://", "image://MxcImage/") + "?scale" : ""
|
2021-07-19 21:11:03 +03:00
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2021-11-10 06:17:00 +03:00
|
|
|
|
2021-07-19 21:11:03 +03:00
|
|
|
VideoOutput {
|
|
|
|
id: videoOutput
|
2021-11-10 07:52:59 +03:00
|
|
|
|
2021-11-10 06:33:16 +03:00
|
|
|
visible: type == MtxEvent.VideoMessage
|
2021-07-19 21:11:03 +03:00
|
|
|
clip: true
|
|
|
|
anchors.fill: parent
|
|
|
|
fillMode: VideoOutput.PreserveAspectFit
|
2021-11-04 04:43:11 +03:00
|
|
|
source: mxcmedia
|
2021-11-09 06:55:16 +03:00
|
|
|
flushMode: VideoOutput.FirstFrame
|
2021-11-15 05:35:35 +03:00
|
|
|
orientation: mxcmedia.orientation
|
2021-11-10 06:33:16 +03:00
|
|
|
}
|
2021-11-04 04:43:11 +03:00
|
|
|
|
2021-11-11 21:18:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-11 23:32:38 +03:00
|
|
|
MediaControls {
|
|
|
|
id: mediaControls
|
|
|
|
|
|
|
|
anchors.left: content.left
|
|
|
|
anchors.right: content.right
|
|
|
|
anchors.bottom: fileInfoLabel.top
|
|
|
|
playingVideo: type == MtxEvent.VideoMessage
|
|
|
|
positionValue: mxcmedia.position
|
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
|
|
|
|
onPositionChanged: mxcmedia.position = position
|
|
|
|
onPlayPauseActivated: mxcmedia.state == MediaPlayer.PlayingState ? mxcmedia.pause() : mxcmedia.play()
|
|
|
|
onLoadActivated: mxcmedia.eventId = eventId
|
|
|
|
}
|
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
|
2021-11-10 06:17:00 +03:00
|
|
|
text: body + " [" + filesize + "]"
|
2021-12-09 01:37:55 +03:00
|
|
|
textFormat: Text.RichText
|
2021-11-10 06:17:00 +03:00
|
|
|
elide: Text.ElideRight
|
|
|
|
color: Nheko.colors.text
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
color: Nheko.colors.base
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-19 21:11:03 +03:00
|
|
|
|
2021-11-10 06:17:00 +03:00
|
|
|
}
|