diff widgets/AudioDial.cpp @ 344:832d246b327b

* better progress reporting in FileSource * fix set-to-default for audio dials with mappers
author Chris Cannam
date Fri, 04 Jan 2008 17:08:10 +0000
parents cd2492c5fe45
children 06b5f110c5d2
line wrap: on
line diff
--- a/widgets/AudioDial.cpp	Tue Dec 18 10:35:55 2007 +0000
+++ b/widgets/AudioDial.cpp	Fri Jan 04 17:08:10 2008 +0000
@@ -75,6 +75,7 @@
     m_knobColor(Qt::black),
     m_meterColor(Qt::white),
     m_defaultValue(0),
+    m_defaultMappedValue(0),
     m_mappedValue(0),
     m_noMappedUpdate(false),
     m_showTooltip(true),
@@ -334,15 +335,24 @@
 void AudioDial::setDefaultValue(int defaultValue)
 {
     m_defaultValue = defaultValue;
+    if (m_rangeMapper) {
+        m_defaultMappedValue = m_rangeMapper->getValueForPosition(defaultValue);
+    }
 }
 
-
 void AudioDial::setValue(int value)
 {
     QDial::setValue(value);
     updateMappedValue(value);
 }
 
+void AudioDial::setDefaultMappedValue(float value)
+{
+    m_defaultMappedValue = value;
+    if (m_rangeMapper) {
+        m_defaultValue = m_rangeMapper->getPositionForValue(value);
+    }
+}
 
 void AudioDial::setMappedValue(float mappedValue)
 {
@@ -407,6 +417,18 @@
     }
 }
 
+void
+AudioDial::setToDefault()
+{
+    if (m_rangeMapper) {
+        setMappedValue(m_defaultMappedValue);
+        return;
+    }
+    int dv = m_defaultValue;
+    if (dv < minimum()) dv = minimum();
+    if (dv > maximum()) dv = maximum();
+    setValue(m_defaultValue);
+}
 
 // Alternate mouse behavior event handlers.
 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent)
@@ -416,10 +438,7 @@
     } else if (mouseEvent->button() == Qt::MidButton ||
                ((mouseEvent->button() == Qt::LeftButton) &&
                 (mouseEvent->modifiers() & Qt::ControlModifier))) {
-	int dv = m_defaultValue;
-	if (dv < minimum()) dv = minimum();
-	if (dv > maximum()) dv = maximum();
-	setValue(m_defaultValue);
+        setToDefault();
     } else if (mouseEvent->button() == Qt::LeftButton) {
 	m_mousePressed = true;
 	m_posMouse = mouseEvent->pos();