diff layer/SpectrumLayer.cpp @ 264:7e9e533f1863

* few more measurement mode bits
author Chris Cannam
date Fri, 15 Jun 2007 12:55:16 +0000
parents 6d113226bb4c
children a3a54632cd4c
line wrap: on
line diff
--- a/layer/SpectrumLayer.cpp	Thu Jun 14 20:57:01 2007 +0000
+++ b/layer/SpectrumLayer.cpp	Fri Jun 15 12:55:16 2007 +0000
@@ -255,20 +255,6 @@
     return false;
 }
 
-bool
-SpectrumLayer::getCrosshairExtents(View *v, QPainter &,
-                                   QPoint cursorPos,
-                                   std::vector<QRect> &extents) const
-{
-    QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y());
-    extents.push_back(vertical);
-
-    QRect horizontal(0, cursorPos.y(), v->width(), 12);
-    extents.push_back(horizontal);
-
-    return true;
-}
-
 float
 SpectrumLayer::getFrequencyForX(float x, float w) const
 {
@@ -327,11 +313,30 @@
 SpectrumLayer::getXScaleValue(View *v, int x, 
                               float &value, QString &unit) const
 {
-    value = getFrequencyForX(x, v->width() - m_xorigins[v]);
+    value = getFrequencyForX(x - m_xorigins[v], v->width() - m_xorigins[v] - 1);
     unit = "Hz";
     return true;
 }
 
+bool
+SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint,
+                                   QPoint cursorPos,
+                                   std::vector<QRect> &extents) const
+{
+    QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y());
+    extents.push_back(vertical);
+
+    QRect horizontal(0, cursorPos.y(), v->width(), 12);
+    extents.push_back(horizontal);
+
+    QRect label(cursorPos.x(), v->height() - paint.fontMetrics().height(),
+                paint.fontMetrics().width("123456 Hz") + 2,
+                paint.fontMetrics().height());
+    extents.push_back(label);
+
+    return true;
+}
+
 void
 SpectrumLayer::paintCrosshairs(View *v, QPainter &paint,
                                QPoint cursorPos) const
@@ -349,6 +354,9 @@
     
     float fundamental = getFrequencyForX(cursorPos.x() - xorigin, w);
 
+    paint.drawText(cursorPos.x() + 2, v->height() - 2,
+                   QString("%1 Hz").arg(fundamental));
+
     int harmonic = 2;
 
     while (harmonic < 100) {