Copy image to the clipboard

Add a context menu option to save an image in the timeline to the clipboard

BUG: 466478
This commit is contained in:
Alessio Mattiazzi
2023-03-05 23:19:02 +00:00
committed by Tobias Fella
parent bd4eeb405b
commit d1f7e7091e
3 changed files with 27 additions and 0 deletions

View File

@@ -67,3 +67,15 @@ void Clipboard::saveText(QString message)
mineData->setText(message.replace(re, ""));
m_clipboard->setMimeData(mineData);
}
void Clipboard::setImage(const QUrl &url)
{
if (url.isLocalFile()) {
QImage img(url.path());
auto *mimeData = new QMimeData;
mimeData->setImageData(img);
if (!img.isNull()) {
m_clipboard->setMimeData(mimeData);
}
}
}

View File

@@ -26,6 +26,7 @@ public:
Q_INVOKABLE QString saveImage(QString localPath = {}) const;
Q_INVOKABLE void saveText(QString message);
Q_INVOKABLE void setImage(const QUrl &image);
private:
QClipboard *m_clipboard;

View File

@@ -55,6 +55,20 @@ MessageDelegateContextMenu {
root.closeFullscreen()
}
},
Kirigami.Action {
text: i18n("Copy")
icon.name: "edit-copy"
onTriggered: {
if(file.downloaded) {
Clipboard.setImage(progressInfo.localPath)
} else {
file.onDownloadedChanged.connect(function() {
Clipboard.setImage(progressInfo.localPath)
});
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
}
}
},
Kirigami.Action {
visible: author.id === currentRoom.localUser.id || currentRoom.canSendState("redact")
text: i18n("Remove")