@@ -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 | connect(this->ui->openFileQpb,SIGNAL(clicked()),this,SLOT(openFile())); |
|
18 | connect(this->ui->openFileQpb,SIGNAL(clicked()),this,SLOT(openFile())); | |
19 | connect(this->ui->removeFileQpb,SIGNAL(clicked()),this,SLOT(removeFiles())); |
|
19 | connect(this->ui->removeFileQpb,SIGNAL(clicked()),this,SLOT(removeFiles())); | |
20 | connect(this->ui->fileList,SIGNAL(cellActivated(int,int)),this,SLOT(fileCellActivated(int,int))); |
|
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 | genericBinaryFileWidget::~genericBinaryFileWidget() |
|
24 | genericBinaryFileWidget::~genericBinaryFileWidget() | |
@@ -33,17 +34,22 void genericBinaryFileWidget::openFile() | |||||
33 | NULL, |
|
34 | NULL, | |
34 | "Binary Files (*.bin);;SREC Files (*.srec);;Elf Files (*)"); |
|
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 | bool fileOpened = false; |
|
44 | bool fileOpened = false; | |
39 | for(int l=0;l<files.count();l++) |
|
45 | for(int l=0;l<files.count();l++) | |
40 | { |
|
46 | { | |
41 |
if( |
|
47 | if(FileList.at(i)==files.at(l)->fileName) | |
42 | { |
|
48 | { | |
43 | fileOpened = true; |
|
49 | fileOpened = true; | |
44 | } |
|
50 | } | |
45 | } |
|
51 | } | |
46 |
QFile file( |
|
52 | QFile file(FileList.at(i)); | |
47 | if(!fileOpened && file.open(QIODevice::ReadOnly)) |
|
53 | if(!fileOpened && file.open(QIODevice::ReadOnly)) | |
48 | { |
|
54 | { | |
49 | char magic[4]; |
|
55 | char magic[4]; | |
@@ -54,7 +60,7 void genericBinaryFileWidget::openFile() | |||||
54 | case 0x7F: |
|
60 | case 0x7F: | |
55 | if((magic[1]=='E') && (magic[2]=='L') && (magic[3]=='F')) |
|
61 | if((magic[1]=='E') && (magic[2]=='L') && (magic[3]=='F')) | |
56 | { |
|
62 | { | |
57 |
files.append(new FileListElement( |
|
63 | files.append(new FileListElement(FileList.at(i),false,Type_Elf,NULL,NULL)); | |
58 | } |
|
64 | } | |
59 | break; |
|
65 | break; | |
60 | case 'S': |
|
66 | case 'S': | |
@@ -62,17 +68,16 void genericBinaryFileWidget::openFile() | |||||
62 | line = file.readLine(); |
|
68 | line = file.readLine(); | |
63 | if(srecFile::checkSum(line)) |
|
69 | if(srecFile::checkSum(line)) | |
64 | { |
|
70 | { | |
65 |
files.append(new FileListElement( |
|
71 | files.append(new FileListElement(FileList.at(i),false,Type_SREC,NULL,NULL)); | |
66 | } |
|
72 | } | |
67 | break; |
|
73 | break; | |
68 | default: |
|
74 | default: | |
69 |
files.append(new FileListElement( |
|
75 | files.append(new FileListElement(FileList.at(i),false,Type_Bin,NULL,NULL)); | |
70 | break; |
|
76 | break; | |
71 | } |
|
77 | } | |
72 | } |
|
78 | } | |
73 | } |
|
79 | } | |
74 | updateFileList(); |
|
80 | updateFileList(); | |
75 |
|
||||
76 | } |
|
81 | } | |
77 |
|
82 | |||
78 | void genericBinaryFileWidget::updateFileList() |
|
83 | void genericBinaryFileWidget::updateFileList() |
@@ -51,6 +51,7 public: | |||||
51 |
|
51 | |||
52 | public slots: |
|
52 | public slots: | |
53 | void openFile(); |
|
53 | void openFile(); | |
|
54 | void openFile(const QStringList& FileList); | |||
54 | void updateFileList(); |
|
55 | void updateFileList(); | |
55 | void removeFiles(); |
|
56 | void removeFiles(); | |
56 | void fileCellActivated(int row, int column); |
|
57 | void fileCellActivated(int row, int column); |
@@ -35,8 +35,8 | |||||
35 | </property> |
|
35 | </property> | |
36 | <property name="iconSize"> |
|
36 | <property name="iconSize"> | |
37 | <size> |
|
37 | <size> | |
38 |
<width> |
|
38 | <width>24</width> | |
39 |
<height> |
|
39 | <height>24</height> | |
40 | </size> |
|
40 | </size> | |
41 | </property> |
|
41 | </property> | |
42 | </widget> |
|
42 | </widget> | |
@@ -52,8 +52,8 | |||||
52 | </property> |
|
52 | </property> | |
53 | <property name="iconSize"> |
|
53 | <property name="iconSize"> | |
54 | <size> |
|
54 | <size> | |
55 |
<width> |
|
55 | <width>24</width> | |
56 |
<height> |
|
56 | <height>24</height> | |
57 | </size> |
|
57 | </size> | |
58 | </property> |
|
58 | </property> | |
59 | </widget> |
|
59 | </widget> | |
@@ -72,7 +72,10 | |||||
72 | </spacer> |
|
72 | </spacer> | |
73 | </item> |
|
73 | </item> | |
74 | <item row="0" column="0" colspan="3"> |
|
74 | <item row="0" column="0" colspan="3"> | |
75 |
<widget class=" |
|
75 | <widget class="FileList" name="fileList"> | |
|
76 | <property name="dragEnabled"> | |||
|
77 | <bool>false</bool> | |||
|
78 | </property> | |||
76 | <column> |
|
79 | <column> | |
77 | <property name="text"> |
|
80 | <property name="text"> | |
78 | <string>File</string> |
|
81 | <string>File</string> | |
@@ -88,6 +91,12 | |||||
88 | </layout> |
|
91 | </layout> | |
89 | </widget> |
|
92 | </widget> | |
90 | <widget class="QTabWidget" name="fileViewerTab"> |
|
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 | <property name="currentIndex"> |
|
100 | <property name="currentIndex"> | |
92 | <number>-1</number> |
|
101 | <number>-1</number> | |
93 | </property> |
|
102 | </property> | |
@@ -96,6 +105,13 | |||||
96 | </item> |
|
105 | </item> | |
97 | </layout> |
|
106 | </layout> | |
98 | </widget> |
|
107 | </widget> | |
|
108 | <customwidgets> | |||
|
109 | <customwidget> | |||
|
110 | <class>FileList</class> | |||
|
111 | <extends>QTableWidget</extends> | |||
|
112 | <header>filelist.h</header> | |||
|
113 | </customwidget> | |||
|
114 | </customwidgets> | |||
99 | <resources> |
|
115 | <resources> | |
100 | <include location="genericBinaryFiles.qrc"/> |
|
116 | <include location="genericBinaryFiles.qrc"/> | |
101 | </resources> |
|
117 | </resources> |
General Comments 0
You need to be logged in to leave comments.
Login now