add: customTabwidget set drag action.
This commit is contained in:
@@ -23,6 +23,7 @@ Control/CompareControl.h Control/CompareControl.cpp Control/CompareControl.ui
|
|||||||
GuiUtil/Public.h GuiUtil/Public.cpp
|
GuiUtil/Public.h GuiUtil/Public.cpp
|
||||||
Control/Transform.h Control/Transform.cpp Control/Transform.ui
|
Control/Transform.h Control/Transform.cpp Control/Transform.ui
|
||||||
../Res/frelay.qrc ../Res/ico.rc
|
../Res/frelay.qrc ../Res/ico.rc
|
||||||
|
Control/cusTableWidget.cpp Control/cusTableWidget.h
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "FileControl.h"
|
#include "FileControl.h"
|
||||||
|
|
||||||
#include <LocalFile.h>
|
#include <LocalFile.h>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
@@ -57,12 +57,25 @@ void FileManager::InitControl()
|
|||||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||||
// ui->tableWidget->setStyleSheet("QTableWidget::item:hover { background-color: transparent; }");
|
// ui->tableWidget->setStyleSheet("QTableWidget::item:hover { background-color: transparent; }");
|
||||||
|
|
||||||
|
ui->tableWidget->setDragEnabled(true);
|
||||||
|
ui->tableWidget->viewport()->setAcceptDrops(true);
|
||||||
|
ui->tableWidget->setDropIndicatorShown(true);
|
||||||
|
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
ui->tableWidget->setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
|
|
||||||
connect(ui->btnHome, &QPushButton::clicked, this, &FileManager::evtHome);
|
connect(ui->btnHome, &QPushButton::clicked, this, &FileManager::evtHome);
|
||||||
connect(ui->btnVisit, &QPushButton::clicked, this, &FileManager::evtFile);
|
connect(ui->btnVisit, &QPushButton::clicked, this, &FileManager::evtFile);
|
||||||
connect(ui->tableWidget, &QTableWidget::cellDoubleClicked, this, &FileManager::doubleClick);
|
connect(ui->tableWidget, &QTableWidget::cellDoubleClicked, this, &FileManager::doubleClick);
|
||||||
connect(ui->btnUp, &QPushButton::clicked, this, &FileManager::evtUp);
|
connect(ui->btnUp, &QPushButton::clicked, this, &FileManager::evtUp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileManager::InitMenu(bool remote)
|
||||||
|
{
|
||||||
|
if (remote) {
|
||||||
|
auto acDown = new QAction(tr("Download"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileManager::ShowPath(const QString& path)
|
void FileManager::ShowPath(const QString& path)
|
||||||
{
|
{
|
||||||
int existingIndex = ui->comboBox->findText(path);
|
int existingIndex = ui->comboBox->findText(path);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#ifndef FILECONTROL_H
|
#ifndef FILECONTROL_H
|
||||||
#define FILECONTROL_H
|
#define FILECONTROL_H
|
||||||
|
|
||||||
#include <ClientCore.h>
|
#include <ClientCore.h>
|
||||||
#include <InfoDirFile.h>
|
#include <InfoDirFile.h>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class FileManager;
|
class FileManager;
|
||||||
@@ -23,6 +24,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void InitControl();
|
void InitControl();
|
||||||
|
void InitMenu(bool remote = false);
|
||||||
void ShowPath(const QString& path);
|
void ShowPath(const QString& path);
|
||||||
void ShowFile(const DirFileInfoVec& info);
|
void ShowFile(const DirFileInfoVec& info);
|
||||||
void doubleClick(int row, int column);
|
void doubleClick(int row, int column);
|
||||||
@@ -35,6 +37,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
Ui::FileManager* ui;
|
Ui::FileManager* ui;
|
||||||
QString curRoot_;
|
QString curRoot_;
|
||||||
|
QMenu* localMenu_;
|
||||||
|
QMenu* remoteMenu_;
|
||||||
std::shared_ptr<DirFileHelper> fileHelper_;
|
std::shared_ptr<DirFileHelper> fileHelper_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,17 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="tableWidget"/>
|
<widget class="CustomTableWidget" name="tableWidget"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>CustomTableWidget</class>
|
||||||
|
<extends>QTableWidget</extends>
|
||||||
|
<header>cusTableWidget.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
67
Gui/Control/cusTableWidget.cpp
Normal file
67
Gui/Control/cusTableWidget.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include "cusTableWidget.h"
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
CustomTableWidget::CustomTableWidget(QWidget* parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomTableWidget::~CustomTableWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomTableWidget::dropEvent(QDropEvent* event)
|
||||||
|
{
|
||||||
|
if (!event->mimeData()->hasFormat("application/x-custom-data")) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QModelIndex index = indexAt(event->pos());
|
||||||
|
if (!index.isValid()) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString data = QString::fromUtf8(event->mimeData()->data("application/x-custom-data"));
|
||||||
|
QStringList items = data.split(",");
|
||||||
|
|
||||||
|
//emit customDropRequested(items.first(), index.row(), index.column(), event->source());
|
||||||
|
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomTableWidget::dragMoveEvent(QDragMoveEvent* event)
|
||||||
|
{
|
||||||
|
const QTableWidget* source = qobject_cast<const QTableWidget*>(event->source());
|
||||||
|
if (source == this) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event->mimeData()->hasFormat("application/x-custom-data")) {
|
||||||
|
event->setDropAction(Qt::MoveAction);
|
||||||
|
event->acceptProposedAction();
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomTableWidget::startDrag(Qt::DropActions supportedActions)
|
||||||
|
{
|
||||||
|
QDrag* drag = new QDrag(this);
|
||||||
|
QMimeData* mimeData = new QMimeData;
|
||||||
|
|
||||||
|
QStringList selectedTexts;
|
||||||
|
foreach (QTableWidgetItem* item, selectedItems()) {
|
||||||
|
selectedTexts << item->text();
|
||||||
|
}
|
||||||
|
mimeData->setData("application/x-custom-data", selectedTexts.join(",").toUtf8());
|
||||||
|
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()));
|
||||||
|
drag->setPixmap(pixmap);
|
||||||
|
drag->exec(supportedActions);
|
||||||
|
}
|
||||||
20
Gui/Control/cusTableWidget.h
Normal file
20
Gui/Control/cusTableWidget.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef CUSTOM_TABLEWIDET_H
|
||||||
|
#define CUSTOM_TABLEWIDET_H
|
||||||
|
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QDropEvent>
|
||||||
|
|
||||||
|
class CustomTableWidget : public QTableWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit CustomTableWidget(QWidget* parent = nullptr);
|
||||||
|
~CustomTableWidget() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
|
void startDrag(Qt::DropActions supportedActions) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user