source: s10k/Vago/libs/DropLineEdit/droplineedit.cpp@ 1144

Last change on this file since 1144 was 1061, checked in by s10k, 8 years ago

Added Vago 1.3

File size: 1.2 KB
Line 
1#include "DropLineEdit.h"
2
3DropLineEdit::DropLineEdit(QWidget *parent) : QLineEdit(parent)
4{
5 //setDragDropMode(QAbstractItemView::DropOnly);
6 setAcceptDrops(true);
7}
8
9void DropLineEdit::dragEnterEvent(QDragEnterEvent *event) {
10
11 const QMimeData* mimeData = event->mimeData();
12
13 // We only accept if our widget is enabled and it is only one file
14 if(
15 !this->isEnabled() ||
16 mimeData->urls().size() != 1 ||
17 // checks if it is a file (folders are ignored)
18 QDir(mimeData->urls().at(0).toLocalFile()).exists()
19 )
20 {
21 event->ignore();
22 }
23 else{
24 event->acceptProposedAction();
25 }
26}
27
28void DropLineEdit::dragMoveEvent(QDragMoveEvent *event) {
29 event->acceptProposedAction();
30}
31
32void DropLineEdit::dropEvent(QDropEvent *event) {
33
34 const QMimeData* mimeData = event->mimeData();
35
36 event->acceptProposedAction();
37
38 QStringList pathList = QStringList();
39
40 if (mimeData->hasUrls())
41 {
42 this->setText(mimeData->urls().at(0).toLocalFile());
43 }
44
45}
46
47void DropLineEdit::dragLeaveEvent(QDragLeaveEvent *event) {
48 event->accept();
49}
Note: See TracBrowser for help on using the repository browser.