-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCFileListView.cpp
More file actions
61 lines (50 loc) · 1.48 KB
/
CFileListView.cpp
File metadata and controls
61 lines (50 loc) · 1.48 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "CFileListView.h"
#include <QDebug>
#include <QMimeData>
#include <QFileSystemModel>
CFileListView::CFileListView(QWidget* a_pParent):
QListView(a_pParent),
m_sPath("")
{
this->setAcceptDrops(true);
this->setDropIndicatorShown(true);
this->setDragDropMode(QAbstractItemView::DragDrop);
this->setDragDropOverwriteMode(true);
}
void CFileListView::SetCurrentPath(QString a_sPath)
{
this->m_sPath = a_sPath;
}
void CFileListView::dropEvent(QDropEvent* a_pEvent)
{
if(a_pEvent->mimeData()->hasFormat("FileName"))
{
QString filePath= a_pEvent->mimeData()->data("FileName");
// Get only the filename not the whole path
QFileInfo fileInfo(filePath);
// Protection if current path not set yet
if(!this->m_sPath.isEmpty())
{
QFile* testFile = new QFile(m_sPath+"\\"+fileInfo.fileName());
if(testFile->exists())
{
qDebug()<<"File already exist, no copy done";
}
else
{
qDebug()<< " Copy from " << filePath << " to " << (m_sPath+"\\"+fileInfo.fileName());
QFile::copy(filePath, m_sPath + "\\" + fileInfo.fileName());
}
}
}
}
void CFileListView::dragEnterEvent(QDragEnterEvent *a_pEvent)
{
qDebug("Drag enter");
a_pEvent->acceptProposedAction();
}
void CFileListView::dragMoveEvent(QDragMoveEvent *a_pEvent)
{
qDebug("Drag move");
a_pEvent->acceptProposedAction();
}