-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLineEdit.cpp
121 lines (112 loc) · 3.74 KB
/
CLineEdit.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "CLineEdit.h"
#include <QDebug>
#include <QMimeData>
#include <QUrl>
#include <QList>
#include <QFileInfo>
#include <QDir>
#include <QRegExp>
#include <QMessageBox>
#include <QRegExpValidator>
#include "CProjectManager.h"
#include "Classes/Engine/Include/CMacroManager.h"
#include "ETypes.h"
CLineEdit::CLineEdit(ETypes::Type a_eType, QWidget* a_pParent):
QLineEdit(a_pParent)
{
this->setAcceptDrops(true);
this->setReadOnly(true);
this->setPlaceholderText("Faites glisser une ressource");
m_eType = a_eType;
// m_lExtensionList.push_back("jpg");
// m_lExtensionList.push_back("png");
// m_lExtensionList.push_back("bmp");
// m_lExtensionList = a_lExtensionList;
// QString sExtRegExp;
// sExtRegExp = QString("^"+CProjectManager::Instance()->QGetProjectPath()+".*(" + a_lExtensionList.join("|") + ")$");
// qDebug() << sExtRegExp;
// setValidator(new QRegExpValidator(QRegExp(sExtRegExp)));
}
void CLineEdit::dropEvent(QDropEvent* a_pEvent)
{
qDebug("call dropEvent");
qDebug()<<a_pEvent->mimeData()->formats();
if(a_pEvent->mimeData()->hasFormat("text/uri-list"))
{
QList<QUrl> urls = a_pEvent->mimeData()->urls();
for(QUrl currentUrl : urls)
{
QString path = currentUrl.toLocalFile();
qDebug() << path;
// selectAll();
// insert(path);
QFileInfo newFile(path);
if(newFile.exists())
{
// if(m_lExtensionList.contains(newFile.suffix()))
if (ETypes::TypeFromExtension(newFile.suffix()) == m_eType)
{
qDebug("accepted format");
// Checking if file is in project path
// if(path.contains(QDir::currentPath()))
QString projectPath = CProjectManager::Instance()->QGetProjectPath();
if (path.contains(projectPath))
{
path.replace(projectPath+'/', "");
selectAll();
insert(path);
// this->setText(path);
}
else
{
qDebug("File not in project path");
}
}
else
{
qDebug("refused format");
}
}
}
}
else if (a_pEvent->mimeData()->hasFormat("text/plain"))
{
QString macro = a_pEvent->mimeData()->text();
if (macro.at(0) == '#')
{
QStringList list = macro.split(':');
QString type = list.takeLast();
if (ETypes::TypeFromString(type) == m_eType)
{
QString name = list.join("");
if (LM::CMacroManager::Instance()->GetDefinition(name.toStdString()).empty())
{
QMessageBox msgBox;
msgBox.setText(tr("Ajout impossible : la macro ne contient pas de définition."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Warning);
int ret = msgBox.exec();
}
else
{
selectAll();
insert(name);
}
}
}
}
else
{
qDebug("No file was droped");
}
}
void CLineEdit::dragEnterEvent(QDragEnterEvent* a_pEvent)
{
qDebug("call dragEnterEvent");
a_pEvent->acceptProposedAction();
}
//void CLineEdit::setPath(QString a_sPath)
//{
// this->setText(a_sPath);
//}