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