Now succesfully adds files from drag and drop

This commit is contained in:
Austen Adler 2014-06-19 14:15:50 -04:00
commit f7085cc49a
3 changed files with 117 additions and 30 deletions

View File

@ -1,15 +1,39 @@
#include "picture.h"
#include <QDrag>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QRegExp>
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()<<fileName;
//}
//qDebug() << "Dropped file:" << fileName;
}
}
void Picture::changeDirectory(){
QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path());
if(path.isNull()==false){
@ -30,7 +54,7 @@ void Picture::fillList() {
}
}
if(ui->fileList->count()==0){
ui->fileList->addItem("<NO PICTURES>");
//ui->fileList->addItem("<NO PICTURES>");
}
}
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("");

View File

@ -40,5 +40,8 @@ private slots:
private:
Ui::Picture *ui;
QDir directory;
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
};
#endif // PICTURE_H

View File

@ -6,8 +6,13 @@
<rect>
<x>0</x>
<y>0</y>
<<<<<<< HEAD
<width>658</width>
<height>434</height>
=======
<width>656</width>
<height>463</height>
>>>>>>> tmp
</rect>
</property>
<property name="windowTitle">
@ -19,8 +24,13 @@
<rect>
<x>0</x>
<y>0</y>
<<<<<<< HEAD
<width>411</width>
<height>341</height>
=======
<width>393</width>
<height>279</height>
>>>>>>> tmp
</rect>
</property>
<property name="currentIndex">
@ -30,6 +40,7 @@
<attribute name="title">
<string>Commands</string>
</attribute>
<<<<<<< HEAD
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
@ -175,37 +186,80 @@
</item>
</layout>
</widget>
=======
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="fileList"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cd">
<property name="text">
<string>Change Directory</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refresh">
<property name="text">
<string>Clear File List</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="erase">
<property name="text">
<string>Erase Metadata</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Label</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
<zorder>layoutWidget</zorder>
<zorder>layoutWidget</zorder>
>>>>>>> tmp
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Log</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTextEdit" name="log">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>192</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearLog">
<property name="geometry">
<rect>
<x>270</x>
<y>220</y>
<width>51</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>