-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
3124 lines (2768 loc) · 107 KB
/
Copy pathmainwindow.cpp
File metadata and controls
3124 lines (2768 loc) · 107 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file mainwindow.cpp
* @brief Action handlers, collapsible panels, and motion feedback.
*/
#include "mainwindow.h"
#include "offline_worker.h"
#include "shimmer.h"
#include "stretchtitlelabel.h"
#include "ui_mainwindow.h"
#include "qcustomplot.h"
#include "ColorMapEditorDialog.h"
#include "channel_detector.h"
#include "channel_band_item.h"
#include "channel_palette.h"
#include "iq_bandpass_filter.h"
#include "measurement_panel.h"
#include "spectrum_traces.h"
#include <QAbstractItemView>
#include <QApplication>
#include <QHeaderView>
#include <QScrollArea>
#include <QAction>
#include <QCheckBox>
#include <QColor>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QInputDialog>
#include <QLineEdit>
#include <QDoubleValidator>
#include <QDoubleSpinBox>
#include <QEasingCurve>
#include <QEvent>
#include <QFileDialog>
#include <QFileInfo>
#include <QFrame>
#include <QGraphicsDropShadowEffect>
#include <QGraphicsOpacityEffect>
#include <QGroupBox>
#include <QIcon>
#include <QKeyEvent>
#include <QGridLayout>
#include <QLayout>
#include <QMutexLocker>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QDateTime>
#include <QDialog>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QPainterPath>
#include <QPixmap>
#include <QPushButton>
#include <QPropertyAnimation>
#include <QProgressDialog>
#include <QStatusBar>
#include <QSlider>
#include <QSignalBlocker>
#include <QSizePolicy>
#include <QStyle>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QThread>
#include <QToolButton>
#include <QTimer>
#include <algorithm>
#include <cmath>
#include <vector>
namespace {
/**
* @brief Hanning window for the GUI-thread FFT (x310 / oscilloscope pattern).
*/
float hanningWindow(int i, int n)
{
if (n <= 1) {
return 1.0f;
}
return static_cast<float>(
0.5 * (1.0 - std::cos(2.0 * M_PI * static_cast<double>(i) / (n - 1))));
}
constexpr size_t kCircBufSize = 100000;
constexpr size_t kDefaultFftSize = 4096;
const QColor kBrandGreen(0x8F, 0xCB, 0x57);
/** @brief Fixed card shadow; never animated so it stays the same at runtime. */
constexpr qreal kCardShadowBlur = 20.0;
constexpr qreal kCardShadowY = 5.0;
const QColor kCardShadowColor(0, 0, 0, 90);
/** @brief Same locked shadow, tighter so title glyphs stay readable. */
/** @brief Fixed spectrum Y span (dB); do not auto-rescale per frame. */
constexpr double kFreqYMinDb = -120.0;
constexpr double kFreqYMaxDb = 40.0;
constexpr qreal kTitleShadowY = 2.0;
class TitleTextShadowFilter : public QObject
{
public:
explicit TitleTextShadowFilter(QObject *parent = nullptr)
: QObject(parent)
{
}
protected:
bool eventFilter(QObject *watched, QEvent *event) override
{
if (event->type() != QEvent::Paint) {
return false;
}
auto *label = qobject_cast<QLabel *>(watched);
if (!label || label->text().isEmpty()) {
return false;
}
// StretchTitleLabel paints its own offset shadow in paintEvent.
if (label->inherits("StretchTitleLabel")) {
return false;
}
QPainter p(label);
p.setRenderHint(QPainter::TextAntialiasing, true);
p.setFont(label->font());
p.setPen(kCardShadowColor);
p.drawText(label->rect().translated(0, static_cast<int>(kTitleShadowY)),
int(label->alignment()),
label->text());
return false;
}
};
/**
* @brief Draws a flat brand-green glyph so command actions are not theme icons.
* @param name One of reset, play, pause.
* @return Transparent pixmap icon in `#8FCB57`.
*/
QIcon brandedCommandIcon(const QString &name)
{
const int s = 128;
QPixmap pm(s, s);
pm.fill(Qt::transparent);
QPainter p(&pm);
p.setRenderHint(QPainter::Antialiasing, true);
const QColor fill(kBrandGreen);
const QColor stroke = fill.darker(118);
if (name == QLatin1String("play")) {
QPainterPath tri;
tri.moveTo(36, 22);
tri.lineTo(36, 106);
tri.lineTo(108, 64);
tri.closeSubpath();
p.setPen(QPen(stroke, 4.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
p.setBrush(fill);
p.drawPath(tri);
} else if (name == QLatin1String("pause")) {
p.setPen(Qt::NoPen);
p.setBrush(fill);
p.drawRoundedRect(QRectF(32, 24, 22, 80), 6, 6);
p.drawRoundedRect(QRectF(74, 24, 22, 80), 6, 6);
} else {
// Clockwise circular arrow (reset / refresh).
p.setBrush(Qt::NoBrush);
p.setPen(QPen(fill, 12.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
p.drawArc(QRectF(24, 24, 80, 80), 50 * 16, 270 * 16);
QPainterPath head;
head.moveTo(88, 24);
head.lineTo(112, 40);
head.lineTo(78, 48);
head.closeSubpath();
p.setPen(Qt::NoPen);
p.setBrush(fill);
p.drawPath(head);
}
return QIcon(pm);
}
/**
* @brief Moves the first child layout of a group box into a hideable widget.
*
* The .ui file places each QFormLayout directly in the group; collapsible
* sections need a QWidget so the title stays visible while the fields hide.
*
* @param box Checkable section group.
* @return Body widget owning the original form layout, or nullptr.
*/
QWidget *extractFormBody(QGroupBox *box)
{
if (!box || !box->layout() || box->layout()->count() == 0) {
return nullptr;
}
QLayoutItem *item = box->layout()->takeAt(0);
auto *body = new QWidget(box);
QLayout *inner = item ? item->layout() : nullptr;
if (inner) {
body->setLayout(inner);
// takeAt() returns the QFormLayout itself (QLayout is a QLayoutItem).
if (item != inner) {
delete item;
}
} else {
delete item;
}
box->layout()->addWidget(body);
return body;
}
/**
* @brief Theme icon with a Qt standard-pixmap fallback.
* @param style Widget style used for the fallback.
* @param theme Freedesktop icon name.
* @param fallback Qt standard pixmap.
* @return Non-null icon when the style provides the pixmap.
*/
QIcon commandIcon(const QStyle *style, const QString &theme, QStyle::StandardPixmap fallback)
{
const QIcon themed = QIcon::fromTheme(theme);
if (!themed.isNull()) {
return themed;
}
return style ? style->standardIcon(fallback) : QIcon();
}
} // namespace
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setupBrandIcon();
setupCollapsibles();
setupPlaybackTimers();
wireActions();
setupChrome();
setupPlots();
setupBodyPanels();
setupPlotScrollAndChannelTable();
setupSideDockScroll();
setupOfflinePipeline();
ui->editSampleRate->setEnabled(true);
ui->cmbSampleRateUnit->setCurrentIndex(2); // MHz
{
auto *validator = new QDoubleValidator(0.0, 1.0e12, 6, ui->editSampleRate);
validator->setNotation(QDoubleValidator::StandardNotation);
ui->editSampleRate->setValidator(validator);
}
ui->cmbSourceType->setCurrentIndex(0);
ui->cmbSourceType->setEnabled(false);
m_liveApplyEnabled = true;
wireLiveParams();
applyLiveParameters();
statusBar()->showMessage(tr("Ready — parameter changes apply immediately."), 5000);
}
void MainWindow::setupBrandIcon()
{
// Wayland/GNOME often hide title-bar icons; keep brand mark in the command bar.
const QPixmap iconPix(QStringLiteral(":/resources/icons/app_icon.png"));
if (!iconPix.isNull()) {
ui->lblAppIcon->setPixmap(
iconPix.scaled(44, 44, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
}
void MainWindow::setupCollapsibles()
{
wireCollapsible(ui->groupSource, extractFormBody(ui->groupSource));
wireCollapsible(ui->groupCapture, extractFormBody(ui->groupCapture));
wireCollapsible(ui->groupInterval, extractFormBody(ui->groupInterval));
wireCollapsible(ui->groupFft, extractFormBody(ui->groupFft));
ui->groupSource->setChecked(true);
ui->groupCapture->setChecked(true);
ui->groupInterval->setChecked(true);
ui->groupFft->setChecked(true);
}
void MainWindow::setupSideDockScroll()
{
// Keep docks full-height; let scroll areas shrink contents to the viewport width.
ui->rootLayout->setStretch(1, 1);
ui->bodyLayout->setStretch(0, 0); // measurement
ui->bodyLayout->setStretch(1, 1); // plots
ui->bodyLayout->setStretch(2, 0); // control
ui->sideDock->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
ui->sideScroll->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ui->sideScrollContents->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
ui->sideDockLayout->setStretchFactor(ui->sideScroll, 1);
ui->sideScroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->sideScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->sideScroll->setWidgetResizable(true);
}
void MainWindow::setupBodyPanels()
{
// Designer order is Control | Plots. Reorder to Measurement | Plots | Control
// and attach the SweepPlots-inspired trace/peak manager to freq_widget.
m_measurementPanel = new MeasurementPanel(this);
m_spectrumTraces = new SpectrumTraces(this);
m_spectrumTraces->attach(ui->freq_widget, m_measurementPanel);
connect(m_spectrumTraces, &SpectrumTraces::markerReadoutChanged,
this, &MainWindow::setMarkerReadout);
connect(m_spectrumTraces, &SpectrumTraces::traceModeLabelChanged,
this, [this](const QString &modeName) {
ui->lblBottomVal2->setText(modeName);
flashLabel(ui->lblBottomVal2);
});
connect(m_measurementPanel->buttonChannelizer(), &QPushButton::clicked,
this, &MainWindow::onChannelizerClicked);
connect(m_measurementPanel->buttonClearChannels(), &QPushButton::clicked,
this, &MainWindow::onClearChannelsClicked);
connect(m_measurementPanel->buttonSelectFilterRange(), &QPushButton::clicked,
this, &MainWindow::onSelectFilterRangeClicked);
connect(m_measurementPanel->buttonFilterSave(), &QPushButton::clicked,
this, &MainWindow::onFilterAndSaveClicked);
connect(m_measurementPanel->buttonClearFilter(), &QPushButton::clicked,
this, &MainWindow::onClearFilterClicked);
ui->freq_widget->installEventFilter(this);
ui->bodyLayout->removeWidget(ui->sideDock);
ui->bodyLayout->removeWidget(ui->plotsHost);
ui->bodyLayout->addWidget(m_measurementPanel, /*stretch=*/0);
ui->bodyLayout->addWidget(ui->plotsHost, /*stretch=*/1);
ui->bodyLayout->addWidget(ui->sideDock, /*stretch=*/0);
applySoftCardShadow(m_measurementPanel);
QLabel *measTitle = m_measurementPanel->titleLabel();
if (measTitle) {
applyTitleShadow(measTitle);
ShimmerController::markAsTitle(measTitle);
}
// Overlay must be installed after the panel exists; markAsTitle alone
// only sets a property and does not create the shimmer band.
if (m_shimmer && measTitle) {
m_shimmer->installOn(measTitle);
m_shimmer->rescan();
}
}
void MainWindow::setupPlotScrollAndChannelTable()
{
auto *results = new QFrame(ui->splitterPlots);
results->setObjectName(QStringLiteral("plotChannelResults"));
results->setMinimumHeight(200);
results->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
auto *resultsLayout = new QVBoxLayout(results);
resultsLayout->setContentsMargins(12, 8, 12, 10);
resultsLayout->setSpacing(6);
auto *title = new QLabel(tr("Channelizer Results"), results);
title->setObjectName(QStringLiteral("lblChannelResultsTitle"));
title->setStyleSheet(
QStringLiteral("font-size:13px;font-weight:700;color:#111111;font-family:Georgia,serif;"));
resultsLayout->addWidget(title);
m_channelResultsTable = new QTableWidget(0, 5, results);
m_channelResultsTable->setObjectName(QStringLiteral("tblChannels"));
m_channelResultsTable->setHorizontalHeaderLabels(
{tr("#"), tr("Start"), tr("Stop"), tr("BW"), tr("Peak")});
m_channelResultsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_channelResultsTable->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
m_channelResultsTable->horizontalHeader()->setFixedHeight(26);
m_channelResultsTable->verticalHeader()->setVisible(false);
m_channelResultsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_channelResultsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
m_channelResultsTable->setSelectionMode(QAbstractItemView::SingleSelection);
m_channelResultsTable->setMinimumHeight(140);
m_channelResultsTable->setAlternatingRowColors(true);
m_channelResultsTable->setShowGrid(true);
m_channelResultsTable->setGridStyle(Qt::SolidLine);
m_channelResultsTable->verticalHeader()->setDefaultSectionSize(24);
m_channelResultsTable->setStyleSheet(QStringLiteral(
"QTableWidget {"
" border: 1px solid #C8D5C8;"
" border-radius: 4px;"
" background: #FAFCFA;"
" alternate-background-color: #EDF4ED;"
" gridline-color: #D5E0D5;"
" font-size: 12px;"
"}"
"QTableWidget::item {"
" padding: 2px 6px;"
" border: none;"
"}"
"QTableWidget::item:selected {"
" background: #4A8A5A;"
" color: #FFFFFF;"
"}"
"QHeaderView::section {"
" background: #2E6040;"
" color: #FFFFFF;"
" font-weight: 700;"
" font-size: 12px;"
" padding: 4px;"
" border: none;"
" border-right: 1px solid #3D7A50;"
" border-bottom: 1px solid #1E4030;"
"}"
"QHeaderView::section:last {"
" border-right: none;"
"}"));
resultsLayout->addWidget(m_channelResultsTable, 1);
ui->splitterPlots->addWidget(results);
ui->plotTime->setMinimumHeight(280);
ui->plotSpectrum->setMinimumHeight(280);
ui->plotWaterfall->setMinimumHeight(280);
ui->iq_widget->setMinimumHeight(200);
ui->freq_widget->setMinimumHeight(200);
ui->waterfall_widget->setMinimumHeight(200);
ui->splitterPlots->setMinimumHeight(280 * 3 + 220);
auto *scroll = new QScrollArea(ui->plotsHost);
scroll->setObjectName(QStringLiteral("plotsScroll"));
scroll->setFrameShape(QFrame::NoFrame);
scroll->setWidgetResizable(true);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scroll->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ui->plotsHostLayout->removeWidget(ui->splitterPlots);
scroll->setWidget(ui->splitterPlots);
ui->plotsHostLayout->addWidget(scroll);
}
void MainWindow::setupPlaybackTimers()
{
m_blinkTimer = new QTimer(this);
m_blinkTimer->setInterval(450);
connect(m_blinkTimer, &QTimer::timeout, this, &MainWindow::onBlinkTick);
m_plotTimer = new QTimer(this);
m_plotTimer->setTimerType(Qt::PreciseTimer);
m_plotTimer->setSingleShot(false);
connect(m_plotTimer, &QTimer::timeout, this, &MainWindow::onPlotSweepTick);
m_channelAnimTimer = new QTimer(this);
m_channelAnimTimer->setInterval(33);
connect(m_channelAnimTimer, &QTimer::timeout, this, &MainWindow::onChannelAnimTick);
ui->lblActivityDot->setStyleSheet(QStringLiteral("color:#C5D0C2;"));
}
void MainWindow::setupChrome()
{
for (QWidget *card : {static_cast<QWidget *>(ui->commandBar),
static_cast<QWidget *>(ui->sideDock),
static_cast<QWidget *>(ui->bottomReadout)}) {
applySoftCardShadow(card);
}
const QSize iconSz(28, 28);
ui->btnPlay->setIcon(brandedCommandIcon(QStringLiteral("play")));
ui->btnPlay->setToolTip(tr("Play"));
ui->btnResetParams->setIcon(brandedCommandIcon(QStringLiteral("reset")));
ui->btnBrowseSource->setIcon(commandIcon(style(), QStringLiteral("document-open"),
QStyle::SP_DirOpenIcon));
for (QPushButton *btn : {ui->btnPlay, ui->btnResetParams}) {
btn->setIconSize(iconSz);
btn->setFlat(true);
btn->setText(QString());
btn->setFocusPolicy(Qt::NoFocus);
btn->setGraphicsEffect(nullptr);
}
ui->btnBrowseSource->setIconSize(QSize(18, 18));
for (QWidget *title : {static_cast<QWidget *>(ui->lblAppTitle),
static_cast<QWidget *>(ui->lblDockTitle),
static_cast<QWidget *>(ui->lblPlotTimeTitle),
static_cast<QWidget *>(ui->lblPlotSpectrumTitle),
static_cast<QWidget *>(ui->lblPlotWaterfallTitle)}) {
applyTitleShadow(title);
ShimmerController::markAsTitle(title);
}
ShimmerController::markAsTitle(ui->lblAppIcon);
m_shimmer = new ShimmerController(this, this);
}
void MainWindow::stylePlot(QCustomPlot *plot)
{
plot->setAttribute(Qt::WA_OpaquePaintEvent, true);
plot->setNotAntialiasedElements(QCP::aeAll);
plot->setBackground(QColor(QStringLiteral("#FFFFFF")));
plot->axisRect()->setBackground(QColor(QStringLiteral("#FAFCFA")));
plot->xAxis->setBasePen(QPen(QColor(QStringLiteral("#9AA39A"))));
plot->yAxis->setBasePen(QPen(QColor(QStringLiteral("#9AA39A"))));
plot->xAxis->setTickPen(QPen(QColor(QStringLiteral("#9AA39A"))));
plot->yAxis->setTickPen(QPen(QColor(QStringLiteral("#9AA39A"))));
plot->xAxis->setSubTickPen(QPen(QColor(QStringLiteral("#D9E2D7"))));
plot->yAxis->setSubTickPen(QPen(QColor(QStringLiteral("#D9E2D7"))));
plot->xAxis->setTickLabelColor(QColor(QStringLiteral("#333333")));
plot->yAxis->setTickLabelColor(QColor(QStringLiteral("#333333")));
plot->xAxis->setLabelColor(QColor(QStringLiteral("#555555")));
plot->yAxis->setLabelColor(QColor(QStringLiteral("#555555")));
plot->xAxis->grid()->setPen(QPen(QColor(QStringLiteral("#E4EBE2")), 1, Qt::DotLine));
plot->yAxis->grid()->setPen(QPen(QColor(QStringLiteral("#E4EBE2")), 1, Qt::DotLine));
plot->setInteractions(QCP::iNone);
}
void MainWindow::setupPlots()
{
stylePlot(ui->iq_widget);
stylePlot(ui->freq_widget);
stylePlot(ui->waterfall_widget);
ui->iq_widget->addGraph();
ui->iq_widget->graph(0)->setPen(QPen(QColor(QStringLiteral("#111111")), 1));
ui->iq_widget->graph(0)->setAdaptiveSampling(true);
ui->iq_widget->addGraph();
ui->iq_widget->graph(1)->setPen(QPen(QColor(QStringLiteral("#3D7A9A")), 1));
ui->iq_widget->graph(1)->setAdaptiveSampling(true);
ui->iq_widget->xAxis->setLabel(QStringLiteral("Time (ms)"));
ui->iq_widget->yAxis->setLabel(QStringLiteral("Amplitude"));
ui->iq_widget->xAxis->setRange(0, 1);
ui->iq_widget->yAxis->setRange(-1, 1);
// Frequency graphs are owned by SpectrumTraces (6 traces × primary/secondary/peaks).
ui->freq_widget->xAxis->setLabel(QStringLiteral("Frequency (Hz)"));
ui->freq_widget->yAxis->setLabel(QStringLiteral("Power (dB)"));
ui->freq_widget->xAxis->setRange(0, 1e6);
ui->freq_widget->yAxis->setRange(kFreqYMinDb, kFreqYMaxDb);
m_waterfallMap = new QCPColorMap(ui->waterfall_widget->xAxis, ui->waterfall_widget->yAxis);
m_waterfallMap->setGradient(QCPColorGradient::gpSpectrum);
m_waterfallMap->setInterpolate(false);
m_waterfallMap->data()->setSize(256, static_cast<int>(m_waterfallHistory));
m_waterfallMap->data()->setRange(QCPRange(0, 1e6),
QCPRange(0, static_cast<double>(m_waterfallHistory - 1)));
m_waterfallMap->data()->fill(m_wfColorMin);
m_waterfallMap->setDataRange(QCPRange(m_wfColorMin, m_wfColorMax));
ui->waterfall_widget->xAxis->setLabel(QStringLiteral("Frequency (Hz)"));
ui->waterfall_widget->yAxis->setLabel(QStringLiteral("History"));
ui->waterfall_widget->yAxis->setRangeReversed(true);
setupPlotInteractions();
ui->iq_widget->replot();
ui->freq_widget->replot();
ui->waterfall_widget->replot();
}
MainWindow::~MainWindow()
{
stopOfflineWorker();
destroyGuiFftPlan();
delete m_timeBuffer;
m_timeBuffer = nullptr;
delete m_offlineParams;
m_offlineParams = nullptr;
delete ui;
}
void MainWindow::applySoftCardShadow(QWidget *widget)
{
if (!widget) {
return;
}
auto *shadow = qobject_cast<QGraphicsDropShadowEffect *>(widget->graphicsEffect());
if (!shadow) {
shadow = new QGraphicsDropShadowEffect(widget);
widget->setGraphicsEffect(shadow);
}
shadow->setBlurRadius(kCardShadowBlur);
shadow->setOffset(0.0, kCardShadowY);
shadow->setColor(kCardShadowColor);
shadow->setEnabled(true);
}
void MainWindow::applyCtaButtonShadow(QWidget *widget)
{
applySoftCardShadow(widget);
}
void MainWindow::applyTitleShadow(QWidget *widget)
{
if (!widget) {
return;
}
// Blur-based QGraphicsDropShadowEffect is recomputed on every plot
// replot and makes realtime feel sluggish. Paint a cheap offset copy
// instead so the look stays the same while playing.
widget->setGraphicsEffect(nullptr);
if (qobject_cast<StretchTitleLabel *>(widget)) {
return;
}
widget->installEventFilter(new TitleTextShadowFilter(widget));
}
void MainWindow::wireCollapsible(QGroupBox *box, QWidget *body)
{
if (!box || !body) {
return;
}
box->setCheckable(true);
connect(box, &QGroupBox::toggled, body, &QWidget::setVisible);
connect(box, &QGroupBox::toggled, this, [body, box](bool on) {
if (!on) {
// Opacity effects left on layout bodies cause Wayland ghosting/hover glitches.
body->setGraphicsEffect(nullptr);
return;
}
auto *fx = new QGraphicsOpacityEffect(body);
body->setGraphicsEffect(fx);
auto *fade = new QPropertyAnimation(fx, "opacity", body);
fade->setDuration(220);
fade->setStartValue(0.15);
fade->setEndValue(1.0);
fade->setEasingCurve(QEasingCurve::OutCubic);
// Remove the effect when done: a permanent QGraphicsEffect on a layout body
// breaks hover painting and leaves ghost strips (especially on Wayland).
QObject::connect(fade, &QAbstractAnimation::finished, body, [body]() {
body->setGraphicsEffect(nullptr);
});
fade->start(QAbstractAnimation::DeleteWhenStopped);
});
body->setVisible(box->isChecked());
}
void MainWindow::wireActions()
{
connect(ui->actionOpenSignal, &QAction::triggered, this, &MainWindow::openSignal);
connect(ui->actionResetParams, &QAction::triggered, this, &MainWindow::resetParameters);
connect(ui->actionPlay, &QAction::triggered, this, &MainWindow::playAnalysis);
connect(ui->actionPause, &QAction::triggered, this, &MainWindow::pauseAnalysis);
connect(ui->actionExit, &QAction::triggered, this, &QWidget::close);
connect(ui->actionExpandAll, &QAction::triggered, this, &MainWindow::expandAllSections);
connect(ui->actionCollapseAll, &QAction::triggered, this, &MainWindow::collapseAllSections);
connect(ui->actionMaxPeak, &QAction::triggered, this, &MainWindow::peakMax);
connect(ui->actionMinPeak, &QAction::triggered, this, &MainWindow::peakMin);
connect(ui->actionSearchPeak, &QAction::triggered, this, &MainWindow::peakSearch);
connect(ui->actionNextPeak, &QAction::triggered, this, &MainWindow::peakNext);
connect(ui->actionLeftPeak, &QAction::triggered, this, &MainWindow::peakLeft);
connect(ui->actionRightPeak, &QAction::triggered, this, &MainWindow::peakRight);
connect(ui->btnBrowseSource, &QToolButton::clicked, this, &MainWindow::openSignal);
connect(ui->btnResetParams, &QPushButton::clicked, this, &MainWindow::resetParameters);
connect(ui->btnPlay, &QPushButton::clicked, this, &MainWindow::togglePlayback);
connect(ui->sliderTimeProgress, &QSlider::sliderPressed, this, [this]() {
m_timeSliderHeld = true;
});
connect(ui->sliderTimeProgress, &QSlider::sliderReleased, this, [this]() {
m_timeSliderHeld = false;
onTimeSliderReleased();
});
connect(ui->sliderTimeProgress, &QAbstractSlider::actionTriggered, this,
[this](int action) {
if (action == QAbstractSlider::SliderNoAction) {
return;
}
QTimer::singleShot(0, this, [this]() {
if (!m_timeSliderHeld) {
onTimeSliderReleased();
}
});
});
ui->lbl_chkAutoRepeat->setBuddy(ui->chkAutoRepeat);
connect(ui->chkAutoRepeat, &QCheckBox::toggled, this, [this](bool checked) {
if (m_offlineParams) {
QMutexLocker lock(&m_offlineParams->mutex);
m_offlineParams->autoRepeat = checked;
}
if (m_offlineWorker) {
m_offlineWorker->setAutoRepeat(checked);
}
});
}
void MainWindow::wireLiveParams()
{
// Debounce rapid spin/combo changes (especially RBW) so the GUI thread
// does not run configurePlotsForOffline on every intermediate value.
m_liveParamsDebounce = new QTimer(this);
m_liveParamsDebounce->setSingleShot(true);
m_liveParamsDebounce->setInterval(150);
connect(m_liveParamsDebounce, &QTimer::timeout, this, &MainWindow::applyLiveParameters);
const auto scheduleApply = [this]() {
if (m_liveParamsDebounce) {
m_liveParamsDebounce->start();
}
};
for (QDoubleSpinBox *spin : findChildren<QDoubleSpinBox *>()) {
connect(spin, &QDoubleSpinBox::valueChanged, this, scheduleApply);
}
for (QComboBox *combo : findChildren<QComboBox *>()) {
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, scheduleApply);
}
for (QCheckBox *box : findChildren<QCheckBox *>()) {
connect(box, &QCheckBox::toggled, this, scheduleApply);
}
for (QLineEdit *edit : findChildren<QLineEdit *>()) {
connect(edit, &QLineEdit::editingFinished, this, scheduleApply);
}
}
void MainWindow::animateButtonPress(QWidget *button)
{
if (!button) {
return;
}
const QRect start = button->geometry();
const QRect pressed(start.x() + 2, start.y() + 2, start.width() - 4, start.height() - 4);
auto *anim = new QPropertyAnimation(button, "geometry", button);
anim->setDuration(160);
anim->setKeyValueAt(0.0, start);
anim->setKeyValueAt(0.45, pressed);
anim->setKeyValueAt(1.0, start);
anim->setEasingCurve(QEasingCurve::OutBack);
anim->start(QAbstractAnimation::DeleteWhenStopped);
}
void MainWindow::flashLabel(QWidget *label)
{
if (!label) {
return;
}
// Replace any previous opacity effect so a cancelled flash cannot leave
// SIGNAL/TRACE looking blank.
label->setGraphicsEffect(nullptr);
auto *fx = new QGraphicsOpacityEffect(label);
label->setGraphicsEffect(fx);
auto *fade = new QPropertyAnimation(fx, "opacity", label);
fade->setDuration(350);
fade->setKeyValueAt(0.0, 0.2);
fade->setKeyValueAt(0.5, 1.0);
fade->setKeyValueAt(1.0, 1.0);
fade->setEasingCurve(QEasingCurve::OutCubic);
fade->start(QAbstractAnimation::DeleteWhenStopped);
}
void MainWindow::refreshBottomSignalName()
{
QString path = m_signalPath.trimmed();
if (path.isEmpty() && ui->editSourceFile) {
path = ui->editSourceFile->text().trimmed();
if (!path.isEmpty()) {
m_signalPath = path;
}
}
const QString name = path.isEmpty() ? tr("—") : QFileInfo(path).fileName();
if (ui->lblBottomVal1) {
ui->lblBottomVal1->setGraphicsEffect(nullptr);
ui->lblBottomVal1->setText(name);
ui->lblBottomVal1->setToolTip(path);
}
// Keep TRACE filled whenever we refresh the bottom strip.
if (ui->lblBottomVal2 && m_spectrumTraces) {
const QString mode = m_spectrumTraces->currentTraceModeName();
if (!mode.isEmpty()) {
ui->lblBottomVal2->setGraphicsEffect(nullptr);
ui->lblBottomVal2->setText(mode);
}
}
}
void MainWindow::openSignal()
{
animateButtonPress(ui->btnBrowseSource);
raise();
activateWindow();
QFileDialog dlg(this, tr("Open Signal"));
dlg.setOption(QFileDialog::DontUseNativeDialog, true);
dlg.setFileMode(QFileDialog::ExistingFile);
dlg.setNameFilter(tr("Signal files (*.wav *.bin *.iq *.csv *.dat *.sig);;All files (*)"));
dlg.setWindowModality(Qt::WindowModal);
dlg.setMinimumSize(780, 520);
const int dlgCode = dlg.exec();
const QString path = (dlgCode == QDialog::Accepted) ? dlg.selectedFiles().value(0) : QString();
if (path.isEmpty()) {
return;
}
const QString prevPath = m_signalPath;
m_signalPath = path;
ui->editSourceFile->setText(path);
refreshBottomSignalName();
flashLabel(ui->lblBottomVal1);
statusBar()->showMessage(tr("Signal opened: %1").arg(path), 5000);
if (path != prevPath) {
discardOfflineSession();
}
applyLiveParameters();
{
const QSignalBlocker blocker(ui->sliderTimeProgress);
ui->sliderTimeProgress->setValue(0);
}
ui->sliderTimeProgress->setToolTip(tr("How much of the signal has been displayed"));
playAnalysis();
}
void MainWindow::applyParameters()
{
const QString summary =
tr("%1 | fc=%2 %3 | RBW=%4 %5 | gain=%6 | %7")
.arg(ui->cmbSourceType->currentText())
.arg(ui->spinCenter->value(), 0, 'f', 3)
.arg(ui->cmbCenterUnit->currentText())
.arg(ui->spinRbw->value(), 0, 'f', 3)
.arg(ui->cmbRbwUnit->currentText())
.arg(ui->spinSourceGain->value(), 0, 'f', 2)
.arg(ui->cmbFileSampleType->currentText());
ui->lblBottomVal4->setText(summary);
ui->lblPlotSpectrumMeta->setText(
tr("Center %1 %2")
.arg(ui->spinCenter->value(), 0, 'f', 3)
.arg(ui->cmbCenterUnit->currentText()));
flashLabel(ui->lblBottomVal4);
flashLabel(ui->lblPlotSpectrumMeta);
applyLiveParameters();
statusBar()->showMessage(tr("Parameters applied."), 3000);
}
void MainWindow::resetParameters()
{
animateButtonPress(ui->btnResetParams);
m_liveApplyEnabled = false;
ui->cmbSourceType->setCurrentIndex(0);
ui->cmbSourceType->setEnabled(false);
ui->spinSourceGain->setValue(0.70);
ui->spinSignalFreq->setValue(100.0);
ui->cmbSignalFreqUnit->setCurrentIndex(0);
ui->cmbFileSampleType->setCurrentIndex(0);
ui->chkAutoRepeat->setChecked(true);
ui->spinRefLevel->setValue(-20.0);
ui->cmbRefLevelUnit->setCurrentIndex(0);
ui->spinCenter->setValue(100.0);
ui->cmbCenterUnit->setCurrentIndex(2);
ui->spinStep->setValue(1.0);
ui->cmbStepUnit->setCurrentIndex(0);
ui->editSampleRate->setText(QStringLiteral("40"));
ui->cmbSampleRateUnit->setCurrentIndex(2);
ui->editSampleRate->setEnabled(true);
ui->spinIfBw->setValue(-1.0);
ui->cmbIfBwUnit->setCurrentIndex(0);
ui->chkAutoIfBw->setChecked(true);
ui->spinSwpTime->setValue(200.0);
ui->cmbSwpTimeUnit->setCurrentIndex(1);
ui->chkAutoInterval->setChecked(true);
ui->spinIntervalOffset->setValue(0.0);
ui->cmbIntervalOffsetUnit->setCurrentIndex(0);
ui->spinIntervalLength->setValue(0.0);
ui->cmbIntervalLengthUnit->setCurrentIndex(0);
ui->chkAutoOverlap->setChecked(true);
ui->spinOverlap->setValue(98.999);
ui->spinMaxFft->setValue(1000.0);
ui->spinStepLength->setValue(3.775);
ui->cmbStepLengthUnit->setCurrentIndex(0);
m_liveApplyEnabled = true;
syncRbwSpinFromFftSize(kDefaultFftSize);
applyLiveParameters();
flashLabel(ui->lblBottomVal2);
statusBar()->showMessage(tr("Parameters reset to defaults."), 3000);
}
void MainWindow::playAnalysis()
{
animateButtonPress(ui->btnPlay);
applyParameters();
refreshBottomSignalName();
if (m_signalPath.isEmpty()) {
QMessageBox::warning(this, tr("No signal"),
tr("Please select a signal file before playing."));
return;
}
const bool sameWorkerFile = m_offlineWorker && (m_workerFilePath == m_signalPath);
if (m_offlineWorker && m_offlinePaused && sameWorkerFile) {
m_offlineWorker->setPaused(false);
m_offlinePaused = false;
setPlayingUi(true);
schedulePlotTick(sweepTimeToMs());
statusBar()->showMessage(tr("Resumed offline playback."), 3000);
return;
}
if (m_playing && m_offlineWorker && m_offlineWorker->isRunning()) {
return;
}
try {
fillOfflineParamsFromUi();
{
QMutexLocker lock(&m_offlineParams->mutex);
m_fftSize = m_offlineParams->fftSize;
}
const size_t cap = std::max(kCircBufSize, m_fftSize * 16);
m_timeBuffer->set_capacity(cap);
configurePlotsForOffline();
rebuildGuiFftPlan();
stopOfflineWorker();
m_offlineWorker = new OfflineWorker();
m_offlineThread = new QThread();
m_offlineWorker->moveToThread(m_offlineThread);
connect(m_offlineWorker, &OfflineWorker::errorOccurred,
this, &MainWindow::onOfflineError);
connect(m_offlineWorker, &OfflineWorker::finished,
this, &MainWindow::onOfflineFinished);
connect(this, &MainWindow::startOfflineThread, m_offlineWorker,
[this]() {
m_offlineWorker->runOffline(m_offlineParams, m_timeBuffer);
});
const int sweepMs = sweepTimeToMs();
size_t hop = 0;
{
QMutexLocker lock(&m_offlineParams->mutex);
hop = m_offlineParams->hopSamples;
}
m_offlineThread->start();
if (m_pendingSeekBytes >= 0) {
m_offlineWorker->requestSeek(m_pendingSeekBytes);
m_pendingSeekBytes = -1;
}
emit startOfflineThread();
m_offlinePaused = false;
setPlayingUi(true);
m_waitingForPaint = false;
schedulePlotTick(sweepMs);
m_lastAppliedSweepMs = sweepMs;
m_lastAppliedFftSize = m_fftSize;
m_lastAppliedHop = hop;
m_workerFilePath = m_signalPath;
statusBar()->showMessage(tr("Offline playback started."), 3000);
} catch (const std::exception &ex) {
QMessageBox::warning(this, tr("Exception"),
tr("Cannot start offline playback:\n%1").arg(ex.what()));
} catch (...) {
QMessageBox::warning(this, tr("Exception"),
tr("Invalid input parameters. Check the file, sample rate, and type."));
}
}
void MainWindow::pauseAnalysis()
{
animateButtonPress(ui->btnPlay);
if (m_offlineWorker) {
m_offlineWorker->setPaused(true);
}
m_offlinePaused = true;
m_waitingForPaint = false;
if (m_plotTimer) {
m_plotTimer->stop();
}
setPlayingUi(false);
ui->lblPlotTimeMeta->setText(tr("PAUSED"));
ui->lblPlotWaterfallMeta->setText(tr("PAUSED"));
flashLabel(ui->lblPlotTimeMeta);
statusBar()->showMessage(tr("Paused."), 3000);
}
void MainWindow::togglePlayback()
{