]> sigrok.org Git - pulseview.git/commitdiff
Added hover point to pv::view::View
authorJoel Holdsworth <redacted>
Sun, 28 Oct 2012 15:53:29 +0000 (15:53 +0000)
committerJoel Holdsworth <redacted>
Sun, 28 Oct 2012 15:59:57 +0000 (15:59 +0000)
pv/view/view.cpp
pv/view/view.h

index 9c4920f997f66585d8f75e2e62da15f2f587d531..54871b5ebc3d4c211898f5961fc9eb3978571782 100644 (file)
@@ -25,6 +25,7 @@
 #include <boost/foreach.hpp>
 
 #include <QEvent>
+#include <QMouseEvent>
 #include <QScrollBar>
 
 #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<SignalData> 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()) {
index c87be36913e368c68bbd334a8d304b99c93a9849..6e5710fede733d2aa926236048d94247984dbd99 100644 (file)
@@ -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