BondGraphicsView.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <CViewInterface.h>
  10. class BondItem : public QObject, public QGraphicsRectItem {
  11. public:
  12. BondItem(ns_mat::POINT_INFO_STRUCT point, QGraphicsItem* parent = nullptr);
  13. void setSelected(bool selected);
  14. void setLeftSelected(bool selected);
  15. ns_mat::POINT_INFO_STRUCT point;
  16. int getDieIndex();
  17. private:
  18. QPair<int, int> topLeftIndex;
  19. QPair<int, int> bottomRightIndex;
  20. QPointer<BondItem> selectedItem;
  21. QPointer<BondItem> topLeftItem;
  22. QPointer<BondItem> bottomRightItem;
  23. bool isSelected = false;
  24. int dieIndex;
  25. POINT_INFO_STRUCT m_info;
  26. // 获取单元格状态颜色
  27. QColor getColorByStatus();
  28. protected:
  29. void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
  30. void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
  31. };
  32. class BondGraphicsView : public QGraphicsView {
  33. Q_OBJECT
  34. public:
  35. BondGraphicsView(QGraphicsScene* scene, QWidget* parent = nullptr);
  36. QPixmap convertToPixmap(const ImageInfo& imgData);
  37. void yuv422_to_rgb888(const unsigned char* src, unsigned char* dst, int width, int height);
  38. void setCViewInterface(ns_module::CViewInterface* CViewInterface);
  39. protected:
  40. void mousePressEvent(QMouseEvent* event) override;
  41. void mouseMoveEvent(QMouseEvent* event) override;
  42. void mouseReleaseEvent(QMouseEvent* event) override;
  43. void wheelEvent(QWheelEvent* event) override;
  44. bool eventFilter(QObject* obj, QEvent* event) override;
  45. private:
  46. bool selecting; // 是否正在框选
  47. QPoint lastPos;
  48. QPointF selectionStart; // 框选起点
  49. QGraphicsRectItem* selectionRect; // 框选矩形
  50. double scaleFactor; // 当前缩放比例
  51. bool isDragging = false;
  52. QMap<int, QGraphicsItem*> selectedItemsMap;
  53. QLabel* thumbnailLabel; // 缩略图标签
  54. bool thumbnailVisible; // 缩略图可见状态
  55. QPointer<BondItem> selectedItem;
  56. ns_module::CViewInterface* m_pCViewInterface;
  57. void showThumbnail();
  58. void hideThumbnail();
  59. void clearRegion();
  60. void setRegion();
  61. void checkAndCreateRegion();
  62. };
  63. #endif // BONDGRAPHICSVIEW_H