-
Notifications
You must be signed in to change notification settings - Fork 3
/
ImageViewer.h
50 lines (42 loc) · 1.08 KB
/
ImageViewer.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
#pragma once
#include <QWidget>
class ImageViewer : public QWidget
{
public:
enum ViewType
{
ViewColorImage = 0,
ViewTypeEnd,
};
public:
ImageViewer(QWidget *parent);
~ImageViewer();
public:
void setViewType(ViewType type);
ViewType getViewType()const;
void setColorImage(const QImage& img);
const QImage* getColorImage()const;
float getViewScale()const;
QPointF image2view(QPointF imgPt);
QPointF view2image(QPointF viewPt);
protected:
void paintEvent(QPaintEvent* ev);
void resizeEvent(QResizeEvent* ev);
void mousePressEvent(QMouseEvent* ev);
void mouseReleaseEvent(QMouseEvent* ev);
void mouseMoveEvent(QMouseEvent* ev);
void wheelEvent(QWheelEvent* ev);
void keyPressEvent(QKeyEvent* ev);
void scaleViewRect(QPoint c, float s);
void updateViewRect(bool allowScale = true);
void timerEvent(QTimerEvent* ev);
private:
void drawStrokes(QPainter& painter);
void drawMaskAsPath(QPainter& painter);
private:
QImage m_colorImage;
QRectF m_viewRect;
QPoint m_mousePos;
Qt::MouseButtons m_buttons;
ViewType m_viewType;
};