diff --git a/plot.cpp b/plot.cpp index 84de2b9..4d2d21b 100644 --- a/plot.cpp +++ b/plot.cpp @@ -19,6 +19,11 @@ #include "plot.h" +bool Plot::mouseEvent(QEvent::Type type, QMouseEvent event) +{ + +} + void Plot::paintBack(QPainter &painter, QRect &rect, range_t sampleRange) { painter.save(); diff --git a/plot.h b/plot.h index 0e0e57c..764c0ea 100644 --- a/plot.h +++ b/plot.h @@ -19,6 +19,7 @@ #pragma once +#include #include #include #include "util.h" @@ -28,6 +29,7 @@ class Plot : public QObject Q_OBJECT public: + virtual bool mouseEvent(QEvent::Type type, QMouseEvent event); virtual void paintBack(QPainter &painter, QRect &rect, range_t sampleRange); virtual void paintMid(QPainter &painter, QRect &rect, range_t sampleRange); virtual void paintFront(QPainter &painter, QRect &rect, range_t sampleRange); diff --git a/plotview.cpp b/plotview.cpp index ec257bb..d04dfd6 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -123,6 +123,31 @@ void PlotView::enableCursors(bool enabled) bool PlotView::eventFilter(QObject * obj, QEvent *event) { + // Pass mouse events to individual plot objects + if (event->type() == QEvent::MouseButtonPress || + event->type() == QEvent::MouseMove || + event->type() == QEvent::MouseButtonRelease) { + + QMouseEvent *mouseEvent = static_cast(event); + int plotY = -verticalScrollBar()->value(); + for (auto&& plot : plots) { + bool result = plot->mouseEvent( + event->type(), + QMouseEvent( + event->type(), + QPoint(mouseEvent->pos().x(), mouseEvent->pos().y() - plotY), + mouseEvent->button(), + mouseEvent->buttons(), + QApplication::keyboardModifiers() + ) + ); + if (result) + return true; + plotY += plot->height(); + } + } + + // Handle wheel events for zooming if (event->type() == QEvent::Wheel) { QWheelEvent *wheelEvent = (QWheelEvent*)event; if (QApplication::keyboardModifiers() & Qt::ControlModifier) {