From bceafd7bbd4ed4c82e2a0bee46a29e058c2f325a Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 16 Jul 2020 15:59:54 -0400 Subject: [PATCH] Preview/confirm popup for clipboard pasting --- src/gui/Pages/Chat/Composer/MessageArea.qml | 9 ++- .../Popups/ConfirmClipboardUploadPopup.qml | 74 +++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/gui/Popups/ConfirmClipboardUploadPopup.qml diff --git a/src/gui/Pages/Chat/Composer/MessageArea.qml b/src/gui/Pages/Chat/Composer/MessageArea.qml index 2df54c80..a319455e 100644 --- a/src/gui/Pages/Chat/Composer/MessageArea.qml +++ b/src/gui/Pages/Chat/Composer/MessageArea.qml @@ -161,8 +161,13 @@ HTextArea { } } - onCustomImagePaste: py.callClientCoro( - writingUserId, "send_clipboard_image", [chat.roomId, Clipboard.image], + onCustomImagePaste: utils.makePopup( + "Popups/ConfirmClipboardUploadPopup.qml", + { + userId: chat.userId, + roomId: chat.roomId, + roomName: chat.roomInfo.display_name, + }, ) Keys.onEscapePressed: clearReplyTo() diff --git a/src/gui/Popups/ConfirmClipboardUploadPopup.qml b/src/gui/Popups/ConfirmClipboardUploadPopup.qml new file mode 100644 index 00000000..f21832db --- /dev/null +++ b/src/gui/Popups/ConfirmClipboardUploadPopup.qml @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Layouts 1.12 +import Clipboard 0.1 +import "../Base" +import "../Base/Buttons" + +HColumnPopup { + id: popup + + property string userId + property string roomId + property string roomName + + + page.footer: AutoDirectionLayout { + ApplyButton { + id: uploadButton + text: qsTr("Send") + icon.name: "confirm-uploading-file" + onClicked: { + py.callClientCoro( + popup.userId, + "send_clipboard_image", + [popup.roomId, Clipboard.image], + ) + popup.close() + } + } + + CancelButton { + id: cancelButton + onClicked: popup.close() + } + } + + onOpened: uploadButton.forceActiveFocus() + + SummaryLabel { + text: + qsTr("Send copied image to %1?") + .arg(utils.htmlColorize(roomName, theme.colors.accentText)) + + textFormat: Text.StyledText + } + + HImage { + id: image + + property int updateCounter: 0 + + source: "image://clipboard/" + updateCounter + fillMode: Image.PreserveAspectFit + + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: // TODO: loading spinner? + status === Image.Ready ? + width / (implicitWidth / implicitHeight) : + 0 + + Behavior on Layout.preferredHeight { HNumberAnimation {} } + + Connections { + target: Clipboard + + function onContentChanged() { + Clipboard.hasImage ? image.updateCounter += 1 : popup.close() + } + } + } +}