From: Joel Holdsworth Date: Sun, 23 Nov 2014 19:53:59 +0000 (+0000) Subject: LogicSignal: Added trigger markers X-Git-Tag: pulseview-0.3.0~423 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ddfda54df6070f6188663d9cc17b7cafeb30cc40;p=pulseview.git LogicSignal: Added trigger markers --- diff --git a/pulseview.qrc b/pulseview.qrc index e6c7db97..948ebd3c 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -16,6 +16,11 @@ icons/trigger-falling.svg icons/trigger-high.svg icons/trigger-low.svg + icons/trigger-marker-change.svg + icons/trigger-marker-falling.svg + icons/trigger-marker-high.svg + icons/trigger-marker-low.svg + icons/trigger-marker-rising.svg icons/trigger-none.svg icons/trigger-rising.svg icons/zoom-fit.png diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 4b07c568..22b39bbb 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -81,6 +81,22 @@ const QColor LogicSignal::SignalColours[10] = { QColor(0xEE, 0xEE, 0xEC), // White }; +QColor LogicSignal::TriggerMarkerBackgroundColour = QColor(0xED, 0xD4, 0x00); +const int LogicSignal::TriggerMarkerPadding = 2; +const char* LogicSignal::TriggerMarkerIcons[8] = { + nullptr, + ":/icons/trigger-marker-low.svg", + ":/icons/trigger-marker-high.svg", + ":/icons/trigger-marker-rising.svg", + ":/icons/trigger-marker-falling.svg", + ":/icons/trigger-marker-change.svg", + nullptr, + nullptr +}; + +QCache LogicSignal::icon_cache_; +QCache LogicSignal::pixmap_cache_; + LogicSignal::LogicSignal( pv::Session &session, shared_ptr device, @@ -220,6 +236,45 @@ void LogicSignal::paint_mid(QPainter &p, int left, int right) delete[] cap_lines; } +void LogicSignal::paint_fore(QPainter &p, int left, int right) +{ + (void)left; + + // Draw the trigger marker + if (!trigger_match_) + return; + + const int y = get_visual_y(); + const vector trig_types = get_trigger_types(); + for (int32_t type_id : trig_types) { + const TriggerMatchType *const type = + TriggerMatchType::get(type_id); + if (trigger_match_ != type || type_id < 0 || + (size_t)type_id >= countof(TriggerMarkerIcons) || + !TriggerMarkerIcons[type_id]) + continue; + + const QPixmap *const pixmap = get_pixmap( + TriggerMarkerIcons[type_id]); + if (!pixmap) + continue; + + const int pad = TriggerMarkerPadding; + const QSize size = pixmap->size(); + const QPoint point( + right - size.width() - pad * 2, + y - (SignalHeight + size.height()) / 2); + + p.setPen(QPen(Qt::NoPen)); + p.setBrush(TriggerMarkerBackgroundColour); + p.drawRoundedRect(QRect(point, size).adjusted( + -pad, -pad, pad, pad), pad, pad); + p.drawPixmap(point, *pixmap); + + break; + } +} + void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, vector< pair > &edges, bool level, double samples_per_pixel, double pixels_offset, float x_offset, @@ -378,6 +433,9 @@ void LogicSignal::modify_trigger() session_.session()->set_trigger( new_trigger->stages().empty() ? nullptr : new_trigger); + + if (owner_) + owner_->appearance_changed(false, true); } const QIcon* LogicSignal::get_icon(const char *path) @@ -391,6 +449,17 @@ const QIcon* LogicSignal::get_icon(const char *path) return icon; } +const QPixmap* LogicSignal::get_pixmap(const char *path) +{ + const QPixmap *pixmap = pixmap_cache_.take(path); + if (!pixmap) { + pixmap = new QPixmap(path); + pixmap_cache_.insert(path, pixmap); + } + + return pixmap; +} + void LogicSignal::on_trigger() { QAction *action; diff --git a/pv/view/logicsignal.hpp b/pv/view/logicsignal.hpp index 7a1c62f5..11f81770 100644 --- a/pv/view/logicsignal.hpp +++ b/pv/view/logicsignal.hpp @@ -59,6 +59,10 @@ private: static const QColor SignalColours[10]; + static QColor TriggerMarkerBackgroundColour; + static const int TriggerMarkerPadding; + static const char* TriggerMarkerIcons[8]; + public: LogicSignal(pv::Session &session, std::shared_ptr device, @@ -93,6 +97,14 @@ public: **/ void paint_mid(QPainter &p, int left, int right); + /** + * Paints the foreground layer of the signal with a QPainter + * @param p the QPainter to paint into. + * @param left the x-coordinate of the left edge of the signal + * @param right the x-coordinate of the right edge of the signal + **/ + virtual void paint_fore(QPainter &p, int left, int right); + private: void paint_caps(QPainter &p, QLineF *const lines, std::vector< std::pair > &edges, @@ -110,6 +122,7 @@ private: void modify_trigger(); static const QIcon* get_icon(const char *path); + static const QPixmap* get_pixmap(const char *path); private Q_SLOTS: void on_trigger(); @@ -128,6 +141,7 @@ private: QAction *trigger_change_; static QCache icon_cache_; + static QCache pixmap_cache_; }; } // namespace view