From bc51ea6a3cbbf5f3e736d3020a4063e4a2cfc785 Mon Sep 17 00:00:00 2001 From: Austen Date: Thu, 19 Jun 2014 14:13:48 -0400 Subject: [PATCH] Now succesfully adds files from drag and drop --- picture.cpp | 38 +++++++++++-- picture.h | 3 + picture.ui | 161 ++++++++++++++++++++++------------------------------ 3 files changed, 106 insertions(+), 96 deletions(-) diff --git a/picture.cpp b/picture.cpp index d527653..0f3d712 100644 --- a/picture.cpp +++ b/picture.cpp @@ -1,15 +1,39 @@ #include "picture.h" +#include +#include +#include +#include Picture::Picture(QWidget *parent) : QMainWindow(parent), ui(new Ui::Picture){ ui->setupUi(this); connect(ui->actionOpen_Files,SIGNAL(triggered()),this,SLOT(changeDirectory())); + setAcceptDrops(true); //changeDirectory(); fillList(); } Picture::~Picture(){ delete ui; } +void Picture::dragEnterEvent(QDragEnterEvent *event){ + if(event->mimeData()->hasUrls()){ + event->acceptProposedAction(); + + } +} +void Picture::dropEvent(QDropEvent *event){ + foreach (const QUrl &url, event->mimeData()->urls()) { + const QString &fileName = url.toLocalFile(); + + //if(fileName.contains(QRegExp("\.(?i)(jpe?g|png|gif)$"))){ + ui->fileList->addItem(fileName); + //}else{ + // qDebug()<fileList->count()==0){ - ui->fileList->addItem(""); + //ui->fileList->addItem(""); } } void Picture::on_cd_clicked(){ @@ -38,7 +62,12 @@ void Picture::on_cd_clicked(){ } void Picture::on_erase_clicked(){ bool ignored=false; - foreach(const QString &str,directory.entryList()){ + QStringList myStringList; + for (int i = 0; i < ui->fileList->count(); ++i) + myStringList.append(ui->fileList->item(i)->text()); + qDebug() << myStringList; + //foreach(const QString &str,directory.entryList()){ + foreach(const QString &str,myStringList){ QString tmp=QString("exiv2 rm "); QImageReader reader(directory.absolutePath()+"/"+str); if(!reader.format().isEmpty()){ @@ -67,8 +96,9 @@ void Picture::on_erase_clicked(){ ui->log->append("Done erasing metadata"); } void Picture::on_refresh_clicked(){ - fillList(); - ui->log->append("Refreshed directory"); + //fillList(); + ui->fileList->clear(); + ui->log->append("Cleared File List"); } void Picture::on_clearLog_clicked(){ ui->log->setText(""); diff --git a/picture.h b/picture.h index 807861f..fb9b6ad 100644 --- a/picture.h +++ b/picture.h @@ -40,5 +40,8 @@ private slots: private: Ui::Picture *ui; QDir directory; +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); }; #endif // PICTURE_H diff --git a/picture.ui b/picture.ui index 2d8eb55..a118bd9 100644 --- a/picture.ui +++ b/picture.ui @@ -7,7 +7,7 @@ 0 0 656 - 350 + 463 @@ -19,8 +19,8 @@ 0 0 - 471 - 301 + 393 + 279 @@ -30,101 +30,78 @@ Commands - - - - 20 - 20 - 258 - 229 - - - - - - - - - - - - Change Directory - - - - - - - Refresh Directory - - - - - - - - - - - 300 - 60 - 107 - 62 - - - - - - - Erase Metadata - - - - - - - Label - - - - - - fileList - fileList + + + + + + + + + + + + Change Directory + + + + + + + Clear File List + + + + + + + + + + + + + Erase Metadata + + + + + + + Label + + + + + + + layoutWidget layoutWidget - erase - pushButton Log - - - - 10 - 10 - 381 - 192 - - - - true - - - - - - 270 - 220 - 51 - 30 - - - - Clear - - + + + + + + + true + + + + + + + Clear + + + + + +