]> sigrok.org Git - pulseview.git/commitdiff
Move signal color handling to SignalBase
authorSoeren Apel <redacted>
Mon, 17 Aug 2020 09:37:06 +0000 (11:37 +0200)
committerSoeren Apel <redacted>
Sat, 22 Aug 2020 22:16:19 +0000 (00:16 +0200)
pv/data/mathsignal.cpp
pv/data/signalbase.cpp
pv/data/signalbase.hpp
pv/views/trace/analogsignal.cpp
pv/views/trace/analogsignal.hpp
pv/views/trace/logicsignal.cpp
pv/views/trace/logicsignal.hpp

index 31424e394967af336b97b4312695d50699c8bf00..d9ba5bc369440e3ae051cc4ebecf517338d37484 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "mathsignal.hpp"
 
+#include <extdef.h>
 #include <pv/globalsettings.hpp>
 #include <pv/session.hpp>
 #include <pv/data/analogsegment.hpp>
@@ -90,7 +91,9 @@ MathSignal::MathSignal(pv::Session &session) :
        exprtk_parser_(nullptr),
        fnc_sig_sample_(nullptr)
 {
-       set_name(QString(tr("Math%1")).arg(session_.get_next_signal_index(MathChannel)));
+       uint32_t sig_idx = session_.get_next_signal_index(MathChannel);
+       set_name(QString(tr("Math%1")).arg(sig_idx));
+       set_color(AnalogSignalColors[(sig_idx - 1) % countof(AnalogSignalColors)]);
 
        set_data(std::make_shared<data::Analog>());
 
index fb68724401c4f979acb79d66191192653a8d0a72..c15a44319d21030b3795fcdd3e25b8513869ce49 100644 (file)
@@ -28,8 +28,9 @@
 
 #include <QDebug>
 
-#include <pv/binding/decoder.hpp>
+#include <extdef.h>
 #include <pv/session.hpp>
+#include <pv/binding/decoder.hpp>
 
 using std::dynamic_pointer_cast;
 using std::make_shared;
@@ -41,6 +42,33 @@ using std::unique_lock;
 namespace pv {
 namespace data {
 
+const QColor SignalBase::AnalogSignalColors[8] =
+{
+       QColor(0xC4, 0xA0, 0x00),       // Yellow   HSV:  49 / 100 / 77
+       QColor(0x87, 0x20, 0x7A),       // Magenta  HSV: 308 /  70 / 53
+       QColor(0x20, 0x4A, 0x87),       // Blue     HSV: 216 /  76 / 53
+       QColor(0x4E, 0x9A, 0x06),       // Green    HSV:  91 /  96 / 60
+       QColor(0xBF, 0x6E, 0x00),       // Orange   HSV:  35 / 100 / 75
+       QColor(0x5E, 0x20, 0x80),       // Purple   HSV: 280 /  75 / 50
+       QColor(0x20, 0x80, 0x7A),       // Turqoise HSV: 177 /  75 / 50
+       QColor(0x80, 0x20, 0x24)        // Red      HSV: 358 /  75 / 50
+};
+
+const QColor SignalBase::LogicSignalColors[10] =
+{
+       QColor(0x16, 0x19, 0x1A),       // Black
+       QColor(0x8F, 0x52, 0x02),       // Brown
+       QColor(0xCC, 0x00, 0x00),       // Red
+       QColor(0xF5, 0x79, 0x00),       // Orange
+       QColor(0xED, 0xD4, 0x00),       // Yellow
+       QColor(0x73, 0xD2, 0x16),       // Green
+       QColor(0x34, 0x65, 0xA4),       // Blue
+       QColor(0x75, 0x50, 0x7B),       // Violet
+       QColor(0x88, 0x8A, 0x85),       // Grey
+       QColor(0xEE, 0xEE, 0xEC),       // White
+};
+
+
 const int SignalBase::ColorBGAlpha = 8 * 256 / 100;
 const uint64_t SignalBase::ConversionBlockSize = 4096;
 const uint32_t SignalBase::ConversionDelay = 1000;  // 1 second
@@ -106,6 +134,13 @@ SignalBase::SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_
                this, SLOT(on_delayed_conversion_start()));
        delayed_conversion_starter_.setSingleShot(true);
        delayed_conversion_starter_.setInterval(ConversionDelay);
+
+       // Only logic and analog SR channels can have their colors auto-set
+       // because for them, we have an index that can be used
+       if (channel_type == LogicChannel)
+               set_color(LogicSignalColors[index() % countof(LogicSignalColors)]);
+       else if (channel_type == AnalogChannel)
+               set_color(AnalogSignalColors[index() % countof(AnalogSignalColors)]);
 }
 
 SignalBase::~SignalBase()
index 5a35218f3a2501e87d5e27ef8656532f27191e74..ab1c97a0530ddc55b6a8e5005e9582ec022f0768 100644 (file)
@@ -112,6 +112,9 @@ public:
                DynamicPreset = 0  ///< Conversion uses calculated values
        };
 
