From: Soeren Apel Date: Mon, 17 Aug 2020 09:37:06 +0000 (+0200) Subject: Move signal color handling to SignalBase X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=516b0c4163547a969da7686702c043e7e0335419;p=pulseview.git Move signal color handling to SignalBase --- diff --git a/pv/data/mathsignal.cpp b/pv/data/mathsignal.cpp index 31424e39..d9ba5bc3 100644 --- a/pv/data/mathsignal.cpp +++ b/pv/data/mathsignal.cpp @@ -23,6 +23,7 @@ #include "mathsignal.hpp" +#include #include #include #include @@ -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()); diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index fb687244..c15a4431 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -28,8 +28,9 @@ #include -#include +#include #include +#include 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 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() diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 5a35218f..ab1c97a0 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -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; diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index f64b94ae..ea33823d 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -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(); } diff --git a/pv/views/trace/analogsignal.hpp b/pv/views/trace/analogsignal.hpp index 1dd9893f..4c42e579 100644 --- a/pv/views/trace/analogsignal.hpp +++ b/pv/views/trace/analogsignal.hpp @@ -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; diff --git a/pv/views/trace/logicsignal.cpp b/pv/views/trace/logicsignal.cpp index a3fd7a0b..350f4950 100644 --- a/pv/views/trace/logicsignal.cpp +++ b/pv/views/trace/logicsignal.cpp @@ -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; - base_->set_color(SignalColors[base->index() % countof(SignalColors)]); - GlobalSettings settings; signal_height_ = settings.value(GlobalSettings::Key_View_DefaultLogicHeight).toInt(); show_sampling_points_ = diff --git a/pv/views/trace/logicsignal.hpp b/pv/views/trace/logicsignal.hpp index e066d403..d316fd5d 100644 --- a/pv/views/trace/logicsignal.hpp +++ b/pv/views/trace/logicsignal.hpp @@ -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];