ImageView.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef IMAGEVIEW_H
  2. #define IMAGEVIEW_H
  3. #include <QWidget>
  4. #include <QPixmap>
  5. #include <QMouseEvent>
  6. #include <QGraphicsView>
  7. #include "CameraMaterialGroupWnd/MaterialWindow/DraggableLine.h"
  8. class ImageView : public QGraphicsView
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit ImageView(QWidget* parent = nullptr);
  13. ~ImageView();
  14. //设置图片
  15. void setPixmap(const QPixmap& pixmap);
  16. void setCurPixmap(const QPixmap& pixmap);
  17. //设置标尺
  18. void startRuler();
  19. void endRuler();
  20. bool rulerVisibale();
  21. void setIsDrawing(bool drawing) { m_isDrawing = drawing; }
  22. protected:
  23. void paintEvent(QPaintEvent* event) override;
  24. void mousePressEvent(QMouseEvent* event) override;
  25. void mouseMoveEvent(QMouseEvent* event) override;
  26. void mouseReleaseEvent(QMouseEvent* event) override;
  27. void wheelEvent(QWheelEvent* event) override;
  28. private:
  29. QGraphicsPixmapItem* m_pixmapItem;
  30. QPixmap m_pixmap;
  31. QPoint m_lastMousePos; // 上一次鼠标的位置
  32. QPointF m_imageOffset; // 图片的偏移量
  33. DraggableLine* m_pRuleLine;
  34. bool m_bMouseTranslate;
  35. qreal m_minScale;
  36. bool m_isDrawing;
  37. bool m_curDrawing;
  38. QPainterPath m_currentPath;
  39. QGraphicsPathItem* m_currentPathItem;
  40. QList<QGraphicsPathItem*> m_drawnPaths;
  41. QPoint m_rightClickPressPos;
  42. bool m_rightButtonPressed;
  43. void saveImage();
  44. void clearDrawnLines();
  45. };
  46. #endif // IMAGEVIEW_H