diff --git a/src/gui/Pages/Chat/ChatPage.qml b/src/gui/Pages/Chat/ChatPage.qml index cb1f77d8..02966c77 100644 --- a/src/gui/Pages/Chat/ChatPage.qml +++ b/src/gui/Pages/Chat/ChatPage.qml @@ -25,6 +25,11 @@ HColumnPage { readonly property alias leftBanner: leftBanner readonly property alias composer: composer + readonly property DropArea uploadDropArea: UploadDropArea { + parent: window.mainUI + anchors.fill: parent + } + padding: 0 column.spacing: 0 diff --git a/src/gui/Pages/Chat/UploadDropArea.qml b/src/gui/Pages/Chat/UploadDropArea.qml new file mode 100644 index 00000000..80ad89f9 --- /dev/null +++ b/src/gui/Pages/Chat/UploadDropArea.qml @@ -0,0 +1,95 @@ +// Copyright Mirage authors & contributors +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import QtQuick.Layouts 1.12 +import "../../Base" +import "AutoCompletion" +import "Banners" +import "Composer" +import "FileTransfer" +import "Timeline" + +DropArea { + property var dragEvent: null + property int insertedTextStart: -1 + property int insertedTextEnd: -1 + + function eventFiles() { + if (! dragEvent) return [] + return dragEvent.urls.filter(uri => uri.match(/^file:\/\//)) + } + + function reset() { + if (popup.opened) popup.close() + dragEvent = null + insertedTextStart = -1 + insertedTextEnd = -1 + } + + onPositionChanged: drag => dragEvent = drag + + onEntered: drag => { + print(JSON.stringify( drag, null, 4)) + dragEvent = drag + if (eventFiles().length && ! popup.opened) popup.open() + if (! drag.hasText || eventFiles().length) return + + insertedTextStart = composer.messageArea.cursorPosition + composer.messageArea.insertAtCursor(drag.text.replace(/\n+$/, "")) + insertedTextEnd = composer.messageArea.cursorPosition + } + + onExited: { + if (insertedTextStart !== -1 && insertedTextEnd !== -1) + composer.messageArea.remove(insertedTextStart, insertedTextEnd) + + reset() + } + + onDropped: drag => { + dragEvent = drag + + for (const path of eventFiles()) { + window.makePopup( + "Popups/ConfirmUploadPopup.qml", + { + userId: chat.userId, + roomId: chat.roomId, + roomName: chat.roomInfo.display_name, + filePath: path.replace(/^file:\/\//, ""), + replyToEventId: chat.replyToEventId, + }, + popup => popup.replied.connect(chat.clearReplyTo), + ) + drag.accepted = true + } + + reset() + } + + HPopup { + id: popup + background: null + + Column { + spacing: theme.spacing + + HIcon { + anchors.horizontalCenter: parent.horizontalCenter + svgName: "drop-file-upload" + dimension: Math.min( + 56 * theme.uiScale, + Math.min(window.width, window.height) / 2, + ) + } + + HLabel { + wrapMode: HLabel.Wrap + width: Math.min(implicitWidth, popup.maximumPreferredWidth) + font.pixelSize: theme.fontSize.big + text: qsTr("Drop files to send") + } + } + } +} diff --git a/src/icons/thin/drop-file-upload.svg b/src/icons/thin/drop-file-upload.svg new file mode 100644 index 00000000..a7f76bba --- /dev/null +++ b/src/icons/thin/drop-file-upload.svg @@ -0,0 +1,3 @@ + + +