]> sigrok.org Git - pulseview.git/commitdiff
Added header time hover arrow
authorJoel Holdsworth <redacted>
Sun, 28 Oct 2012 15:56:06 +0000 (15:56 +0000)
committerJoel Holdsworth <redacted>
Sun, 28 Oct 2012 16:01:48 +0000 (16:01 +0000)
pv/view/ruler.cpp
pv/view/ruler.h

index 97c0be6822506ffa1c3056493a629d14428dc6e2..c5f194f2f76f4011009107659c2ad70790605e6f 100644 (file)
 
 #include "ruler.h"
 #include "view.h"
+#include "viewport.h"
 
 #include <extdef.h>
 
 #include <assert.h>
 #include <math.h>
 
+#include <QMouseEvent>
 #include <QPainter>
 #include <QTextStream>
 
@@ -39,10 +41,16 @@ const QString Ruler::SIPrefixes[9] =
        {"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
 const int Ruler::FirstSIPrefixPower = -15;
 
+const int Ruler::HoverArrowSize = 5;
+
 Ruler::Ruler(View &parent) :
        QWidget(&parent),
        _view(parent)
 {
+       setMouseTracking(true);
+
+       connect(&_view, SIGNAL(hover_point_changed()),
+               this, SLOT(hover_point_changed()));
 }
 
 void Ruler::paintEvent(QPaintEvent *event)
@@ -115,8 +123,34 @@ void Ruler::paintEvent(QPaintEvent *event)
                division++;
        }
 
+       // Draw the hover mark
+       draw_hover_mark(p);
+
        p.end();
 }
 
+void Ruler::draw_hover_mark(QPainter &p)
+{
+       const int x = _view.hover_point().x();
+       if(x == -1)
+               return;
+
+       p.setPen(QPen(Qt::NoPen));
+       p.setBrush(QBrush(QColor(Qt::black)));
+
+       const int b = height() - 1;
+       const QPointF points[] = {
+               QPointF(x, b),
+               QPointF(x - HoverArrowSize, b - HoverArrowSize),
+               QPointF(x + HoverArrowSize, b - HoverArrowSize)
+       };
+       p.drawPolygon(points, countof(points));
+}
+
+void Ruler::hover_point_changed()
+{
+       update();
+}
+
 } // namespace view
 } // namespace pv
index f855185b904a75209ce521ec12c4399913bd6d5e..1bda06427d253787389d1c87ca59dda26ad9fe71 100644 (file)
@@ -39,12 +39,23 @@ private:
        static const QString SIPrefixes[9];
        static const int FirstSIPrefixPower;
 
+       static const int HoverArrowSize;
+
 public:
        Ruler(View &parent);
 
 private:
        void paintEvent(QPaintEvent *event);
 
+private:
+       /**
+        * Draw a hover arrow under the cursor position.
+        */
+       void draw_hover_mark(QPainter &p);
+
+private slots:
+       void hover_point_changed();
+
 private:
        View &_view;
 };