diff layer/SpectrogramLayer.cpp @ 283:86a112b5b319

* Make it possible to "measure" a feature on the spectrogram by double- clicking in measure mode * Make shift-click-drag (for zoom to region) work in measure mode as well as navigate mode. It would be nice to be able to shift-doubleclick to zoom on a feature directly using a combination of these last two features, but that isn't possible yet. * Make Del delete the measurement under the mouse pointer.
author Chris Cannam
date Thu, 05 Jul 2007 15:36:37 +0000
parents 4edaff85875d
children 1284955856ab
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Thu Jul 05 11:07:01 2007 +0000
+++ b/layer/SpectrogramLayer.cpp	Thu Jul 05 15:36:37 2007 +0000
@@ -23,7 +23,9 @@
 #include "base/Preferences.h"
 #include "base/RangeMapper.h"
 #include "base/LogRange.h"
+#include "base/CommandHistory.h"
 #include "ColourMapper.h"
+#include "ImageRegionFinder.h"
 
 #include <QPainter>
 #include <QImage>
@@ -32,6 +34,7 @@
 #include <QTimer>
 #include <QApplication>
 #include <QMessageBox>
+#include <QMouseEvent>
 
 #include <iostream>
 
@@ -2458,6 +2461,26 @@
     return true;
 } 
 
+void
+SpectrogramLayer::measureDoubleClick(View *v, QMouseEvent *e)
+{
+    PixmapCache &cache = m_pixmapCaches[v];
+
+    std::cerr << "cache width: " << cache.pixmap.width() << ", height: "
+              << cache.pixmap.height() << std::endl;
+
+    QImage image = cache.pixmap.toImage();
+
+    ImageRegionFinder finder;
+    QRect rect = finder.findRegionExtents(&image, e->pos());
+    if (rect.isValid()) {
+        MeasureRect mr;
+        setMeasureRectFromPixrect(v, mr, rect);
+        CommandHistory::getInstance()->addCommand
+            (new AddMeasurementRectCommand(this, mr));
+    }
+}
+
 bool
 SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint,
                                       QPoint cursorPos,
@@ -2502,6 +2525,9 @@
                                   QPoint cursorPos) const
 {
     paint.save();
+
+    int sw = getVerticalScaleWidth(v, paint);
+
     QFont fn = paint.font();
     if (fn.pointSize() > 8) {
         fn.setPointSize(fn.pointSize() - 1);
@@ -2514,7 +2540,6 @@
     
     float fundamental = getFrequencyForY(v, cursorPos.y());
 
-    int sw = getVerticalScaleWidth(v, paint);
     v->drawVisibleText(paint,
                        sw + 2,
                        cursorPos.y() - 2,