Mercurial > hg > svgui
comparison widgets/AudioDial.cpp @ 187:e7cf6044c2a0
* better icon
* support range mappers in thumbwheel
* supply range mapper for vertical zoom from spectrogram
* fix bug in fftmodel for scaled ffts
* make the various widgets all respond to double-click for edit, middle-click
for reset, ctrl-left-click for reset
author | Chris Cannam |
---|---|
date | Fri, 12 Jan 2007 14:49:18 +0000 |
parents | 42118892f428 |
children | 5b7472db612b |
comparison
equal
deleted
inserted
replaced
186:8dd247c4c5f1 | 187:e7cf6044c2a0 |
---|---|
72 m_knobColor(Qt::black), | 72 m_knobColor(Qt::black), |
73 m_meterColor(Qt::white), | 73 m_meterColor(Qt::white), |
74 m_defaultValue(0), | 74 m_defaultValue(0), |
75 m_mappedValue(0), | 75 m_mappedValue(0), |
76 m_noMappedUpdate(false), | 76 m_noMappedUpdate(false), |
77 m_showTooltip(false), | 77 m_showTooltip(true), |
78 m_rangeMapper(0) | 78 m_rangeMapper(0) |
79 { | 79 { |
80 m_mouseDial = false; | 80 m_mouseDial = false; |
81 m_mousePressed = false; | 81 m_mousePressed = false; |
82 } | 82 } |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 void AudioDial::setRangeMapper(RangeMapper *mapper) | 92 void AudioDial::setRangeMapper(RangeMapper *mapper) |
93 { | 93 { |
94 if (m_rangeMapper == mapper) return; | |
95 | |
94 if (!m_rangeMapper && mapper) { | 96 if (!m_rangeMapper && mapper) { |
95 connect(this, SIGNAL(valueChanged(int)), | 97 connect(this, SIGNAL(valueChanged(int)), |
96 this, SLOT(updateMappedValue(int))); | 98 this, SLOT(updateMappedValue(int))); |
97 } | 99 } |
98 | 100 |
99 delete m_rangeMapper; | 101 delete m_rangeMapper; |
100 m_rangeMapper = mapper; | 102 m_rangeMapper = mapper; |
101 | 103 |
102 if (m_rangeMapper) { | 104 updateMappedValue(value()); |
103 m_mappedValue = m_rangeMapper->getValueForPosition(value()); | |
104 } else { | |
105 m_mappedValue = value(); | |
106 } | |
107 } | 105 } |
108 | 106 |
109 | 107 |
110 void AudioDial::paintEvent(QPaintEvent *) | 108 void AudioDial::paintEvent(QPaintEvent *) |
111 { | 109 { |
344 } else { | 342 } else { |
345 emit valueChanged(newPosition); | 343 emit valueChanged(newPosition); |
346 } | 344 } |
347 m_noMappedUpdate = false; | 345 m_noMappedUpdate = false; |
348 } else { | 346 } else { |
349 setValue(mappedValue); | 347 setValue(int(mappedValue)); |
350 } | 348 } |
351 } | 349 } |
352 | 350 |
353 | 351 |
354 void AudioDial::setShowToolTip(bool show) | 352 void AudioDial::setShowToolTip(bool show) |
398 // Alternate mouse behavior event handlers. | 396 // Alternate mouse behavior event handlers. |
399 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) | 397 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent) |
400 { | 398 { |
401 if (m_mouseDial) { | 399 if (m_mouseDial) { |
402 QDial::mousePressEvent(mouseEvent); | 400 QDial::mousePressEvent(mouseEvent); |
403 } else if (mouseEvent->button() == Qt::LeftButton) { | 401 } else if (mouseEvent->button() == Qt::MidButton || |
404 m_mousePressed = true; | 402 ((mouseEvent->button() == Qt::LeftButton) && |
405 m_posMouse = mouseEvent->pos(); | 403 (mouseEvent->modifiers() & Qt::ControlModifier))) { |
406 } else if (mouseEvent->button() == Qt::MidButton) { | |
407 int dv = m_defaultValue; | 404 int dv = m_defaultValue; |
408 if (dv < minimum()) dv = minimum(); | 405 if (dv < minimum()) dv = minimum(); |
409 if (dv > maximum()) dv = maximum(); | 406 if (dv > maximum()) dv = maximum(); |
410 setValue(m_defaultValue); | 407 setValue(m_defaultValue); |
408 } else if (mouseEvent->button() == Qt::LeftButton) { | |
409 m_mousePressed = true; | |
410 m_posMouse = mouseEvent->pos(); | |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 | 414 |
415 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) | 415 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent) |
416 { | 416 { |
417 //!!! needs a common base class with Thumbwheel | |
418 | |
417 if (m_mouseDial) { | 419 if (m_mouseDial) { |
418 QDial::mouseDoubleClickEvent(mouseEvent); | 420 QDial::mouseDoubleClickEvent(mouseEvent); |
419 } else if (mouseEvent->button() == Qt::LeftButton) { | 421 } else if (mouseEvent->button() != Qt::LeftButton) { |
420 | 422 return; |
421 bool ok = false; | 423 } |
422 | 424 |
423 if (m_rangeMapper) { | 425 bool ok = false; |
424 | 426 |
425 float min = m_rangeMapper->getValueForPosition(minimum()); | 427 if (m_rangeMapper) { |
426 float max = m_rangeMapper->getValueForPosition(maximum()); | 428 |
427 | 429 float min = m_rangeMapper->getValueForPosition(minimum()); |
428 QString unit = m_rangeMapper->getUnit(); | 430 float max = m_rangeMapper->getValueForPosition(maximum()); |
429 | 431 |
430 QString text; | 432 if (min > max) { |
431 if (objectName() != "") { | 433 float tmp = min; |
432 if (unit != "") { | 434 min = max; |
433 text = tr("New value for %1, from %2 to %3 %4:") | 435 max = tmp; |
434 .arg(objectName()).arg(min).arg(max).arg(unit); | 436 } |
435 } else { | 437 |
436 text = tr("New value for %1, from %2 to %3:") | 438 QString unit = m_rangeMapper->getUnit(); |
437 .arg(objectName()).arg(min).arg(max); | 439 |
438 } | 440 QString text; |
441 if (objectName() != "") { | |
442 if (unit != "") { | |
443 text = tr("New value for %1, from %2 to %3 %4:") | |
444 .arg(objectName()).arg(min).arg(max).arg(unit); | |
439 } else { | 445 } else { |
440 if (unit != "") { | 446 text = tr("New value for %1, from %2 to %3:") |
441 text = tr("Enter a new value from %1 to %2 %3:") | 447 .arg(objectName()).arg(min).arg(max); |
442 .arg(min).arg(max).arg(unit); | |
443 } else { | |
444 text = tr("Enter a new value from %1 to %2:") | |
445 .arg(min).arg(max); | |
446 } | |
447 } | 448 } |
448 | 449 } else { |
449 float newValue = QInputDialog::getDouble | 450 if (unit != "") { |
450 (this, | 451 text = tr("Enter a new value from %1 to %2 %3:") |
451 tr("Enter new value"), | 452 .arg(min).arg(max).arg(unit); |
452 text, | 453 } else { |
453 m_mappedValue, | 454 text = tr("Enter a new value from %1 to %2:") |
454 min, | 455 .arg(min).arg(max); |
455 max, | |
456 4, | |
457 &ok); | |
458 | |
459 if (ok) { | |
460 setMappedValue(newValue); | |
461 } | 456 } |
462 | 457 } |
463 } else { | 458 |
464 | 459 float newValue = QInputDialog::getDouble |
465 int newPosition = QInputDialog::getInteger | 460 (this, |
466 (this, | 461 tr("Enter new value"), |
467 tr("Enter new value"), | 462 text, |
468 tr("Enter a new value from %1 to %2:") | 463 m_mappedValue, |
469 .arg(minimum()).arg(maximum()), | 464 min, |
470 value(), minimum(), maximum(), pageStep(), &ok); | 465 max, |
471 | 466 4, |
472 if (ok) { | 467 &ok); |
473 setValue(newPosition); | 468 |
474 } | 469 if (ok) { |
470 setMappedValue(newValue); | |
471 } | |
472 | |
473 } else { | |
474 | |
475 int newPosition = QInputDialog::getInteger | |
476 (this, | |
477 tr("Enter new value"), | |
478 tr("Enter a new value from %1 to %2:") | |
479 .arg(minimum()).arg(maximum()), | |
480 value(), minimum(), maximum(), pageStep(), &ok); | |
481 | |
482 if (ok) { | |
483 setValue(newPosition); | |
475 } | 484 } |
476 } | 485 } |
477 } | 486 } |
478 | 487 |
479 | 488 |