36 lines
704 B
C++
36 lines
704 B
C++
#pragma once
|
|
|
|
#include <QGraphicsView>
|
|
#include <QImage>
|
|
#include <QPixmap>
|
|
|
|
class QGraphicsPixmapItem;
|
|
class QGraphicsScene;
|
|
class QWheelEvent;
|
|
class QMouseEvent;
|
|
|
|
class ImageView final : public QGraphicsView
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ImageView(QWidget *parent = nullptr);
|
|
|
|
void setImage(const QImage &image);
|
|
void clearImage();
|
|
void fitImageToView();
|
|
bool hasImage() const;
|
|
|
|
protected:
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
|
|
|
private:
|
|
void resetSceneRect();
|
|
|
|
QGraphicsScene *scene_ = nullptr;
|
|
QGraphicsPixmapItem *pixmapItem_ = nullptr;
|
|
QPixmap pixmap_;
|
|
double zoomFactor_ = 1.0;
|
|
};
|