From 9472f4476b27336e9187635015169e308bfe8af7 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 4 Sep 2013 13:44:52 +0100 Subject: [PATCH] Initial decode painting --- pv/view/decode/annotation.cpp | 28 ++++++++++++++++++++++++++++ pv/view/decode/annotation.h | 3 +++ pv/view/decodesignal.cpp | 28 +++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/pv/view/decode/annotation.cpp b/pv/view/decode/annotation.cpp index 4d9a0483..741569b2 100644 --- a/pv/view/decode/annotation.cpp +++ b/pv/view/decode/annotation.cpp @@ -22,6 +22,8 @@ extern "C" { #include } +#include + #include "annotation.h" using namespace boost; @@ -42,6 +44,32 @@ Annotation::Annotation(const srd_proto_data *const pdata) : } } +void Annotation::paint(QPainter &p, int left, int right, + double samples_per_pixel, double pixels_offset, int y) +{ + const int AnnotationHeight = 40; + + const double start = _start_sample / samples_per_pixel - + pixels_offset; + const double end = _end_sample / samples_per_pixel - + pixels_offset; + + if (start > right) + return; + if (end < left) + return; + + QRectF rect(start, y - AnnotationHeight/2, + end - start, AnnotationHeight); + + p.setPen(Qt::black); + p.fillRect(rect, QBrush(Qt::red)); + p.drawRect(rect); + + if(!_annotations.empty()) + p.drawText(rect, Qt::AlignCenter, _annotations.front()); +} + } // namespace decode } // namespace view } // namespace pv diff --git a/pv/view/decode/annotation.h b/pv/view/decode/annotation.h index 4e24121c..7ba7d367 100644 --- a/pv/view/decode/annotation.h +++ b/pv/view/decode/annotation.h @@ -36,6 +36,9 @@ class Annotation public: Annotation(const srd_proto_data *const pdata); + void paint(QPainter &p, int left, int right, double samples_per_pixel, + double pixels_offset, int y); + private: uint64_t _start_sample; uint64_t _end_sample; diff --git a/pv/view/decodesignal.cpp b/pv/view/decodesignal.cpp index 44144d1b..33ea33f3 100644 --- a/pv/view/decodesignal.cpp +++ b/pv/view/decodesignal.cpp @@ -26,6 +26,7 @@ extern "C" { #include #include +#include using namespace boost; using namespace std; @@ -61,9 +62,30 @@ void DecodeSignal::set_view(pv::view::View *view) void DecodeSignal::paint(QPainter &p, int left, int right) { - (void)p; - (void)left; - (void)right; + using namespace pv::view::decode; + + assert(_view); + const int y = _v_offset - _view->v_offset(); + + const double scale = _view->scale(); + assert(scale > 0); + + double samplerate = _decoder->get_samplerate(); + + // Show sample rate as 1Hz when it is unknown + if (samplerate == 0.0) + samplerate = 1.0; + + const double pixels_offset = (_view->offset() - + _decoder->get_start_time()) / scale; + const double samples_per_pixel = samplerate * scale; + + assert(_decoder); + vector< shared_ptr > annotations(_decoder->annotations()); + BOOST_FOREACH(shared_ptr a, annotations) { + assert(a); + a->paint(p, left, right, samples_per_pixel, pixels_offset, y); + } } const list DecodeSignal::get_context_bar_actions() -- 2.30.2