-
Notifications
You must be signed in to change notification settings - Fork 0
/
droplistwidget.cpp
46 lines (39 loc) · 1.17 KB
/
droplistwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <QFileInfo>
#include <QDir>
#include <QDragEnterEvent>
#include <QUrl>
#include <QMimeData>
#include "droplistwidget.h"
DropListWidget::DropListWidget(QWidget *parent) :
QListWidget(parent) {
setAcceptDrops(true);
setDropIndicatorShown(false);
}
bool DropListWidget::dropMimeData(int index, const QMimeData *data,
Qt::DropAction action) {
QList<QUrl> urlList = data->urls();
foreach (QUrl url, urlList) {
addItem(QDir::toNativeSeparators(url.toLocalFile()));
}
return true;
}
QStringList DropListWidget::mimeTypes() const {
return QStringList("text/uri-list");
}
Qt::DropActions DropListWidget::supportedDropActions() const {
return Qt::CopyAction;
}
DropExtListWidget::DropExtListWidget(QWidget *parent):
DropListWidget(parent){
}
bool DropExtListWidget::dropMimeData(int index, const QMimeData *data,
Qt::DropAction action) {
QList<QUrl> urlList = data->urls();
foreach (QUrl url, urlList) {
QString file = url.toLocalFile();
QFileInfo fileInfo(file);
if (!fileInfo.isDir())
addItem(fileInfo.completeSuffix());
}
return true;
}