Simplify & fix bugs event images context menu
Fix copy menu entries for messages with URL thumbnail previews
This commit is contained in:
parent
648c37f413
commit
b3ca5599cf
@ -8,11 +8,7 @@ import "../../../Base"
|
||||
import "../../../Base/MediaPlayer"
|
||||
|
||||
AudioPlayer {
|
||||
id: audio
|
||||
readonly property bool hovered: hover.hovered
|
||||
|
||||
HoverHandler {
|
||||
onHoveredChanged:
|
||||
eventDelegate.hoveredMediaTypeUrl =
|
||||
hovered ? [Utils.Media.Audio, audio.source, loader.title] : []
|
||||
}
|
||||
HoverHandler { id: hover }
|
||||
}
|
||||
|
@ -41,8 +41,11 @@ HRowLayout {
|
||||
|
||||
readonly property bool pureMedia: ! contentText && linksRepeater.count
|
||||
|
||||
readonly property string hoveredLink: contentLabel.hoveredLink
|
||||
readonly property bool hoveredSelectable: contentHover.hovered
|
||||
readonly property string hoveredLink:
|
||||
linksRepeater.lastHovered && linksRepeater.lastHovered.hovered ?
|
||||
linksRepeater.lastHovered.mediaUrl :
|
||||
contentLabel.hoveredLink
|
||||
|
||||
readonly property alias contentLabel: contentLabel
|
||||
|
||||
@ -295,6 +298,11 @@ HRowLayout {
|
||||
|
||||
HRepeater {
|
||||
id: linksRepeater
|
||||
|
||||
property EventMediaLoader lastHovered: null
|
||||
property var pr: lastHovered
|
||||
onPrChanged: print("pr changed:", pr)
|
||||
|
||||
model: {
|
||||
const links = JSON.parse(eventDelegate.currentModel.links)
|
||||
|
||||
@ -313,6 +321,8 @@ HRowLayout {
|
||||
|
||||
transform: Translate { x: xOffset }
|
||||
|
||||
onHoveredChanged: if (hovered) linksRepeater.lastHovered = this
|
||||
|
||||
Layout.bottomMargin: pureMedia ? 0 : contentLabel.bottomPadding
|
||||
Layout.leftMargin: pureMedia ? 0 : eventContent.spacing
|
||||
Layout.rightMargin: pureMedia ? 0 : eventContent.spacing
|
||||
|
@ -13,7 +13,6 @@ HMenu {
|
||||
property HListView eventList
|
||||
property int eventIndex: 0
|
||||
property Item eventDelegate: null // TODO: Qt 5.13: just use itemAtIndex()
|
||||
property var hoveredMedia: [] // [Utils.Media.<Type>, url, title]
|
||||
property string hoveredLink: ""
|
||||
|
||||
readonly property QtObject event: eventList.model.get(eventIndex)
|
||||
@ -21,19 +20,20 @@ HMenu {
|
||||
readonly property bool isEncryptedMedia:
|
||||
Object.keys(JSON.parse(event.media_crypt_dict)).length > 0
|
||||
|
||||
function spawn(eventIndex, eventDelegate, hoveredMedia=[], hoveredUrl="") {
|
||||
readonly property var mediaType: // Utils.Media.<Type> or null
|
||||
event.media_http_url ? eventList.getMediaType(event) :
|
||||
hoveredLink ? utils.getLinkType(hoveredLink) :
|
||||
null
|
||||
|
||||
function spawn(eventIndex, eventDelegate, hoveredLink="") {
|
||||
menu.eventIndex = eventIndex
|
||||
menu.eventDelegate = eventDelegate
|
||||
menu.hoveredMedia = hoveredMedia
|
||||
menu.hoveredLink = hoveredUrl
|
||||
menu.hoveredLink = hoveredLink
|
||||
menu.popup()
|
||||
}
|
||||
|
||||
|
||||
onClosed: {
|
||||
hoveredMedia = []
|
||||
hoveredLink = ""
|
||||
}
|
||||
onClosed: hoveredLink = ""
|
||||
|
||||
HMenuItem {
|
||||
icon.name: "toggle-select-message"
|
||||
@ -74,38 +74,23 @@ HMenu {
|
||||
HMenuItem {
|
||||
id: copyMedia
|
||||
icon.name: "copy-link"
|
||||
visible: menu.mediaType && ! menu.isEncryptedMedia
|
||||
text:
|
||||
menu.hoveredMedia.length === 0 ||
|
||||
menu.isEncryptedMedia ?
|
||||
"" :
|
||||
! visible ? "" :
|
||||
menu.mediaType === Utils.Media.File ? qsTr("Copy file address") :
|
||||
menu.mediaType === Utils.Media.Image ? qsTr("Copy image address") :
|
||||
menu.mediaType === Utils.Media.Video ? qsTr("Copy video address") :
|
||||
menu.mediaType === Utils.Media.Audio ? qsTr("Copy audio address") :
|
||||
qsTr("Copy link address")
|
||||
|
||||
menu.hoveredMedia[0] === Utils.Media.File ?
|
||||
qsTr("Copy file address") :
|
||||
|
||||
menu.hoveredMedia[0] === Utils.Media.Image ?
|
||||
qsTr("Copy image address") :
|
||||
|
||||
menu.hoveredMedia[0] === Utils.Media.Video ?
|
||||
qsTr("Copy video address") :
|
||||
|
||||
qsTr("Copy audio address")
|
||||
|
||||
visible: Boolean(text)
|
||||
onTriggered: Clipboard.text = event.media_http_url // FIXME
|
||||
}
|
||||
|
||||
HMenuItem {
|
||||
icon.name: "copy-link"
|
||||
text: qsTr("Copy link address")
|
||||
visible: Boolean(menu.hoveredLink)
|
||||
onTriggered: Clipboard.text = menu.hoveredLink
|
||||
onTriggered: Clipboard.text = event.media_http_url || menu.hoveredLink
|
||||
}
|
||||
|
||||
HMenuItem {
|
||||
icon.name: "copy-text"
|
||||
text:
|
||||
eventList.selectedCount ? qsTr("Copy selection") :
|
||||
menu.hoveredMedia.length > 0 ? qsTr("Copy filename") :
|
||||
event.media_url ? qsTr("Copy filename") :
|
||||
qsTr("Copy text")
|
||||
|
||||
onTriggered: {
|
||||
|
@ -10,8 +10,6 @@ import "../../../PythonBridge"
|
||||
HColumnLayout {
|
||||
id: eventDelegate
|
||||
|
||||
property var hoveredMediaTypeUrl: [] // [] or [mediaType, url, title]
|
||||
|
||||
property var fetchProfilesFuture: null
|
||||
|
||||
// Remember timeline goes from newest message at index 0 to oldest
|
||||
@ -32,11 +30,8 @@ HColumnLayout {
|
||||
eventList.canDayBreak(previousModel, model)
|
||||
|
||||
readonly property int cursorShape:
|
||||
eventContent.hoveredLink || hoveredMediaTypeUrl.length === 3 ?
|
||||
Qt.PointingHandCursor :
|
||||
|
||||
eventContent.hoveredLink ? Qt.PointingHandCursor :
|
||||
eventContent.hoveredSelectable ? Qt.IBeamCursor :
|
||||
|
||||
Qt.ArrowCursor
|
||||
|
||||
readonly property int separationSpacing:
|
||||
@ -57,10 +52,7 @@ HColumnLayout {
|
||||
|
||||
function openContextMenu() {
|
||||
eventList.contextMenu.spawn(
|
||||
model.index,
|
||||
eventDelegate,
|
||||
hoveredMediaTypeUrl,
|
||||
eventContent.hoveredLink,
|
||||
model.index, eventDelegate, eventContent.hoveredLink,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -54,16 +54,6 @@ HTile {
|
||||
|
||||
Qt.openUrlExternally(loader.mediaUrl)
|
||||
|
||||
onHoveredChanged: {
|
||||
if (! hovered) {
|
||||
eventDelegate.hoveredMediaTypeUrl = []
|
||||
return
|
||||
}
|
||||
|
||||
eventDelegate.hoveredMediaTypeUrl =
|
||||
[Utils.Media.File, loader.mediaUrl, loader.title]
|
||||
}
|
||||
|
||||
Binding on backgroundColor {
|
||||
value: theme.chat.message.checkedBackground
|
||||
when: eventDelegate.checked
|
||||
|
@ -42,6 +42,8 @@ HMxcImage {
|
||||
Math.max(maxHeight, theme.chat.message.thumbnailMinSize.height),
|
||||
)
|
||||
|
||||
readonly property bool hovered: hover.hovered
|
||||
|
||||
function openInternally() {
|
||||
eventList.openImageViewer(
|
||||
singleMediaInfo,
|
||||
@ -118,15 +120,6 @@ HMxcImage {
|
||||
|
||||
HoverHandler {
|
||||
id: hover
|
||||
onHoveredChanged: {
|
||||
if (! hovered) {
|
||||
eventDelegate.hoveredMediaTypeUrl = []
|
||||
return
|
||||
}
|
||||
|
||||
eventDelegate.hoveredMediaTypeUrl =
|
||||
[Utils.Media.Image, loader.mediaUrl, loader.title]
|
||||
}
|
||||
}
|
||||
|
||||
EventImageTextBubble {
|
||||
|
@ -28,9 +28,10 @@ HLoader {
|
||||
utils.getLinkType(mediaUrl)
|
||||
|
||||
readonly property string cachedLocalPath: ""
|
||||
|
||||
readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url
|
||||
|
||||
readonly property bool hovered: item ? item.hovered : false
|
||||
|
||||
|
||||
visible: Boolean(item)
|
||||
x: eventContent.spacing
|
||||
|
@ -8,9 +8,7 @@ import "../../../Base"
|
||||
import "../../../Base/MediaPlayer"
|
||||
|
||||
VideoPlayer {
|
||||
id: video
|
||||
readonly property bool hovered: hover.hovered
|
||||
|
||||
onHoveredChanged:
|
||||
eventDelegate.hoveredMediaTypeUrl =
|
||||
hovered ? [Utils.Media.Video, video.source, loader.title] : []
|
||||
HoverHandler { id: hover }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user