WaffleGraphicsView.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef WAFFLEGRAPHICSVIEW_H
  2. #define WAFFLEGRAPHICSVIEW_H
  3. #include <QGraphicsView>
  4. #include <QGraphicsScene>
  5. #include <QGraphicsRectItem>
  6. #include <QMouseEvent>
  7. #include <QLabel>
  8. #include <QPointer>
  9. #include <CViewInterface.h>
  10. #include <QColor>
  11. #include <QDebug>
  12. #include <QPen>
  13. #include <QMenu>
  14. #include <QGraphicsSceneContextMenuEvent>
  15. #include <CWaferMatrix.h>
  16. class WaffleItem : public QObject, public QGraphicsRectItem {
  17. public:
  18. WaffleItem(ns_mat::WAFFLE_MATRIX_POINT_STRUCT point, double penSize, QGraphicsItem* parent = nullptr);
  19. void setSelected(bool selected);
  20. void setLeftSelected(bool selected);
  21. void setPenSize(double size);
  22. void WaffleItem::setRightSelected(bool selected);
  23. ns_mat::WAFFLE_MATRIX_POINT_STRUCT getPoint();
  24. private:
  25. // 获取单元格状态颜色
  26. QColor getColorByStatus();
  27. WAFFLE_MATRIX_POINT_STRUCT point;
  28. double penSize;
  29. protected:
  30. void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
  31. void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
  32. };
  33. class WaffleGraphicsView : public QGraphicsView {
  34. Q_OBJECT
  35. public:
  36. WaffleGraphicsView(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. QVector <QGraphicsItem*> selectedItems;
  54. QLabel *thumbnailLabel; // 缩略图标签
  55. bool thumbnailVisible; // 缩略图可见状态
  56. QPair<int, int> topLeftIndex;
  57. QPair<int, int> bottomRightIndex;
  58. QPointer<WaffleItem> selectedItem;
  59. QPointer<WaffleItem> topLeftItem;
  60. QPointer<WaffleItem> bottomRightItem;
  61. void showThumbnail();
  62. void hideThumbnail();
  63. void checkAndCreateRegion();
  64. void clearRegion();
  65. void setRegion();
  66. ns_module::CViewInterface* m_pCViewInterface;
  67. };
  68. #endif // WAFFLEGRAPHICSVIEW_H