js8call/plotter.cpp

751 lines
18 KiB
C++
Raw Normal View History

2018-02-08 21:28:33 -05:00
#include "plotter.h"
#include <algorithm>
2024-10-26 06:31:47 -07:00
#include <cmath>
#include <type_traits>
2024-10-24 07:16:12 -07:00
#include <utility>
2018-02-08 21:28:33 -05:00
#include <QDebug>
2024-09-01 20:03:35 -07:00
#include <QMouseEvent>
#include <QPainter>
#include <QPen>
#include <QScopedValueRollback>
2024-09-01 08:01:23 -07:00
#include <QToolTip>
2024-09-01 20:03:35 -07:00
#include <QWheelEvent>
2018-02-08 21:28:33 -05:00
#include "commons.h"
#include "moc_plotter.cpp"
#include "DriftingDateTime.h"
#include "JS8Submode.hpp"
2018-03-05 14:49:51 -05:00
extern "C" {
void flat4_(float swide[], int* iz, bool* bflatten);
2018-03-05 14:49:51 -05:00
void plotsave_(float swide[], int* m_w , int* m_h1, int* irow);
}
namespace
{
// 30 meter band: 10.130-10.140 RTTY
// 10.140-10.150 Packet
2024-10-24 21:25:49 -07:00
constexpr float BAND_30M_START = 10.13f;
constexpr float BAND_30M_END = 10.15f;
2024-10-24 21:25:49 -07:00
// The WSPR range starts at 10.1401 MHz and runs for 200 Hz.
2024-10-24 21:25:49 -07:00
constexpr float WSPR_START = 10.1401f;
constexpr int WSPR_RANGE = 200;
// FFT bin width, as with NSPS, a constant; see the JT9 documentation
// for the reasoning behind the values used here, but in short, since
// NSPS is always 6912, 1500 for nsps2 and 2048 for nfft3 are optimal.
constexpr double FFT_BIN_WIDTH = 1500.0 / 2048.0;
// Vertical divisions in the spectrum display.
constexpr std::size_t VERT_DIVS = 7;
2024-10-26 06:31:47 -07:00
// Given a floating point value, return the fractional portion of the
// value e.g., 42.7 -> 0.7.
template <typename T,
typename = std::enable_if_t<std::is_floating_point_v<T>>>
constexpr auto
2024-10-26 06:31:47 -07:00
fractionalPart(T const v)
{
T integralPart;
return std::modf(v, &integralPart);
}
// Given the frequency span of the entire viewable plot region, return
// the frequency span that each division should occupy.
int
2024-10-25 13:32:16 -07:00
freqPerDiv(double const fSpan)
{
2024-09-08 20:13:33 -07:00
if (fSpan > 2500) { return 500; }
if (fSpan > 1000) { return 200; }
if (fSpan > 500) { return 100; }
if (fSpan > 250) { return 50; }
if (fSpan > 100) { return 20; }
return 10;
}
}
2024-10-19 13:44:02 -07:00
CPlotter::CPlotter(QWidget * parent)
2024-10-26 04:30:16 -07:00
: QFrame{parent}
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
m_freqPerPixel = m_binsPerPixel * FFT_BIN_WIDTH;
2018-02-08 21:28:33 -05:00
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setFocusPolicy(Qt::StrongFocus);
setAttribute(Qt::WA_PaintOnScreen,false);
setAutoFillBackground(false);
setAttribute(Qt::WA_OpaquePaintEvent, false);
setAttribute(Qt::WA_NoSystemBackground, true);
setMouseTracking(true);
2018-02-08 21:28:33 -05:00
}
2024-09-08 12:43:10 -07:00
CPlotter::~CPlotter() = default;
2018-02-08 21:28:33 -05:00
2024-10-19 09:19:01 -07:00
QSize
CPlotter::minimumSizeHint() const
2018-02-08 21:28:33 -05:00
{
return QSize(50, 50);
}
2024-10-19 09:19:01 -07:00
QSize
CPlotter::sizeHint() const
2018-02-08 21:28:33 -05:00
{
return QSize(180, 180);
}
2024-10-19 09:19:01 -07:00
void
2024-10-20 21:25:26 -07:00
CPlotter::resizeEvent(QResizeEvent *)
2018-02-08 21:28:33 -05:00
{
2024-09-08 10:00:57 -07:00
if (!size().isValid()) return;
2024-11-07 07:31:29 -08:00
auto const makePixmap = [dpr = devicePixelRatio()](QSize const & size,
QColor const & fill)
{
auto pixmap = QPixmap(size * dpr);
pixmap.setDevicePixelRatio(dpr);
pixmap.fill(fill);
return pixmap;
};
if ((m_size != size()) ||
2024-10-20 21:25:26 -07:00
(m_percent2DScreen != m_percent2DScreen0))
2024-09-08 10:00:57 -07:00
{
2024-10-19 13:49:37 -07:00
m_size = size();
m_w = m_size.width();
m_h = m_size.height();
2024-10-20 21:25:26 -07:00
m_h2 = m_percent2DScreen * m_h / 100.0;
2024-09-08 10:00:57 -07:00
if (m_h2 > m_h - 30) m_h2 = m_h - 30;
if (m_h2 < 1) m_h2 = 1;
m_h1 = m_h - m_h2;
2024-11-07 07:31:29 -08:00
m_FilterOverlayPixmap = makePixmap(m_size, QColor(0, 0, 0, std::clamp(m_filterOpacity, 0, 255)));
m_ScalePixmap = makePixmap({m_w, 30}, Qt::white);
m_WaterfallPixmap = makePixmap({m_w, m_h1}, Qt::black);
m_OverlayPixmap = makePixmap({m_w, m_h2}, Qt::black);
2024-09-08 14:17:32 -07:00
makeDialPixmaps();
2024-10-31 07:08:48 -07:00
// The overlay pixmap acts as a prototype for the spectrum pixmap;
// each time we draw the spectrum, we do so by first making a copy
// of the overlay, then drawing the spectrum line into it.
2024-11-07 07:31:29 -08:00
m_SpectrumPixmap = m_OverlayPixmap.copy();
2024-10-20 21:25:26 -07:00
m_percent2DScreen0 = m_percent2DScreen;
2018-02-08 21:28:33 -05:00
}
drawOverlay();
2018-02-08 21:28:33 -05:00
}
2024-10-19 09:19:01 -07:00
void
2024-10-20 21:25:26 -07:00
CPlotter::paintEvent(QPaintEvent *)
2018-02-08 21:28:33 -05:00
{
if (m_paintEventBusy) return;
QScopedValueRollback scoped(m_paintEventBusy, true);
2024-10-31 06:53:30 -07:00
QPainter p(this);
2024-10-31 06:53:30 -07:00
p.drawPixmap(0, 0, m_ScalePixmap);
p.drawPixmap(0, 30, m_WaterfallPixmap);
p.drawPixmap(0, m_h1, m_SpectrumPixmap);
auto const x = xFromFreq(freq());
p.drawPixmap(x, 30, m_DialPixmap[0]);
if (m_lastMouseX >= 0 &&
m_lastMouseX != x)
{
p.drawPixmap(m_lastMouseX, 30, m_DialPixmap[1]);
}
if (m_filterEnabled && m_filterWidth > 0)
{
2024-10-31 06:53:30 -07:00
p.drawPixmap(0, 0, m_FilterOverlayPixmap);
}
2018-02-08 21:28:33 -05:00
}
2024-09-13 14:08:06 -07:00
void
CPlotter::draw(float swide[],
bool const bScroll)
2018-02-08 21:28:33 -05:00
{
2024-10-31 06:53:30 -07:00
// Move current data down one line; we must do this before
// attaching a QPainter.
2024-10-31 06:26:44 -07:00
if (bScroll && !m_replot)
{
m_WaterfallPixmap.scroll(0, 1, m_WaterfallPixmap.rect());
}
2024-09-08 09:00:09 -07:00
2024-10-31 06:53:30 -07:00
QPainter p(&m_WaterfallPixmap);
2024-09-08 20:09:29 -07:00
auto iz = xFromFreq(5000.0);
2024-09-08 20:09:29 -07:00
if (bScroll && swide[0] < 1.e29)
2024-09-08 20:09:29 -07:00
{
flat4_(swide, &iz, &m_flatten);
2018-02-08 21:28:33 -05:00
}
2024-10-31 06:53:30 -07:00
if(swide[0] > 1.e29 && swide[0] < 1.5e30) p.setPen(Qt::green); // horizontal line
if(swide[0] > 1.4e30 ) p.setPen(Qt::yellow);
2024-09-08 20:09:29 -07:00
2024-10-31 06:26:44 -07:00
if (!m_replot)
2024-09-08 20:09:29 -07:00
{
m_j = 0;
int irow = -1;
plotsave_(swide, &m_w, &m_h1, &irow);
2018-03-05 14:49:51 -05:00
}
2024-09-08 20:09:29 -07:00
double const fac = sqrt(m_binsPerPixel * m_waterfallAvg / 15.0);
double const gain = fac * pow(10.0, 0.015 * m_plotGain);
double const gain2d = pow(10.0, 0.02 * m_plot2dGain);
auto const base = static_cast<int>(m_startFreq / FFT_BIN_WIDTH + 0.5);
2024-09-13 14:08:06 -07:00
auto ymin = 1.e30f;
// First loop; draws points into the waterfall and determines the
// minimum y extent.
2024-09-08 20:01:56 -07:00
for(int i = 0; i < iz; i++)
{
float const y = swide[i];
2024-09-13 10:49:58 -07:00
if (y < ymin ) ymin = y;
2024-10-31 06:53:30 -07:00
if (y < 1.e29) p.setPen(m_colors[std::clamp(static_cast<int>(10.0 * gain * y + m_plotZero), 0, 254)]);
p.drawPoint(i, m_j);
2018-02-08 21:28:33 -05:00
}
2024-09-13 14:08:06 -07:00
// Summarization method, used when scrolling and during computation of
// linear average.
auto const sum = [base,
bins = m_binsPerPixel](float const * const data,
auto const index)
{
float sum = 0.0f;
int k = base + bins * index;
for (int l = 0; l < bins; l++)
{
sum += data[k++];
}
return sum;
};
// Second loop, determines how we're going to draw the spectrum.
2024-10-19 09:19:01 -07:00
// Updates the sums if we're scrolling, updates the points to draw.
2024-09-13 14:08:06 -07:00
2024-09-08 20:01:56 -07:00
for (int i = 0; i < iz; i++)
{
2024-09-13 13:03:50 -07:00
if (bScroll)
2024-09-08 20:09:29 -07:00
{
2024-09-13 14:08:06 -07:00
m_sum[i] = sum(dec_data.savg, i);
2018-02-08 21:28:33 -05:00
}
2024-09-14 22:26:48 -07:00
float y = 0;
2024-09-13 13:03:50 -07:00
switch (m_spectrum)
2024-09-08 20:09:29 -07:00
{
case Spectrum::Current:
y = gain2d * (swide[i] - ymin) + m_plot2dZero + (m_flatten ? 0 : 15);
break;
case Spectrum::Cumulative:
y = gain2d * (m_sum[i] / m_binsPerPixel + m_plot2dZero) + (m_flatten ? 0 : 15);
break;
case Spectrum::LinearAvg:
y = 2.0 * gain2d * sum(spectra_.syellow, i) / m_binsPerPixel + m_plot2dZero;
break;
2018-02-08 21:28:33 -05:00
}
m_points[i].setX(i);
2024-09-13 13:03:50 -07:00
m_points[i].setY(int(0.9 * m_h2 - y * m_h2 / 70.0));
2018-02-08 21:28:33 -05:00
}
2024-09-08 20:01:56 -07:00
2024-10-31 06:53:30 -07:00
drawSpectrum(iz - 1);
if (m_replot) return;
2018-02-08 21:28:33 -05:00
// If we've just drawn a decode line, compute the number of lines required
// before we need to draw the decode text. If that wasn't a decode line,
// see if we've reached the point where we should draw the decode text.
if (swide[0] > 1.0e29)
{
m_line = p.fontMetrics().height() * devicePixelRatio();
}
else if (--m_line == 0)
2024-09-08 17:53:35 -07:00
{
m_line = std::numeric_limits<int>::max();
2024-09-08 06:18:53 -07:00
qint64 const ms = DriftingDateTime::currentMSecsSinceEpoch() % 86400000;
int const n = (ms/1000) % m_TRperiod;
auto const t1 = DriftingDateTime::currentDateTimeUtc().addSecs(-n);
auto const ts = t1.toString(m_TRperiod < 60 ? "hh:mm:ss" : "hh:mm");
2024-10-31 06:53:30 -07:00
p.setPen(Qt::white);
p.drawText(5,
p.fontMetrics().ascent(),
2024-10-31 06:53:30 -07:00
QString("%1 %2").arg(ts).arg(m_band));
2018-02-08 21:28:33 -05:00
}
2024-10-26 04:30:16 -07:00
update();
2024-09-08 20:01:56 -07:00
m_scaleOK = true;
2018-02-08 21:28:33 -05:00
}
2024-10-31 07:08:48 -07:00
// Draw the spectrum by copying the overlay prototype, then drawing the
// current array of points into it, up to the limit specified. If linear
// averaging has been requested for the spectrum, use a yellow line; any
// other type of spectral display gets a green line.
2024-10-31 06:53:30 -07:00
void
CPlotter::drawSpectrum(int const pointCount)
{
m_SpectrumPixmap = m_OverlayPixmap.copy();
QPainter p(&m_SpectrumPixmap);
p.setPen(m_spectrum == Spectrum::LinearAvg ? Qt::yellow : Qt::green);
p.drawPolyline(m_points.data(), pointCount);
}
2024-10-19 09:19:01 -07:00
void
CPlotter::drawDecodeLine(QColor const & color,
int const ia,
int const ib)
2018-02-08 21:28:33 -05:00
{
auto const x1 = xFromFreq(ia);
auto const x2 = xFromFreq(ib);
2020-05-06 11:15:41 -04:00
2024-10-25 20:41:55 -07:00
QPainter p(&m_WaterfallPixmap);
2024-09-08 17:53:35 -07:00
2024-10-25 20:41:55 -07:00
p.setPen(color);
p.drawLine(qMin(x1, x2), 4, qMax(x1, x2), 4);
p.drawLine(qMin(x1, x2), 0, qMin(x1, x2), 9);
p.drawLine(qMax(x1, x2), 0, qMax(x1, x2), 9);
2018-02-08 21:28:33 -05:00
}
2024-10-19 09:19:01 -07:00
void
CPlotter::drawHorizontalLine(QColor const & color,
int const x,
int const width)
{
2024-10-25 20:41:55 -07:00
QPainter p(&m_WaterfallPixmap);
2024-09-08 19:54:14 -07:00
2024-10-25 20:41:55 -07:00
p.setPen(color);
p.drawLine(x, 0, width <= 0 ? m_w : x + width, 0);
}
2024-10-19 09:19:01 -07:00
void
CPlotter::replot()
2018-03-05 14:49:51 -05:00
{
resizeEvent(nullptr);
2018-03-05 14:49:51 -05:00
float swide[m_w];
2024-09-08 19:54:14 -07:00
2024-10-31 06:26:44 -07:00
QScopedValueRollback scoped(m_replot, true);
2024-09-08 19:54:14 -07:00
for (int irow = 0; irow < m_h1; irow++)
{
m_j = irow;
plotsave_(swide, &m_w, &m_h1, &irow);
draw(swide, false);
2018-03-05 14:49:51 -05:00
}
2024-09-08 19:54:14 -07:00
2024-10-20 21:25:26 -07:00
update();
2018-03-05 14:49:51 -05:00
}
void
CPlotter::drawOverlay()
2018-02-08 21:28:33 -05:00
{
2024-09-08 14:37:43 -07:00
if (m_OverlayPixmap.isNull() ||
m_WaterfallPixmap.isNull()) return;
2018-02-08 21:28:33 -05:00
2024-10-20 21:25:26 -07:00
QLinearGradient gradient(0, 0, 0, m_h2);
2018-02-08 21:28:33 -05:00
gradient.setColorAt(1, Qt::black);
gradient.setColorAt(0, Qt::darkBlue);
QPainter p(&m_OverlayPixmap);
p.setBrush(gradient);
p.drawRect(0, 0, m_w, m_h2);
p.setBrush(Qt::SolidPattern);
2024-10-26 04:30:16 -07:00
auto const fSpan = m_w * m_freqPerPixel;
2024-10-25 13:32:16 -07:00
auto const fpd = freqPerDiv(fSpan);
2024-10-26 04:30:16 -07:00
float const ppdV = fpd / m_freqPerPixel;
2024-10-25 13:32:16 -07:00
float const ppdH = (float)m_h2 / VERT_DIVS;
std::size_t const hdivs = fSpan / fpd + 1.9999;
2024-10-26 06:31:47 -07:00
auto const x0 = static_cast<int>(fractionalPart((double)m_startFreq / fpd) * ppdV + 0.5);
2024-09-09 11:40:50 -07:00
p.setPen(QPen(Qt::white, 1, Qt::DotLine));
2024-10-25 13:32:16 -07:00
// Draw vertical grids.
for (std::size_t i = 1; i < hdivs; i++)
{
2024-10-25 13:32:16 -07:00
if (auto const x = static_cast<int>(i * ppdV) - x0;
x >= 0 &&
x <= m_w)
{
p.drawLine(x, 0, x , m_h2);
2018-02-08 21:28:33 -05:00
}
}
2024-10-25 13:32:16 -07:00
// Draw horizontal grids.
for (std::size_t i = 1; i < VERT_DIVS; i++)
{
2024-10-25 13:32:16 -07:00
auto const y = static_cast<int>(i * ppdH);
p.drawLine(0, y, m_w, y);
2018-02-08 21:28:33 -05:00
}
2024-10-25 13:32:16 -07:00
drawOverlayScale(fpd, ppdV, hdivs);
drawOverlayFilter();
2024-09-09 07:50:19 -07:00
}
void
2024-10-25 13:32:16 -07:00
CPlotter::drawOverlayScale(int const fpd,
float const ppdV,
std::size_t const hdivs)
2024-09-09 07:50:19 -07:00
{
QPen const penOrange (QColor(230, 126, 34), 3);
QPen const penGray (QColor(149, 165, 166), 3);
QPen const penLightGreen (QColor( 46, 204, 113), 3);
QPen const penLightYellow(QColor(241, 196, 15), 3);
m_ScalePixmap.fill(Qt::white);
2024-09-09 07:50:19 -07:00
QPainter p(&m_ScalePixmap);
2024-10-24 07:16:12 -07:00
p.setFont(QFont("Arial"));
2024-09-09 07:50:19 -07:00
p.setPen(Qt::black);
2024-09-12 13:04:50 -07:00
p.drawRect(0, 0, m_w, 30);
2024-09-09 07:50:19 -07:00
int const fOffset = ((m_startFreq + fpd - 1) / fpd) * fpd;
double const xOffset = double(fOffset - m_startFreq) / fpd;
2024-10-25 13:32:16 -07:00
std::size_t const nMajor = hdivs - 1;
std::size_t const nMinor = fpd == 200 ? 4: 5;
2024-09-12 19:00:35 -07:00
float const ppdVM = ppdV / nMinor;
float const ppdVL = ppdV / 2;
2024-09-12 19:00:35 -07:00
// Draw ticks and labels.
2024-09-09 07:50:19 -07:00
2024-10-25 13:32:16 -07:00
for (std::size_t iMajor = 0; iMajor < nMajor; iMajor++)
{
2024-09-12 19:00:35 -07:00
auto const rMajor = (xOffset + iMajor) * ppdV;
auto const xMajor = static_cast<int>(rMajor);
p.drawLine(xMajor, 18, xMajor, 30);
2024-09-12 19:00:35 -07:00
for (std::size_t iMinor = 1; iMinor < nMinor; iMinor++)
{
2024-09-12 19:00:35 -07:00
auto const xMinor = static_cast<int>(rMajor + iMinor * ppdVM);
p.drawLine(xMinor, 22, xMinor, 30);
}
2024-09-12 19:00:35 -07:00
if (xMajor > 70)
{
p.drawText(QRect(xMajor - static_cast<int>(ppdVL), 0, static_cast<int>(ppdV), 20),
Qt::AlignCenter,
QString::number(fOffset + iMajor * fpd));
2024-09-12 19:00:35 -07:00
}
2018-02-08 21:28:33 -05:00
}
2024-10-24 07:16:12 -07:00
// Given a starting frequency and range to cover, return corresponding
// X values for the sub-band.
auto const bandX = [this](float const start,
int const range)
{
return std::make_pair(xFromFreq(start),
xFromFreq(start + range));
};
// Given a pair of X values, draw a band line, if visible.
2024-10-24 07:16:12 -07:00
auto const drawBand = [this, &p](auto const & bandX)
{
2024-10-24 07:16:12 -07:00
auto const [x1, x2] = bandX;
2024-09-10 06:36:41 -07:00
2024-09-10 06:26:15 -07:00
if (x1 <= m_w && x2 > 0)
2024-09-08 21:28:23 -07:00
{
2024-09-09 07:50:19 -07:00
p.drawLine(x1 + 1, 26, x2 - 2, 26);
p.drawLine(x1 + 1, 28, x2 - 2, 28);
2024-09-08 21:28:23 -07:00
}
2024-10-24 07:16:12 -07:00
};
// Colorize the JS8 sub-bands.
2024-10-24 21:31:34 -07:00
p.setPen(penGray); drawBand(bandX( 0.0f, 4000));
p.setPen(penLightYellow); drawBand(bandX( 500.0f, 2500));
p.setPen(penLightGreen); drawBand(bandX(1000.0f, 1500));
// If we're in the 30 meter band, we'd rather that the WSPR sub-band not
// get stomped on; draw an orange indicator in the scale to denote the
// WSPR portion of the band.
//
// Note that given the way XfromFreq() works, we're always going to see
// clamped X values here, either 0 or m_w, if the frequency is outside
// of the range, so we're always going to draw. If the WSPR range is not
// in the displayed range, the effect will be, given the pen size, that
// an orange indicator will indicate in which direction the WSPR range
// lies.
if (in30MBand())
{
2024-10-24 21:31:34 -07:00
auto const wspr = bandX(1.0e6f * (WSPR_START - m_dialFreq), WSPR_RANGE);
p.setPen(penOrange);
2024-10-24 07:16:12 -07:00
p.setFont(QFont("Arial", 10, QFont::Bold));
drawBand(wspr);
p.drawText(QRect(wspr.first, 0, wspr.second - wspr.first, 25),
Qt::AlignHCenter|Qt::AlignBottom,
"WSPR");
}
// Thin black line below the sub-band indicators; our work is done here.
2024-09-09 07:50:19 -07:00
p.setPen(Qt::black);
p.drawLine(0, 29, m_w, 29);
}
// Paint the filter overlay pixmap, if the filter is enabled and has a width
// greater than zero. Note that we could be more clever here and ensure the
// filter is actually visible prior to painting, but what we're doing here
// is reasonably trivial, so probably not worth the effort.
void
CPlotter::drawOverlayFilter()
{
if (m_filterEnabled && m_filterWidth > 0)
{
QPainter p(&m_FilterOverlayPixmap);
p.setCompositionMode(QPainter::CompositionMode_Source);
auto const start = xFromFreq(static_cast<float>(m_filterCenter - m_filterWidth / 2));
auto const end = xFromFreq(static_cast<float>(m_filterCenter + m_filterWidth / 2));
2024-11-07 07:00:04 -08:00
// Remove the bandpass from the filter.
p.fillRect(start, 0, end - start, m_h, Qt::transparent);
// Yellow vertical lines, showing the filter edges.
p.setPen(Qt::yellow);
p.drawLine(start, 30, start, m_h);
p.drawLine(end, 30, end, m_h);
}
2018-02-08 21:28:33 -05:00
}
void
CPlotter::makeDialPixmaps()
{
auto const width = static_cast<int>(JS8::Submode::bandwidth(m_nSubMode) / m_freqPerPixel + 0.5);
auto const height = size().height() - 30;
auto const dialPixmap = [size = QSize(width, height),
rect = QRect(1, 1, width - 2, height - 2),
dpr = devicePixelRatio()](QColor const & color,
QBrush const & brush)
{
QPixmap pixmap = QPixmap(size * dpr);
pixmap.setDevicePixelRatio(dpr);
pixmap.fill(Qt::transparent);
QPainter p(&pixmap);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.setBrush(brush);
p.setPen(QPen(QBrush(color), 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
p.drawRect(rect);
return pixmap;
};
m_DialPixmap = {
dialPixmap(Qt::red, QBrush(QColor(255, 255, 255, 75), Qt::Dense4Pattern)),
dialPixmap(Qt::white, Qt::transparent)
};
}
bool
CPlotter::in30MBand() const
{
return (m_dialFreq >= BAND_30M_START &&
m_dialFreq <= BAND_30M_END);
}
int
2024-10-20 21:20:32 -07:00
CPlotter::xFromFreq(float const f) const
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
return std::clamp(static_cast<int>((f - m_startFreq) / m_freqPerPixel + 0.5), 0, m_w);
2018-02-08 21:28:33 -05:00
}
float
2024-10-20 21:20:32 -07:00
CPlotter::freqFromX(int const x) const
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
return m_startFreq + x * m_freqPerPixel;
2018-02-08 21:28:33 -05:00
}
void
CPlotter::leaveEvent(QEvent * event)
{
2024-10-19 09:19:01 -07:00
m_lastMouseX = -1;
event->ignore();
}
void
CPlotter::wheelEvent(QWheelEvent * event)
2024-09-08 19:54:14 -07:00
{
2024-10-20 21:20:32 -07:00
auto const y = event->angleDelta().y();
2024-09-08 19:54:14 -07:00
2024-10-20 21:20:32 -07:00
if (auto const d = ((y > 0) - (y < 0)))
2024-09-08 19:54:14 -07:00
{
2024-10-20 21:20:32 -07:00
emit changeFreq(event->modifiers() & Qt::ControlModifier
? freq() + d
: freq() / 10 * 10 + d * 10);
2024-09-08 19:54:14 -07:00
}
else
{
2024-10-20 21:20:32 -07:00
event->ignore();
}
}
void
CPlotter::mouseMoveEvent(QMouseEvent * event)
{
2024-10-19 13:49:37 -07:00
m_lastMouseX = std::clamp(static_cast<int>(event->position().x()), 0, m_w);
2024-09-08 09:00:09 -07:00
update();
event->ignore();
2018-02-08 21:28:33 -05:00
2024-09-08 09:00:09 -07:00
QToolTip::showText(event->globalPosition().toPoint(),
QString::number(static_cast<int>(freqFromX(m_lastMouseX))));
2024-09-08 09:00:09 -07:00
}
void
CPlotter::mouseReleaseEvent(QMouseEvent * event)
2024-09-08 09:00:09 -07:00
{
if (Qt::LeftButton == event->button())
{
emit changeFreq(static_cast<int>(freqFromX(m_lastMouseX)));
2018-02-08 21:28:33 -05:00
}
2024-09-08 09:00:09 -07:00
else
{
2024-10-20 21:20:32 -07:00
event->ignore();
2018-02-08 21:28:33 -05:00
}
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setBand(QString const & band)
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
m_band = band;
drawOverlay();
update();
2018-02-08 21:28:33 -05:00
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setBinsPerPixel(int const binsPerPixel)
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
m_binsPerPixel = std::max(1, binsPerPixel);
m_freqPerPixel = m_binsPerPixel * FFT_BIN_WIDTH;
drawOverlay();
2018-02-08 21:28:33 -05:00
update();
}
void
2024-10-24 21:25:49 -07:00
CPlotter::setDialFreq(float const dialFreq)
2018-02-08 21:28:33 -05:00
{
2024-10-24 21:25:49 -07:00
m_dialFreq = dialFreq;
drawOverlay();
2018-02-08 21:28:33 -05:00
update();
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setFilterCenter(int const center)
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
m_filterCenter = center;
drawOverlay();
2018-11-04 22:37:14 -05:00
update();
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setFilterEnabled(bool const enabled)
2024-09-08 09:00:09 -07:00
{
2024-10-26 04:30:16 -07:00
m_filterEnabled = enabled;
drawOverlay();
update();
}
void
CPlotter::setFilterOpacity(int const alpha)
{
m_filterOpacity = alpha;
drawOverlay();
update();
}
void
CPlotter::setFilterWidth(int const width)
{
2024-09-08 09:00:09 -07:00
m_filterWidth = width;
drawOverlay();
update();
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setFreq(int const freq)
2024-09-08 09:00:09 -07:00
{
2024-10-26 04:30:16 -07:00
m_freq = freq;
drawOverlay();
update();
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setPercent2DScreen(int percent)
2024-09-08 09:00:09 -07:00
{
2024-10-26 04:30:16 -07:00
m_percent2DScreen = percent;
resizeEvent(nullptr);
2024-09-09 05:43:55 -07:00
update();
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setPeriod(int const period)
{
2024-10-26 04:30:16 -07:00
m_TRperiod = period;
drawOverlay();
update();
}
void
2024-10-26 04:30:16 -07:00
CPlotter::setPlot2dGain(int const plot2dGain)
2018-02-08 21:28:33 -05:00
{
2024-10-26 04:30:16 -07:00
m_plot2dGain = plot2dGain;
update();
}
void
CPlotter::setStartFreq(int const startFreq)
{
m_startFreq = startFreq;
2024-09-08 09:00:09 -07:00
resizeEvent(nullptr);
2024-10-26 04:30:16 -07:00
drawOverlay();
update();
}
void
CPlotter::setSubMode(int const nSubMode)
{
if (m_nSubMode != nSubMode)
{
m_nSubMode = nSubMode;
makeDialPixmaps();
update();
}
2018-02-08 21:28:33 -05:00
}