From 473a73c7112e9fbcd441fa1bf5ff7b1f96ee28bd Mon Sep 17 00:00:00 2001 From: Thanos Doukoudakis Date: Mon, 8 May 2017 11:50:57 +0100 Subject: Fix an issue when sending a file in a chat When you drop a file in the chat input, the file path was being sent to the chat, instead of initialising a file transfer. This patch fixes this issue and starts the file transfer. Test-Information: Tested on Windows 10 with Qt5.7. Drag a file and drop in the chat input. Change-Id: Ie6c31e0ba56ac7171442370bf7d8edbefce208d6 diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 48d331e..7051683 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -150,6 +150,7 @@ QtChatWindow::QtChatWindow(const QString& contact, QtChatTheme* theme, UIEventSt connect(input_, SIGNAL(receivedFocus()), this, SLOT(handleTextInputReceivedFocus())); connect(input_, SIGNAL(lostFocus()), this, SLOT(handleTextInputLostFocus())); + connect(input_, SIGNAL(itemDropped(QDropEvent*)), this, SLOT(dropEvent(QDropEvent*))); QPushButton* emojisButton_ = new QPushButton(this); #ifdef SWIFTEN_PLATFORM_MACOSX diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 1b4d76d..168e6fc 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -179,6 +180,15 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { delete menu; } +void QtTextEdit::dropEvent(QDropEvent* event) { + if (event->mimeData()->hasUrls()) { + itemDropped(event); + } + else { + QTextEdit::dropEvent(event); + } +} + void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) { replaceWordActions_.clear(); diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h index 228aa9e..7ce5d88 100644 --- a/Swift/QtUI/QtTextEdit.h +++ b/Swift/QtUI/QtTextEdit.h @@ -35,6 +35,7 @@ namespace Swift { void unhandledKeyPressEvent(QKeyEvent* event); void receivedFocus(); void lostFocus(); + void itemDropped(QDropEvent* event); public slots: void handleSettingChanged(const std::string& settings); @@ -44,6 +45,7 @@ namespace Swift { virtual void focusInEvent(QFocusEvent* event); virtual void focusOutEvent(QFocusEvent* event); virtual void contextMenuEvent(QContextMenuEvent* event); + virtual void dropEvent(QDropEvent* event); private slots: void handleTextChanged(); -- cgit v0.10.2-6-g49f6