]> sigrok.org Git - pulseview.git/commitdiff
Initial decode painting
authorJoel Holdsworth <redacted>
Wed, 4 Sep 2013 12:44:52 +0000 (13:44 +0100)
committerJoel Holdsworth <redacted>
Sun, 29 Sep 2013 14:55:45 +0000 (23:55 +0900)
pv/view/decode/annotation.cpp
pv/view/decode/annotation.h
pv/view/decodesignal.cpp

index 4d9a048357bbe1ea7054edeb0dd64388d5217833..741569b2e055f18ed5948ed738c3981dac56eeab 100644 (file)
@@ -22,6 +22,8 @@ extern "C" {
 #include <libsigrokdecode/libsigrokdecode.h>
 }
 
+#include <QPainter>
+
 #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
index 4e24121c50622923e5b0284cc8bd475a777d9261..7ba7d3676b0b1a5c87e726e63eb6d61119007937 100644 (file)
@@ -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;
index 44144d1b8b8e31a37648e6d44fb03221e20e94bb..33ea33f381e484391c82ec7cb83427b45d3a252f 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 
 #include <pv/data/decoder.h>
 #include <pv/view/view.h>
+#include <pv/view/decode/annotation.h>
 
 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<Annotation> > annotations(_decoder->annotations());
+       BOOST_FOREACH(shared_ptr<Annotation> a, annotations) {
+               assert(a);
+               a->paint(p, left, right, samples_per_pixel, pixels_offset, y);
+       }
 }
 
 const list<QAction*> DecodeSignal::get_context_bar_actions()