mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
added drop support to EmptyFolderWidget
This commit is contained in:
parent
773e990821
commit
a64733d70b
@ -4,9 +4,12 @@
|
||||
#include <QLabel>
|
||||
#include <QListView>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
#include <QStringListModel>
|
||||
|
||||
#include "comic.h"
|
||||
#include "comic_files_manager.h"
|
||||
#include "QsLog.h"
|
||||
|
||||
void testListView(QListView * l)
|
||||
{
|
||||
QStringListModel * slm = new QStringListModel(QStringList() << "Lorem ipsum" << "Hailer skualer"<< "Mumbaluba X" << "Finger layden" << "Pacum tactus filer" << "Aposum" << "En" << "Lorem ipsum" << "Hailer skualer" << "Mumbaluba X" << "Finger layden" << "Pacum tactus filer" << "Aposum" << "En" );
|
||||
@ -67,6 +70,8 @@ EmptyFolderWidget::EmptyFolderWidget(QWidget *parent) :
|
||||
setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding );
|
||||
setLayout(layout);
|
||||
|
||||
setAcceptDrops(true);
|
||||
|
||||
connect(foldersView,SIGNAL(clicked(QModelIndex)),this,SLOT(onItemClicked(QModelIndex)));
|
||||
}
|
||||
|
||||
@ -87,3 +92,51 @@ void EmptyFolderWidget::paintEvent(QPaintEvent *)
|
||||
QPainter painter (this);
|
||||
painter.fillRect(0,0,width(),height(),QColor("#2A2A2A"));
|
||||
}
|
||||
|
||||
//TODO remove repeated code in drag & drop support....
|
||||
void EmptyFolderWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
QList<QUrl> urlList;
|
||||
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
urlList = event->mimeData()->urls();
|
||||
QString currentPath;
|
||||
foreach (QUrl url, urlList)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmptyFolderWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QLOG_DEBUG() << "drop in emptyfolder" << event->dropAction();
|
||||
|
||||
bool validAction = event->dropAction() == Qt::CopyAction || event->dropAction() & Qt::MoveAction;
|
||||
|
||||
if(validAction)
|
||||
{
|
||||
|
||||
QList<QPair<QString, QString> > droppedFiles = ComicFilesManager::getDroppedFiles(event->mimeData()->urls());
|
||||
|
||||
if(event->dropAction() == Qt::CopyAction)
|
||||
{
|
||||
QLOG_DEBUG() << "copy in emptyfolder:" << droppedFiles;
|
||||
emit copyComicsToCurrentFolder(droppedFiles);
|
||||
}
|
||||
else if(event->dropAction() & Qt::MoveAction)
|
||||
{
|
||||
QLOG_DEBUG() << "move in emptyfolder:" << droppedFiles;
|
||||
emit moveComicsToCurrentFolder(droppedFiles);
|
||||
}
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,10 @@ public:
|
||||
signals:
|
||||
void subfolderSelected(QModelIndex, int);
|
||||
|
||||
//Drops
|
||||
void copyComicsToCurrentFolder(QList<QPair<QString, QString> >);
|
||||
void moveComicsToCurrentFolder(QList<QPair<QString, QString> >);
|
||||
|
||||
public slots:
|
||||
void onItemClicked(const QModelIndex & mi);
|
||||
|
||||
@ -27,6 +31,10 @@ protected:
|
||||
QModelIndex parent;
|
||||
QStringListModel * subfoldersModel;
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
//Drop to import
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
};
|
||||
|
||||
#endif // EMPTY_FOLDER_WIDGET_H
|
||||
|
@ -1069,6 +1069,9 @@ void LibraryWindow::createConnections()
|
||||
connect(comicsModel,SIGNAL(isEmpty()),this,SLOT(showEmptyFolderView()));
|
||||
connect(comicsModel,SIGNAL(searchNumResults(int)),this,SLOT(checkSearchNumResults(int)));
|
||||
connect(emptyFolderWidget,SIGNAL(subfolderSelected(QModelIndex,int)),this,SLOT(selectSubfolder(QModelIndex,int)));
|
||||
//Drops
|
||||
connect(emptyFolderWidget, SIGNAL(copyComicsToCurrentFolder(QList<QPair<QString, QString> >)), this, SLOT(copyAndImportComicsToCurrentFolder(QList<QPair<QString, QString> >)));
|
||||
connect(emptyFolderWidget, SIGNAL(moveComicsToCurrentFolder(QList<QPair<QString, QString> >)), this, SLOT(moveAndImportComicsToCurrentFolder(QList<QPair<QString, QString> >)));
|
||||
|
||||
connect(showEditShortcutsAction,SIGNAL(triggered()),editShortcutsDialog,SLOT(show()));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user