update: add dray trigger task.
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#include "cusTableWidget.h"
|
||||
|
||||
#include <InfoDirFile.h>
|
||||
#include <InfoPack.hpp>
|
||||
#include <QApplication>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
#include "FileControl.h"
|
||||
|
||||
CustomTableWidget::CustomTableWidget(QWidget* parent) : QTableWidget(parent)
|
||||
{
|
||||
@@ -13,6 +16,36 @@ CustomTableWidget::~CustomTableWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void CustomTableWidget::setIsRemote(bool isRemote)
|
||||
{
|
||||
isRemote_ = isRemote;
|
||||
}
|
||||
|
||||
void CustomTableWidget::setBasePathCall(const std::function<QString()>& call)
|
||||
{
|
||||
basePathCall_ = call;
|
||||
}
|
||||
|
||||
void CustomTableWidget::setOtherSidePathCall(const std::function<QString()>& call)
|
||||
{
|
||||
otherSideCall_ = call;
|
||||
}
|
||||
|
||||
QString FileManager::GetCurRoot()
|
||||
{
|
||||
return curRoot_;
|
||||
}
|
||||
|
||||
void CustomTableWidget::setOwnIDCall(const std::function<QString()>& call)
|
||||
{
|
||||
oidCall_ = call;
|
||||
}
|
||||
|
||||
void CustomTableWidget::setRemoteIDCall(const std::function<QString()>& call)
|
||||
{
|
||||
ridCall_ = call;
|
||||
}
|
||||
|
||||
void CustomTableWidget::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if (!event->mimeData()->hasFormat("application/x-custom-data")) {
|
||||
@@ -31,6 +64,25 @@ void CustomTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
}
|
||||
if (event->mimeData()->hasFormat("application/x-custom-data")) {
|
||||
event->acceptProposedAction();
|
||||
auto dirinfo = infoUnpack<DirFileInfoVec>(event->mimeData()->data("application/x-custom-data"));
|
||||
QVector<TransTask> tasks;
|
||||
// generate task
|
||||
for (const auto& df : dirinfo.vec) {
|
||||
TransTask task;
|
||||
task.isUpload = isRemote_;
|
||||
task.localId = oidCall_();
|
||||
task.remoteId = ridCall_();
|
||||
if (isRemote_) {
|
||||
task.remotePath = basePathCall_();
|
||||
task.localPath = Util::Join(otherSideCall_(), df.name);
|
||||
}
|
||||
else {
|
||||
task.remotePath = Util::Join(otherSideCall_(), df.name);
|
||||
task.localPath = basePathCall_();
|
||||
}
|
||||
tasks.push_back(task);
|
||||
}
|
||||
emit sigTasks(tasks);
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
@@ -48,18 +100,20 @@ void CustomTableWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
|
||||
QStringList selectedTexts;
|
||||
DirFileInfoVec v;
|
||||
v.root = basePathCall_();
|
||||
foreach (QTableWidgetItem* item, selectedItems()) {
|
||||
if (item->column() == 1) {
|
||||
selectedTexts << item->text();
|
||||
DirFileInfo df;
|
||||
df.name = item->text();
|
||||
}
|
||||
}
|
||||
mimeData->setData("application/x-custom-data", selectedTexts.join("|").toUtf8());
|
||||
mimeData->setData("application/x-custom-data", infoPack<DirFileInfoVec>(v));
|
||||
drag->setMimeData(mimeData);
|
||||
QPixmap pixmap(100, 50);
|
||||
pixmap.fill(Qt::lightGray);
|
||||
QPainter painter(&pixmap);
|
||||
painter.drawText(pixmap.rect(), Qt::AlignCenter, QString("%1 ITEM").arg(selectedTexts.count()));
|
||||
painter.drawText(pixmap.rect(), Qt::AlignCenter, QString("%1 ITEM").arg(v.vec.size()));
|
||||
drag->setPixmap(pixmap);
|
||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user