BondGraphicsView.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef BONDGRAPHICSVIEW_H
  2. #define BONDGRAPHICSVIEW_H
  3. #include <QGraphicsView>
  4. #include <QMap>
  5. #include <QLabel>
  6. #include <QGraphicsRectItem>
  7. #include <QPointer>
  8. #include <CBondMatrix.h>
  9. class BondItem : public QObject, public QGraphicsRectItem {
  10. public:
  11. BondItem(ns_mat::POINT_INFO_STRUCT point, QGraphicsItem* parent = nullptr);
  12. void setSelected(bool selected);
  13. void setLeftSelected(bool selected);
  14. ns_mat::POINT_INFO_STRUCT point;
  15. private:
  16. bool isSelected = false;
  17. // 获取单元格状态颜色
  18. QColor getColorByStatus(ns_mat::DIE_STATUS status);
  19. };
  20. class BondGraphicsView : public QGraphicsView {
  21. Q_OBJECT
  22. public:
  23. BondGraphicsView(QGraphicsScene* scene, QWidget* parent = nullptr);
  24. protected:
  25. void mousePressEvent(QMouseEvent* event) override;
  26. void mouseMoveEvent(QMouseEvent* event) override;
  27. void mouseReleaseEvent(QMouseEvent* event) override;
  28. void wheelEvent(QWheelEvent* event) override;
  29. bool eventFilter(QObject* obj, QEvent* event) override;
  30. private:
  31. bool selecting; // 是否正在框选
  32. QPoint lastPos;
  33. QPointF selectionStart; // 框选起点
  34. QGraphicsRectItem* selectionRect; // 框选矩形
  35. double scaleFactor; // 当前缩放比例
  36. bool isDragging = false;
  37. QMap<int, QGraphicsItem*> selectedItemsMap;
  38. QLabel* thumbnailLabel; // 缩略图标签
  39. bool thumbnailVisible; // 缩略图可见状态
  40. QPointer<BondItem> selectedItem;
  41. void showThumbnail();
  42. void hideThumbnail();
  43. void clearRegion();
  44. void setRegion();
  45. };
  46. #endif // BONDGRAPHICSVIEW_H