* @brief Draws the live hover cursor -- vertical & horizontal crosshair lines clipped to the plot * rect, plus a small tooltip with the freq + time readings under the pointer (zoom/pan-aware). */
| 1067 | * rect, plus a small tooltip with the freq + time readings under the pointer (zoom/pan-aware). |
| 1068 | */ |
| 1069 | void Widgets::Waterfall::drawCursor(QPainter* painter, const QRectF& plotRect) const |
| 1070 | { |
| 1071 | if (plotRect.isEmpty() || !plotRect.contains(m_cursorPos)) |
| 1072 | return; |
| 1073 | |
| 1074 | static auto& fonts = Misc::CommonFonts::instance(); |
| 1075 | painter->setFont(fonts.widgetFont(0.83, false)); |
| 1076 | painter->setRenderHint(QPainter::TextAntialiasing, true); |
| 1077 | |
| 1078 | const double cx = qBound(plotRect.left(), m_cursorPos.x(), plotRect.right()); |
| 1079 | const double cy = qBound(plotRect.top(), m_cursorPos.y(), plotRect.bottom()); |
| 1080 | |
| 1081 | painter->setPen(QPen(QColor(255, 255, 255, 178), 1)); |
| 1082 | painter->drawLine(QPointF(cx, plotRect.top()), QPointF(cx, plotRect.bottom())); |
| 1083 | painter->drawLine(QPointF(plotRect.left(), cy), QPointF(plotRect.right(), cy)); |
| 1084 | |
| 1085 | double freqHz = 0.0; |
| 1086 | double yVal = 0.0; |
| 1087 | cursorReadoutValues(plotRect, cx, cy, freqHz, yVal); |
| 1088 | |
| 1089 | auto fmtFreq = [](double hz) -> QString { |
| 1090 | const double abs = std::fabs(hz); |
| 1091 | if (abs >= 1e6) |
| 1092 | return QString::number(hz / 1e6, 'f', 2) + QStringLiteral(" MHz"); |
| 1093 | |
| 1094 | if (abs >= 1e3) |
| 1095 | return QString::number(hz / 1e3, 'f', 2) + QStringLiteral(" kHz"); |
| 1096 | |
| 1097 | return QString::number(hz, 'f', 1) + QStringLiteral(" Hz"); |
| 1098 | }; |
| 1099 | auto fmtTime = [](double s) -> QString { |
| 1100 | if (s < 1.0) |
| 1101 | return QString::number(std::round(s * 1000.0), 'f', 0) + QStringLiteral(" ms"); |
| 1102 | |
| 1103 | if (s >= 100.0) |
| 1104 | return QString::number(s, 'f', 0) + QStringLiteral(" s"); |
| 1105 | |
| 1106 | return QString::number(s, 'f', 2) + QStringLiteral(" s"); |
| 1107 | }; |
| 1108 | |
| 1109 | const QString freqText = QObject::tr("Freq: %1").arg(fmtFreq(freqHz)); |
| 1110 | const QString timeText = |
| 1111 | m_campbellMode ? QStringLiteral("%1: %2").arg(m_yAxisTitle, QString::number(yVal, 'f', 2)) |
| 1112 | : QObject::tr("Time: −%1").arg(fmtTime(yVal)); |
| 1113 | |
| 1114 | drawCursorTooltip(painter, plotRect, cx, cy, freqText, timeText); |
| 1115 | } |
| 1116 | |
| 1117 | /** |
| 1118 | * @brief Maps cursor pixel position to the visible Hz axis and the Y axis value. |