Skip to content

Commit 1d976fe

Browse files
Jacob Gilbertjacobagilbert
Jacob Gilbert
authored andcommitted
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 <[email protected]>
1 parent 290572e commit 1d976fe

9 files changed

+46
-6
lines changed

src/inputsource.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <QJsonObject>
3939
#include <QJsonArray>
4040
#include <QFile>
41+
#include <QColor>
4142

4243

4344
class ComplexF32SampleAdapter : public SampleAdapter {
@@ -339,10 +340,20 @@ void InputSource::readMetaData(const QString &filename)
339340
auto frequencyRange = range_t<double>{freq_lower_edge, freq_upper_edge};
340341

341342
auto label = sigmf_annotation["core:label"].toString();
342-
343+
343344
auto comment = sigmf_annotation["core:comment"].toString();
344345

345-
annotationList.emplace_back(sampleRange, frequencyRange, label, comment);
346+
auto sigmf_color = sigmf_annotation["presentation:color"].toString();
347+
// SigMF uses the format "#RRGGBBAA" for alpha-channel colors, QT uses "#AARRGGBB"
348+
if ((sigmf_color.at(0) == '#') && (sigmf_color.length()) == 9) {
349+
sigmf_color = "#" + sigmf_color.mid(7,2) + sigmf_color.mid(1,6);
350+
}
351+
auto boxColor = QString::fromStdString("white");
352+
if (QColor::isValidColor(sigmf_color)) {
353+
boxColor = sigmf_color;
354+
}
355+
356+
annotationList.emplace_back(sampleRange, frequencyRange, label, comment, boxColor);
346357
}
347358
}
348359
}

src/mainwindow.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ MainWindow::MainWindow()
5353
connect(dock->annosCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotations);
5454
connect(dock->annosCheckBox, &QCheckBox::stateChanged, dock, &SpectrogramControls::enableAnnotations);
5555
connect(dock->commentsCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotationCommentsTooltips);
56+
connect(dock->annoColorCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnoColors);
5657
connect(dock->cursorSymbolsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), plots, &PlotView::setCursorSegments);
5758

5859
// Connect dock outputs

src/plotview.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0})
5353
enableAnnotations(true);
5454
enableAnnotationCommentsTooltips(true);
5555

56+
enableAnnoColors(true);
57+
5658
addPlot(spectrogramPlot);
5759

5860
mainSampleSource->subscribe(this);
@@ -654,6 +656,14 @@ void PlotView::enableAnnotationCommentsTooltips(bool enabled)
654656
viewport()->update();
655657
}
656658

659+
void PlotView::enableAnnoColors(bool enabled)
660+
{
661+
if (spectrogramPlot != nullptr)
662+
spectrogramPlot->enableAnnoColors(enabled);
663+
664+
viewport()->update();
665+
}
666+
657667
int PlotView::sampleToColumn(size_t sample)
658668
{
659669
return sample / samplesPerColumn();

src/plotview.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public slots:
4848
void enableScales(bool enabled);
4949
void enableAnnotations(bool enabled);
5050
void enableAnnotationCommentsTooltips(bool enabled);
51+
void enableAnnoColors(bool enabled);
5152
void invalidateEvent() override;
5253
void repaint();
5354
void setCursorSegments(int segments);

src/samplesource.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "util.h"
2727
#include <QString>
2828
#include <QObject>
29+
#include <QColor>
2930

3031
class Annotation
3132
{
@@ -34,11 +35,12 @@ class Annotation
3435
range_t<double> frequencyRange;
3536
QString label;
3637
QString comment;
38+
QColor boxColor;
3739

3840
Annotation(range_t<size_t> sampleRange, range_t<double>frequencyRange, QString label,
39-
QString comment)
41+
QString comment, QColor boxColor)
4042
: sampleRange(sampleRange), frequencyRange(frequencyRange), label(label),
41-
comment(comment) {}
43+
comment(comment), boxColor(boxColor) {}
4244
};
4345

4446
template<typename T>

src/spectrogramcontrols.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent
100100
annosCheckBox = new QCheckBox(widget);
101101
layout->addRow(new QLabel(tr("Display Annotations:")), annosCheckBox);
102102
commentsCheckBox = new QCheckBox(widget);
103-
layout->addRow(new QLabel(tr("Display annotation comments tooltips:")), commentsCheckBox);
103+
layout->addRow(new QLabel(tr("Annotation comments:")), commentsCheckBox);
104+
annoColorCheckBox = new QCheckBox(widget);
105+
layout->addRow(new QLabel(tr("Annotation Colors:")), annoColorCheckBox);
104106

105107
widget->setLayout(layout);
106108
setWidget(widget);
@@ -136,7 +138,7 @@ void SpectrogramControls::setDefaults()
136138
cursorSymbolsSpinBox->setValue(1);
137139

138140
annosCheckBox->setCheckState(Qt::Checked);
139-
commentsCheckBox->setCheckState(Qt::Checked);
141+
annoColorCheckBox->setCheckState(Qt::Checked);
140142

141143
// Try to set the sample rate from the last-used value
142144
QSettings settings;

src/spectrogramcontrols.h

+1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ private slots:
7676
QCheckBox *scalesCheckBox;
7777
QCheckBox *annosCheckBox;
7878
QCheckBox *commentsCheckBox;
79+
QCheckBox *annoColorCheckBox;
7980
};

src/spectrogramplot.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float
4040
sampleRate = 0;
4141
frequencyScaleEnabled = false;
4242
sigmfAnnotationsEnabled = true;
43+
sigmfAnnotationColors = true;
4344

4445
for (int i = 0; i < 256; i++) {
4546
float p = (float)i / 256;
@@ -194,6 +195,10 @@ void SpectrogramPlot::paintAnnotations(QPainter &painter, QRect &rect, range_t<s
194195
int height = (a.frequencyRange.maximum - a.frequencyRange.minimum) / sampleRate * rect.height();
195196
int width = (a.sampleRange.maximum - a.sampleRange.minimum) / getStride();
196197

198+
if (sigmfAnnotationColors) {
199+
painter.setPen(a.boxColor);
200+
}
201+
197202
// Draw the label 2 pixels above the box
198203
painter.drawText(x, y - 2, a.label);
199204
painter.drawRect(x, y, width, height);
@@ -417,6 +422,11 @@ bool SpectrogramPlot::isAnnotationsEnabled(void)
417422
return sigmfAnnotationsEnabled;
418423
}
419424

425+
void SpectrogramPlot::enableAnnoColors(bool enabled)
426+
{
427+
sigmfAnnotationColors = enabled;
428+
}
429+
420430
bool SpectrogramPlot::tunerEnabled()
421431
{
422432
return (tunerTransform->subscriberCount() > 0);

src/spectrogramplot.h

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class SpectrogramPlot : public Plot
5353
void enableScales(bool enabled);
5454
void enableAnnotations(bool enabled);
5555
bool isAnnotationsEnabled();
56+
void enableAnnoColors(bool enabled);
5657
QString *mouseAnnotationComment(const QMouseEvent *event);
5758

5859
public slots:
@@ -81,6 +82,7 @@ public slots:
8182
double sampleRate;
8283
bool frequencyScaleEnabled;
8384
bool sigmfAnnotationsEnabled;
85+
bool sigmfAnnotationColors;
8486

8587
Tuner tuner;
8688
std::shared_ptr<TunerTransform> tunerTransform;

0 commit comments

Comments
 (0)