Spectral/imports/Spectral/Component/Timeline/ImageDelegate.qml

227 lines
5.9 KiB
QML
Raw Normal View History

2018-12-07 01:18:42 +00:00
import QtQuick 2.12
2018-12-22 14:25:03 +00:00
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls.Material 2.12
2018-11-22 09:15:14 +00:00
import QtGraphicalEffects 1.0
2018-12-15 14:29:51 +00:00
import Qt.labs.platform 1.0 as Platform
2018-11-22 09:15:14 +00:00
import Spectral 0.1
import Spectral.Setting 0.1
import Spectral.Component 2.0
import Spectral.Dialog 2.0
2019-04-30 03:05:35 +00:00
import Spectral.Menu.Timeline 2.0
import Spectral.Effect 2.0
2018-11-22 09:15:14 +00:00
import Spectral.Font 0.1
2019-05-11 08:25:55 +00:00
RowLayout {
readonly property bool avatarVisible: showAuthor && !sentByMe
2018-11-22 09:15:14 +00:00
readonly property bool sentByMe: author === currentRoom.localUser
2018-12-15 14:29:51 +00:00
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
2018-11-22 09:15:14 +00:00
id: root
2019-05-11 08:25:55 +00:00
spacing: 4
z: -5
2018-11-22 09:15:14 +00:00
2019-05-01 02:59:09 +00:00
onDownloadedChanged: {
if (downloaded && openOnFinished) {
openSavedFile()
openOnFinished = false
}
2019-05-01 02:59:09 +00:00
}
2018-12-15 14:29:51 +00:00
2019-05-11 08:25:55 +00:00
Avatar {
2019-05-11 13:03:44 +00:00
Layout.preferredWidth: 36
Layout.preferredHeight: 36
Layout.alignment: Qt.AlignBottom
2018-11-22 09:15:14 +00:00
visible: avatarVisible
2019-05-11 08:25:55 +00:00
hint: author.displayName
source: author.avatarMediaId
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
Component {
id: userDetailDialog
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
UserDetailDialog {}
}
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
RippleEffect {
anchors.fill: parent
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
circular: true
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": author}).open()
}
}
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
Label {
2019-05-11 13:03:44 +00:00
Layout.preferredWidth: 36
Layout.preferredHeight: 36
2019-05-11 08:25:55 +00:00
visible: !(sentByMe || avatarVisible)
}
2019-05-11 08:25:55 +00:00
BusyIndicator {
Layout.preferredWidth: 64
Layout.preferredHeight: 64
2019-05-11 08:25:55 +00:00
visible: img.status == Image.Loading
}
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
Image {
2019-05-11 13:03:44 +00:00
Layout.maximumWidth: messageListView.width - (!sentByMe ? 36 + root.spacing : 0) - 48
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
id: img
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
source: "image://mxc/" +
(content.info && content.info.thumbnail_info ?
content.thumbnailMediaId : content.mediaId)
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
sourceSize.width: 720
sourceSize.height: 720
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
fillMode: Image.PreserveAspectCrop
2019-05-11 08:25:55 +00:00
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
width: img.width
height: img.height
2019-05-19 18:24:36 +00:00
radius: 2
2019-05-11 08:25:55 +00:00
}
}
2019-05-11 08:25:55 +00:00
Control {
anchors.bottom: parent.bottom
anchors.bottomMargin: 8
anchors.right: parent.right
anchors.rightMargin: 8
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
horizontalPadding: 8
verticalPadding: 4
2019-05-11 08:25:55 +00:00
contentItem: RowLayout {
Label {
text: Qt.formatTime(time, "hh:mm AP")
2019-05-11 08:25:55 +00:00
color: "white"
font.pixelSize: 12
}
2018-11-22 09:15:14 +00:00
2019-05-11 08:25:55 +00:00
Label {
text: author.displayName
color: "white"
font.pixelSize: 12
2019-01-04 12:17:26 +00:00
}
2018-11-22 09:15:14 +00:00
}
2019-05-11 08:25:55 +00:00
background: Rectangle {
radius: height / 2
color: "black"
opacity: 0.3
}
}
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
Rectangle {
anchors.fill: parent
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
visible: progressInfo.active && !downloaded
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
color: "#BB000000"
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
ProgressBar {
anchors.centerIn: parent
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
width: parent.width * 0.8
from: 0
to: progressInfo.total
value: progressInfo.progress
2019-05-01 02:59:09 +00:00
}
2019-05-11 08:25:55 +00:00
}
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
RippleEffect {
anchors.fill: parent
id: messageMouseArea
onPrimaryClicked: fullScreenImage.createObject(parent, {"filename": eventId, "localPath": currentRoom.urlToDownload(eventId)}).show()
onSecondaryClicked: {
var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay)
contextMenu.viewSource.connect(function() {
messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open()
})
contextMenu.downloadAndOpen.connect(downloadAndOpen)
contextMenu.saveFileAs.connect(saveFileAs)
contextMenu.reply.connect(function() {
roomPanelInput.replyUser = author
roomPanelInput.replyEventID = eventId
roomPanelInput.replyContent = message
roomPanelInput.isReply = true
roomPanelInput.focus()
})
contextMenu.redact.connect(function() {
currentRoom.redactEvent(eventId)
})
contextMenu.popup()
}
2019-05-11 08:25:55 +00:00
Component {
id: messageSourceDialog
2019-05-11 08:25:55 +00:00
MessageSourceDialog {}
}
2019-05-11 08:25:55 +00:00
Component {
id: openFolderDialog
2019-04-30 09:02:00 +00:00
2019-05-11 08:25:55 +00:00
OpenFolderDialog {}
}
2019-04-30 09:02:00 +00:00
2019-05-11 08:25:55 +00:00
Component {
id: imageDelegateContextMenu
2018-12-15 14:29:51 +00:00
2019-05-11 08:25:55 +00:00
FileDelegateContextMenu {}
}
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
Component {
id: fullScreenImage
2019-05-01 02:59:09 +00:00
2019-05-11 08:25:55 +00:00
FullScreenImage {}
2018-11-22 09:15:14 +00:00
}
}
}
2018-12-15 14:29:51 +00:00
2019-04-30 09:02:00 +00:00
function saveFileAs() {
var folderDialog = openFolderDialog.createObject(ApplicationWindow.overlay)
2019-04-30 09:02:00 +00:00
folderDialog.chosen.connect(function(path) {
2019-04-30 09:02:00 +00:00
if (!path) return
currentRoom.downloadFile(eventId, path + "/" + currentRoom.fileNameToDownload(eventId))
2019-04-30 09:02:00 +00:00
})
folderDialog.open()
2019-04-30 09:02:00 +00:00
}
2018-12-15 14:29:51 +00:00
function downloadAndOpen()
{
if (downloaded) openSavedFile()
else
{
openOnFinished = true
currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
2018-12-15 14:29:51 +00:00
}
}
function openSavedFile()
{
if (Qt.openUrlExternally(progressInfo.localPath)) return;
if (Qt.openUrlExternally(progressInfo.localDir)) return;
}
2018-11-22 09:15:14 +00:00
}