Enabled drop to import into info comics view.

This commit is contained in:
Luis Ángel San Martín 2016-04-18 17:36:06 +02:00
parent dd5f413ce2
commit 4f0bd14f3d
3 changed files with 33 additions and 6 deletions

View File

@ -2,6 +2,8 @@
#include <QtQuick>
#include "comic.h"
#include "comic_files_manager.h"
#include "comic_model.h"
#include "comic_db.h"
#include "yacreader_comics_selection_helper.h"
@ -83,10 +85,9 @@ void InfoComicsView::setModel(ComicModel *model)
ctxt->setContextProperty("comicsSelectionHelper", this);
ctxt->setContextProperty("comicRatingHelper", this);
ctxt->setContextProperty("dummyValue", true);
ctxt->setContextProperty("dragManager", this);
ctxt->setContextProperty("dragManager", this);*/
ctxt->setContextProperty("dropManager", this);
updateBackgroundConfig();*/
if(model->rowCount()>0)
{
@ -160,3 +161,30 @@ void InfoComicsView::selectAll()
{
selectionHelper->selectAll();
}
bool InfoComicsView::canDropUrls(const QList<QUrl> &urls, Qt::DropAction action)
{
if(action == Qt::CopyAction)
{
QString currentPath;
foreach (QUrl url, urls)
{
//comics or folders are accepted, folders' content is validate in dropEvent (avoid any lag before droping)
currentPath = url.toLocalFile();
if(Comic::fileIsComic(currentPath) || QFileInfo(currentPath).isDir())
return true;
}
}
return false;
}
void InfoComicsView::droppedFiles(const QList<QUrl> &urls, Qt::DropAction action)
{
bool validAction = action == Qt::CopyAction; //TODO add move
if(validAction)
{
QList<QPair<QString, QString> > droppedFiles = ComicFilesManager::getDroppedFiles(urls);
emit copyComicsToCurrentFolder(droppedFiles);
}
}

View File

@ -36,6 +36,9 @@ public slots:
protected slots:
void setCurrentIndex(int index);
bool canDropUrls(const QList<QUrl> & urls, Qt::DropAction action);
void droppedFiles(const QList<QUrl> & urls, Qt::DropAction action);
protected:
QToolBar * toolbar;
QObject *flow;

View File

@ -108,10 +108,6 @@ Rectangle {
}else
drag.accepted = false;
}
else if (dropManager.canDropFormats(drag.formats)) {
drag.accepted = true;
} else
drag.accepted = false;
}
onDropped: {