-
Notifications
You must be signed in to change notification settings - Fork 0
/
mygraphicsview.h
99 lines (73 loc) · 2.32 KB
/
mygraphicsview.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
#ifndef MYGRAPHICSVIEW_H
#define MYGRAPHICSVIEW_H
#include <QGraphicsView>
#include <QGraphicsRectItem>
#include <QPixmap>
#include <QMouseEvent>
#include <QGraphicsScene>
#include <QImage>
class MyGraphicsView : public QGraphicsView
{
Q_OBJECT
protected:
QGraphicsScene* mScene;
QImage mOrigImage;
public:
explicit MyGraphicsView(QWidget *parent = 0);
// override
const QPixmap * pixmap() const {
return &mPixmap;
}
void setZoomLimits( double min, double max) { mZoomMax = max; mZoomMin = min; }
double scaleFactor() const { return mScaleFactor; }
void setImage( const QImage &img, const QRect &updateRect = QRect() );
// returns 'viewable rect' in image (pixmap) coordinates
QRect getViewableRect() const;
// pan / scale
void scale(double factor);
void pan( double x, double y );
inline QPoint screenToImage( const QPoint &ev )
{
QPointF pf = mapToScene( ev );
return QPoint( pf.x(), pf.y() );
}
signals:
protected:
//Holds the current centerpoint for the view, used for panning and zooming
QPointF CurrentCenterPoint;
QPixmap mPixmap;
double mScaleFactor;
double mZoomMax, mZoomMin; // max and min zoom factor
//From panning the view
QPoint mLastMouseMovePt;
//Set the current centerpoint in the
void SetCenter(const QPointF& centerPoint);
QPointF GetCenter() { return CurrentCenterPoint; }
virtual void wheelEvent ( QWheelEvent * event ) {
emit wheelEventSignal(event);
}
virtual void mouseMoveEvent ( QMouseEvent * ev ) {
mLastMouseMovePt = ev->pos();
emit mouseMoveEventSignal(ev);
}
virtual void mouseReleaseEvent ( QMouseEvent * ev ) {
emit mouseReleaseEventSignal(ev);
}
virtual void mousePressEvent ( QMouseEvent * ev ) {
emit mousePressEventSignal(ev);
}
virtual void resizeEvent(QResizeEvent* event);
signals:
void wheelEventSignal( QWheelEvent *event );
void mouseMoveEventSignal( QMouseEvent *event );
void mouseReleaseEventSignal( QMouseEvent *event );
void mousePressEventSignal( QMouseEvent *event );
public slots:
// fits the image within the scrollarea size
void zoomFit()
{
qDebug("zoomfit: Implement me!");
mScaleFactor = 1.0;
}
};
#endif // MYGRAPHICSVIEW_H