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