diff 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
line wrap: on
line diff
--- a/widgets/AudioDial.cpp	Mon Oct 16 13:13:57 2006 +0000
+++ b/widgets/AudioDial.cpp	Mon Oct 16 20:42:23 2006 +0000
@@ -37,6 +37,8 @@
 
 #include "AudioDial.h"
 
+#include "base/RangeMapper.h"
+
 #include <cmath>
 #include <iostream>
 
@@ -68,7 +70,8 @@
 AudioDial::AudioDial(QWidget *parent) :
     QDial(parent),
     m_knobColor(Qt::black), m_meterColor(Qt::white),
-    m_defaultValue(0)
+    m_defaultValue(0),
+    m_rangeMapper(0)
 {
     m_mouseDial = false;
     m_mousePressed = false;
@@ -78,6 +81,14 @@
 // Destructor.
 AudioDial::~AudioDial (void)
 {
+    delete m_rangeMapper;
+}
+
+
+void AudioDial::setRangeMapper(RangeMapper *mapper)
+{
+    delete m_rangeMapper;
+    m_rangeMapper = mapper;
 }
 
 
@@ -306,6 +317,13 @@
 }
 
 
+float AudioDial::mappedValue() const
+{
+    if (m_rangeMapper) return m_rangeMapper->getValueForPosition(value());
+    else return value();
+}
+
+
 // Alternate mouse behavior event handlers.
 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent)
 {
@@ -328,7 +346,67 @@
     if (m_mouseDial) {
 	QDial::mouseDoubleClickEvent(mouseEvent);
     } else if (mouseEvent->button() == Qt::LeftButton) {
+
 	bool ok = false;
+
+        int newPosition = value();
+
+        if (m_rangeMapper) {
+
+            float min = m_rangeMapper->getValueForPosition(minimum());
+            float max = m_rangeMapper->getValueForPosition(maximum());
+
+            QString unit = m_rangeMapper->getUnit();
+
+            QString text;
+            if (objectName() != "") {
+                if (unit != "") {
+                    text = tr("New value for %1, from %2 to %3 %4:")
+                        .arg(objectName()).arg(min).arg(max).arg(unit);
+                } else {
+                    text = tr("New value for %1, from %2 to %3:")
+                        .arg(objectName()).arg(min).arg(max);
+                }
+            } else {
+                if (unit != "") {
+                    text = tr("Enter a new value from %1 to %2 %3:")
+                        .arg(min).arg(max).arg(unit);
+                } else {
+                    text = tr("Enter a new value from %1 to %2:")
+                        .arg(min).arg(max);
+                }
+            }
+
+            float newValue = QInputDialog::getDouble
+                (this,
+                 tr("Enter new value"),
+                 text,
+                 m_rangeMapper->getValueForPosition(value()),
+                 min,
+                 max,
+                 5, 
+                 &ok);
+
+            //!!! need to avoid this rounding by storing the float value
+
+            newPosition = m_rangeMapper->getPositionForValue(newValue);
+
+        } else {
+
+            newPosition = QInputDialog::getInteger
+                (this,
+                 tr("Enter new value"),
+                 tr("Enter a new value from %1 to %2:")
+                 .arg(minimum()).arg(maximum()),
+                 value(), minimum(), maximum(), pageStep(), &ok);
+        }
+
+        if (ok) {
+            setValue(newPosition);
+        }
+
+
+/*!!!
 	int newValue = QInputDialog::getInteger
 	    (this,
 	     tr("Enter new value"),
@@ -338,6 +416,7 @@
 	if (ok) {
 	    setValue(newValue);
 	}
+*/
     }
 }