BondGraphicsView.h 2.3 KB

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