# HG changeset patch # User Jeandet Alexis # Date 2014-06-18 17:04:43 # Node ID 4b45cc285cfb78184206a662c4fbba8d2fcd33e2 # Parent 00ff7d3b610fafd6408d2aabdcab6ae5ef618770 Added Drag and Drop for opening files. diff --git a/filelist.cpp b/filelist.cpp new file mode 100644 --- /dev/null +++ b/filelist.cpp @@ -0,0 +1,37 @@ +#include "filelist.h" +#include + +FileList::FileList(QWidget *parent) : + QTableWidget(parent) +{ + setHorizontalHeaderLabels(QStringList()<<"File"<<"Type"); + this->setAcceptDrops(true); +} + +void FileList::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} + +void FileList::dragMoveEvent(QDragMoveEvent *event) +{ + event->acceptProposedAction(); +} + +void FileList::dropEvent(QDropEvent *event) +{ + const QMimeData* mimeData = event->mimeData(); + + if (mimeData->hasUrls()) + { + QStringList pathList; + QList urlList = mimeData->urls(); + + for (int i = 0; i < urlList.size() && i < 32; ++i) + { + pathList.append(urlList.at(i).toLocalFile()); + } + emit openFiles(pathList); + event->acceptProposedAction(); + } +} diff --git a/filelist.h b/filelist.h new file mode 100644 --- /dev/null +++ b/filelist.h @@ -0,0 +1,26 @@ +#ifndef FILELIST_H +#define FILELIST_H + +#include +#include +#include +#include +#include +#include + +class FileList : public QTableWidget +{ + Q_OBJECT +public: + explicit FileList(QWidget *parent = 0); + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + +signals: + void openFiles(const QStringList& files); +public slots: + +}; + +#endif // FILELIST_H diff --git a/genericbinaryfilewidget.cpp b/genericbinaryfilewidget.cpp --- a/genericbinaryfilewidget.cpp +++ b/genericbinaryfilewidget.cpp @@ -18,6 +18,7 @@ genericBinaryFileWidget::genericBinaryFi connect(this->ui->openFileQpb,SIGNAL(clicked()),this,SLOT(openFile())); connect(this->ui->removeFileQpb,SIGNAL(clicked()),this,SLOT(removeFiles())); connect(this->ui->fileList,SIGNAL(cellActivated(int,int)),this,SLOT(fileCellActivated(int,int))); + connect(this->ui->fileList,SIGNAL(openFiles(QStringList)),this,SLOT(openFile(QStringList))); } genericBinaryFileWidget::~genericBinaryFileWidget() @@ -33,17 +34,22 @@ void genericBinaryFileWidget::openFile() NULL, "Binary Files (*.bin);;SREC Files (*.srec);;Elf Files (*)"); - for(int i=0;ifileName) + if(FileList.at(i)==files.at(l)->fileName) { fileOpened = true; } } - QFile file(filesNames.at(i)); + QFile file(FileList.at(i)); if(!fileOpened && file.open(QIODevice::ReadOnly)) { char magic[4]; @@ -54,7 +60,7 @@ void genericBinaryFileWidget::openFile() case 0x7F: if((magic[1]=='E') && (magic[2]=='L') && (magic[3]=='F')) { - files.append(new FileListElement(filesNames.at(i),false,Type_Elf,NULL,NULL)); + files.append(new FileListElement(FileList.at(i),false,Type_Elf,NULL,NULL)); } break; case 'S': @@ -62,17 +68,16 @@ void genericBinaryFileWidget::openFile() line = file.readLine(); if(srecFile::checkSum(line)) { - files.append(new FileListElement(filesNames.at(i),false,Type_SREC,NULL,NULL)); + files.append(new FileListElement(FileList.at(i),false,Type_SREC,NULL,NULL)); } break; default: - files.append(new FileListElement(filesNames.at(i),false,Type_Bin,NULL,NULL)); + files.append(new FileListElement(FileList.at(i),false,Type_Bin,NULL,NULL)); break; } } } updateFileList(); - } void genericBinaryFileWidget::updateFileList() diff --git a/genericbinaryfilewidget.h b/genericbinaryfilewidget.h --- a/genericbinaryfilewidget.h +++ b/genericbinaryfilewidget.h @@ -51,6 +51,7 @@ public: public slots: void openFile(); + void openFile(const QStringList& FileList); void updateFileList(); void removeFiles(); void fileCellActivated(int row, int column); diff --git a/genericbinaryfilewidget.ui b/genericbinaryfilewidget.ui --- a/genericbinaryfilewidget.ui +++ b/genericbinaryfilewidget.ui @@ -35,8 +35,8 @@ - 32 - 32 + 24 + 24 @@ -52,8 +52,8 @@ - 32 - 32 + 24 + 24 @@ -72,7 +72,10 @@ - + + + false + File @@ -88,6 +91,12 @@ + + + 300 + 0 + + -1 @@ -96,6 +105,13 @@ + + + FileList + QTableWidget +
filelist.h
+
+