12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #ifndef IMAGEVIEW_H
- #define IMAGEVIEW_H
- #include <QWidget>
- #include <QPixmap>
- #include <QMouseEvent>
- #include <QGraphicsView>
- #include "CameraMaterialGroupWnd/MaterialWindow/DraggableLine.h"
- class ImageView : public QGraphicsView
- {
- Q_OBJECT
- public:
- explicit ImageView(QWidget* parent = nullptr);
- ~ImageView();
- //设置图片
- void setPixmap(const QPixmap& pixmap);
- void setCurPixmap(const QPixmap& pixmap);
- //设置标尺
- void startRuler();
- void endRuler();
- bool rulerVisibale();
- void setIsDrawing(bool drawing) { m_isDrawing = drawing; }
- protected:
- void paintEvent(QPaintEvent* event) override;
- void mousePressEvent(QMouseEvent* event) override;
- void mouseMoveEvent(QMouseEvent* event) override;
- void mouseReleaseEvent(QMouseEvent* event) override;
- void wheelEvent(QWheelEvent* event) override;
- private:
- QGraphicsPixmapItem* m_pixmapItem;
- QPixmap m_pixmap;
- QPoint m_lastMousePos; // 上一次鼠标的位置
- QPointF m_imageOffset; // 图片的偏移量
- DraggableLine* m_pRuleLine;
- bool m_bMouseTranslate;
- qreal m_minScale;
- bool m_isDrawing;
- bool m_curDrawing;
- QPainterPath m_currentPath;
- QGraphicsPathItem* m_currentPathItem;
- QList<QGraphicsPathItem*> m_drawnPaths;
- QPoint m_rightClickPressPos;
- bool m_rightButtonPressed;
- void saveImage();
- void clearDrawnLines();
- };
- #endif // IMAGEVIEW_H
|