]> sigrok.org Git - pulseview.git/commitdiff
Added decode error display
authorJoel Holdsworth <redacted>
Fri, 25 Oct 2013 16:32:09 +0000 (17:32 +0100)
committerJoel Holdsworth <redacted>
Tue, 19 Nov 2013 19:32:10 +0000 (19:32 +0000)
pv/view/decodesignal.cpp
pv/view/decodesignal.h

index 885312088c2ba11db0d6170687c294b837c06553..1cbce00d6be4843802132e961006603d89836061 100644 (file)
@@ -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<pv::data::Decoder> 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)
index c1b53d5711fc87a9abefe8fcd5bd85db5c8896aa..efa3449575942e1a4b69170276c3094b770c8256 100644 (file)
@@ -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();