mirror of
https://github.com/YACReader/yacreader
synced 2025-07-23 15:35:03 -04:00
Added support for dropping folders to import them. TODO update the foldersView properly (now all the tree model is reloaded).
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include "treemodel.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comic_files_manager.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
@ -77,9 +78,12 @@ void YACReaderTreeView::dragEnterEvent(QDragEnterEvent *event)
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
urlList = event->mimeData()->urls();
|
||||
QString currentPath;
|
||||
foreach (QUrl url, urlList)
|
||||
{
|
||||
if(Comic::fileIsComic(url))
|
||||
//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())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
return;
|
||||
@ -88,20 +92,25 @@ void YACReaderTreeView::dragEnterEvent(QDragEnterEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void YACReaderTreeView::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
||||
void YACReaderTreeView::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
QTreeView::dragMoveEvent(event);
|
||||
event->acceptProposedAction();
|
||||
|
||||
//fix for drop auto expand
|
||||
QModelIndex lastExpanded = indexAt(expandPos);
|
||||
QModelIndex underMouse = indexAt(event->pos());
|
||||
if( underMouse.isValid() && (underMouse != lastExpanded)) {
|
||||
if( underMouse.isValid()) {
|
||||
expandPos = event->pos();
|
||||
connect(&expandTimer,SIGNAL(timeout()),this,SLOT(expandCurrent()));
|
||||
expandTimer.start(750);
|
||||
expandTimer.setSingleShot(true);
|
||||
expandTimer.start(500);
|
||||
}
|
||||
//TODO force mouse hover decoration, why the event loop is not working here?
|
||||
//force mouse hover decoration, TODO why the event loop is not working here?
|
||||
if(!t.isActive())
|
||||
{
|
||||
t.setSingleShot(true);
|
||||
@ -114,24 +123,33 @@ void YACReaderTreeView::dragMoveEvent(QDragMoveEvent *event)
|
||||
|
||||
void YACReaderTreeView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
t.stop();
|
||||
|
||||
QTreeView::dropEvent(event);
|
||||
|
||||
bool accepted = false;
|
||||
QLOG_DEBUG() << "drop on tree" << event->dropAction();
|
||||
if(event->dropAction() == Qt::CopyAction)
|
||||
{
|
||||
QLOG_DEBUG() << "copy - tree";
|
||||
emit copyComicsToFolder(Comic::filterInvalidComicFiles(event->mimeData()->urls()),indexAt(event->pos()));
|
||||
|
||||
}
|
||||
else if(event->dropAction() & Qt::MoveAction)
|
||||
{
|
||||
QLOG_DEBUG() << "move - tree";
|
||||
emit moveComicsToFolder(Comic::filterInvalidComicFiles(event->mimeData()->urls()),indexAt(event->pos()));
|
||||
}
|
||||
bool validAction = event->dropAction() == Qt::CopyAction || event->dropAction() & Qt::MoveAction;
|
||||
|
||||
if(validAction)
|
||||
{
|
||||
|
||||
QList<QPair<QString, QString> > droppedFiles = ComicFilesManager::getDroppedFiles(event->mimeData()->urls());
|
||||
QModelIndex destinationIndex = indexAt(event->pos());
|
||||
|
||||
if(event->dropAction() == Qt::CopyAction)
|
||||
{
|
||||
QLOG_DEBUG() << "copy - tree :" << droppedFiles;
|
||||
emit copyComicsToFolder(droppedFiles, destinationIndex);
|
||||
}
|
||||
else if(event->dropAction() & Qt::MoveAction)
|
||||
{
|
||||
QLOG_DEBUG() << "move - tree :" << droppedFiles;
|
||||
emit moveComicsToFolder(droppedFiles, destinationIndex);
|
||||
}
|
||||
|
||||
if(accepted)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,8 +11,8 @@ public:
|
||||
|
||||
signals:
|
||||
//Drops
|
||||
void copyComicsToFolder(QList<QString>,QModelIndex);
|
||||
void moveComicsToFolder(QList<QString>,QModelIndex);
|
||||
void copyComicsToFolder(QList<QPair<QString,QString> >,QModelIndex);
|
||||
void moveComicsToFolder(QList<QPair<QString,QString> >,QModelIndex);
|
||||
|
||||
protected slots:
|
||||
//fix for drop auto expand
|
||||
@ -21,9 +21,11 @@ protected slots:
|
||||
protected:
|
||||
//Drop to import
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dragLeaveEvent(QDragLeaveEvent *event);
|
||||
void dragMoveEvent(QDragMoveEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
|
||||
//fix for drop auto expand
|
||||
QTimer expandTimer;
|
||||
QTimer t;
|
||||
|
Reference in New Issue
Block a user