-
Notifications
You must be signed in to change notification settings - Fork 26
/
imageviewerbase.h
102 lines (82 loc) · 1.75 KB
/
imageviewerbase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef IMAGEVIEWERBASE_H
#define IMAGEVIEWERBASE_H
#include <QPixmap>
#include <QLabel>
#include <QImage>
#include <QRect>
class QPainter;
class QTimer;
/*
* Base image viewer widget with auto scaling
*/
class ImageViewerBase : public QWidget
{
Q_OBJECT
public:
explicit ImageViewerBase(QWidget *parent = 0);
virtual ~ImageViewerBase() = default;
/*
* Display an image in the view
*/
void setImage(const QImage &image);
/*
* Current zoom
*/
double zoom() const;
/*
* Clear and reset view to initial state with no actual image set
*/
virtual void reset();
protected:
virtual void resizeEvent(QResizeEvent *event) override;
virtual void paintEvent(QPaintEvent *event) override;
/*
* Getters for derived classes
*/
QPixmap pixmap() const;
QImage image() const;
QRect pixmapBoundingRect() const;
/*
* Pixmap will be scaled right now!
*/
virtual void pixmapAboutToBeChanged() = 0;
/*
* Pixmap has been scaled and all the internal data has been updated
*/
virtual void pixmapChanged() = 0;
/*
* Draw viewer-specific stuff
*/
virtual void draw(QPainter *painter) = 0;
signals:
void zoomChanged(double);
private slots:
void updatePixmap();
private:
QTimer *m_timerDelayedUpdate;
QImage m_image;
QPixmap m_pixmap;
double m_zoom;
QRect m_pixmapBoundingRect;
};
inline
double ImageViewerBase::zoom() const
{
return m_zoom;
}
inline
QPixmap ImageViewerBase::pixmap() const
{
return m_pixmap;
}
inline
QImage ImageViewerBase::image() const
{
return m_image;
}
inline
QRect ImageViewerBase::pixmapBoundingRect() const
{
return m_pixmapBoundingRect;
}
#endif // IMAGEVIEWERBASE_H