]> sigrok.org Git - pulseview.git/commitdiff
LogicSignal: Added trigger markers
authorJoel Holdsworth <redacted>
Sun, 23 Nov 2014 19:53:59 +0000 (19:53 +0000)
committerJoel Holdsworth <redacted>
Sun, 23 Nov 2014 20:12:47 +0000 (20:12 +0000)
pulseview.qrc
pv/view/logicsignal.cpp
pv/view/logicsignal.hpp

index e6c7db971dfef134ba48d78454114bf6fa47cc80..948ebd3c63f7f92e22b573b2fec227332722d6c3 100644 (file)
        <file>icons/trigger-falling.svg</file>
        <file>icons/trigger-high.svg</file>
        <file>icons/trigger-low.svg</file>
+       <file>icons/trigger-marker-change.svg</file>
+       <file>icons/trigger-marker-falling.svg</file>
+       <file>icons/trigger-marker-high.svg</file>
+       <file>icons/trigger-marker-low.svg</file>
+       <file>icons/trigger-marker-rising.svg</file>
        <file>icons/trigger-none.svg</file>
        <file>icons/trigger-rising.svg</file>
        <file>icons/zoom-fit.png</file>
index 4b07c568d90268dcccb5b5c25c251e07902c45ff..22b39bbbcfaa49f907696c005fb991508e3cb3eb 100644 (file)
@@ -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<QString, const QIcon> LogicSignal::icon_cache_;
+QCache<QString, const QPixmap> LogicSignal::pixmap_cache_;
+
 LogicSignal::LogicSignal(
        pv::Session &session,
        shared_ptr<Device> 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<int32_t> 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<int64_t, bool> > &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;
index 7a1c62f570d37227890bf07677284fe72489458f..11f81770ce174d0abbe45a063c834fe13a90a67e 100644 (file)
@@ -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<sigrok::Device> 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<int64_t, bool> > &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<QString, const QIcon> icon_cache_;
+       static QCache<QString, const QPixmap> pixmap_cache_;
 };
 
 } // namespace view