ImageWidget.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef IMAGEWIDGET_H
  2. #define IMAGEWIDGET_H
  3. #include <QWidget>
  4. #include <QPixmap>
  5. #include <QMouseEvent>
  6. namespace Ui {
  7. class ImageWidget;
  8. }
  9. class ImageWidget : public QWidget
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit ImageWidget(QWidget *parent = nullptr);
  14. ~ImageWidget();
  15. void setPixmap(const QPixmap& pixmap);
  16. void setPixmapAndPoint(const QPixmap& pixmap, double previousScaleFactor, qreal scaleFactor, QPoint mousePos);
  17. void clearPixmap();
  18. signals:
  19. void sendDoubleClicksignal();
  20. protected:
  21. void paintEvent(QPaintEvent *event) override;
  22. void mousePressEvent(QMouseEvent *event) override;
  23. void mouseMoveEvent(QMouseEvent *event) override;
  24. void mouseReleaseEvent(QMouseEvent *event) override;
  25. void mouseDoubleClickEvent(QMouseEvent *event) override;
  26. private:
  27. void DrawCrossWithScale(QPainter* painter, double dImgWidth, double dImgHeight, const QSize& sourceImageSize, const QPointF& sourceImagePosition);
  28. void drawCross(QPainter* painter, QRect rect);
  29. private:
  30. Ui::ImageWidget *ui;
  31. QPixmap pixmap;
  32. QPoint lastMousePos = {}; // 上一次鼠标的位置
  33. QPointF imageOffset = {}; // 图片的偏移量
  34. bool isDragging = false; // 是否正在拖动
  35. public:
  36. /**是否是SingleCameraOperationWnd
  37. */
  38. int m_nSingleCameraOperationWnd = false;
  39. };
  40. #endif // IMAGEWIDGET_H