#include <libsigrokdecode/libsigrokdecode.h>
}
+#include <QPainter>
+
#include "annotation.h"
using namespace boost;
}
}
+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
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;
#include <pv/data/decoder.h>
#include <pv/view/view.h>
+#include <pv/view/decode/annotation.h>
using namespace boost;
using namespace std;
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()