+       static const QColor AnalogSignalColors[8];
+       static const QColor LogicSignalColors[10];
+
 private:
        static const int ColorBGAlpha;
        static const uint64_t ConversionBlockSize;
index f64b94ae4d20b4f0791689fa03cfc34544fd93d9..ea33823d26fcd63031ac3fffb567381fd1f793c4 100644 (file)
@@ -71,13 +71,6 @@ namespace pv {
 namespace views {
 namespace trace {
 
-const QColor AnalogSignal::SignalColors[4] = {
-       QColor(0xC4, 0xA0, 0x00),       // Yellow
-       QColor(0x87, 0x20, 0x7A),       // Magenta
-       QColor(0x20, 0x4A, 0x87),       // Blue
-       QColor(0x4E, 0x9A, 0x06)        // Green
-};
-
 const QPen AnalogSignal::AxisPen(QColor(0, 0, 0, 30 * 256 / 100), 2);
 const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40 * 256 / 100);
 const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20 * 256 / 100);
@@ -135,7 +128,6 @@ AnalogSignal::AnalogSignal(
                settings.value(GlobalSettings::Key_View_ConversionThresholdDispMode).toInt();
        div_height_ = settings.value(GlobalSettings::Key_View_DefaultDivHeight).toInt();
 
-       base_->set_color(SignalColors[base_->index() % countof(SignalColors)]);
        update_scale();
 }
 
index 1dd9893f1b9812f78c0a8d7c442491d1252107f5..4c42e579b662e596289b65828b9a3c6edf4e3f56 100644 (file)
@@ -48,7 +48,6 @@ class AnalogSignal : public Signal
 
 private:
        static const QPen AxisPen;
-       static const QColor SignalColors[4];
        static const QColor GridMajorColor, GridMinorColor;
        static const QColor SamplingPointColor;
        static const QColor SamplingPointColorLo;
index a3fd7a0bbdcf9dc18c3561673497414c65a3b1b5..350f495048f3344d66a3d367e86a38a57138d27b 100644 (file)
@@ -70,19 +70,6 @@ const QColor LogicSignal::HighColor(0x00, 0xC0, 0x00);
 const QColor LogicSignal::LowColor(0xC0, 0x00, 0x00);
 const QColor LogicSignal::SamplingPointColor(0x77, 0x77, 0x77);
 
-const QColor LogicSignal::SignalColors[10] = {
-       QColor(0x16, 0x19, 0x1A),       // Black
-       QColor(0x8F, 0x52, 0x02),       // Brown
-       QColor(0xCC, 0x00, 0x00),       // Red
-       QColor(0xF5, 0x79, 0x00),       // Orange
-       QColor(0xED, 0xD4, 0x00),       // Yellow
-       QColor(0x73, 0xD2, 0x16),       // Green
-       QColor(0x34, 0x65, 0xA4),       // Blue
-       QColor(0x75, 0x50, 0x7B),       // Violet
-       QColor(0x88, 0x8A, 0x85),       // Grey
-       QColor(0xEE, 0xEE, 0xEC),       // White
-};
-
 QColor LogicSignal::TriggerMarkerBackgroundColor = QColor(0xED, 0xD4, 0x00);
 const int LogicSignal::TriggerMarkerPadding = 2;
 const char* LogicSignal::TriggerMarkerIcons[8] = {
@@ -115,8 +102,6 @@ LogicSignal::LogicSignal(
 {
        shared_ptr<Trigger> trigger;
 
-       base_->set_color(SignalColors[base->index() % countof(SignalColors)]);
-
        GlobalSettings settings;
        signal_height_ = settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt();
        show_sampling_points_ =
index e066d40340ee97f65c0993fc74a9e73769a70126..d316fd5de7947ca8934cd4b471b4cfb4ef14877c 100644 (file)
@@ -65,8 +65,6 @@ public:
        static const QColor LowColor;
        static const QColor SamplingPointColor;
 
-       static const QColor SignalColors[10];
-
        static QColor TriggerMarkerBackgroundColor;
        static const int TriggerMarkerPadding;
        static const char* TriggerMarkerIcons[8];