forked from uqzzhao/Hodogram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoomer.cpp
96 lines (81 loc) · 2.03 KB
/
zoomer.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
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
#include "Zoomer.h"
#include "qwt_scale_widget.h"
#include "qwt_plot.h"
Zoomer::Zoomer(QwtPlotCanvas *canvas,QRectF rect, bool bDir):
QwtPlotZoomer(canvas)
{
m_bDir = bDir;
m_rect = rect.normalized();
}
void Zoomer::rescale()
{
QwtScaleWidget *scaleWidget = plot()->axisWidget(yAxis());
QwtScaleDraw *sd = scaleWidget->scaleDraw();
int minExtent = 0;
if ( zoomRectIndex() > 0 )
{
// When scrolling in vertical direction
// the plot is jumping in horizontal direction
// because of the different widths of the labels
// So we better use a fixed extent.
minExtent = sd->spacing() + 1;//+ sd->majTickLength()
minExtent += sd->labelSize(
scaleWidget->font(), c_rangeMax).width();
}
sd->setMinimumExtent(minExtent);
QwtPlotZoomer::rescale();
}
void Zoomer::updateRange(QRectF rect)
{
m_rect = rect.normalized();
}
void Zoomer::zoom( const QRectF &rect )
{
QRectF zoomRect = rect.normalized();
QwtPlot *plot = QwtPlotZoomer::plot();
if ( !plot )
return;
QPointF lt = zoomRect.topLeft();
QPointF rb = zoomRect.bottomRight();
if(m_bDir)
{
lt.setY(m_rect.top());
rb.setY(m_rect.bottom());
if(lt.x()-m_rect.left()<1e-10)
lt.setX(m_rect.left());
if(rb.x()-m_rect.left()<1e-10)
rb.setX(m_rect.left());
if(lt.x()-m_rect.right()>1e-10)
lt.setX(m_rect.right());
if(rb.x()-m_rect.right()>1e-10)
rb.setX(m_rect.right());
QRectF zoom(lt,rb);
QwtPlotZoomer::zoom(zoom);
}
else
{
lt.setX(m_rect.left());
rb.setX(m_rect.right());
if(lt.y()-m_rect.top()<1e-10)
lt.setY(m_rect.top());
if(rb.y()-m_rect.top()<1e-10)
rb.setY(m_rect.top());
if(lt.y()-m_rect.bottom()>1e-10)
lt.setY(m_rect.bottom());
if(rb.y()-m_rect.bottom()>1e-10)
rb.setY(m_rect.bottom());
QRectF zoom(lt,rb);
QwtPlotZoomer::zoom(zoom);
}
plot->replot();
}
void Zoomer::zoom( int up )
{
QwtPlotZoomer::zoom(up);
QwtPlot *plot = QwtPlotZoomer::plot();
plot->replot();
}
void Zoomer::setRect(QRectF rect)
{
m_rect=rect;
}