From 1d976fec85731ba3deef69e26baec91ff737b196 Mon Sep 17 00:00:00 2001 From: Jacob Gilbert Date: Mon, 28 Mar 2022 10:36:20 -0600 Subject: [PATCH] adding the ability to color annotations this is done through the `presentation` sigmf extensions simple, annotation by annotation color setting mechanism Signed-off-by: Jacob Gilbert --- src/inputsource.cpp | 15 +++++++++++++-- src/mainwindow.cpp | 1 + src/plotview.cpp | 10 ++++++++++ src/plotview.h | 1 + src/samplesource.h | 6 ++++-- src/spectrogramcontrols.cpp | 6 ++++-- src/spectrogramcontrols.h | 1 + src/spectrogramplot.cpp | 10 ++++++++++ src/spectrogramplot.h | 2 ++ 9 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/inputsource.cpp b/src/inputsource.cpp index ebbf749..f188232 100644 --- a/src/inputsource.cpp +++ b/src/inputsource.cpp @@ -38,6 +38,7 @@ #include #include #include +#include class ComplexF32SampleAdapter : public SampleAdapter { @@ -339,10 +340,20 @@ void InputSource::readMetaData(const QString &filename) auto frequencyRange = range_t{freq_lower_edge, freq_upper_edge}; auto label = sigmf_annotation["core:label"].toString(); - + auto comment = sigmf_annotation["core:comment"].toString(); - annotationList.emplace_back(sampleRange, frequencyRange, label, comment); + auto sigmf_color = sigmf_annotation["presentation:color"].toString(); + // SigMF uses the format "#RRGGBBAA" for alpha-channel colors, QT uses "#AARRGGBB" + if ((sigmf_color.at(0) == '#') && (sigmf_color.length()) == 9) { + sigmf_color = "#" + sigmf_color.mid(7,2) + sigmf_color.mid(1,6); + } + auto boxColor = QString::fromStdString("white"); + if (QColor::isValidColor(sigmf_color)) { + boxColor = sigmf_color; + } + + annotationList.emplace_back(sampleRange, frequencyRange, label, comment, boxColor); } } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dc62d76..5e37bcb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -53,6 +53,7 @@ MainWindow::MainWindow() connect(dock->annosCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotations); connect(dock->annosCheckBox, &QCheckBox::stateChanged, dock, &SpectrogramControls::enableAnnotations); connect(dock->commentsCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotationCommentsTooltips); + connect(dock->annoColorCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnoColors); connect(dock->cursorSymbolsSpinBox, static_cast(&QSpinBox::valueChanged), plots, &PlotView::setCursorSegments); // Connect dock outputs diff --git a/src/plotview.cpp b/src/plotview.cpp index d1c6bea..411c096 100644 --- a/src/plotview.cpp +++ b/src/plotview.cpp @@ -53,6 +53,8 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0}) enableAnnotations(true); enableAnnotationCommentsTooltips(true); + enableAnnoColors(true); + addPlot(spectrogramPlot); mainSampleSource->subscribe(this); @@ -654,6 +656,14 @@ void PlotView::enableAnnotationCommentsTooltips(bool enabled) viewport()->update(); } +void PlotView::enableAnnoColors(bool enabled) +{ + if (spectrogramPlot != nullptr) + spectrogramPlot->enableAnnoColors(enabled); + + viewport()->update(); +} + int PlotView::sampleToColumn(size_t sample) { return sample / samplesPerColumn(); diff --git a/src/plotview.h b/src/plotview.h index 326d547..1a18cd3 100644 --- a/src/plotview.h +++ b/src/plotview.h @@ -48,6 +48,7 @@ public slots: void enableScales(bool enabled); void enableAnnotations(bool enabled); void enableAnnotationCommentsTooltips(bool enabled); + void enableAnnoColors(bool enabled); void invalidateEvent() override; void repaint(); void setCursorSegments(int segments); diff --git a/src/samplesource.h b/src/samplesource.h index 3f0b299..58789f6 100644 --- a/src/samplesource.h +++ b/src/samplesource.h @@ -26,6 +26,7 @@ #include "util.h" #include #include +#include class Annotation { @@ -34,11 +35,12 @@ class Annotation range_t frequencyRange; QString label; QString comment; + QColor boxColor; Annotation(range_t sampleRange, range_tfrequencyRange, QString label, - QString comment) + QString comment, QColor boxColor) : sampleRange(sampleRange), frequencyRange(frequencyRange), label(label), - comment(comment) {} + comment(comment), boxColor(boxColor) {} }; template diff --git a/src/spectrogramcontrols.cpp b/src/spectrogramcontrols.cpp index 0e0f9aa..d5bd42c 100644 --- a/src/spectrogramcontrols.cpp +++ b/src/spectrogramcontrols.cpp @@ -100,7 +100,9 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent annosCheckBox = new QCheckBox(widget); layout->addRow(new QLabel(tr("Display Annotations:")), annosCheckBox); commentsCheckBox = new QCheckBox(widget); - layout->addRow(new QLabel(tr("Display annotation comments tooltips:")), commentsCheckBox); + layout->addRow(new QLabel(tr("Annotation comments:")), commentsCheckBox); + annoColorCheckBox = new QCheckBox(widget); + layout->addRow(new QLabel(tr("Annotation Colors:")), annoColorCheckBox); widget->setLayout(layout); setWidget(widget); @@ -136,7 +138,7 @@ void SpectrogramControls::setDefaults() cursorSymbolsSpinBox->setValue(1); annosCheckBox->setCheckState(Qt::Checked); - commentsCheckBox->setCheckState(Qt::Checked); + annoColorCheckBox->setCheckState(Qt::Checked); // Try to set the sample rate from the last-used value QSettings settings; diff --git a/src/spectrogramcontrols.h b/src/spectrogramcontrols.h index 69e7d60..71da242 100644 --- a/src/spectrogramcontrols.h +++ b/src/spectrogramcontrols.h @@ -76,4 +76,5 @@ private slots: QCheckBox *scalesCheckBox; QCheckBox *annosCheckBox; QCheckBox *commentsCheckBox; + QCheckBox *annoColorCheckBox; }; diff --git a/src/spectrogramplot.cpp b/src/spectrogramplot.cpp index 3ab57ec..a458fa2 100644 --- a/src/spectrogramplot.cpp +++ b/src/spectrogramplot.cpp @@ -40,6 +40,7 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptrsubscriberCount() > 0); diff --git a/src/spectrogramplot.h b/src/spectrogramplot.h index 2e52cb4..d28b27a 100644 --- a/src/spectrogramplot.h +++ b/src/spectrogramplot.h @@ -53,6 +53,7 @@ class SpectrogramPlot : public Plot void enableScales(bool enabled); void enableAnnotations(bool enabled); bool isAnnotationsEnabled(); + void enableAnnoColors(bool enabled); QString *mouseAnnotationComment(const QMouseEvent *event); public slots: @@ -81,6 +82,7 @@ public slots: double sampleRate; bool frequencyScaleEnabled; bool sigmfAnnotationsEnabled; + bool sigmfAnnotationColors; Tuner tuner; std::shared_ptr tunerTransform;