From b3ca5599cf6e0c782cb3ed4487ec19051e1b62c0 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 2 Sep 2020 10:40:37 -0400 Subject: [PATCH] Simplify & fix bugs event images context menu Fix copy menu entries for messages with URL thumbnail previews --- src/gui/Pages/Chat/Timeline/EventAudio.qml | 8 +-- src/gui/Pages/Chat/Timeline/EventContent.qml | 12 ++++- .../Pages/Chat/Timeline/EventContextMenu.qml | 49 +++++++------------ src/gui/Pages/Chat/Timeline/EventDelegate.qml | 12 +---- src/gui/Pages/Chat/Timeline/EventFile.qml | 10 ---- src/gui/Pages/Chat/Timeline/EventImage.qml | 11 +---- .../Pages/Chat/Timeline/EventMediaLoader.qml | 3 +- src/gui/Pages/Chat/Timeline/EventVideo.qml | 6 +-- 8 files changed, 38 insertions(+), 73 deletions(-) diff --git a/src/gui/Pages/Chat/Timeline/EventAudio.qml b/src/gui/Pages/Chat/Timeline/EventAudio.qml index 1c1da909..e13c807a 100644 --- a/src/gui/Pages/Chat/Timeline/EventAudio.qml +++ b/src/gui/Pages/Chat/Timeline/EventAudio.qml @@ -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 } } diff --git a/src/gui/Pages/Chat/Timeline/EventContent.qml b/src/gui/Pages/Chat/Timeline/EventContent.qml index d2c5bfe4..f668d13c 100644 --- a/src/gui/Pages/Chat/Timeline/EventContent.qml +++ b/src/gui/Pages/Chat/Timeline/EventContent.qml @@ -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 diff --git a/src/gui/Pages/Chat/Timeline/EventContextMenu.qml b/src/gui/Pages/Chat/Timeline/EventContextMenu.qml index f316e171..0c0b9541 100644 --- a/src/gui/Pages/Chat/Timeline/EventContextMenu.qml +++ b/src/gui/Pages/Chat/Timeline/EventContextMenu.qml @@ -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., 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. 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: { diff --git a/src/gui/Pages/Chat/Timeline/EventDelegate.qml b/src/gui/Pages/Chat/Timeline/EventDelegate.qml index 7f7b78cb..21f860a2 100644 --- a/src/gui/Pages/Chat/Timeline/EventDelegate.qml +++ b/src/gui/Pages/Chat/Timeline/EventDelegate.qml @@ -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, ) } diff --git a/src/gui/Pages/Chat/Timeline/EventFile.qml b/src/gui/Pages/Chat/Timeline/EventFile.qml index 0d3fa4b1..eb75a38b 100644 --- a/src/gui/Pages/Chat/Timeline/EventFile.qml +++ b/src/gui/Pages/Chat/Timeline/EventFile.qml @@ -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 diff --git a/src/gui/Pages/Chat/Timeline/EventImage.qml b/src/gui/Pages/Chat/Timeline/EventImage.qml index f24ccbb0..5942e02c 100644 --- a/src/gui/Pages/Chat/Timeline/EventImage.qml +++ b/src/gui/Pages/Chat/Timeline/EventImage.qml @@ -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 { diff --git a/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml b/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml index 797d217e..cbf09a45 100644 --- a/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml +++ b/src/gui/Pages/Chat/Timeline/EventMediaLoader.qml @@ -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 diff --git a/src/gui/Pages/Chat/Timeline/EventVideo.qml b/src/gui/Pages/Chat/Timeline/EventVideo.qml index 58de0829..9ea9f060 100644 --- a/src/gui/Pages/Chat/Timeline/EventVideo.qml +++ b/src/gui/Pages/Chat/Timeline/EventVideo.qml @@ -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 } }