WaffleGraphicsView.h 2.2 KB

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