From: Soeren Apel Date: Thu, 7 Apr 2016 20:03:40 +0000 (+0200) Subject: AnalogSignal: Implement info text for V/div display X-Git-Tag: pulseview-0.4.0~314 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=03cc651d78a85308107e0ef3e5e514503d7c723c;p=pulseview.git AnalogSignal: Implement info text for V/div display --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 6703ce9e..7e5bcd11 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "analogsignal.hpp" #include "pv/data/analog.hpp" @@ -66,6 +67,9 @@ const int AnalogSignal::MaximumVDivs = 10; const int AnalogSignal::MinScaleIndex = -6; const int AnalogSignal::MaxScaleIndex = 7; +const int AnalogSignal::InfoTextMarginRight = 20; +const int AnalogSignal::InfoTextMarginBottom = 5; + AnalogSignal::AnalogSignal( pv::Session &session, shared_ptr channel, @@ -173,6 +177,27 @@ void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp) pixels_offset, samples_per_pixel); } +void AnalogSignal::paint_fore(QPainter &p, const ViewItemPaintParams &pp) +{ + if (!enabled()) + return; + + const int y = get_visual_y(); + + // Show the info section on the right side of the trace + const QString infotext = QString("%1 V/div").arg(resolution_); + + p.setPen(colour_); + p.setFont(QApplication::font()); + + const QRectF bounding_rect = QRectF(pp.left(), + y + v_extents().first, + pp.width() - InfoTextMarginRight, + v_extents().second - v_extents().first - InfoTextMarginBottom); + + p.drawText(bounding_rect, Qt::AlignRight | Qt::AlignBottom, infotext); +} + void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right) { p.setPen(QPen(GridMajorColor, 0.5, Qt::DashLine)); diff --git a/pv/view/analogsignal.hpp b/pv/view/analogsignal.hpp index 9c9c6db8..47a9980c 100644 --- a/pv/view/analogsignal.hpp +++ b/pv/view/analogsignal.hpp @@ -48,6 +48,7 @@ private: static const int MaximumVDivs; static const int MaxScaleIndex, MinScaleIndex; + static const int InfoTextMarginRight, InfoTextMarginBottom; public: AnalogSignal(pv::Session &session, @@ -96,6 +97,13 @@ public: */ void paint_mid(QPainter &p, const ViewItemPaintParams &pp); + /** + * Paints the foreground layer of the item with a QPainter + * @param p the QPainter to paint into. + * @param pp the painting parameters object to paint with. + */ + void paint_fore(QPainter &p, const ViewItemPaintParams &pp); + private: void paint_grid(QPainter &p, int y, int left, int right);