##// END OF EJS Templates
Added Drag and Drop for opening files.
Jeandet Alexis -
r5:4b45cc285cfb default
parent child
Show More
@@ -0,0 +1,37
1 #include "filelist.h"
2 #include <QMimeData>
3
4 FileList::FileList(QWidget *parent) :
5 QTableWidget(parent)
6 {
7 setHorizontalHeaderLabels(QStringList()<<"File"<<"Type");
8 this->setAcceptDrops(true);
9 }
10
11 void FileList::dragEnterEvent(QDragEnterEvent *event)
12 {
13 event->acceptProposedAction();
14 }
15
16 void FileList::dragMoveEvent(QDragMoveEvent *event)
17 {
18 event->acceptProposedAction();
19 }
20
21 void FileList::dropEvent(QDropEvent *event)
22 {
23 const QMimeData* mimeData = event->mimeData();
24
25 if (mimeData->hasUrls())
26 {
27 QStringList pathList;
28 QList<QUrl> urlList = mimeData->urls();
29
30 for (int i = 0; i < urlList.size() && i < 32; ++i)
31 {
32 pathList.append(urlList.at(i).toLocalFile());
33 }
34 emit openFiles(pathList);
35 event->acceptProposedAction();
36 }
37 }
@@ -0,0 +1,26
1 #ifndef FILELIST_H
2 #define FILELIST_H
3
4 #include <QTableWidget>
5 #include <QDropEvent>
6 #include <QDragEnterEvent>
7 #include <QDragMoveEvent>
8 #include <QString>
9 #include <QStringList>
10
11 class FileList : public QTableWidget
12 {
13 Q_OBJECT
14 public:
15 explicit FileList(QWidget *parent = 0);
16 void dragEnterEvent(QDragEnterEvent *event);
17 void dragMoveEvent(QDragMoveEvent *event);
18 void dropEvent(QDropEvent *event);
19
20 signals:
21 void openFiles(const QStringList& files);
22 public slots:
23
24 };
25
26 #endif // FILELIST_H
@@ -18,6 +18,7 genericBinaryFileWidget::genericBinaryFi
18 18 connect(this->ui->openFileQpb,SIGNAL(clicked()),this,SLOT(openFile()));
19 19 connect(this->ui->removeFileQpb,SIGNAL(clicked()),this,SLOT(removeFiles()));
20 20 connect(this->ui->fileList,SIGNAL(cellActivated(int,int)),this,SLOT(fileCellActivated(int,int)));
21 connect(this->ui->fileList,SIGNAL(openFiles(QStringList)),this,SLOT(openFile(QStringList)));
21 22 }
22 23
23 24 genericBinaryFileWidget::~genericBinaryFileWidget()
@@ -33,17 +34,22 void genericBinaryFileWidget::openFile()
33 34 NULL,
34 35 "Binary Files (*.bin);;SREC Files (*.srec);;Elf Files (*)");
35 36
36 for(int i=0;i<filesNames.count();i++)
37 openFile(filesNames);
38 }
39
40 void genericBinaryFileWidget::openFile(const QStringList &FileList)
41 {
42 for(int i=0;i<FileList.count();i++)
37 43 {
38 44 bool fileOpened = false;
39 45 for(int l=0;l<files.count();l++)
40 46 {
41 if(filesNames.at(i)==files.at(l)->fileName)
47 if(FileList.at(i)==files.at(l)->fileName)
42 48 {
43 49 fileOpened = true;
44 50 }
45 51 }
46 QFile file(filesNames.at(i));
52 QFile file(FileList.at(i));
47 53 if(!fileOpened && file.open(QIODevice::ReadOnly))
48 54 {
49 55 char magic[4];
@@ -54,7 +60,7 void genericBinaryFileWidget::openFile()
54 60 case 0x7F:
55 61 if((magic[1]=='E') && (magic[2]=='L') && (magic[3]=='F'))
56 62 {
57 files.append(new FileListElement(filesNames.at(i),false,Type_Elf,NULL,NULL));
63 files.append(new FileListElement(FileList.at(i),false,Type_Elf,NULL,NULL));
58 64 }
59 65 break;
60 66 case 'S':
@@ -62,17 +68,16 void genericBinaryFileWidget::openFile()
62 68 line = file.readLine();
63 69 if(srecFile::checkSum(line))
64 70 {
65 files.append(new FileListElement(filesNames.at(i),false,Type_SREC,NULL,NULL));
71 files.append(new FileListElement(FileList.at(i),false,Type_SREC,NULL,NULL));
66 72 }
67 73 break;
68 74 default:
69 files.append(new FileListElement(filesNames.at(i),false,Type_Bin,NULL,NULL));
75 files.append(new FileListElement(FileList.at(i),false,Type_Bin,NULL,NULL));
70 76 break;
71 77 }
72 78 }
73 79 }
74 80 updateFileList();
75
76 81 }
77 82
78 83 void genericBinaryFileWidget::updateFileList()
@@ -51,6 +51,7 public:
51 51
52 52 public slots:
53 53 void openFile();
54 void openFile(const QStringList& FileList);
54 55 void updateFileList();
55 56 void removeFiles();
56 57 void fileCellActivated(int row, int column);
@@ -35,8 +35,8
35 35 </property>
36 36 <property name="iconSize">
37 37 <size>
38 <width>32</width>
39 <height>32</height>
38 <width>24</width>
39 <height>24</height>
40 40 </size>
41 41 </property>
42 42 </widget>
@@ -52,8 +52,8
52 52 </property>
53 53 <property name="iconSize">
54 54 <size>
55 <width>32</width>
56 <height>32</height>
55 <width>24</width>
56 <height>24</height>
57 57 </size>
58 58 </property>
59 59 </widget>
@@ -72,7 +72,10
72 72 </spacer>
73 73 </item>
74 74 <item row="0" column="0" colspan="3">
75 <widget class="QTableWidget" name="fileList">
75 <widget class="FileList" name="fileList">
76 <property name="dragEnabled">
77 <bool>false</bool>
78 </property>
76 79 <column>
77 80 <property name="text">
78 81 <string>File</string>
@@ -88,6 +91,12
88 91 </layout>
89 92 </widget>
90 93 <widget class="QTabWidget" name="fileViewerTab">
94 <property name="minimumSize">
95 <size>
96 <width>300</width>
97 <height>0</height>
98 </size>
99 </property>
91 100 <property name="currentIndex">
92 101 <number>-1</number>
93 102 </property>
@@ -96,6 +105,13
96 105 </item>
97 106 </layout>
98 107 </widget>
108 <customwidgets>
109 <customwidget>
110 <class>FileList</class>
111 <extends>QTableWidget</extends>
112 <header>filelist.h</header>
113 </customwidget>
114 </customwidgets>
99 115 <resources>
100 116 <include location="genericBinaryFiles.qrc"/>
101 117 </resources>
General Comments 0
You need to be logged in to leave comments. Login now