changeset 1147:1badacff7ab2 3.0-integration

Introduce labels in RangeMapper and use them in AudioDial, though only for tooltip at present. Make use of this for spectrogram magic -81dB/-Inf threshold. Also introduce static strings for inf/pi and use where appropriate.
author Chris Cannam
date Fri, 05 Aug 2016 17:48:52 +0100
parents 74f2706995b7
children c0d841cb8ab9 0d04b1cdb9f9
files layer/PaintAssistant.cpp layer/SpectrogramLayer.cpp layer/SpectrumLayer.cpp layer/WaveformLayer.cpp widgets/AudioDial.cpp
diffstat 5 files changed, 35 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/layer/PaintAssistant.cpp	Fri Aug 05 15:05:02 2016 +0100
+++ b/layer/PaintAssistant.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -18,6 +18,7 @@
 #include "LayerGeometryProvider.h"
 
 #include "base/AudioLevel.h"
+#include "base/Strings.h"
 
 #include <QPaintDevice>
 #include <QPainter>
@@ -81,7 +82,7 @@
             text = QString("%1").arg(meterdbs[i]);
             if (i == n) text = "0dB";
             if (i == 0) {
-                text = "-Inf";
+                text = Strings::minus_infinity;
                 val = 0.0;
             }
             break;
@@ -91,7 +92,7 @@
             text = QString("%1").arg(-(10*n) + i * 10);
             if (i == n) text = "0dB";
             if (i == 0) {
-                text = "-Inf";
+                text = Strings::minus_infinity;
                 val = 0.0;
             }
             break;
--- a/layer/SpectrogramLayer.cpp	Fri Aug 05 15:05:02 2016 +0100
+++ b/layer/SpectrogramLayer.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -24,6 +24,7 @@
 #include "base/RangeMapper.h"
 #include "base/LogRange.h"
 #include "base/ColumnOp.h"
+#include "base/Strings.h"
 #include "widgets/CommandHistory.h"
 #include "data/model/Dense3DModelPeakCache.h"
 
@@ -529,7 +530,8 @@
         return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
     }
     if (name == "Threshold") {
-        return new LinearRangeMapper(-81, -1, -81, -1, tr("dB"));
+        return new LinearRangeMapper(-81, -1, -81, -1, tr("dB"), false,
+                                     { { -81, Strings::minus_infinity } });
     }
     return 0;
 }
@@ -1956,12 +1958,12 @@
 	QString dbMinString;
 	QString dbMaxString;
 	if (dbMin == AudioLevel::DB_FLOOR) {
-	    dbMinString = tr("-Inf");
+	    dbMinString = Strings::minus_infinity;
 	} else {
 	    dbMinString = QString("%1").arg(lrint(dbMin));
 	}
 	if (dbMax == AudioLevel::DB_FLOOR) {
-	    dbMaxString = tr("-Inf");
+	    dbMaxString = Strings::minus_infinity;
 	} else {
 	    dbMaxString = QString("%1").arg(lrint(dbMax));
 	}
@@ -2219,10 +2221,7 @@
     int ch = h - textHeight * (topLines + 1) - 8;
     paint.drawRect(4 + cw - cbw, textHeight * topLines + 4, cbw - 1, ch + 1);
 
-    QString top, bottom, middle;
-    top = QString("%1").arg(QChar(0x3c0)); // pi
-    bottom = "-" + top;
-    middle = "0";
+    QString top = Strings::pi, bottom = Strings::minus_pi, middle = "0";
     
     double min = -M_PI;
     double max =  M_PI;
--- a/layer/SpectrumLayer.cpp	Fri Aug 05 15:05:02 2016 +0100
+++ b/layer/SpectrumLayer.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -21,6 +21,7 @@
 #include "base/Preferences.h"
 #include "base/RangeMapper.h"
 #include "base/Pitch.h"
+#include "base/Strings.h"
 
 #include "ColourMapper.h"
 #include "PaintAssistant.h"
@@ -607,12 +608,12 @@
     QString mindbstr;
     QString maxdbstr;
     if (mindb == AudioLevel::DB_FLOOR) {
-        mindbstr = tr("-Inf");
+        mindbstr = Strings::minus_infinity;
     } else {
         mindbstr = QString("%1").arg(lrint(mindb));
     }
     if (maxdb == AudioLevel::DB_FLOOR) {
-        maxdbstr = tr("-Inf");
+        maxdbstr = Strings::minus_infinity;
     } else {
         maxdbstr = QString("%1").arg(lrint(maxdb));
     }
--- a/layer/WaveformLayer.cpp	Fri Aug 05 15:05:02 2016 +0100
+++ b/layer/WaveformLayer.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -19,6 +19,7 @@
 #include "view/View.h"
 #include "base/Profiler.h"
 #include "base/RangeMapper.h"
+#include "base/Strings.h"
 
 #include "ColourDatabase.h"
 #include "PaintAssistant.h"
@@ -1203,7 +1204,7 @@
 	return paint.fontMetrics().width("0.0") + 13;
     } else {
 	return std::max(paint.fontMetrics().width(tr("0dB")),
-			paint.fontMetrics().width(tr("-Inf"))) + 13;
+			paint.fontMetrics().width(Strings::minus_infinity)) + 13;
     }
 }
 
@@ -1257,7 +1258,7 @@
 		text = QString("%1").arg(meterdbs[i]);
 		if (i == n) text = tr("0dB");
 		if (i == 0) {
-                    text = tr("-Inf");
+                    text = Strings::minus_infinity;
                     val = 0.0;
 		}
                 break;
@@ -1267,7 +1268,7 @@
 		text = QString("%1").arg(-(10*n) + i * 10);
 		if (i == n) text = tr("0dB");
 		if (i == 0) {
-                    text = tr("-Inf");
+                    text = Strings::minus_infinity;
                     val = 0.0;
 		}
                 break;
--- a/widgets/AudioDial.cpp	Fri Aug 05 15:05:02 2016 +0100
+++ b/widgets/AudioDial.cpp	Fri Aug 05 17:48:52 2016 +0100
@@ -409,13 +409,27 @@
 
     if (m_showTooltip) {
         QString name = objectName();
-        QString unit = "";
+        QString label;
+        if (m_rangeMapper) {
+            label = m_rangeMapper->getLabel(value);
+        }
         QString text;
-        if (m_rangeMapper) unit = m_rangeMapper->getUnit();
-        if (name != "") {
-            text = tr("%1: %2%3").arg(name).arg(m_mappedValue).arg(unit);
+        if (label != "") {
+            if (name != "") {
+                text = tr("%1: %2").arg(name).arg(label);
+            } else {
+                text = label;
+            }
         } else {
-            text = tr("%2%3").arg(m_mappedValue).arg(unit);
+            QString unit = "";
+            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);
     }