Mercurial > hg > svgui
changeset 168:d4be66d61c04
* Make audio dial remember its more accurate mapped value as well as its
display position
* Add tool tip support to audio dial to show values
author | Chris Cannam |
---|---|
date | Tue, 17 Oct 2006 13:04:49 +0000 |
parents | 53b9c7656798 |
children | 86cee2b060c7 |
files | widgets/AudioDial.cpp widgets/AudioDial.h widgets/PluginParameterBox.cpp widgets/PropertyBox.cpp |
diffstat | 4 files changed, 107 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/widgets/AudioDial.cpp Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/AudioDial.cpp Tue Oct 17 13:04:49 2006 +0000 @@ -25,7 +25,7 @@ * * Ported to Qt4 by Chris Cannam. * - * This file copyright 2003-2005 Chris Cannam, copyright 2005 Pedro + * This file copyright 2003-2006 Chris Cannam, copyright 2005 Pedro * Lopez-Cabanillas. * * This program is free software; you can redistribute it and/or @@ -71,6 +71,9 @@ QDial(parent), m_knobColor(Qt::black), m_meterColor(Qt::white), m_defaultValue(0), + m_mappedValue(0), + m_noMappedUpdate(false), + m_showTooltip(false), m_rangeMapper(0) { m_mouseDial = false; @@ -87,8 +90,13 @@ void AudioDial::setRangeMapper(RangeMapper *mapper) { + if (!m_rangeMapper) { + connect(this, SIGNAL(valueChanged(int)), + this, SLOT(updateMappedValue(int))); + } delete m_rangeMapper; m_rangeMapper = mapper; + m_mappedValue = m_rangeMapper->getValueForPosition(value()); } @@ -317,10 +325,45 @@ } +void AudioDial::setShowToolTip(bool show) +{ + m_showTooltip = show; + m_noMappedUpdate = true; + updateMappedValue(value()); + m_noMappedUpdate = false; +} + + float AudioDial::mappedValue() const { - if (m_rangeMapper) return m_rangeMapper->getValueForPosition(value()); - else return value(); + if (m_rangeMapper) { + std::cerr << "AudioDial::mappedValue(): value = " << value() << ", mappedValue = " << m_mappedValue << std::endl; + return m_mappedValue; + } + return value(); +} + + +void AudioDial::updateMappedValue(int value) +{ + if (m_rangeMapper) { + if (!m_noMappedUpdate) { + m_mappedValue = m_rangeMapper->getValueForPosition(value); + } + } + + if (m_showTooltip) { + QString name = objectName(); + QString unit = ""; + QString text; + if (m_rangeMapper) unit = m_rangeMapper->getUnit(); + if (name != "") { + text = tr("%1: %2%3").arg(name).arg(m_mappedValue).arg(unit); + } else { + text = tr("%2%3").arg(m_mappedValue).arg(unit); + } + setToolTip(text); + } } @@ -381,15 +424,24 @@ (this, tr("Enter new value"), text, - m_rangeMapper->getValueForPosition(value()), + m_mappedValue, min, max, - 5, + 4, &ok); - //!!! need to avoid this rounding by storing the float value + newPosition = m_rangeMapper->getPositionForValue(newValue); - newPosition = m_rangeMapper->getPositionForValue(newValue); + if (ok) { + m_mappedValue = newValue; + m_noMappedUpdate = true; + if (newPosition != value()) { + setValue(newPosition); + } else { + emit valueChanged(newPosition); + } + m_noMappedUpdate = false; + } } else { @@ -399,24 +451,11 @@ tr("Enter a new value from %1 to %2:") .arg(minimum()).arg(maximum()), value(), minimum(), maximum(), pageStep(), &ok); + + if (ok) { + setValue(newPosition); + } } - - if (ok) { - setValue(newPosition); - } - - -/*!!! - int newValue = QInputDialog::getInteger - (this, - tr("Enter new value"), - tr("Select a new value in the range %1 to %2:") - .arg(minimum()).arg(maximum()), - value(), minimum(), maximum(), pageStep(), &ok); - if (ok) { - setValue(newValue); - } -*/ } }
--- a/widgets/AudioDial.h Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/AudioDial.h Tue Oct 17 13:04:49 2006 +0000 @@ -72,8 +72,10 @@ bool getMouseDial() const { return m_mouseDial; } void setRangeMapper(RangeMapper *mapper); // I take ownership, will delete + const RangeMapper *rangeMapper() const { return m_rangeMapper; } + float mappedValue() const; - float mappedValue() const; + void setShowToolTip(bool show); public slots: /** @@ -107,17 +109,24 @@ virtual void mouseReleaseEvent(QMouseEvent *pMouseEvent); virtual void mouseDoubleClickEvent(QMouseEvent *pMouseEvent); +protected slots: + void updateMappedValue(int value); + private: QColor m_knobColor; QColor m_meterColor; int m_defaultValue; + float m_mappedValue; + bool m_noMappedUpdate; // Alternate mouse behavior tracking. bool m_mouseDial; bool m_mousePressed; QPoint m_posMouse; + bool m_showTooltip; + RangeMapper *m_rangeMapper; };
--- a/widgets/PluginParameterBox.cpp Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/PluginParameterBox.cpp Tue Oct 17 13:04:49 2006 +0000 @@ -163,6 +163,7 @@ dial->setFixedHeight(32); dial->setRangeMapper(new LinearRangeMapper (imin, imax, min, max, unit)); + dial->setShowToolTip(true); connect(dial, SIGNAL(valueChanged(int)), this, SLOT(dialChanged(int))); m_layout->addWidget(dial, i + offset, 1); @@ -208,15 +209,30 @@ float min = params.minValue; float max = params.maxValue; + float newValue; + float qtz = 0.0; if (params.isQuantized) qtz = params.quantizeStep; + + AudioDial *ad = dynamic_cast<AudioDial *>(obj); - if (qtz == 0.0) { - qtz = (max - min) / 100.0; + if (ad && ad->rangeMapper()) { + + newValue = ad->mappedValue(); + if (newValue < min) newValue = min; + if (newValue > max) newValue = max; + if (qtz != 0.0) { + ival = lrintf((newValue - min) / qtz); + newValue = min + ival * qtz; + } + + } else { + if (qtz == 0.0) { + qtz = (max - min) / 100.0; + } + newValue = min + ival * qtz; } - float newValue = min + ival * qtz; - QDoubleSpinBox *spin = m_params[name].spin; if (spin) { spin->blockSignals(true);
--- a/widgets/PropertyBox.cpp Mon Oct 16 20:42:23 2006 +0000 +++ b/widgets/PropertyBox.cpp Tue Oct 17 13:04:49 2006 +0000 @@ -181,11 +181,12 @@ gainDial->setFixedWidth(24); gainDial->setFixedHeight(24); gainDial->setNotchesVisible(false); - gainDial->setToolTip(tr("Playback Level")); +//!!! gainDial->setToolTip(tr("Playback Level")); gainDial->setDefaultValue(0); - gainDial->setObjectName(tr("Playback Level")); + gainDial->setObjectName(tr("Playback Gain")); gainDial->setRangeMapper(new LinearRangeMapper (-50, 50, -25, 25, tr("dB"))); + gainDial->setShowToolTip(true); connect(gainDial, SIGNAL(valueChanged(int)), this, SLOT(playGainDialChanged(int))); connect(params, SIGNAL(playGainChanged(float)), @@ -207,7 +208,8 @@ panDial->setNotchesVisible(false); panDial->setToolTip(tr("Playback Pan / Balance")); panDial->setDefaultValue(0); - gainDial->setObjectName(tr("Playback Pan / Balance")); + panDial->setObjectName(tr("Playback Pan / Balance")); + panDial->setShowToolTip(true); connect(panDial, SIGNAL(valueChanged(int)), this, SLOT(playPanDialChanged(int))); connect(params, SIGNAL(playPanChanged(float)), @@ -324,13 +326,14 @@ dial->setNotchesVisible((max - min) <= 12); dial->setDefaultValue(value); dial->setRangeMapper(m_container->getNewPropertyRangeMapper(name)); + dial->setShowToolTip(true); connect(dial, SIGNAL(valueChanged(int)), this, SLOT(propertyControllerChanged(int))); if (inGroup) { dial->setFixedWidth(24); dial->setFixedHeight(24); - dial->setToolTip(propertyLabel); +//!!! dial->setToolTip(propertyLabel); m_groupLayouts[groupName]->addWidget(dial); } else { dial->setFixedWidth(32); @@ -485,13 +488,13 @@ m_container->setPropertyWithCommand(name, value); } - if (type == PropertyContainer::RangeProperty) { - AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]); - if (dial) { - dial->setToolTip(QString("%1: %2").arg(name).arg(value)); - //!!! unfortunately this doesn't update an already-visible tooltip - } - } +// if (type == PropertyContainer::RangeProperty) { +// AudioDial *dial = dynamic_cast<AudioDial *>(m_propertyControllers[name]); +//!!! if (dial) { +// dial->setToolTip(QString("%1: %2").arg(name).arg(value)); +// //!!! unfortunately this doesn't update an already-visible tooltip +// } +// } } void