Mercurial > hg > svgui
comparison widgets/AudioDial.cpp @ 1266:a34a2a25907c
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 1badacff7ab2 |
children | c8a6fd3f9dff |
comparison
equal
deleted
inserted
replaced
1265:6e724c81f18f | 1266:a34a2a25907c |
---|---|
120 Profiler profiler("AudioDial::paintEvent"); | 120 Profiler profiler("AudioDial::paintEvent"); |
121 | 121 |
122 QPainter paint; | 122 QPainter paint; |
123 | 123 |
124 double angle = AUDIO_DIAL_MIN // offset | 124 double angle = AUDIO_DIAL_MIN // offset |
125 + (AUDIO_DIAL_RANGE * | 125 + (AUDIO_DIAL_RANGE * |
126 (double(QDial::value() - QDial::minimum()) / | 126 (double(QDial::value() - QDial::minimum()) / |
127 (double(QDial::maximum() - QDial::minimum())))); | 127 (double(QDial::maximum() - QDial::minimum())))); |
128 int degrees = int(angle * 180.0 / M_PI); | 128 int degrees = int(angle * 180.0 / M_PI); |
129 | 129 |
130 int ns = notchSize(); | 130 int ns = notchSize(); |
131 int numTicks = 1 + (maximum() + ns - minimum()) / ns; | 131 int numTicks = 1 + (maximum() + ns - minimum()) / ns; |
132 | 132 |
133 QColor knobColor(m_knobColor); | 133 QColor knobColor(m_knobColor); |
134 if (knobColor == Qt::black) | 134 if (knobColor == Qt::black) |
135 knobColor = palette().window().color(); | 135 knobColor = palette().window().color(); |
136 | 136 |
137 QColor meterColor(m_meterColor); | 137 QColor meterColor(m_meterColor); |
138 if (!isEnabled()) | 138 if (!isEnabled()) |
139 meterColor = palette().mid().color(); | 139 meterColor = palette().mid().color(); |
140 else if (m_meterColor == Qt::white) | 140 else if (m_meterColor == Qt::white) |
141 meterColor = palette().highlight().color(); | 141 meterColor = palette().highlight().color(); |
142 | 142 |
143 int m_size = width() < height() ? width() : height(); | 143 int m_size = width() < height() ? width() : height(); |
144 int scale = 1; | 144 int scale = 1; |
145 int width = m_size - 2*scale; | 145 int width = m_size - 2*scale; |
146 | 146 |
155 | 155 |
156 c = knobColor; | 156 c = knobColor; |
157 pen.setColor(knobColor); | 157 pen.setColor(knobColor); |
158 pen.setWidth(scale * 2); | 158 pen.setWidth(scale * 2); |
159 pen.setCapStyle(Qt::FlatCap); | 159 pen.setCapStyle(Qt::FlatCap); |
160 | 160 |
161 paint.setPen(pen); | 161 paint.setPen(pen); |
162 paint.setBrush(c); | 162 paint.setBrush(c); |
163 | 163 |
164 int indent = (int)(width * 0.15 + 1); | 164 int indent = (int)(width * 0.15 + 1); |
165 | 165 |
167 | 167 |
168 pen.setWidth(3 * scale); | 168 pen.setWidth(3 * scale); |
169 int pos = indent-1 + (width-2*indent) / 20; | 169 int pos = indent-1 + (width-2*indent) / 20; |
170 int darkWidth = (width-2*indent) * 3 / 4; | 170 int darkWidth = (width-2*indent) * 3 / 4; |
171 while (darkWidth) { | 171 while (darkWidth) { |
172 c = c.light(102); | 172 c = c.light(102); |
173 pen.setColor(c); | 173 pen.setColor(c); |
174 paint.setPen(pen); | 174 paint.setPen(pen); |
175 paint.drawEllipse(pos, pos, darkWidth, darkWidth); | 175 paint.drawEllipse(pos, pos, darkWidth, darkWidth); |
176 if (!--darkWidth) break; | 176 if (!--darkWidth) break; |
177 paint.drawEllipse(pos, pos, darkWidth, darkWidth); | 177 paint.drawEllipse(pos, pos, darkWidth, darkWidth); |
178 if (!--darkWidth) break; | 178 if (!--darkWidth) break; |
179 paint.drawEllipse(pos, pos, darkWidth, darkWidth); | 179 paint.drawEllipse(pos, pos, darkWidth, darkWidth); |
180 ++pos; --darkWidth; | 180 ++pos; --darkWidth; |
181 } | 181 } |
182 | 182 |
183 // Tick notches... | 183 // Tick notches... |
184 | 184 |
185 if ( notchesVisible() ) { | 185 if ( notchesVisible() ) { |
186 // cerr << "Notches visible" << endl; | 186 // cerr << "Notches visible" << endl; |
187 pen.setColor(palette().dark().color()); | 187 pen.setColor(palette().dark().color()); |
188 pen.setWidth(scale); | 188 pen.setWidth(scale); |
189 paint.setPen(pen); | 189 paint.setPen(pen); |
190 for (int i = 0; i < numTicks; ++i) { | 190 for (int i = 0; i < numTicks; ++i) { |
191 int div = numTicks; | 191 int div = numTicks; |
192 if (div > 1) --div; | 192 if (div > 1) --div; |
193 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div, | 193 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div, |
194 width, true); | 194 width, true); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 // The bright metering bit... | 198 // The bright metering bit... |
199 | 199 |
200 c = meterColor; | 200 c = meterColor; |
206 | 206 |
207 int arcLen = -(degrees - 45) * 16; | 207 int arcLen = -(degrees - 45) * 16; |
208 if (arcLen == 0) arcLen = -16; | 208 if (arcLen == 0) arcLen = -16; |
209 | 209 |
210 paint.drawArc(indent/2, indent/2, | 210 paint.drawArc(indent/2, indent/2, |
211 width-indent, width-indent, (180 + 45) * 16, arcLen); | 211 width-indent, width-indent, (180 + 45) * 16, arcLen); |
212 | 212 |
213 paint.setBrush(Qt::NoBrush); | 213 paint.setBrush(Qt::NoBrush); |
214 | 214 |
215 // Shadowing... | 215 // Shadowing... |
216 | 216 |
220 // Knob shadow... | 220 // Knob shadow... |
221 | 221 |
222 int shadowAngle = -720; | 222 int shadowAngle = -720; |
223 c = knobColor.dark(); | 223 c = knobColor.dark(); |
224 for (int arc = 120; arc < 2880; arc += 240) { | 224 for (int arc = 120; arc < 2880; arc += 240) { |
225 pen.setColor(c); | 225 pen.setColor(c); |
226 paint.setPen(pen); | 226 paint.setPen(pen); |
227 paint.drawArc(indent, indent, | 227 paint.drawArc(indent, indent, |
228 width-2*indent, width-2*indent, shadowAngle + arc, 240); | 228 width-2*indent, width-2*indent, shadowAngle + arc, 240); |
229 paint.drawArc(indent, indent, | 229 paint.drawArc(indent, indent, |
230 width-2*indent, width-2*indent, shadowAngle - arc, 240); | 230 width-2*indent, width-2*indent, shadowAngle - arc, 240); |
231 c = c.light(110); | 231 c = c.light(110); |
232 } | 232 } |
233 | 233 |
234 // Scale shadow, omitting the bottom part... | 234 // Scale shadow, omitting the bottom part... |
235 | 235 |
236 shadowAngle = 2160; | 236 shadowAngle = 2160; |
237 c = palette().shadow().color(); | 237 c = palette().shadow().color(); |
238 for (int i = 0; i < 5; ++i) { | 238 for (int i = 0; i < 5; ++i) { |
239 pen.setColor(c); | 239 pen.setColor(c); |
240 paint.setPen(pen); | 240 paint.setPen(pen); |
241 int arc = i * 240 + 120; | 241 int arc = i * 240 + 120; |
242 paint.drawArc(scale/2, scale/2, | 242 paint.drawArc(scale/2, scale/2, |
243 width-scale, width-scale, shadowAngle + arc, 240); | 243 width-scale, width-scale, shadowAngle + arc, 240); |
244 c = c.light(110); | 244 c = c.light(110); |
245 } | 245 } |
246 c = palette().shadow().color(); | 246 c = palette().shadow().color(); |
247 for (int i = 0; i < 12; ++i) { | 247 for (int i = 0; i < 12; ++i) { |
248 pen.setColor(c); | 248 pen.setColor(c); |
249 paint.setPen(pen); | 249 paint.setPen(pen); |
250 int arc = i * 240 + 120; | 250 int arc = i * 240 + 120; |
251 paint.drawArc(scale/2, scale/2, | 251 paint.drawArc(scale/2, scale/2, |
252 width-scale, width-scale, shadowAngle - arc, 240); | 252 width-scale, width-scale, shadowAngle - arc, 240); |
253 c = c.light(110); | 253 c = c.light(110); |
254 } | 254 } |
255 | 255 |
256 // Scale ends... | 256 // Scale ends... |
257 | 257 |
258 pen.setColor(palette().shadow().color()); | 258 pen.setColor(palette().shadow().color()); |
259 pen.setWidth(scale); | 259 pen.setWidth(scale); |
260 paint.setPen(pen); | 260 paint.setPen(pen); |
261 for (int i = 0; i < numTicks; ++i) { | 261 for (int i = 0; i < numTicks; ++i) { |
262 if (i != 0 && i != numTicks - 1) continue; | 262 if (i != 0 && i != numTicks - 1) continue; |
263 int div = numTicks; | 263 int div = numTicks; |
264 if (div > 1) --div; | 264 if (div > 1) --div; |
265 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div, | 265 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div, |
266 width, false); | 266 width, false); |
267 } | 267 } |
268 | 268 |
269 // Pointer notch... | 269 // Pointer notch... |
270 | 270 |
271 double hyp = double(width) / 2.0; | 271 double hyp = double(width) / 2.0; |
287 paint.end(); | 287 paint.end(); |
288 } | 288 } |
289 | 289 |
290 | 290 |
291 void AudioDial::drawTick(QPainter &paint, | 291 void AudioDial::drawTick(QPainter &paint, |
292 double angle, int size, bool internal) | 292 double angle, int size, bool internal) |
293 { | 293 { |
294 double hyp = double(size) / 2.0; | 294 double hyp = double(size) / 2.0; |
295 double x0 = hyp - (hyp - 1) * sin(angle); | 295 double x0 = hyp - (hyp - 1) * sin(angle); |
296 double y0 = hyp + (hyp - 1) * cos(angle); | 296 double y0 = hyp + (hyp - 1) * cos(angle); |
297 | 297 |
298 // cerr << "drawTick: angle " << angle << ", size " << size << ", internal " << internal << endl; | 298 // cerr << "drawTick: angle " << angle << ", size " << size << ", internal " << internal << endl; |
299 | 299 |
300 if (internal) { | 300 if (internal) { |
301 | 301 |
302 double len = hyp / 4; | 302 double len = hyp / 4; |
303 double x1 = hyp - (hyp - len) * sin(angle); | 303 double x1 = hyp - (hyp - len) * sin(angle); |
304 double y1 = hyp + (hyp - len) * cos(angle); | 304 double y1 = hyp + (hyp - len) * cos(angle); |
305 | 305 |
306 paint.drawLine(int(x0), int(y0), int(x1), int(y1)); | 306 paint.drawLine(int(x0), int(y0), int(x1), int(y1)); |
307 | 307 |
308 } else { | 308 } else { |
309 | 309 |
310 double len = hyp / 4; | 310 double len = hyp / 4; |
311 double x1 = hyp - (hyp + len) * sin(angle); | 311 double x1 = hyp - (hyp + len) * sin(angle); |
312 double y1 = hyp + (hyp + len) * cos(angle); | 312 double y1 = hyp + (hyp + len) * cos(angle); |
313 | 313 |
314 paint.drawLine(int(x0), int(y0), int(x1), int(y1)); | 314 paint.drawLine(int(x0), int(y0), int(x1), int(y1)); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 | 318 |
319 void AudioDial::setKnobColor(const QColor& color) | 319 void AudioDial::setKnobColor(const QColor& color) |
450 | 450 |
451 // Alternate mouse behavior event handlers. | 451 // Alternate mouse behavior event handlers. |
452 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) | 452 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) |
453 { | 453 { |
454 if (m_mouseDial) { | 454 if (m_mouseDial) { |
455 QDial::mousePressEvent(mouseEvent); | 455 QDial::mousePressEvent(mouseEvent); |
456 } else if (mouseEvent->button() == Qt::MidButton || | 456 } else if (mouseEvent->button() == Qt::MidButton || |
457 ((mouseEvent->button() == Qt::LeftButton) && | 457 ((mouseEvent->button() == Qt::LeftButton) && |
458 (mouseEvent->modifiers() & Qt::ControlModifier))) { | 458 (mouseEvent->modifiers() & Qt::ControlModifier))) { |
459 setToDefault(); | 459 setToDefault(); |
460 } else if (mouseEvent->button() == Qt::LeftButton) { | 460 } else if (mouseEvent->button() == Qt::LeftButton) { |
461 m_mousePressed = true; | 461 m_mousePressed = true; |
462 m_posMouse = mouseEvent->pos(); | 462 m_posMouse = mouseEvent->pos(); |
463 } | 463 } |
464 } | 464 } |
465 | 465 |
466 | 466 |
467 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) | 467 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) |
468 { | 468 { |
469 //!!! needs a common base class with Thumbwheel | 469 //!!! needs a common base class with Thumbwheel |
470 | 470 |
471 if (m_mouseDial) { | 471 if (m_mouseDial) { |
472 QDial::mouseDoubleClickEvent(mouseEvent); | 472 QDial::mouseDoubleClickEvent(mouseEvent); |
473 } else if (mouseEvent->button() != Qt::LeftButton) { | 473 } else if (mouseEvent->button() != Qt::LeftButton) { |
474 return; | 474 return; |
475 } | 475 } |
476 | 476 |
477 bool ok = false; | 477 bool ok = false; |
539 | 539 |
540 | 540 |
541 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent) | 541 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent) |
542 { | 542 { |
543 if (m_mouseDial) { | 543 if (m_mouseDial) { |
544 QDial::mouseMoveEvent(mouseEvent); | 544 QDial::mouseMoveEvent(mouseEvent); |
545 } else if (m_mousePressed) { | 545 } else if (m_mousePressed) { |
546 const QPoint& posMouse = mouseEvent->pos(); | 546 const QPoint& posMouse = mouseEvent->pos(); |
547 int v = QDial::value() | 547 int v = QDial::value() |
548 + (posMouse.x() - m_posMouse.x()) | 548 + (posMouse.x() - m_posMouse.x()) |
549 + (m_posMouse.y() - posMouse.y()); | 549 + (m_posMouse.y() - posMouse.y()); |
550 if (v > QDial::maximum()) | 550 if (v > QDial::maximum()) |
551 v = QDial::maximum(); | 551 v = QDial::maximum(); |
552 else | 552 else |
553 if (v < QDial::minimum()) | 553 if (v < QDial::minimum()) |
554 v = QDial::minimum(); | 554 v = QDial::minimum(); |
555 m_posMouse = posMouse; | 555 m_posMouse = posMouse; |
556 QDial::setValue(v); | 556 QDial::setValue(v); |
557 } | 557 } |
558 } | 558 } |
559 | 559 |
560 | 560 |
561 void AudioDial::mouseReleaseEvent(QMouseEvent *mouseEvent) | 561 void AudioDial::mouseReleaseEvent(QMouseEvent *mouseEvent) |
562 { | 562 { |
563 if (m_mouseDial) { | 563 if (m_mouseDial) { |
564 QDial::mouseReleaseEvent(mouseEvent); | 564 QDial::mouseReleaseEvent(mouseEvent); |
565 } else if (m_mousePressed) { | 565 } else if (m_mousePressed) { |
566 m_mousePressed = false; | 566 m_mousePressed = false; |
567 } | 567 } |
568 } | 568 } |
569 | 569 |
570 void | 570 void |
571 AudioDial::enterEvent(QEvent *e) | 571 AudioDial::enterEvent(QEvent *e) |