| 447 | } |
| 448 | |
| 449 | void WaveformWidget::drawGraph(QPainter& painter, |
| 450 | const QRectF& plotRect, |
| 451 | int clipCount) |
| 452 | { |
| 453 | const int columnCount = std::max(1, static_cast<int>(std::floor(plotRect.width()))); |
| 454 | buildColumns(columnCount); |
| 455 | if (m_columns.isEmpty()) |
| 456 | return; |
| 457 | |
| 458 | const qreal centerY = plotRect.center().y(); |
| 459 | const qreal halfHeight = std::max<qreal>(1.0, plotRect.height() * 0.5 - 2.0); |
| 460 | const qreal left = plotRect.left(); |
| 461 | const QColor wave = waveformColor(); |
| 462 | |
| 463 | QPainterPath peakTop; |
| 464 | QPainterPath peakBottom; |
| 465 | QPainterPath rmsTop; |
| 466 | QPainterPath rmsBottom; |
| 467 | |
| 468 | painter.setPen(QPen(wave, waveformLineWidth(), Qt::SolidLine, Qt::RoundCap)); |
| 469 | for (int x = 0; x < m_columns.size(); ++x) { |
| 470 | const ColumnStats& c = m_columns[x]; |
| 471 | const qreal px = left + x + 0.5; |
| 472 | const qreal minY = centerY - std::clamp(c.min * m_amplitudeZoom, -1.0f, 1.0f) * halfHeight; |
| 473 | const qreal maxY = centerY - std::clamp(c.max * m_amplitudeZoom, -1.0f, 1.0f) * halfHeight; |
| 474 | painter.drawLine(QPointF(px, minY), QPointF(px, maxY)); |
| 475 | |
| 476 | const qreal peak = std::clamp(c.peak * m_amplitudeZoom, 0.0f, 1.0f); |
| 477 | const qreal rms = std::clamp(c.rms * m_amplitudeZoom, 0.0f, 1.0f); |
| 478 | const qreal peakTopY = centerY - peak * halfHeight; |
| 479 | const qreal peakBottomY = centerY + peak * halfHeight; |
| 480 | const qreal rmsTopY = centerY - rms * halfHeight; |
| 481 | const qreal rmsBottomY = centerY + rms * halfHeight; |
| 482 | if (x == 0) { |
| 483 | peakTop.moveTo(px, peakTopY); |
| 484 | peakBottom.moveTo(px, peakBottomY); |
| 485 | rmsTop.moveTo(px, rmsTopY); |
| 486 | rmsBottom.moveTo(px, rmsBottomY); |
| 487 | } else { |
| 488 | peakTop.lineTo(px, peakTopY); |
| 489 | peakBottom.lineTo(px, peakBottomY); |
| 490 | rmsTop.lineTo(px, rmsTopY); |
| 491 | rmsBottom.lineTo(px, rmsBottomY); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | painter.setRenderHint(QPainter::Antialiasing, true); |
| 496 | painter.setPen(QPen(kPeakColor(), 1.0)); |
| 497 | painter.drawPath(peakTop); |
| 498 | painter.drawPath(peakBottom); |
| 499 | painter.setPen(QPen(kRmsColor(), 1.4)); |
| 500 | painter.drawPath(rmsTop); |
| 501 | painter.drawPath(rmsBottom); |
| 502 | painter.setRenderHint(QPainter::Antialiasing, false); |
| 503 | |
| 504 | if (clipCount > 0) { |
| 505 | painter.setPen(QPen(kClipColor(), 1.0)); |
| 506 | for (int x = 0; x < m_columns.size(); ++x) { |
nothing calls this directly
no test coverage detected