Mercurial > hg > svgui
comparison widgets/AudioDial.cpp @ 167:53b9c7656798
* Use RangeMappers in various places in plugin parameters, layer properties,
playback parameters &c
author | Chris Cannam |
---|---|
date | Mon, 16 Oct 2006 20:42:23 +0000 |
parents | 82482231b6b1 |
children | d4be66d61c04 |
comparison
equal
deleted
inserted
replaced
166:48182241f594 | 167:53b9c7656798 |
---|---|
35 * COPYING included with this distribution for more information. | 35 * COPYING included with this distribution for more information. |
36 */ | 36 */ |
37 | 37 |
38 #include "AudioDial.h" | 38 #include "AudioDial.h" |
39 | 39 |
40 #include "base/RangeMapper.h" | |
41 | |
40 #include <cmath> | 42 #include <cmath> |
41 #include <iostream> | 43 #include <iostream> |
42 | 44 |
43 #include <QTimer> | 45 #include <QTimer> |
44 #include <QPainter> | 46 #include <QPainter> |
66 | 68 |
67 // Constructor. | 69 // Constructor. |
68 AudioDial::AudioDial(QWidget *parent) : | 70 AudioDial::AudioDial(QWidget *parent) : |
69 QDial(parent), | 71 QDial(parent), |
70 m_knobColor(Qt::black), m_meterColor(Qt::white), | 72 m_knobColor(Qt::black), m_meterColor(Qt::white), |
71 m_defaultValue(0) | 73 m_defaultValue(0), |
74 m_rangeMapper(0) | |
72 { | 75 { |
73 m_mouseDial = false; | 76 m_mouseDial = false; |
74 m_mousePressed = false; | 77 m_mousePressed = false; |
75 } | 78 } |
76 | 79 |
77 | 80 |
78 // Destructor. | 81 // Destructor. |
79 AudioDial::~AudioDial (void) | 82 AudioDial::~AudioDial (void) |
80 { | 83 { |
84 delete m_rangeMapper; | |
85 } | |
86 | |
87 | |
88 void AudioDial::setRangeMapper(RangeMapper *mapper) | |
89 { | |
90 delete m_rangeMapper; | |
91 m_rangeMapper = mapper; | |
81 } | 92 } |
82 | 93 |
83 | 94 |
84 void AudioDial::paintEvent(QPaintEvent *) | 95 void AudioDial::paintEvent(QPaintEvent *) |
85 { | 96 { |
304 { | 315 { |
305 m_defaultValue = defaultValue; | 316 m_defaultValue = defaultValue; |
306 } | 317 } |
307 | 318 |
308 | 319 |
320 float AudioDial::mappedValue() const | |
321 { | |
322 if (m_rangeMapper) return m_rangeMapper->getValueForPosition(value()); | |
323 else return value(); | |
324 } | |
325 | |
326 | |
309 // Alternate mouse behavior event handlers. | 327 // Alternate mouse behavior event handlers. |
310 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) | 328 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) |
311 { | 329 { |
312 if (m_mouseDial) { | 330 if (m_mouseDial) { |
313 QDial::mousePressEvent(mouseEvent); | 331 QDial::mousePressEvent(mouseEvent); |
326 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) | 344 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) |
327 { | 345 { |
328 if (m_mouseDial) { | 346 if (m_mouseDial) { |
329 QDial::mouseDoubleClickEvent(mouseEvent); | 347 QDial::mouseDoubleClickEvent(mouseEvent); |
330 } else if (mouseEvent->button() == Qt::LeftButton) { | 348 } else if (mouseEvent->button() == Qt::LeftButton) { |
349 | |
331 bool ok = false; | 350 bool ok = false; |
351 | |
352 int newPosition = value(); | |
353 | |
354 if (m_rangeMapper) { | |
355 | |
356 float min = m_rangeMapper->getValueForPosition(minimum()); | |
357 float max = m_rangeMapper->getValueForPosition(maximum()); | |
358 | |
359 QString unit = m_rangeMapper->getUnit(); | |
360 | |
361 QString text; | |
362 if (objectName() != "") { | |
363 if (unit != "") { | |
364 text = tr("New value for %1, from %2 to %3 %4:") | |
365 .arg(objectName()).arg(min).arg(max).arg(unit); | |
366 } else { | |
367 text = tr("New value for %1, from %2 to %3:") | |
368 .arg(objectName()).arg(min).arg(max); | |
369 } | |
370 } else { | |
371 if (unit != "") { | |
372 text = tr("Enter a new value from %1 to %2 %3:") | |
373 .arg(min).arg(max).arg(unit); | |
374 } else { | |
375 text = tr("Enter a new value from %1 to %2:") | |
376 .arg(min).arg(max); | |
377 } | |
378 } | |
379 | |
380 float newValue = QInputDialog::getDouble | |
381 (this, | |
382 tr("Enter new value"), | |
383 text, | |
384 m_rangeMapper->getValueForPosition(value()), | |
385 min, | |
386 max, | |
387 5, | |
388 &ok); | |
389 | |
390 //!!! need to avoid this rounding by storing the float value | |
391 | |
392 newPosition = m_rangeMapper->getPositionForValue(newValue); | |
393 | |
394 } else { | |
395 | |
396 newPosition = QInputDialog::getInteger | |
397 (this, | |
398 tr("Enter new value"), | |
399 tr("Enter a new value from %1 to %2:") | |
400 .arg(minimum()).arg(maximum()), | |
401 value(), minimum(), maximum(), pageStep(), &ok); | |
402 } | |
403 | |
404 if (ok) { | |
405 setValue(newPosition); | |
406 } | |
407 | |
408 | |
409 /*!!! | |
332 int newValue = QInputDialog::getInteger | 410 int newValue = QInputDialog::getInteger |
333 (this, | 411 (this, |
334 tr("Enter new value"), | 412 tr("Enter new value"), |
335 tr("Select a new value in the range %1 to %2:") | 413 tr("Select a new value in the range %1 to %2:") |
336 .arg(minimum()).arg(maximum()), | 414 .arg(minimum()).arg(maximum()), |
337 value(), minimum(), maximum(), pageStep(), &ok); | 415 value(), minimum(), maximum(), pageStep(), &ok); |
338 if (ok) { | 416 if (ok) { |
339 setValue(newValue); | 417 setValue(newValue); |
340 } | 418 } |
419 */ | |
341 } | 420 } |
342 } | 421 } |
343 | 422 |
344 | 423 |
345 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent) | 424 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent) |