-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractive_qchart.cpp
68 lines (57 loc) · 1.49 KB
/
interactive_qchart.cpp
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
#include "interactive_qchart.h"
InteractiveQChart::InteractiveQChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) :
QChart(parent, wFlags)
{
m_buttonPressed = false;
m_lastMousePos = QPointF(0,0);
}
void InteractiveQChart::wheelEvent(QGraphicsSceneWheelEvent *event) {
if (event->buttons() | Qt::MidButton) {
int delta = event->delta();
if (delta > 0) {
zoom(1.1);
}
else if (delta < 0) {
zoom(0.9);
}
event->accept();
}
else {
event->ignore();
}
}
void InteractiveQChart::mousePressEvent(QGraphicsSceneMouseEvent *event) {
if (event->buttons() == Qt::MidButton) {
zoomReset();
event->accept();
}
else if (event->buttons() == Qt::RightButton) {
m_buttonPressed = true;
m_lastMousePos = event->pos();
event->accept();
}
else {
event->ignore();
}
}
void InteractiveQChart::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
if (m_buttonPressed) {
auto deltaPos = event->pos() - m_lastMousePos;
scroll(-deltaPos.x(), deltaPos.y());
m_lastMousePos = event->pos();
event->accept();
}
else {
event->ignore();
}
}
void InteractiveQChart::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
if (event->buttons() == Qt::RightButton) {
m_buttonPressed = false;
m_lastMousePos = QPointF(0,0);
event->accept();
}
else {
event->ignore();
}
}