From: Joel Holdsworth Date: Fri, 25 Oct 2013 16:32:09 +0000 (+0100) Subject: Added decode error display X-Git-Tag: pulseview-0.2.0~226 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ad50ac1af2b9e8bc0a8c520d80debfd8ad95c904;p=pulseview.git Added decode error display --- diff --git a/pv/view/decodesignal.cpp b/pv/view/decodesignal.cpp index 88531208..1cbce00d 100644 --- a/pv/view/decodesignal.cpp +++ b/pv/view/decodesignal.cpp @@ -49,6 +49,8 @@ const QColor DecodeSignal::DecodeColours[4] = { QColor(0x72, 0x9F, 0xCF) // Blue }; +const QColor DecodeSignal::ErrorBgColour = QColor(0xEF, 0x29, 0x29); + DecodeSignal::DecodeSignal(pv::SigSession &session, boost::shared_ptr decoder, int index) : Trace(session, QString(decoder->get_decoder()->name)), @@ -87,6 +89,13 @@ void DecodeSignal::paint_mid(QPainter &p, int left, int right) { using namespace pv::view::decode; + assert(_decoder); + const QString err = _decoder->error_message(); + if (!err.isEmpty()) { + draw_error(p, err, left, right); + return; + } + assert(_view); const int y = get_y(); @@ -126,6 +135,27 @@ QMenu* DecodeSignal::create_context_menu(QWidget *parent) return menu; } +void DecodeSignal::draw_error(QPainter &p, const QString &message, + int left, int right) +{ + const int y = get_y(); + + p.setPen(ErrorBgColour.darker()); + p.setBrush(ErrorBgColour); + + const QRectF bounding_rect = + QRectF(left, INT_MIN / 2 + y, right - left, INT_MAX); + const QRectF text_rect = p.boundingRect(bounding_rect, + Qt::AlignCenter, message); + const float r = text_rect.height() / 4; + + p.drawRoundedRect(text_rect.adjusted(-r, -r, r, r), r, r, + Qt::AbsoluteSize); + + p.setPen(get_text_colour()); + p.drawText(text_rect, message); +} + void DecodeSignal::on_new_decode_data() { if (_view) diff --git a/pv/view/decodesignal.h b/pv/view/decodesignal.h index c1b53d57..efa34495 100644 --- a/pv/view/decodesignal.h +++ b/pv/view/decodesignal.h @@ -39,6 +39,7 @@ class DecodeSignal : public Trace private: static const QColor DecodeColours[4]; + static const QColor ErrorBgColour; public: DecodeSignal(pv::SigSession &session, @@ -70,6 +71,10 @@ public: void delete_pressed(); +private: + void draw_error(QPainter &p, const QString &message, + int left, int right); + private slots: void on_new_decode_data();