| 516 | } |
| 517 | |
| 518 | void WaveformWidget::drawEnvelope(QPainter& painter, |
| 519 | const QRectF& plotRect, |
| 520 | int clipCount) |
| 521 | { |
| 522 | const int columnCount = std::max(1, static_cast<int>(std::floor(plotRect.width()))); |
| 523 | buildColumns(columnCount); |
| 524 | if (m_columns.isEmpty()) |
| 525 | return; |
| 526 | |
| 527 | const qreal centerY = plotRect.center().y(); |
| 528 | const qreal halfHeight = std::max<qreal>(1.0, plotRect.height() * 0.5 - 2.0); |
| 529 | const qreal left = plotRect.left(); |
| 530 | const QColor wave = waveformColor(); |
| 531 | |
| 532 | QVector<QPointF> rmsTop; |
| 533 | QVector<QPointF> rmsBottom; |
| 534 | QPainterPath peakTop; |
| 535 | QPainterPath peakBottom; |
| 536 | QPainterPath rmsLineTop; |
| 537 | QPainterPath rmsLineBottom; |
| 538 | |
| 539 | rmsTop.reserve(m_columns.size()); |
| 540 | rmsBottom.reserve(m_columns.size()); |
| 541 | |
| 542 | for (int x = 0; x < m_columns.size(); ++x) { |
| 543 | const ColumnStats& c = m_columns[x]; |
| 544 | const qreal px = left + x + 0.5; |
| 545 | const qreal peak = std::clamp(c.peak * m_amplitudeZoom, 0.0f, 1.0f); |
| 546 | const qreal rms = std::clamp(c.rms * m_amplitudeZoom, 0.0f, 1.0f); |
| 547 | const qreal peakTopY = centerY - peak * halfHeight; |
| 548 | const qreal peakBottomY = centerY + peak * halfHeight; |
| 549 | const qreal rmsTopY = centerY - rms * halfHeight; |
| 550 | const qreal rmsBottomY = centerY + rms * halfHeight; |
| 551 | |
| 552 | rmsTop.append(QPointF(px, rmsTopY)); |
| 553 | rmsBottom.append(QPointF(px, rmsBottomY)); |
| 554 | |
| 555 | if (x == 0) { |
| 556 | peakTop.moveTo(px, peakTopY); |
| 557 | peakBottom.moveTo(px, peakBottomY); |
| 558 | rmsLineTop.moveTo(px, rmsTopY); |
| 559 | rmsLineBottom.moveTo(px, rmsBottomY); |
| 560 | } else { |
| 561 | peakTop.lineTo(px, peakTopY); |
| 562 | peakBottom.lineTo(px, peakBottomY); |
| 563 | rmsLineTop.lineTo(px, rmsTopY); |
| 564 | rmsLineBottom.lineTo(px, rmsBottomY); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | QPainterPath fillPath; |
| 569 | fillPath.moveTo(rmsTop.first()); |
| 570 | for (int i = 1; i < rmsTop.size(); ++i) |
| 571 | fillPath.lineTo(rmsTop[i]); |
| 572 | for (int i = rmsBottom.size() - 1; i >= 0; --i) |
| 573 | fillPath.lineTo(rmsBottom[i]); |
| 574 | fillPath.closeSubpath(); |
| 575 |
nothing calls this directly
no test coverage detected