comparison 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
comparison
equal deleted inserted replaced
282:4edaff85875d 283:86a112b5b319
21 #include "base/Window.h" 21 #include "base/Window.h"
22 #include "base/Pitch.h" 22 #include "base/Pitch.h"
23 #include "base/Preferences.h" 23 #include "base/Preferences.h"
24 #include "base/RangeMapper.h" 24 #include "base/RangeMapper.h"
25 #include "base/LogRange.h" 25 #include "base/LogRange.h"
26 #include "base/CommandHistory.h"
26 #include "ColourMapper.h" 27 #include "ColourMapper.h"
28 #include "ImageRegionFinder.h"
27 29
28 #include <QPainter> 30 #include <QPainter>
29 #include <QImage> 31 #include <QImage>
30 #include <QPixmap> 32 #include <QPixmap>
31 #include <QRect> 33 #include <QRect>
32 #include <QTimer> 34 #include <QTimer>
33 #include <QApplication> 35 #include <QApplication>
34 #include <QMessageBox> 36 #include <QMessageBox>
37 #include <QMouseEvent>
35 38
36 #include <iostream> 39 #include <iostream>
37 40
38 #include <cassert> 41 #include <cassert>
39 #include <cmath> 42 #include <cmath>
2456 } 2459 }
2457 2460
2458 return true; 2461 return true;
2459 } 2462 }
2460 2463
2464 void
2465 SpectrogramLayer::measureDoubleClick(View *v, QMouseEvent *e)
2466 {
2467 PixmapCache &cache = m_pixmapCaches[v];
2468
2469 std::cerr << "cache width: " << cache.pixmap.width() << ", height: "
2470 << cache.pixmap.height() << std::endl;
2471
2472 QImage image = cache.pixmap.toImage();
2473
2474 ImageRegionFinder finder;
2475 QRect rect = finder.findRegionExtents(&image, e->pos());
2476 if (rect.isValid()) {
2477 MeasureRect mr;
2478 setMeasureRectFromPixrect(v, mr, rect);
2479 CommandHistory::getInstance()->addCommand
2480 (new AddMeasurementRectCommand(this, mr));
2481 }
2482 }
2483
2461 bool 2484 bool
2462 SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint, 2485 SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint,
2463 QPoint cursorPos, 2486 QPoint cursorPos,
2464 std::vector<QRect> &extents) const 2487 std::vector<QRect> &extents) const
2465 { 2488 {
2500 void 2523 void
2501 SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint, 2524 SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint,
2502 QPoint cursorPos) const 2525 QPoint cursorPos) const
2503 { 2526 {
2504 paint.save(); 2527 paint.save();
2528
2529 int sw = getVerticalScaleWidth(v, paint);
2530
2505 QFont fn = paint.font(); 2531 QFont fn = paint.font();
2506 if (fn.pointSize() > 8) { 2532 if (fn.pointSize() > 8) {
2507 fn.setPointSize(fn.pointSize() - 1); 2533 fn.setPointSize(fn.pointSize() - 1);
2508 paint.setFont(fn); 2534 paint.setFont(fn);
2509 } 2535 }
2512 paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y()); 2538 paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y());
2513 paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->height()); 2539 paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->height());
2514 2540
2515 float fundamental = getFrequencyForY(v, cursorPos.y()); 2541 float fundamental = getFrequencyForY(v, cursorPos.y());
2516 2542
2517 int sw = getVerticalScaleWidth(v, paint);
2518 v->drawVisibleText(paint, 2543 v->drawVisibleText(paint,
2519 sw + 2, 2544 sw + 2,
2520 cursorPos.y() - 2, 2545 cursorPos.y() - 2,
2521 QString("%1 Hz").arg(fundamental), 2546 QString("%1 Hz").arg(fundamental),
2522 View::OutlinedText); 2547 View::OutlinedText);