From: Joel Holdsworth Date: Sun, 28 Oct 2012 15:53:29 +0000 (+0000) Subject: Added hover point to pv::view::View X-Git-Tag: pulseview-0.1.0~236 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cbd80f64b2637f13020da7ca003fadcb9be8d46f;p=pulseview.git Added hover point to pv::view::View --- diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 9c4920f9..54871b5e 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "header.h" @@ -61,7 +62,8 @@ View::View(SigSession &session, QWidget *parent) : _data_length(0), _scale(1e-6), _offset(0), - _v_offset(0) + _v_offset(0), + _hover_point(-1, -1) { connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(h_scroll_value_changed(int))); @@ -72,6 +74,10 @@ View::View(SigSession &session, QWidget *parent) : setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0); setViewport(_viewport); + + _viewport->installEventFilter(this); + _ruler->installEventFilter(this); + _header->installEventFilter(this); } SigSession& View::session() @@ -122,6 +128,11 @@ void View::set_scale_offset(double scale, double offset) _viewport->update(); } +const QPoint& View::hover_point() const +{ + return _hover_point; +} + void View::get_scroll_layout(double &length, double &offset) const { const shared_ptr sig_data = _session.get_data(); @@ -160,6 +171,31 @@ void View::update_scroll() _viewport->get_total_height() - areaSize.height()); } +bool View::eventFilter(QObject *object, QEvent *event) +{ + const QEvent::Type type = event->type(); + if(type == QEvent::MouseMove) { + + const QMouseEvent *const mouse_event = (QMouseEvent*)event; + if(object == _viewport) + _hover_point = mouse_event->pos(); + else if(object == _ruler) + _hover_point = QPoint(mouse_event->x(), 0); + else if(object == _header) + _hover_point = QPoint(0, mouse_event->y()); + else + _hover_point = QPoint(-1, -1); + + hover_point_changed(); + + } else if(type == QEvent::Leave) { + _hover_point = QPoint(-1, -1); + hover_point_changed(); + } + + return QObject::eventFilter(object, event); +} + bool View::viewportEvent(QEvent *e) { switch(e->type()) { diff --git a/pv/view/view.h b/pv/view/view.h index c87be369..6e5710fe 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -64,17 +64,25 @@ public: void set_scale_offset(double scale, double offset); + const QPoint& hover_point() const; + +signals: + void hover_point_changed(); + private: void get_scroll_layout(double &length, double &offset) const; void update_scroll(); private: + bool eventFilter(QObject *object, QEvent *event); + bool viewportEvent(QEvent *e); void resizeEvent(QResizeEvent *e); private slots: + void h_scroll_value_changed(int value); void v_scroll_value_changed(int value); @@ -93,6 +101,8 @@ private: double _offset; int _v_offset; + + QPoint _hover_point; }; } // namespace view