qavrg 0.0.28
|
00001 #include "qavrgmeasurer.h" 00002 //#include <qwt_data.h> 00003 #include <stdio.h> 00004 00005 QavrgMeasurer::QavrgMeasurer(int xAxis, int yAxis, QWidget *canvas) 00006 : QwtPlotPicker(xAxis, yAxis, canvas), 00007 m_StartPoint(), 00008 m_Started(false) 00009 { 00010 connections(); 00011 } 00012 00013 void QavrgMeasurer::connections() 00014 { 00015 connect(this, SIGNAL(appended(const QPointF&)), 00016 this, SLOT(onAppended(const QPointF&))); 00017 00018 connect(this, SIGNAL(selected(const QVector<QPointF>&)), 00019 this, SLOT(onSelected(const QVector<QPointF>&))); 00020 } 00021 00022 QwtText QavrgMeasurer::trackerText(const QPointF &pos) const 00023 { 00024 QwtText res; 00025 00026 if (m_Started) { 00027 res = QwtText(tr("Start %1,%2\nEnd %3,%4\nDelta %5,%6") 00028 .arg(m_StartPoint.x()) 00029 .arg(m_StartPoint.y()) 00030 .arg(pos.x()) 00031 .arg(pos.y()) 00032 .arg(pos.x()-m_StartPoint.x()) 00033 .arg(pos.y()-m_StartPoint.y())); 00034 } else { 00035 res = QwtText(tr("%1,%2") 00036 .arg(pos.x()) 00037 .arg(pos.y())); 00038 } 00039 00040 res.setColor(Qt::black); 00041 // res.setBackgroundPen(QPen(Qt::white)); 00042 res.setBackgroundBrush(QBrush(Qt::white, Qt::SolidPattern)); 00043 00044 // QFont font; 00045 // font.setPointSize(7); 00046 // res.setFont(font); 00047 return res; 00048 } 00049 00050 void QavrgMeasurer::onAppended(const QPointF &pt) 00051 { 00052 // printf("appended %g,%g\n", pt.x(), pt.y()); 00053 m_StartPoint = pt; 00054 m_Started = true; 00055 } 00056 00057 void QavrgMeasurer::onSelected(const QVector<QPointF> &poly) 00058 { 00059 // printf("selected\n"); 00060 m_Started = false; 00061 00062 QPointF pos = poly[1]; 00063 00064 emit printMessage(tr("Start (%1,%2) End (%3,%4) Delta (%5,%6)") 00065 .arg(m_StartPoint.x()) 00066 .arg(m_StartPoint.y()) 00067 .arg(pos.x()) 00068 .arg(pos.y()) 00069 .arg(pos.x()-m_StartPoint.x()) 00070 .arg(pos.y()-m_StartPoint.y())); 00071 }