-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageviewer.h
97 lines (75 loc) · 2.82 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
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
#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H
#include <QImage>
#include <QWidget>
#include "label.h"
#include "labeleditor.h"
class ImageLabel;
class ImageViewer : public QWidget {
Q_OBJECT
public:
explicit ImageViewer(QWidget *parent = nullptr);
protected:
// begin: qt widget events
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
// end: qt widget events
public slots:
void zoomIn();
void zoomOut();
void fitToView();
void resetToOriginalSize();
void loadImage(const QString &filepath);
void setImage(const QImage &img);
QImage image() const;
QImage rendering() const;
void setInSelect(bool pixelSelect);
void addLabel(const QSharedPointer<Label> &label);
void removeLabel(const QSharedPointer<Label> &label);
void clearLabel();
void addEditor(const QSharedPointer<LabelEditor> &editor);
void removeEditor(const QSharedPointer<LabelEditor> &editor);
void clearEditor();
signals:
void scaleFactorChanged(double factor);
void imageSizeChanged(const QSize &size);
void pixelValueChanged(const QPoint &pos, const QColor &value);
private:
void resetWorldTransform();
QTransform getWorldTransform() const;
void setWorldScale(double value);
double getWorldScale() const;
void setWorldScaleAndUpdate(double value);
QPointF getMousePos();
void setMousePos(QMouseEvent *);
void displayInfo(QPainter &painter);
private:
// file model
QSharedPointer<ImageLabel> mImageLabel;
QSharedPointer<LabelEditor> mSelectedEditor;
QList<QSharedPointer<LabelEditor>> mEditors;
QList<QSharedPointer<Label>> mLabels;
// scale and transform of the objects on the desktop
double mWorldScale = 1;
const double mScaleFactor = 1.1;
QPointF mWorldOffset = {1, 1};
QPointF mImageOriginOffset = {-0.5, -0.5};
const double mMinScale = 0.01;
const double mMaxScale = 100.;
const double mScaleStep = 0.1;
bool mFitToViewOnLoad = true; // fit loaded image to view when it is loaded by SetBackground
bool mFitToViewOnResize = true; // fit loaded image to view when widow is resized
QPointF mMousePos; // mouse position in background picture coordinates
QPoint mMousePosPixels; // mouse position in window coordinate system
double mMouseAngle = 0;
// current mode
bool mInPixelSelect = false;
QColor mSelectedColor;
QImage mBackground;
};
#endif // IMAGEVIEWER_H