Browse Source

添加遗漏提交

lsw 1 day ago
parent
commit
6dc79e3d6e

+ 130 - 0
View/die-bonder-ui/Src/MatrixDialogs/NoBondPtEditDialog.cpp

@@ -0,0 +1,130 @@
+#include "NoBondPtEditDialog.h"
+
+// 构造函数实现
+NoBondPtEditDialog::NoBondPtEditDialog(int rows, int cols, const std::vector<XY_LONG_STRUCT>& selectedPts, QWidget* parent)
+    : QDialog(parent)
+{
+    this->setStyleSheet(R"(
+        QDialog {
+            background-color: #f0f0f0;
+            color: black;
+        }
+        QPushButton {
+            background-color: white;
+            color: black;
+            border: 1px solid gray;
+            border-radius: 4px;
+        }
+        QPushButton:hover {
+            background-color: #e0e0e0;
+        }
+    )");
+
+    QVBoxLayout* mainLayout = new QVBoxLayout(this);
+    QGridLayout* gridLayout = new QGridLayout();
+
+    // 初始化已选点集合
+    for (const auto& pt : selectedPts) {
+        selectedSet.insert({ pt.x, pt.y });
+    }
+
+    for (int r = 0; r < rows; ++r) {
+        for (int c = 0; c < cols; ++c) {
+            QPushButton* btn = new QPushButton(QString("%1,%2").arg(r).arg(c));
+            btn->setFixedSize(40, 30);
+
+            QPair<int, int> pos(r, c);
+            buttonMap[btn] = pos;
+
+            bool selected = selectedSet.contains(pos);
+            btn->setStyleSheet(selected ? "background-color: gray;" : "background-color: lightgreen;");
+
+            connect(btn, &QPushButton::clicked, this, [=]() {
+                if (selectedSet.contains(pos)) {
+                    selectedSet.remove(pos);
+                    btn->setStyleSheet("background-color: lightgreen;");
+                }
+                else {
+                    selectedSet.insert(pos);
+                    btn->setStyleSheet("background-color: gray;");
+                }
+                });
+
+            gridLayout->addWidget(btn, r, c);
+        }
+    }
+
+    mainLayout->addLayout(gridLayout);
+
+    // 底部按钮
+    QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+    connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
+    connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
+    mainLayout->addWidget(buttons);
+}
+
+// 获取选中的点
+QVector<XY_LONG_STRUCT> NoBondPtEditDialog::getSelectedPoints() const {
+    QVector<XY_LONG_STRUCT> result;
+    for (const auto& pos : selectedSet) {
+        XY_LONG_STRUCT pt;
+        pt.x = pos.first;
+        pt.y = pos.second;
+        result.append(pt);
+    }
+    return result;
+}
+
+void NoBondPtEditDialog::mousePressEvent(QMouseEvent* event) {
+    if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
+        dragStart = event->pos();
+        dragButton = event->button();  // 记录当前拖动按钮
+
+        if (!rubberBand)
+            rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
+        rubberBand->setGeometry(QRect(dragStart, QSize()));
+        rubberBand->show();
+        isDragging = true;
+    }
+}
+
+
+void NoBondPtEditDialog::mouseMoveEvent(QMouseEvent* event) {
+    if (isDragging && rubberBand) {
+        rubberBand->setGeometry(QRect(dragStart, event->pos()).normalized());
+    }
+}
+
+void NoBondPtEditDialog::mouseReleaseEvent(QMouseEvent* event) {
+    if (!rubberBand || !isDragging || event->button() != dragButton) return;
+
+    rubberBand->hide();
+    QRect selectionRect = rubberBand->geometry();
+
+    for (auto it = buttonMap.begin(); it != buttonMap.end(); ++it) {
+        QPushButton* btn = it.key();
+        QPair<int, int> pos = it.value();
+
+        if (btn->geometry().intersects(selectionRect)) {
+            if (dragButton == Qt::LeftButton) {
+                // toggle:如果选中就取消,否则加入
+                if (selectedSet.contains(pos)) {
+                    selectedSet.remove(pos);
+                    btn->setStyleSheet("background-color: lightgreen;");
+                }
+                else {
+                    selectedSet.insert(pos);
+                    btn->setStyleSheet("background-color: gray;");
+                }
+            }
+            else if (dragButton == Qt::RightButton) {
+                // 强制取消
+                selectedSet.remove(pos);
+                btn->setStyleSheet("background-color: lightgreen;");
+            }
+        }
+    }
+
+    isDragging = false;
+    dragButton = Qt::NoButton;
+}

+ 37 - 0
View/die-bonder-ui/Src/MatrixDialogs/NoBondPtEditDialog.h

@@ -0,0 +1,37 @@
+#ifndef NO_BOND_PT_EDIT_DIALOG_H
+#define NO_BOND_PT_EDIT_DIALOG_H
+
+#include <QDialog>
+#include <QPushButton>
+#include <QDialogButtonBox>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QMap>
+#include <QSet>
+#include <QPair>
+#include <QMouseEvent>
+#include <QRubberBand>
+#include <QVector>
+#include "dt.h"
+
+class NoBondPtEditDialog : public QDialog {
+    Q_OBJECT
+public:
+    NoBondPtEditDialog(int rows, int cols, const std::vector<XY_LONG_STRUCT>& selectedPts, QWidget* parent = nullptr);
+    QVector<XY_LONG_STRUCT> getSelectedPoints() const;
+
+protected:
+    void mousePressEvent(QMouseEvent* event) override;
+    void mouseMoveEvent(QMouseEvent* event) override;
+    void mouseReleaseEvent(QMouseEvent* event) override;
+
+private:
+    QSet<QPair<int, int>> selectedSet;
+    Qt::MouseButton dragButton = Qt::NoButton;
+    QMap<QPushButton*, QPair<int, int>> buttonMap;
+    QRubberBand* rubberBand = nullptr;
+    QPoint dragStart;
+    bool isDragging = false;
+};
+
+#endif // NO_BOND_PT_EDIT_DIALOG_H