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

Method drawGrid

src/gui/WaveformWidget.cpp:797–859  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

795}
796
797void WaveformWidget::drawGrid(QPainter& painter,
798 const QRectF& plotRect,
799 int sampleRate) const
800{
801 Q_UNUSED(sampleRate);
802
803 painter.save();
804
805 if (showGrid()) {
806 painter.setPen(QPen(kGridMinor(), 1.0));
807 for (int i = 0; i <= 10; ++i) {
808 const qreal x = plotRect.left() + plotRect.width() * i / 10.0;
809 painter.drawLine(QPointF(x, plotRect.top()),
810 QPointF(x, plotRect.bottom()));
811 }
812 }
813
814 const qreal centerY = plotRect.center().y();
815 const qreal halfHeight = std::max<qreal>(1.0, plotRect.height() * 0.5 - 2.0);
816 const int refs[] = {0, -6, -12, -24, -48};
817
818 QFont labelFont = font();
819 labelFont.setPointSizeF(std::max(7.0, labelFont.pointSizeF() - 2.0));
820 painter.setFont(labelFont);
821
822 for (int db : refs) {
823 const qreal rawOffset = dbToAmplitude(static_cast<float>(db)) * m_amplitudeZoom * halfHeight;
824 if (db <= -48 && rawOffset < 3.0)
825 continue;
826 const qreal offset = std::min(rawOffset, halfHeight);
827
828 painter.setPen(QPen(db >= -12 ? kGridMajor() : kGridMinor(), 1.0));
829 const qreal yTop = centerY - offset;
830 const qreal yBottom = centerY + offset;
831 if (rawOffset <= halfHeight + 0.5) {
832 painter.drawLine(QPointF(plotRect.left(), yTop), QPointF(plotRect.right(), yTop));
833 painter.drawLine(QPointF(plotRect.left(), yBottom), QPointF(plotRect.right(), yBottom));
834 } else {
835 painter.drawLine(QPointF(plotRect.left(), plotRect.top()),
836 QPointF(plotRect.right(), plotRect.top()));
837 painter.drawLine(QPointF(plotRect.left(), plotRect.bottom()),
838 QPointF(plotRect.right(), plotRect.bottom()));
839 }
840
841 painter.setPen(kMutedLabel());
842 painter.drawText(QRectF(plotRect.right() + 4.0, yTop - 7.0,
843 width() - plotRect.right() - 5.0, 14.0),
844 Qt::AlignLeft | Qt::AlignVCenter,
845 QString::number(db));
846 }
847
848 painter.setPen(QPen(kCenterLine(), 1.0));
849 painter.drawLine(QPointF(plotRect.left(), centerY),
850 QPointF(plotRect.right(), centerY));
851
852 painter.setPen(kMutedLabel());
853 painter.drawText(QRectF(plotRect.right() + 4.0, plotRect.bottom() - 12.0,
854 width() - plotRect.right() - 5.0, 12.0),

Callers

nothing calls this directly

Calls 7

drawTextMethod · 0.80
showGridFunction · 0.70
kGridMinorFunction · 0.70
kGridMajorFunction · 0.70
kMutedLabelFunction · 0.70
kCenterLineFunction · 0.70
saveMethod · 0.45

Tested by

no test coverage detected