]> sigrok.org Git - pulseview.git/blobdiff - pv/view/decode/annotation.cpp
Initial decode painting
[pulseview.git] / pv / view / decode / annotation.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