#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H

#include <QWidget>
#include <QPixmap>
#include <QMouseEvent>

namespace Ui {
class ImageWidget;
}

class ImageWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ImageWidget(QWidget *parent = nullptr);
    ~ImageWidget();

    void setPixmap(const QPixmap& pixmap);
    void setPixmapAndPoint(const QPixmap& pixmap, double previousScaleFactor, qreal scaleFactor, QPoint mousePos);
    void clearPixmap();
signals:
    void sendDoubleClicksignal();
protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseDoubleClickEvent(QMouseEvent *event) override;
private:
    Ui::ImageWidget *ui;
    QPixmap pixmap;
    QPoint lastMousePos;  // 上一次鼠标的位置
    QPointF imageOffset;  // 图片的偏移量
    bool isDragging;     // 是否正在拖动
};

#endif // IMAGEWIDGET_H
