From: Soeren Apel Date: Thu, 4 Feb 2016 21:38:34 +0000 (+0100) Subject: DecodeTrace: Try to keep annotation labels within the view X-Git-Tag: pulseview-0.4.0~346 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7352be721b90b630efd742b53e1a0ea16bb834b8;p=pulseview.git DecodeTrace: Try to keep annotation labels within the view Up until now, annotation labels were always drawn centered, even if the annotation was very wide and mostly off-screen. This resulted in annotation labels being out of view, even if there would be enough space to draw it within the view. This patch fixes this. --- diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index e7ffbbb6..eb1f7f83 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -425,7 +425,7 @@ void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a, if (a.start_sample() == a.end_sample()) draw_instant(a, p, fill, outline, h, start, y); else - draw_range(a, p, fill, outline, h, start, end, y); + draw_range(a, p, fill, outline, h, start, end, y, pp); } void DecodeTrace::draw_annotation_block( @@ -485,7 +485,7 @@ void DecodeTrace::draw_instant(const pv::data::decode::Annotation &a, QPainter & void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p, QColor fill, QColor outline, int h, double start, - double end, int y) const + double end, int y, const ViewItemPaintParams &pp) const { const double top = y + .5 - h / 2; const double bottom = y + .5 + h / 2; @@ -516,8 +516,15 @@ void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p, if (annotations.empty()) return; - QRectF rect(start + cap_width, y - h / 2, - end - start - cap_width * 2, h); + const int ann_start = start + cap_width; + const int ann_end = end - cap_width; + + const int real_start = std::max(ann_start, pp.left()); + const int real_end = std::min(ann_end, pp.right()); + + const int real_width = real_end - real_start; + + QRectF rect(real_start, y - h / 2, real_width, h); if (rect.width() <= 4) return; diff --git a/pv/view/decodetrace.hpp b/pv/view/decodetrace.hpp index 4964a95d..af915181 100644 --- a/pv/view/decodetrace.hpp +++ b/pv/view/decodetrace.hpp @@ -141,7 +141,7 @@ private: void draw_range(const pv::data::decode::Annotation &a, QPainter &p, QColor fill, QColor outline, int h, double start, - double end, int y) const; + double end, int y, const ViewItemPaintParams &pp) const; void draw_error(QPainter &p, const QString &message, const ViewItemPaintParams &pp);