From: Joel Holdsworth Date: Sun, 28 Oct 2012 15:56:06 +0000 (+0000) Subject: Added header time hover arrow X-Git-Tag: pulseview-0.1.0~235 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b3a7c0136e427d823eec18b14780182740e9de5d;p=pulseview.git Added header time hover arrow --- diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 97c0be68..c5f194f2 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -20,12 +20,14 @@ #include "ruler.h" #include "view.h" +#include "viewport.h" #include #include #include +#include #include #include @@ -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 diff --git a/pv/view/ruler.h b/pv/view/ruler.h index f855185b..1bda0642 100644 --- a/pv/view/ruler.h +++ b/pv/view/ruler.h @@ -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; };