-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmygraphicsview.h
94 lines (70 loc) · 2.17 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
#ifndef MYGRAPHICSVIEW_H
#define MYGRAPHICSVIEW_H
#include <QGraphicsView>
#include <QGraphicsRectItem>
/**
* @page MyGraphicsView Class MyGraphicsView.
* Class which inheritates of QGraphicsView and reimplements few original methods to improve to functionality.
*/
class MyGraphicsView : public QGraphicsView
{
Q_OBJECT;
public:
/**
* Constructor for MyGraphicsView Class.@n
* Sets the QGraphcsView constructor.
* @param QWidget*
*/
MyGraphicsView(QWidget* parent = NULL);
/**
* Variable containing the difference between two points in X axis during mouse move.
*/
int diffX;
/**
* Variable containing the difference between two points in Y axis during mouse move.
*/
int diffY;
public:
//Holds the current centerpoint for the view, used for panning and zooming
QPointF CurrentCenterPoint;
//From panning the view
QPoint LastPanPoint;
QPoint EventPos;
/**
* Sets the current centerpoint. Also updates the scene's center point.
* Unlike centerOn, which has no way of getting the floating point center
* back, SetCenter() stores the center point. It also handles the special
* sidebar case. This function will claim the centerPoint to sceneRec ie.
* the centerPoint must be within the sceneRec.
* @param const QPointF&
* @return void
*/
void SetCenter(const QPointF& centerPoint);
QPointF GetCenter() { return CurrentCenterPoint; }
//Take over the interaction
/**
* Handles when the mouse button is pressed
* @param QMouseEvent*
* @return void
*/
virtual void mousePressEvent(QMouseEvent* event);
/**
* Handles when the mouse button is released
* @param QMouseEvent*
* @return void
*/
virtual void mouseReleaseEvent(QMouseEvent* event);
/**
* Handles when the mouse is moved and stores iformations about movement in diffX and diffY.
* @param QMouseEvent*
* @return void
*/
virtual void mouseMoveEvent(QMouseEvent* event);
/**
* Zoom the view in and out.
* @param QMouseEvent*
* @return void
*/
virtual void wheelEvent(QWheelEvent* event);
};
#endif // MYGRAPHICSVIEW_H