Add drag and drop support.

This commit is contained in:
Black Hat 2019-05-17 19:46:59 +08:00
parent 75c5c71855
commit b4281896ba
3 changed files with 43 additions and 23 deletions

View File

@ -23,6 +23,18 @@ Item {
room: currentRoom room: currentRoom
} }
DropArea {
anchors.fill: parent
enabled: currentRoom
onDropped: {
if (!drop.hasUrls) return
currentRoom.uploadFile(drop.urls[0])
}
}
Column { Column {
anchors.centerIn: parent anchors.centerIn: parent

View File

@ -47,7 +47,15 @@ inline QSize getImageSize(const QUrl& imageUrl) {
void SpectralRoom::chooseAndUploadFile() { void SpectralRoom::chooseAndUploadFile() {
auto localFile = QFileDialog::getOpenFileUrl(Q_NULLPTR, tr("Save File as")); auto localFile = QFileDialog::getOpenFileUrl(Q_NULLPTR, tr("Save File as"));
if (!localFile.isEmpty()) { if (!localFile.isEmpty()) {
QString txnID = postFile(localFile.fileName(), localFile, false); uploadFile(localFile);
}
}
void SpectralRoom::uploadFile(const QUrl& url) {
if (url.isEmpty())
return;
QString txnID = postFile(url.fileName(), url, false);
setHasFileUploading(true); setHasFileUploading(true);
connect(this, &Room::fileTransferCompleted, connect(this, &Room::fileTransferCompleted,
[=](QString id, QUrl localFile, QUrl mxcUrl) { [=](QString id, QUrl localFile, QUrl mxcUrl) {
@ -70,7 +78,6 @@ void SpectralRoom::chooseAndUploadFile() {
setFileUploadingProgress(int(float(progress) / float(total) * 100)); setFileUploadingProgress(int(float(progress) / float(total) * 100));
} }
}); });
}
} }
void SpectralRoom::acceptInvitation() { void SpectralRoom::acceptInvitation() {

View File

@ -255,6 +255,7 @@ class SpectralRoom : public Room {
public slots: public slots:
void chooseAndUploadFile(); void chooseAndUploadFile();
void uploadFile(const QUrl& url);
void acceptInvitation(); void acceptInvitation();
void forget(); void forget();
void sendTypingNotification(bool isTyping); void sendTypingNotification(bool isTyping);