X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fruler.cpp;h=83863e61ea203e3a3efb08f772425a8510da029d;hp=97c0be6822506ffa1c3056493a629d14428dc6e2;hb=f76af6375b8aea6b7edb2d6ee838e1589c3490f3;hpb=ce6e73a8e2a2a353233b440f4bbbd53007602e1a diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 97c0be68..83863e61 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -20,15 +20,19 @@ #include "ruler.h" #include "view.h" +#include "viewport.h" #include #include #include +#include #include #include +using namespace std; + namespace pv { namespace view { @@ -39,10 +43,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 +125,48 @@ void Ruler::paintEvent(QPaintEvent *event) division++; } + // Draw the cursors + draw_cursors(p); + + // Draw the hover mark + draw_hover_mark(p); + p.end(); } +void Ruler::draw_cursors(QPainter &p) +{ + if(!_view.cursors_shown()) + return; + + const QRect r = rect(); + pair &cursors = _view.cursors(); + cursors.first.paint_label(p, r); + cursors.second.paint_label(p, r); +} + +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