forked from githubdoe/DFTFringe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastigzoomer.cpp
54 lines (44 loc) · 1.47 KB
/
astigzoomer.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
#include "astigzoomer.h"
#include <qwt_scale_map.h>
#include <qwt_plot.h>
#include <qwt_plot_marker.h>
#include <QtMath>
astigZoomer::astigZoomer( QWidget *canvas, QwtPlot * plot ):
QwtPlotZoomer( canvas ),mPlot(plot)
{
setRubberBandPen( QColor( Qt::lightGray ) );
setTrackerMode( QwtPlotPicker::AlwaysOn );
}
QwtText astigZoomer::trackerTextF( const QPointF &p ) const
{
QString s("");
const QwtScaleMap xMap = mPlot->canvasMap(2);
const QwtScaleMap yMap = mPlot->canvasMap(QwtPlot::yLeft);
const double cx = xMap.transform( p.x());
const double cy = yMap.transform(p.y());
const QwtPlotItemList& itmList = mPlot->itemList();
for ( QwtPlotItemIterator it = itmList.begin();
it != itmList.end(); ++it )
{
if (( *it )->rtti() == QwtPlotItem::Rtti_PlotMarker){
QwtPlotMarker *mark = static_cast<QwtPlotMarker *>( *it );
QPointF pm = mark->value();
double delx = cx - xMap.transform(pm.x());
double dely = cy - yMap.transform(pm.y());
double r = qSqrt(delx * delx + dely * dely);
if (r < 4) {
s = mark->title().text();
break;
}
}
}
QwtText text( s );
text.setColor( Qt::black );
text.setFont(QFont("Arial",12));
QColor c = rubberBandPen().color();
text.setBorderPen( QPen( c ) );
text.setBorderRadius( 6 );
c.setAlpha( 170 );
text.setBackgroundBrush( c );
return text;
}