fix: drag bug.
This commit is contained in:
@@ -66,7 +66,7 @@ void FileManager::InitControl()
|
||||
ui->tableWidget->viewport()->setAcceptDrops(true);
|
||||
ui->tableWidget->setDropIndicatorShown(true);
|
||||
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
ui->tableWidget->setDragDropMode(QAbstractItemView::NoDragDrop);
|
||||
ui->tableWidget->setDragDropMode(QAbstractItemView::DragDrop);
|
||||
|
||||
connect(ui->btnHome, &QPushButton::clicked, this, &FileManager::evtHome);
|
||||
connect(ui->btnVisit, &QPushButton::clicked, this, &FileManager::evtFile);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
|
||||
#include "FileControl.h"
|
||||
|
||||
CustomTableWidget::CustomTableWidget(QWidget* parent) : QTableWidget(parent)
|
||||
@@ -43,11 +44,19 @@ void CustomTableWidget::setRemoteIDCall(const std::function<QString()>& call)
|
||||
|
||||
void CustomTableWidget::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if (!event->mimeData()->hasFormat("application/x-custom-data")) {
|
||||
if (!event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
QTableWidget::dropEvent(event);
|
||||
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||
|
||||
QList<QTableWidgetItem*> draggedItems;
|
||||
while (!stream.atEnd()) {
|
||||
int row, col;
|
||||
QMap<int, QVariant> roleData;
|
||||
stream >> row >> col >> roleData;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
@@ -57,67 +66,9 @@ void CustomTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
if (event->mimeData()->hasFormat("application/x-custom-data")) {
|
||||
if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
||||
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(dirinfo.root, df.name);
|
||||
}
|
||||
else {
|
||||
task.remotePath = Util::Join(dirinfo.root, df.name);
|
||||
task.localPath = basePathCall_();
|
||||
}
|
||||
tasks.push_back(task);
|
||||
}
|
||||
emit sigTasks(tasks);
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void CustomTableWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
if (!(event->buttons() & Qt::LeftButton)) {
|
||||
return;
|
||||
}
|
||||
if ((event->pos() - startPos_).manhattanLength() < QApplication::startDragDistance()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
|
||||
DirFileInfoVec v;
|
||||
v.root = basePathCall_();
|
||||
foreach (QTableWidgetItem* item, selectedItems()) {
|
||||
if (item->column() == 1) {
|
||||
DirFileInfo df;
|
||||
df.name = item->text();
|
||||
v.vec.push_back(df);
|
||||
}
|
||||
}
|
||||
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(v.vec.size()));
|
||||
drag->setPixmap(pixmap);
|
||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
|
||||
void CustomTableWidget::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
QTableWidget::mousePressEvent(event);
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
startPos_ = event->pos();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,6 @@ public:
|
||||
protected:
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
void dragEnterEvent(QDragEnterEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
protected:
|
||||
bool isRemote_{false};
|
||||
|
||||
@@ -102,8 +102,8 @@ void TransForm::handleUI(const TransTask& task)
|
||||
void TransForm::showEvent(QShowEvent* event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
workTh_ = new TranFromTh(this);
|
||||
fileTrans_->moveToThread(workTh_);
|
||||
workTh_ = new TranFromTh(this, this);
|
||||
//fileTrans_->moveToThread(workTh_);
|
||||
connect(workTh_, &QThread::finished, fileTrans_, &QObject::deleteLater);
|
||||
workTh_->start();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ void frelayGUI::InitControl()
|
||||
|
||||
compare_ = new Compare(this);
|
||||
transform_ = new TransForm(this);
|
||||
transform_->SetClientCore(clientCore_);
|
||||
|
||||
connecter_ = new Connecter(this);
|
||||
connecter_->SetClientCore(clientCore_);
|
||||
|
||||
Reference in New Issue
Block a user