* @brief Renders the two-line crosshair tooltip box, flipping sides as needed. */
| 1153 | * @brief Renders the two-line crosshair tooltip box, flipping sides as needed. |
| 1154 | */ |
| 1155 | void Widgets::Waterfall::drawCursorTooltip(QPainter* painter, |
| 1156 | const QRectF& plotRect, |
| 1157 | double cx, |
| 1158 | double cy, |
| 1159 | const QString& freqText, |
| 1160 | const QString& timeText) const |
| 1161 | { |
| 1162 | const QFontMetrics fm(painter->font()); |
| 1163 | const int padX = 8; |
| 1164 | const int padY = 5; |
| 1165 | const int gap = 2; |
| 1166 | const int w = std::max(fm.horizontalAdvance(freqText), fm.horizontalAdvance(timeText)) + padX * 2; |
| 1167 | const int h = fm.height() * 2 + gap + padY * 2; |
| 1168 | |
| 1169 | double tx = cx + 12; |
| 1170 | double ty = cy + 12; |
| 1171 | if (tx + w > plotRect.right()) |
| 1172 | tx = cx - 12 - w; |
| 1173 | |
| 1174 | if (ty + h > plotRect.bottom()) |
| 1175 | ty = cy - 12 - h; |
| 1176 | |
| 1177 | tx = qBound(plotRect.left() + 2, tx, plotRect.right() - w - 2); |
| 1178 | ty = qBound(plotRect.top() + 2, ty, plotRect.bottom() - h - 2); |
| 1179 | |
| 1180 | const QRectF tipRect(tx, ty, w, h); |
| 1181 | painter->setPen(Qt::NoPen); |
| 1182 | painter->setBrush(QColor(0, 0, 0, 184)); |
| 1183 | painter->drawRoundedRect(tipRect, 3, 3); |
| 1184 | |
| 1185 | painter->setPen(QColor(Qt::white)); |
| 1186 | const double textBaseline = ty + padY + fm.ascent(); |
| 1187 | painter->drawText(QPointF(tx + padX, textBaseline), freqText); |
| 1188 | painter->drawText(QPointF(tx + padX, textBaseline + fm.height() + gap), timeText); |
| 1189 | } |
| 1190 | |
| 1191 | //-------------------------------------------------------------------------------------------------- |
| 1192 | // Tick generation |