]> sigrok.org Git - pulseview.git/blobdiff - pv/view/decodetrace.cpp
DecodeTrace: Make an empty decode trace appear symmetrical
[pulseview.git] / pv / view / decodetrace.cpp
index 19decfd4928420f484cf213c8329f0899dd068cd..20de3755be482688be6cc2ce4f28220c2bd84f5c 100644 (file)
@@ -141,6 +141,10 @@ DecodeTrace::DecodeTrace(pv::Session &session,
 {
        assert(decoder_stack_);
 
+       // Determine shortest string we want to see displayed in full
+       QFontMetrics m(QApplication::font());
+       min_useful_label_width_ = m.width("XX"); // e.g. two hex characters
+
        set_colour(DecodeColours[index % countof(DecodeColours)]);
 
        connect(decoder_stack_.get(), SIGNAL(new_decode_data()),
@@ -165,7 +169,10 @@ pair<int, int> DecodeTrace::v_extents() const
 {
        const int row_height = (ViewItemPaintParams::text_height() * 6) / 4;
 
-       return make_pair(-row_height, row_height * max_visible_rows_);
+       // Make an empty decode trace appear symmetrical
+       const int row_count = max(1, max_visible_rows_);
+
+       return make_pair(-row_height, row_height * row_count);
 }
 
 void DecodeTrace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
@@ -373,7 +380,7 @@ void DecodeTrace::draw_annotations(vector<pv::data::decode::Annotation> annotati
                bool a_is_separate = false;
 
                // Annotation wider than the threshold for a useful label width?
-               if (a_width > 20) {
+               if (a_width >= min_useful_label_width_) {
                        for (const QString &ann_text : a.annotations()) {
                                const int w = p.boundingRect(QRectF(), 0, ann_text).width();
                                // Annotation wide enough to fit a label? Don't put it in a block then