From 3bcc8c29211202bdef531962c7fdaa42d6458cf1 Mon Sep 17 00:00:00 2001 From: taynpg Date: Mon, 30 Jun 2025 01:05:28 +0800 Subject: [PATCH] add: try to visit compare's dir. --- Gui/Control/CompareControl.cpp | 49 +++++++++++++++++++++++++++++++++- Gui/Control/CompareControl.h | 6 +++++ Gui/Control/FileControl.cpp | 9 +++++++ Gui/Control/FileControl.h | 1 + Gui/Control/cpTableWidget.cpp | 30 --------------------- Gui/Control/cpTableWidget.h | 8 ------ Gui/frelayGUI.cpp | 9 +++++++ Note/version.md | 2 +- 8 files changed, 74 insertions(+), 40 deletions(-) diff --git a/Gui/Control/CompareControl.cpp b/Gui/Control/CompareControl.cpp index 0eb0aa4..b2cb033 100644 --- a/Gui/Control/CompareControl.cpp +++ b/Gui/Control/CompareControl.cpp @@ -11,6 +11,7 @@ Compare::Compare(QWidget* parent) : QWidget(parent), ui(new Ui::Compare) { ui->setupUi(this); InitControl(); + InitMenu(); } Compare::~Compare() @@ -18,6 +19,33 @@ Compare::~Compare() delete ui; } +void Compare::InitMenu() +{ + menu_ = new QMenu(ui->tableWidget); + menu_->addAction(tr("Try2Local"), this, [this]() { + auto selected = ui->tableWidget->selectedItems(); + if (selected.size() != 3) { + return; + } + auto item = selected[1]; + auto path = item->text(); + emit sigTryVisit(true, path); + }); + menu_->addAction(tr("Try2Remote"), this, [this]() { + auto selected = ui->tableWidget->selectedItems(); + if (selected.size() != 3) { + return; + } + auto item = selected[2]; + auto path = item->text(); + emit sigTryVisit(false, path); + }); + menu_->addAction(tr("Delete"), this, [this]() { deleteSelectedRows(); }); + menu_->addSeparator(); + connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this, + [this](const QPoint& pos) { menu_->exec(QCursor::pos()); }); +} + void Compare::InitControl() { InitTabWidget(); @@ -26,7 +54,6 @@ void Compare::InitControl() connect(ui->btnLoad, &QPushButton::clicked, this, &Compare::Load); connect(ui->btnLeft, &QPushButton::clicked, this, &Compare::TransToLeft); connect(ui->btnRight, &QPushButton::clicked, this, &Compare::TransToRight); - LoadTitles(); } @@ -49,6 +76,7 @@ void Compare::InitTabWidget() // ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch); ui->tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch); + ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); ui->tableWidget->setDragEnabled(false); ui->tableWidget->viewport()->setAcceptDrops(true); @@ -278,3 +306,22 @@ void Compare::TransToRight() emit sigTasks(tasks); } + +void Compare::deleteSelectedRows() +{ + auto r = FTCommon::affirm(this, tr("confirm"), tr("delete selected rows?")); + if (!r) { + return; + } + QList rowsToDelete; + for (QTableWidgetItem* item : ui->tableWidget->selectedItems()) { + int row = item->row(); + if (!rowsToDelete.contains(row)) { + rowsToDelete.append(row); + } + } + std::sort(rowsToDelete.begin(), rowsToDelete.end(), std::greater()); + for (int row : rowsToDelete) { + ui->tableWidget->removeRow(row); + } +} \ No newline at end of file diff --git a/Gui/Control/CompareControl.h b/Gui/Control/CompareControl.h index 05447da..91f7aa2 100644 --- a/Gui/Control/CompareControl.h +++ b/Gui/Control/CompareControl.h @@ -19,10 +19,12 @@ public: signals: void sigTasks(const QVector& tasks); + void sigTryVisit(bool local, const QString& path); private: void InitControl(); void InitTabWidget(); + void InitMenu(); private: void Save(); @@ -32,7 +34,11 @@ private: void TransToLeft(); void TransToRight(); +private slots: + void deleteSelectedRows(); + private: + QMenu* menu_; Ui::Compare* ui; }; diff --git a/Gui/Control/FileControl.cpp b/Gui/Control/FileControl.cpp index dd9f37b..ab80d7d 100644 --- a/Gui/Control/FileControl.cpp +++ b/Gui/Control/FileControl.cpp @@ -327,6 +327,15 @@ void FileManager::HeaderClicked(int column) QMetaObject::invokeMethod(this, "RefreshTab", Qt::QueuedConnection); } +void FileManager::SetUiCurrentPath(const QString& path) +{ + if (path.isEmpty()) { + return; + } + ui->comboBox->addItem(path); + ui->comboBox->setCurrentText(path); +} + void FileManager::FilterFile(const QStringList& selectedTypes) { if (selectedTypes.contains("*")) { diff --git a/Gui/Control/FileControl.h b/Gui/Control/FileControl.h index c04016c..9a0efb8 100644 --- a/Gui/Control/FileControl.h +++ b/Gui/Control/FileControl.h @@ -37,6 +37,7 @@ public: public: QString GetRoot(); + void SetUiCurrentPath(const QString& path); void SetModeStr(const QString& modeStr, int type = 0, ClientCore* clientCore = nullptr); signals: diff --git a/Gui/Control/cpTableWidget.cpp b/Gui/Control/cpTableWidget.cpp index ad15c73..86b019a 100644 --- a/Gui/Control/cpTableWidget.cpp +++ b/Gui/Control/cpTableWidget.cpp @@ -11,23 +11,12 @@ CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent) { - contexMenu_ = new QMenu(this); - delAction_ = new QAction(tr("delete"), this); - connect(delAction_, &QAction::triggered, this, &CpTableWidget::deleteSelectedRows); - contexMenu_->addAction(delAction_); } CpTableWidget::~CpTableWidget() { } -void CpTableWidget::contextMenuEvent(QContextMenuEvent* event) -{ - if (selectedItems().count() > 0) { - contexMenu_->exec(event->globalPos()); - } -} - void CpTableWidget::dropEvent(QDropEvent* event) { if (!event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) { @@ -102,22 +91,3 @@ void CpTableWidget::dragEnterEvent(QDragEnterEvent* event) event->ignore(); } } - -void CpTableWidget::deleteSelectedRows() -{ - auto r = FTCommon::affirm(this, tr("confirm"), tr("delete selected rows?")); - if (!r) { - return; - } - QList rowsToDelete; - for (QTableWidgetItem* item : selectedItems()) { - int row = item->row(); - if (!rowsToDelete.contains(row)) { - rowsToDelete.append(row); - } - } - std::sort(rowsToDelete.begin(), rowsToDelete.end(), std::greater()); - for (int row : rowsToDelete) { - removeRow(row); - } -} \ No newline at end of file diff --git a/Gui/Control/cpTableWidget.h b/Gui/Control/cpTableWidget.h index b33e94d..49301fa 100644 --- a/Gui/Control/cpTableWidget.h +++ b/Gui/Control/cpTableWidget.h @@ -16,14 +16,6 @@ public: protected: void dropEvent(QDropEvent* event) override; void dragEnterEvent(QDragEnterEvent* event); - void contextMenuEvent(QContextMenuEvent* event) override; - -private slots: - void deleteSelectedRows(); - -private: - QMenu* contexMenu_; - QAction* delAction_; }; #endif // CP_TABLEWIDET_H diff --git a/Gui/frelayGUI.cpp b/Gui/frelayGUI.cpp index 72bc1d3..bc1482a 100644 --- a/Gui/frelayGUI.cpp +++ b/Gui/frelayGUI.cpp @@ -66,6 +66,15 @@ void frelayGUI::InitControl() connect(localFile_, &FileManager::sigSendTasks, this, &frelayGUI::HandleTask); connect(remoteFile_, &FileManager::sigSendTasks, this, &frelayGUI::HandleTask); connect(compare_, &Compare::sigTasks, this, &frelayGUI::HandleTask); + connect(compare_, &Compare::sigTryVisit, this, [this](bool local, const QString& path) { + if (local) { + localFile_->SetUiCurrentPath(path); + localFile_->evtFile(); + } else { + remoteFile_->SetUiCurrentPath(path); + remoteFile_->evtFile(); + } + }); connect(connecter_, &Connecter::sigConfirmUse, remoteFile_, &FileManager::evtHome); } diff --git a/Note/version.md b/Note/version.md index 364eb35..4be87b8 100644 --- a/Note/version.md +++ b/Note/version.md @@ -23,7 +23,7 @@ | 9 | 优化 | 输入路径后可以直接回车访问。 | | 0.1 | 0.2 | | 8 | 功能 | 文件浏览页面要支持按照类型排序,时间排序,和文件后缀筛选。 | | 0.1 | 0.2 | | 7 | 优化 | IP和Port宽度要合理一些,IP过小,Port宽度过大。 | | 0.1 | 0.2 | -| 6 | 功能 | 比对控件添加可尝试目录浏览控件跳转到指定目录。 | | 0.1 | | +| 6 | 功能 | 比对控件添加可尝试目录浏览控件跳转到指定目录。 | | 0.1 | 0.2 | | 5 | 问题 | 未设置心跳包,导致超时被Server端踢出。 | 必改 | 0.1 | 0.2 | | 4 | 问题 | 重复链接Server会崩溃。 | | 0.1 | 0.2 | | 3 | 优化 | 首次启动时应当按照当前分辨率进行初始化大小,而不是指定大小。 | | 0.1 | 0.2 |