MCPcopy Create free account
hub / github.com/aethersdr/AetherSDR / paintEvent

Method paintEvent

src/gui/WaveformWidget.cpp:168–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168void WaveformWidget::paintEvent(QPaintEvent* event)
169{
170 Q_UNUSED(event);
171
172 QPainter painter(this);
173 painter.setRenderHint(QPainter::Antialiasing, false);
174 painter.fillRect(rect(), kBackground());
175
176 QRectF plotRect = QRectF(rect()).adjusted(5.0, 18.0, -34.0, -17.0);
177 if (plotRect.width() < 24.0 || plotRect.height() < 36.0)
178 plotRect = QRectF(rect()).adjusted(4.0, 17.0, -30.0, -16.0);
179
180 const RingBuffer& buffer = activeBuffer();
181 const QString source = (m_paused ? m_pausedTransmitting : m_transmitting)
182 ? QStringLiteral("TX")
183 : QStringLiteral("RX");
184 const int sampleRate = sanitizeSampleRate(m_paused
185 ? m_pausedSampleRate
186 : buffer.sampleRate);
187 if (m_paused) {
188 m_displaySamples = m_pausedSamples;
189 } else {
190 const int windowSamples = std::max(1, sampleRate * m_windowMs / 1000);
191 copyLatest(buffer, windowSamples, m_displaySamples);
192 }
193
194 float peak = 0.0f;
195 double sumSq = 0.0;
196 int clipCount = 0;
197 for (float s : m_displaySamples) {
198 const float a = std::abs(s);
199 peak = std::max(peak, a);
200 sumSq += static_cast<double>(s) * s;
201 if (a >= 0.98f)
202 ++clipCount;
203 }
204 const float rms = m_displaySamples.isEmpty()
205 ? 0.0f
206 : static_cast<float>(std::sqrt(sumSq / m_displaySamples.size()));
207 const float peakDb = linearToDb(peak);
208 const float rmsDb = linearToDb(rms);
209
210 if (m_viewMode == ViewMode::VerticalBars) {
211 drawBarsGrid(painter, plotRect);
212 if (!m_displaySamples.isEmpty())
213 drawVerticalBars(painter, plotRect, sampleRate);
214 } else if (m_viewMode == ViewMode::Envelope) {
215 drawGrid(painter, plotRect, sampleRate);
216 if (!m_displaySamples.isEmpty())
217 drawEnvelope(painter, plotRect, clipCount);
218 } else if (m_viewMode == ViewMode::Bars) {
219 drawBarsGrid(painter, plotRect);
220 if (!m_displaySamples.isEmpty())
221 drawBars(painter, plotRect);
222 } else {
223 drawGrid(painter, plotRect, sampleRate);
224 if (!m_displaySamples.isEmpty())
225 drawGraph(painter, plotRect, clipCount);

Callers

nothing calls this directly

Calls 10

drawTextMethod · 0.80
kBackgroundFunction · 0.70
linearToDbFunction · 0.70
kLabelColorFunction · 0.70
kClipColorFunction · 0.70
kMutedLabelFunction · 0.70
formatSampleRateFunction · 0.70
isEmptyMethod · 0.45
sizeMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected