-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomPlotZoom.cpp
More file actions
105 lines (92 loc) · 3.1 KB
/
CustomPlotZoom.cpp
File metadata and controls
105 lines (92 loc) · 3.1 KB
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
100
101
102
103
104
105
#include <QRubberBand>
#include "CustomPlotZoom.h"
CustomPlotZoom::CustomPlotZoom(QCustomPlot * parent)
: mZoomMode(false)
{
qP = parent;
mRubberBand = new QRubberBand(QRubberBand::Rectangle, qP);
}
CustomPlotZoom::~CustomPlotZoom()
{
delete mRubberBand;
}
void CustomPlotZoom::setZoomMode(bool mode)
{
mZoomMode = mode;
}
void CustomPlotZoom::mousePressEvent(QMouseEvent * event)
{
if (event->button() == Qt::RightButton)
{
mOrigin = event->pos();
mRubberBand->setGeometry(QRect(mOrigin, QSize()));
mRubberBand->show();
}
QCustomPlot::mousePressEvent(event);
}
void CustomPlotZoom::mouseMoveEvent(QMouseEvent * event)
{
if (mRubberBand->isVisible())
{
mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized());
}
QCustomPlot::mouseMoveEvent(event);
}
void CustomPlotZoom::mouseReleaseEvent(QMouseEvent * event)
{
if (mRubberBand->isVisible())
{
const QRect & zoomRect = mRubberBand->geometry();
int xp1, yp1, xp2, yp2;
zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
auto x1 = qP->xAxis->pixelToCoord(xp1);
auto x2 = qP->xAxis->pixelToCoord(xp2);
auto y1 = qP->yAxis->pixelToCoord(yp1);
auto y2 = qP->yAxis->pixelToCoord(yp2);
qP->xAxis->setRange(x1, x2);
qP->yAxis->setRange(y1, y2);
mRubberBand->hide();
qP->replot();
}
QCustomPlot::mouseReleaseEvent(event);
}
SelectEl::SelectEl(QCustomPlot * parent, QVector<double> &d)
:data(d),
Selected(-1)
{
qP = parent;
mRubberBand = new QRubberBand(QRubberBand::Rectangle, qP);
}
void SelectEl::setSelect(int el)
{
Selected=el;
}
void SelectEl::mousePressEvent(QMouseEvent * event)
{
// qWarning()<<event->pos().x()<<event->pos().y()<<
// qP->xAxis->coordToPixel(qP->xAxis->range().size())<<
// qP->yAxis->coordToPixel(data[(int)qP->xAxis->pixelToCoord(event->pos().x())]);
if (event->button() == Qt::LeftButton&&
event->pos().x()>qP->xAxis->coordToPixel(0)&&
event->pos().x()<qP->xAxis->coordToPixel(qP->xAxis->range().size())&&
event->pos().y()<qP->yAxis->coordToPixel(0)&&
event->pos().y()>qP->yAxis->coordToPixel(data[(int)qP->xAxis->pixelToCoord(event->pos().x())])
)
{
if(Selected==(int)qP->xAxis->pixelToCoord(event->pos().x())){
mRubberBand->hide();
Selected=-1;
}
else{
QPoint mOrigin1 = QPoint(qP->xAxis->coordToPixel((int)qP->xAxis->pixelToCoord(event->pos().x())),
qP->yAxis->coordToPixel(data[(int)qP->xAxis->pixelToCoord(event->pos().x())]));
QPoint mOrigin2 = QPoint(qP->xAxis->coordToPixel(1+(int)qP->xAxis->pixelToCoord(event->pos().x())),
qP->yAxis->coordToPixel(0));
mRubberBand->setGeometry(QRect(mOrigin1, mOrigin2));
mRubberBand->show();
Selected = (int)qP->xAxis->pixelToCoord(event->pos().x());
}
// QCPBarData a=tmp->data()->value(0.5);
}
QCustomPlot::mousePressEvent(event);
}