Support drag and drop between splits

Change-Id: Ia1e43cb44639e332ee4f9100c7ce3029e9485198
Reviewed-by: Alessandro Portale <alessandro.portale@digia.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Eike Ziller
2014-09-04 20:43:09 +02:00
parent 67421f6c53
commit e0c5d2365f
6 changed files with 110 additions and 27 deletions

View File

@@ -711,8 +711,9 @@ static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0)
return hasFiles;
}
FileDropSupport::FileDropSupport(QWidget *parentWidget)
: QObject(parentWidget)
FileDropSupport::FileDropSupport(QWidget *parentWidget, const DropFilterFunction &filterFunction)
: QObject(parentWidget),
m_filterFunction(filterFunction)
{
QTC_ASSERT(parentWidget, return);
parentWidget->setAcceptDrops(true);
@@ -744,15 +745,22 @@ bool FileDropSupport::eventFilter(QObject *obj, QEvent *event)
Q_UNUSED(obj)
if (event->type() == QEvent::DragEnter) {
auto dee = static_cast<QDragEnterEvent *>(event);
if (isDesktopFileManagerDrop(dee->mimeData()))
if (isDesktopFileManagerDrop(dee->mimeData())
&& (!m_filterFunction || m_filterFunction(dee)))
event->accept();
else
event->ignore();
return true;
} else if (event->type() == QEvent::DragMove) {
event->accept();
return true;
} else if (event->type() == QEvent::Drop) {
auto de = static_cast<QDropEvent *>(event);
QStringList tempFiles;
if (isDesktopFileManagerDrop(de->mimeData(), &tempFiles)) {
if (isDesktopFileManagerDrop(de->mimeData(), &tempFiles)
&& (!m_filterFunction || m_filterFunction(de))) {
event->accept();
de->acceptProposedAction();
bool needToScheduleEmit = m_files.isEmpty();
m_files.append(tempFiles);
if (needToScheduleEmit) // otherwise we already have a timer pending
@@ -760,6 +768,7 @@ bool FileDropSupport::eventFilter(QObject *obj, QEvent *event)
} else {
event->ignore();
}
return true;
}
return false;
}