From 5df45136f74c34f4cd93fda9a8b427e3866a09e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 15:45:48 +0000 Subject: [PATCH] freqdisplay: auto-fit font to available width and height so text is always fully visible Agent-Logs-Url: https://github.com/srcejon/sdrangel/sessions/a5adfa9d-7047-46b6-8d9f-ded5f125ab8c Co-authored-by: srcejon <57259258+srcejon@users.noreply.github.com> --- .../feature/freqdisplay/freqdisplaygui.cpp | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/plugins/feature/freqdisplay/freqdisplaygui.cpp b/plugins/feature/freqdisplay/freqdisplaygui.cpp index 5bba06e0d..fa20e4c02 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.cpp +++ b/plugins/feature/freqdisplay/freqdisplaygui.cpp @@ -11,9 +11,6 @@ #include "freqdisplaygui.h" namespace { -// For typical feature windows this keeps the text close to ~22% of the smallest -// widget dimension, which yields large readable digits without clipping. -constexpr double frequencyFontScale = 0.22; constexpr const char* rxTxChannelKinds = "RT"; constexpr int pollIntervalMs = 1000; constexpr int minimumFrequencyFontPointSize = 10; @@ -239,13 +236,33 @@ void FreqDisplayGUI::updateFrequencyText() void FreqDisplayGUI::updateFrequencyFont() { - const int minDimension = qMin(ui->frequencyValue->width(), ui->frequencyValue->height()); - if (minDimension <= 0) { + const int availableWidth = ui->frequencyValue->width(); + const int availableHeight = ui->frequencyValue->height(); + if (availableWidth <= 0 || availableHeight <= 0) { return; } - const int pointSize = qMax(minimumFrequencyFontPointSize, static_cast(minDimension * frequencyFontScale)); + const QString text = ui->frequencyValue->text(); + if (text.isEmpty()) { + return; + } + + // Probe at a large reference size to get accurate text dimensions, then + // scale linearly to find the largest point size that fits in both directions. QFont font = ui->frequencyValue->font(); + constexpr int probeSize = 200; + font.setPointSize(probeSize); + const QFontMetrics fm(font); + const int textWidth = fm.horizontalAdvance(text); + const int textHeight = fm.height(); + + if (textWidth <= 0 || textHeight <= 0) { + return; + } + + const int maxFromWidth = probeSize * availableWidth / textWidth; + const int maxFromHeight = probeSize * availableHeight / textHeight; + const int pointSize = qMax(minimumFrequencyFontPointSize, qMin(maxFromWidth, maxFromHeight)); font.setPointSize(pointSize); ui->frequencyValue->setFont(font); }