Mercurial > hg > easaier-soundaccess
comparison widgets/Plotter.cpp @ 235:7ab3e81f52d4
enable/disable alternatively draw curve and simple mode in the equalizer filter
author | lbajardsilogic |
---|---|
date | Fri, 07 Mar 2008 15:01:27 +0000 |
parents | 628531da16ef |
children | 858a1121ebf7 |
comparison
equal
deleted
inserted
replaced
234:cff926c60430 | 235:7ab3e81f52d4 |
---|---|
17 | 17 |
18 Plotter::Plotter(QWidget *parent): | 18 Plotter::Plotter(QWidget *parent): |
19 m_signalWidth(400), | 19 m_signalWidth(400), |
20 m_signalHeight(120), | 20 m_signalHeight(120), |
21 m_margin(5), | 21 m_margin(5), |
22 m_curveMaskActive(false) | 22 m_curveMaskActive(false), |
23 m_enableDrawCurve(false) | |
23 { | 24 { |
24 //m_curveMask = new int[m_signalWidth]; | 25 //m_curveMask = new int[m_signalWidth]; |
25 for(int i = 0 ; i < m_signalWidth ; i++){ | 26 for(int i = 0 ; i < m_signalWidth ; i++){ |
26 m_curveMask.push_back(0); | 27 m_curveMask.push_back(0); |
27 } | 28 } |
64 | 65 |
65 void Plotter::mousePressEvent(QMouseEvent *event){ | 66 void Plotter::mousePressEvent(QMouseEvent *event){ |
66 QRect rect(m_margin, m_margin, | 67 QRect rect(m_margin, m_margin, |
67 m_signalWidth + m_margin, m_signalHeight + m_margin); | 68 m_signalWidth + m_margin, m_signalHeight + m_margin); |
68 | 69 |
69 if (event->button() == Qt::LeftButton) { | 70 if (m_enableDrawCurve) |
70 if (rect.contains(event->pos())) { | 71 { |
71 m_curveMaskActive = true; | 72 if (event->button() == Qt::LeftButton) { |
72 int x = event->pos().x()- m_margin; | 73 if (rect.contains(event->pos())) { |
73 int y = event->pos().y()- m_margin; | 74 m_curveMaskActive = true; |
75 int x = event->pos().x()- m_margin; | |
76 int y = event->pos().y()- m_margin; | |
77 m_curveMask[x] = y; | |
78 m_lastPoint.setX(x); | |
79 m_lastPoint.setY(y); | |
80 setCursor(Qt::CrossCursor); | |
81 refreshPixmap(); | |
82 } | |
83 } | |
84 } | |
85 } | |
86 | |
87 void Plotter::mouseMoveEvent(QMouseEvent *event){ | |
88 QRect rect(m_margin, m_margin, | |
89 m_signalWidth + m_margin , m_signalHeight + m_margin); | |
90 | |
91 if (m_enableDrawCurve) | |
92 { | |
93 if(m_curveMaskActive && rect.contains(event->pos())){ | |
94 int x = event->pos().x() - m_margin; | |
95 int y = event->pos().y() - m_margin; | |
96 if(y>m_signalHeight-1) | |
97 y= m_signalHeight-1; | |
98 if(x>m_signalWidth-1) | |
99 y= m_signalWidth-1; | |
100 int xlast = m_lastPoint.x(); | |
101 int ylast = m_lastPoint.y(); | |
102 | |
103 //regul mask curve | |
104 int minx, maxx, miny, maxy; | |
105 if(x>xlast){ | |
106 minx = xlast; | |
107 maxx = x; | |
108 }else{ | |
109 minx = x; | |
110 maxx = xlast; | |
111 } | |
112 if(y>ylast){ | |
113 miny = ylast; | |
114 maxy = y; | |
115 }else{ | |
116 miny = y; | |
117 maxy = ylast; | |
118 } | |
119 | |
120 if((maxx - minx)>1){ | |
121 double incr = (double)(maxy - miny)/(double)(maxx - minx); | |
122 if(x>xlast){ | |
123 for (int i = xlast + 1 ; i < x ; i++){ | |
124 if(ylast > y){ | |
125 m_curveMask[i] = ylast - (i-xlast)*incr; | |
126 }else{ | |
127 m_curveMask[i] = ylast + (i-xlast)*incr; | |
128 } | |
129 } | |
130 }else{ | |
131 for (int i = xlast - 1 ; i > x ; i--){ | |
132 if(ylast > y){ | |
133 m_curveMask[i] = ylast + (i-xlast)*incr; | |
134 }else{ | |
135 m_curveMask[i] = ylast - (i-xlast)*incr; | |
136 } | |
137 } | |
138 } | |
139 } | |
74 m_curveMask[x] = y; | 140 m_curveMask[x] = y; |
75 m_lastPoint.setX(x); | 141 m_lastPoint.setX(x); |
76 m_lastPoint.setY(y); | 142 m_lastPoint.setY(y); |
77 setCursor(Qt::CrossCursor); | |
78 refreshPixmap(); | 143 refreshPixmap(); |
79 } | |
80 } | |
81 } | |
82 | |
83 void Plotter::mouseMoveEvent(QMouseEvent *event){ | |
84 QRect rect(m_margin, m_margin, | |
85 m_signalWidth + m_margin , m_signalHeight + m_margin); | |
86 | |
87 if(m_curveMaskActive && rect.contains(event->pos())){ | |
88 int x = event->pos().x() - m_margin; | |
89 int y = event->pos().y() - m_margin; | |
90 if(y>m_signalHeight-1) | |
91 y= m_signalHeight-1; | |
92 if(x>m_signalWidth-1) | |
93 y= m_signalWidth-1; | |
94 int xlast = m_lastPoint.x(); | |
95 int ylast = m_lastPoint.y(); | |
96 | |
97 //regul mask curve | |
98 int minx, maxx, miny, maxy; | |
99 if(x>xlast){ | |
100 minx = xlast; | |
101 maxx = x; | |
102 }else{ | |
103 minx = x; | |
104 maxx = xlast; | |
105 } | 144 } |
106 if(y>ylast){ | 145 } |
107 miny = ylast; | 146 } |
108 maxy = y; | 147 |
109 }else{ | 148 void Plotter::mouseReleaseEvent(QMouseEvent *event){ |
110 miny = y; | 149 if (m_enableDrawCurve) |
111 maxy = ylast; | 150 { |
151 if ((event->button() == Qt::LeftButton) && m_curveMaskActive) { | |
152 m_curveMaskActive = false; | |
153 unsetCursor(); | |
154 emit filterChanged(m_curveMask); | |
112 } | 155 } |
113 | 156 } |
114 if((maxx - minx)>1){ | |
115 double incr = (double)(maxy - miny)/(double)(maxx - minx); | |
116 if(x>xlast){ | |
117 for (int i = xlast + 1 ; i < x ; i++){ | |
118 if(ylast > y){ | |
119 m_curveMask[i] = ylast - (i-xlast)*incr; | |
120 }else{ | |
121 m_curveMask[i] = ylast + (i-xlast)*incr; | |
122 } | |
123 } | |
124 }else{ | |
125 for (int i = xlast - 1 ; i > x ; i--){ | |
126 if(ylast > y){ | |
127 m_curveMask[i] = ylast + (i-xlast)*incr; | |
128 }else{ | |
129 m_curveMask[i] = ylast - (i-xlast)*incr; | |
130 } | |
131 } | |
132 } | |
133 } | |
134 m_curveMask[x] = y; | |
135 m_lastPoint.setX(x); | |
136 m_lastPoint.setY(y); | |
137 refreshPixmap(); | |
138 } | |
139 } | |
140 | |
141 void Plotter::mouseReleaseEvent(QMouseEvent *event){ | |
142 if ((event->button() == Qt::LeftButton) && m_curveMaskActive) { | |
143 m_curveMaskActive = false; | |
144 unsetCursor(); | |
145 emit filterChanged(m_curveMask); | |
146 } | |
147 } | 157 } |
148 | 158 |
149 void Plotter::drawGrid(QPainter *painter){ | 159 void Plotter::drawGrid(QPainter *painter){ |
150 QPixmap pm(":icons/grid.png"); | 160 QPixmap pm(":icons/grid.png"); |
151 painter->drawPixmap(0,0,pm); | 161 painter->drawPixmap(0,0,pm); |
203 { | 213 { |
204 m_curveMask.push_back((int) (m_signalHeight - filter[i]*(m_signalHeight/2-1))); | 214 m_curveMask.push_back((int) (m_signalHeight - filter[i]*(m_signalHeight/2-1))); |
205 } | 215 } |
206 refreshPixmap(); | 216 refreshPixmap(); |
207 } | 217 } |
218 | |
219 void Plotter::enableDrawCurve(bool enable) | |
220 { | |
221 m_enableDrawCurve = enable; | |
222 } |