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

Method drawGrid

src/gui/StripWaveform.cpp:802–864  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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