Mercurial > hg > easaier-soundaccess
comparison widgets/Plotter.cpp @ 231:fd17abdbef2d
plotter with the curve inside (not a good version)
author | benoitrigolleau |
---|---|
date | Thu, 06 Mar 2008 14:50:00 +0000 |
parents | 7d5d51145b81 |
children | 70b88fbbfb5c |
comparison
equal
deleted
inserted
replaced
230:3c473495403f | 231:fd17abdbef2d |
---|---|
10 License, or (at your option) any later version. See the file | 10 License, or (at your option) any later version. See the file |
11 COPYING included with this distribution for more information. | 11 COPYING included with this distribution for more information. |
12 */ | 12 */ |
13 | 13 |
14 #include "Plotter.h" | 14 #include "Plotter.h" |
15 #include <math.h> | |
15 #include <QtGui> | 16 #include <QtGui> |
16 | 17 |
17 Plotter::Plotter(QWidget *parent): | 18 Plotter::Plotter(QWidget *parent): |
18 m_signalWidth(400), | 19 m_signalWidth(400), |
19 m_signalHeight(180), | 20 m_signalHeight(180), |
22 { | 23 { |
23 //m_curveMask = new int[m_signalWidth]; | 24 //m_curveMask = new int[m_signalWidth]; |
24 for(int i = 0 ; i < m_signalWidth ; i++){ | 25 for(int i = 0 ; i < m_signalWidth ; i++){ |
25 m_curveMask.push_back(0); | 26 m_curveMask.push_back(0); |
26 } | 27 } |
27 | |
28 | |
29 m_curve.push_back(QPoint(399,179)); | |
30 m_curve.push_back(QPoint(300,20)); | |
31 m_curve.push_back(QPoint(60,150)); | |
32 m_curve.push_back(QPoint(10,30)); | |
33 m_curve.push_back(QPoint(0,0)); | |
34 | 28 |
35 setMinimumSize(QSize(m_signalWidth + 10, m_signalHeight + 10)); | 29 setMinimumSize(QSize(m_signalWidth + 10, m_signalHeight + 10)); |
36 | 30 |
37 refreshPixmap(); | 31 refreshPixmap(); |
38 | 32 |
44 } | 38 } |
45 | 39 |
46 void Plotter::setCurve(float * curve) | 40 void Plotter::setCurve(float * curve) |
47 { | 41 { |
48 m_curve.clear(); | 42 m_curve.clear(); |
49 for (int i=0; i< 400; i++) | 43 for (int i=0; i< m_signalWidth; i++) |
50 { | 44 { |
51 m_curve.push_back(QPoint(i, curve[i])); | 45 m_curve.push_back(QPoint(i, curve[i])); |
52 } | 46 } |
53 refreshPixmap(); | 47 refreshPixmap(); |
54 } | 48 } |
92 if(m_curveMaskActive && rect.contains(event->pos())){ | 86 if(m_curveMaskActive && rect.contains(event->pos())){ |
93 int x = event->pos().x() - m_margin; | 87 int x = event->pos().x() - m_margin; |
94 int y = event->pos().y() - m_margin; | 88 int y = event->pos().y() - m_margin; |
95 if(y>m_signalHeight-1) | 89 if(y>m_signalHeight-1) |
96 y= m_signalHeight-1; | 90 y= m_signalHeight-1; |
91 if(x>m_signalWidth-1) | |
92 y= m_signalWidth-1; | |
97 int xlast = m_lastPoint.x(); | 93 int xlast = m_lastPoint.x(); |
98 int ylast = m_lastPoint.y(); | 94 int ylast = m_lastPoint.y(); |
99 | 95 |
100 //regul mask curve | 96 //regul mask curve |
101 int minx, maxx, miny, maxy; | 97 int minx, maxx, miny, maxy; |
153 QPixmap pm(":icons/grid.png"); | 149 QPixmap pm(":icons/grid.png"); |
154 painter->drawPixmap(0,0,pm); | 150 painter->drawPixmap(0,0,pm); |
155 } | 151 } |
156 | 152 |
157 void Plotter::drawCurve(QPainter *painter){ | 153 void Plotter::drawCurve(QPainter *painter){ |
158 painter->setRenderHint (QPainter::Antialiasing, true ); | 154 //painter->setRenderHint (QPainter::Antialiasing, true ); |
159 QPolygonF polyline(m_signalWidth); | 155 QPolygonF polyline(m_signalWidth); |
156 | |
160 for(int i = 0 ; i < m_curve.count() ; i++){ | 157 for(int i = 0 ; i < m_curve.count() ; i++){ |
161 polyline[i] = QPoint(m_curve.at(i).x()+m_margin, m_curve.at(i).y()+m_margin); | 158 int m=-(1*floor((m_curve.at(i).y()/0.1))); // Calculates pixel coordinate and Plots FFT (in green) |
159 if (m>m_signalHeight){m = m_signalHeight;} | |
160 if (m<0){m = 0;} | |
161 int y= m_signalHeight - m; | |
162 polyline[i] = QPoint(m_curve.at(i).x() + m_margin, /*m_curve.at(i).y()*/y + m_margin); | |
162 } | 163 } |
164 | |
163 painter->setPen(Qt::green); | 165 painter->setPen(Qt::green); |
164 painter->drawPolyline(polyline); | 166 painter->drawPolyline(polyline); |
165 } | 167 } |
166 | 168 |
167 void Plotter::drawMaskCurve(QPainter *painter){ | 169 void Plotter::drawMaskCurve(QPainter *painter){ |