File drag&drop: Move mime data creation to central place

Especially when this gets more complicated with additional fancy windows
mime types and custom mime type for opening a file at a specific
location (dropping from Outline, Type Hierarchy et al), we should not
create that complex mime data everywhere by hand.

Change-Id: I37f6ceb287b0cd055501fdd033ac29816434a020
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Eike Ziller
2014-09-10 14:00:12 +02:00
parent e815fdac76
commit d19628ddf8
3 changed files with 30 additions and 7 deletions

View File

@@ -30,6 +30,7 @@
#include "fileutils.h"
#include "savefile.h"
#include "algorithm.h"
#include "hostosinfo.h"
#include "qtcassert.h"
@@ -718,6 +719,26 @@ FileDropSupport::FileDropSupport(QWidget *parentWidget)
parentWidget->installEventFilter(this);
}
QStringList FileDropSupport::mimeTypesForFilePaths()
{
return QStringList() << QStringLiteral("text/uri-list");
}
QMimeData *FileDropSupport::mimeDataForFilePaths(const QStringList &filePaths)
{
QList<QUrl> localUrls = Utils::transform(filePaths, [filePaths](const QString &path) {
return QUrl::fromLocalFile(path);
});
auto data = new QMimeData;
data->setUrls(localUrls);
return data;
}
QMimeData *FileDropSupport::mimeDataForFilePath(const QString &filePath)
{
return mimeDataForFilePaths(QStringList() << filePath);
}
bool FileDropSupport::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj)