-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiledroplabel.cpp
More file actions
31 lines (28 loc) · 1.03 KB
/
filedroplabel.cpp
File metadata and controls
31 lines (28 loc) · 1.03 KB
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
#include "filedroplabel.h"
FileDropLabel::FileDropLabel(QWidget* p): QLabel(p){
setAcceptDrops(true);
setAlignment(Qt::AlignCenter);
setMinimumHeight(110);
setText("Drop files/folders here (or URLs)");
setFrameShape(QFrame::StyledPanel);
setObjectName("drop");
}
void FileDropLabel::dragEnterEvent(QDragEnterEvent *e){
if(e->mimeData()->hasUrls() || e->mimeData()->hasText()) e->acceptProposedAction();
}
void FileDropLabel::dropEvent(QDropEvent *e){
QStringList paths, links;
if(e->mimeData()->hasUrls()){
for(const QUrl &u: e->mimeData()->urls()){
if(u.isLocalFile()) paths<<u.toLocalFile();
else links<<u.toString();
}
} else if(e->mimeData()->hasText()){
for (const QString &line : e->mimeData()->text().split(QRegExp("[\r\n]"), Qt::SkipEmptyParts)){
const QString s=line.trimmed();
if(QUrl(s).isValid()) links<<s;
}
}
if(!paths.isEmpty()) emit filesDropped(paths);
if(!links.isEmpty()) emit urlsDropped(links);
}