2025-06-17 17:20:54 +08:00
|
|
|
#include "cusTableWidget.h"
|
2025-06-18 10:19:54 +08:00
|
|
|
|
2025-06-18 14:53:56 +08:00
|
|
|
#include <InfoDirFile.h>
|
|
|
|
|
#include <InfoPack.hpp>
|
2025-06-18 10:19:54 +08:00
|
|
|
#include <QApplication>
|
2025-06-17 17:20:54 +08:00
|
|
|
#include <QDrag>
|
|
|
|
|
#include <QMimeData>
|
|
|
|
|
#include <QPainter>
|
2025-06-18 14:53:56 +08:00
|
|
|
#include "FileControl.h"
|
2025-06-17 17:20:54 +08:00
|
|
|
|
2025-06-18 10:19:54 +08:00
|
|
|
CustomTableWidget::CustomTableWidget(QWidget* parent) : QTableWidget(parent)
|
2025-06-17 17:20:54 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CustomTableWidget::~CustomTableWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-18 14:53:56 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 17:20:54 +08:00
|
|
|
void CustomTableWidget::dropEvent(QDropEvent* event)
|
|
|
|
|
{
|
|
|
|
|
if (!event->mimeData()->hasFormat("application/x-custom-data")) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-18 10:19:54 +08:00
|
|
|
QTableWidget::dropEvent(event);
|
2025-06-17 17:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 10:19:54 +08:00
|
|
|
void CustomTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
2025-06-17 17:20:54 +08:00
|
|
|
{
|
|
|
|
|
const QTableWidget* source = qobject_cast<const QTableWidget*>(event->source());
|
|
|
|
|
if (source == this) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (event->mimeData()->hasFormat("application/x-custom-data")) {
|
|
|
|
|
event->acceptProposedAction();
|
2025-06-18 14:53:56 +08:00
|
|
|
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);
|
2025-06-17 17:20:54 +08:00
|
|
|
} else {
|
|
|
|
|
event->ignore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-18 10:19:54 +08:00
|
|
|
void CustomTableWidget::mouseMoveEvent(QMouseEvent* event)
|
2025-06-17 17:20:54 +08:00
|
|
|
{
|
2025-06-18 10:19:54 +08:00
|
|
|
if (!(event->buttons() & Qt::LeftButton)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ((event->pos() - startPos_).manhattanLength() < QApplication::startDragDistance()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 17:20:54 +08:00
|
|
|
QDrag* drag = new QDrag(this);
|
|
|
|
|
QMimeData* mimeData = new QMimeData;
|
|
|
|
|
|
2025-06-18 14:53:56 +08:00
|
|
|
DirFileInfoVec v;
|
|
|
|
|
v.root = basePathCall_();
|
2025-06-17 17:20:54 +08:00
|
|
|
foreach (QTableWidgetItem* item, selectedItems()) {
|
2025-06-18 10:19:54 +08:00
|
|
|
if (item->column() == 1) {
|
2025-06-18 14:53:56 +08:00
|
|
|
DirFileInfo df;
|
|
|
|
|
df.name = item->text();
|
2025-06-18 10:19:54 +08:00
|
|
|
}
|
2025-06-17 17:20:54 +08:00
|
|
|
}
|
2025-06-18 14:53:56 +08:00
|
|
|
mimeData->setData("application/x-custom-data", infoPack<DirFileInfoVec>(v));
|
2025-06-17 17:20:54 +08:00
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
QPixmap pixmap(100, 50);
|
|
|
|
|
pixmap.fill(Qt::lightGray);
|
|
|
|
|
QPainter painter(&pixmap);
|
2025-06-18 14:53:56 +08:00
|
|
|
painter.drawText(pixmap.rect(), Qt::AlignCenter, QString("%1 ITEM").arg(v.vec.size()));
|
2025-06-17 17:20:54 +08:00
|
|
|
drag->setPixmap(pixmap);
|
2025-06-18 10:19:54 +08:00
|
|
|
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomTableWidget::mousePressEvent(QMouseEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QTableWidget::mousePressEvent(event);
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
|
startPos_ = event->pos();
|
|
|
|
|
}
|
2025-06-17 17:20:54 +08:00
|
|
|
}
|