diff --git a/plugins/feature/freqdisplay/freqdisplaygui.cpp b/plugins/feature/freqdisplay/freqdisplaygui.cpp index 567b91b9b..5295dd611 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.cpp +++ b/plugins/feature/freqdisplay/freqdisplaygui.cpp @@ -98,6 +98,8 @@ FreqDisplayGUI::FreqDisplayGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, connect(ui->speech, &ButtonSwitch::toggled, this, &FreqDisplayGUI::on_speech_toggled); connect(ui->fontFamily, &QFontComboBox::currentFontChanged, this, &FreqDisplayGUI::on_fontFamily_currentFontChanged); connect(ui->transparentBackground, &ButtonSwitch::toggled, this, &FreqDisplayGUI::on_transparentBackground_toggled); + connect(ui->frequencyUnits, qOverload(&QComboBox::currentIndexChanged), this, &FreqDisplayGUI::on_frequencyUnits_currentIndexChanged); + connect(ui->showUnits, &ButtonSwitch::toggled, this, &FreqDisplayGUI::on_showUnits_toggled); connect(&m_pollTimer, &QTimer::timeout, this, &FreqDisplayGUI::pollSelectedChannel); m_pollTimer.start(pollIntervalMs); @@ -141,6 +143,14 @@ void FreqDisplayGUI::displaySettings() ui->transparentBackground->setChecked(m_settings.m_transparentBackground); ui->transparentBackground->blockSignals(false); + ui->frequencyUnits->blockSignals(true); + ui->frequencyUnits->setCurrentIndex(static_cast(m_settings.m_frequencyUnits)); + ui->frequencyUnits->blockSignals(false); + + ui->showUnits->blockSignals(true); + ui->showUnits->setChecked(m_settings.m_showUnits); + ui->showUnits->blockSignals(false); + applyTransparency(); applySpeech(); updateChannelList(); @@ -161,6 +171,8 @@ void FreqDisplayGUI::applySettings(bool force) settingsKeys.append("transparentBackground"); settingsKeys.append("displayMode"); settingsKeys.append("speechEnabled"); + settingsKeys.append("frequencyUnits"); + settingsKeys.append("showUnits"); m_freqDisplay->applySettings(m_settings, settingsKeys, force); } @@ -297,7 +309,7 @@ void FreqDisplayGUI::updateFrequencyText() } const qint64 absoluteFrequency = qRound64(centerFrequencyHz) + static_cast(offsetHz); - freqText = tr("%1 Hz").arg(QLocale().toString(absoluteFrequency)); + freqText = formatFrequency(absoluteFrequency); } // --- Power --- @@ -307,11 +319,21 @@ void FreqDisplayGUI::updateFrequencyText() double power = 0.0; if (!ChannelWebAPIUtils::getChannelReportValue(selectedChannel.m_superIndex, selectedChannel.m_index, "channelPowerDB", power)) { - setLabelText(tr("Power unavailable")); - updateFrequencyFont(); - return; + if (mode == FreqDisplaySettings::Power) + { + // Power-only mode: nothing else to show + setLabelText(tr("Power unavailable")); + updateFrequencyFont(); + return; + } + // Both mode: power unavailable but frequency is valid — show frequency only + } + else + { + powerText = m_settings.m_showUnits + ? QString("%1 dB").arg(power, 0, 'f', 1) + : QString("%1").arg(power, 0, 'f', 1); } - powerText = QString("%1 dBFS").arg(power, 0, 'f', 1); } // --- Compose display text --- @@ -320,7 +342,8 @@ void FreqDisplayGUI::updateFrequencyText() } else if (mode == FreqDisplaySettings::Power) { setLabelText(powerText); } else { - setLabelText(freqText + "\n" + powerText); + // Both: show frequency alone when power is unavailable + setLabelText(powerText.isEmpty() ? freqText : freqText + "\n" + powerText); } updateFrequencyFont(); @@ -456,11 +479,10 @@ void FreqDisplayGUI::applyTransparency() const QPoint mdiPos = savedMdi->viewport()->mapFromGlobal(currentGlobalPos); // Defer re-embedding to the next event loop iteration. QTimer::singleShot(0, this, [this, savedMdi, mdiPos, savedMdiGeometry]() { - // Hide first to prevent a flash of the overlay appearing as an - // opaque window before it is re-embedded in the MDI area. - hide(); // Clear translucency before native-window recreation so the - // window is rebuilt as opaque. + // window is rebuilt as opaque. Do this while the window is + // still visible: changing flags on a hidden window can deadlock + // on some platforms due to window-manager communication. setAttribute(Qt::WA_TranslucentBackground, false); // Remove the WindowStaysOnTopHint that was added when entering // transparent mode; without this the re-embedded QMdiSubWindow @@ -515,6 +537,47 @@ void FreqDisplayGUI::on_fontFamily_currentFontChanged(const QFont& font) updateFrequencyFont(); } +void FreqDisplayGUI::on_frequencyUnits_currentIndexChanged(int index) +{ + m_settings.m_frequencyUnits = static_cast(index); + applySettings(); + updateFrequencyText(); +} + +void FreqDisplayGUI::on_showUnits_toggled(bool checked) +{ + m_settings.m_showUnits = checked; + applySettings(); + updateFrequencyText(); +} + +QString FreqDisplayGUI::formatFrequency(qint64 frequencyHz) const +{ + const QLocale locale; + const bool showUnits = m_settings.m_showUnits; + + switch (m_settings.m_frequencyUnits) + { + case FreqDisplaySettings::kHz: { + const QString s = locale.toString(frequencyHz / 1e3, 'f', 3); + return showUnits ? s + tr(" kHz") : s; + } + case FreqDisplaySettings::MHz: { + const QString s = locale.toString(frequencyHz / 1e6, 'f', 6); + return showUnits ? s + tr(" MHz") : s; + } + case FreqDisplaySettings::GHz: { + const QString s = locale.toString(frequencyHz / 1e9, 'f', 9); + return showUnits ? s + tr(" GHz") : s; + } + case FreqDisplaySettings::Hz: + default: { + const QString s = locale.toString(frequencyHz); + return showUnits ? s + tr(" Hz") : s; + } + } +} + void FreqDisplayGUI::on_transparentBackground_toggled(bool checked) { m_settings.m_transparentBackground = checked; diff --git a/plugins/feature/freqdisplay/freqdisplaygui.h b/plugins/feature/freqdisplay/freqdisplaygui.h index 9a38dbee3..ecbb32e7a 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.h +++ b/plugins/feature/freqdisplay/freqdisplaygui.h @@ -73,6 +73,7 @@ private: void updateFrequencyFont(); void applyTransparency(); void applySpeech(); + QString formatFrequency(qint64 frequencyHz) const; private slots: void channelsOrFeaturesChanged(const QStringList& renameFrom, const QStringList& renameTo, const QStringList& removed, const QStringList& added); @@ -81,6 +82,8 @@ private slots: void on_speech_toggled(bool checked); void on_fontFamily_currentFontChanged(const QFont& font); void on_transparentBackground_toggled(bool checked); + void on_frequencyUnits_currentIndexChanged(int index); + void on_showUnits_toggled(bool checked); void pollSelectedChannel(); #ifdef QT_TEXTTOSPEECH_FOUND void speechStateChanged(QTextToSpeech::State state); diff --git a/plugins/feature/freqdisplay/freqdisplaygui.ui b/plugins/feature/freqdisplay/freqdisplaygui.ui index 23b47d674..c078be344 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.ui +++ b/plugins/feature/freqdisplay/freqdisplaygui.ui @@ -7,13 +7,13 @@ 0 0 520 - 200 + 220 420 - 180 + 200 @@ -25,7 +25,7 @@ 0 0 520 - 51 + 75 @@ -148,13 +148,74 @@ + + + + + + Units + + + + + + + Select units for the displayed frequency value + + + + Hz + + + + + kHz + + + + + MHz + + + + + GHz + + + + + + + + Show or hide unit labels in the display + + + U + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + 10 - 70 + 90 501 111 diff --git a/plugins/feature/freqdisplay/freqdisplaysettings.cpp b/plugins/feature/freqdisplay/freqdisplaysettings.cpp index 6b0f1b6cf..171b52ddd 100644 --- a/plugins/feature/freqdisplay/freqdisplaysettings.cpp +++ b/plugins/feature/freqdisplay/freqdisplaysettings.cpp @@ -17,6 +17,8 @@ void FreqDisplaySettings::resetToDefaults() m_transparentBackground = false; m_displayMode = Frequency; m_speechEnabled = false; + m_frequencyUnits = Hz; + m_showUnits = true; } QByteArray FreqDisplaySettings::serialize() const @@ -31,6 +33,8 @@ QByteArray FreqDisplaySettings::serialize() const s.writeBool(6, m_transparentBackground); s.writeS32(7, static_cast(m_displayMode)); s.writeBool(8, m_speechEnabled); + s.writeS32(9, static_cast(m_frequencyUnits)); + s.writeBool(10, m_showUnits); return s.final(); } @@ -61,6 +65,10 @@ bool FreqDisplaySettings::deserialize(const QByteArray& data) d.readS32(7, &displayMode, 0); m_displayMode = static_cast(displayMode); d.readBool(8, &m_speechEnabled, false); + int frequencyUnits = 0; + d.readS32(9, &frequencyUnits, 0); + m_frequencyUnits = static_cast(frequencyUnits); + d.readBool(10, &m_showUnits, true); return true; } @@ -91,4 +99,10 @@ void FreqDisplaySettings::applySettings(const QStringList& settingsKeys, const F if (settingsKeys.contains("speechEnabled")) { m_speechEnabled = settings.m_speechEnabled; } + if (settingsKeys.contains("frequencyUnits")) { + m_frequencyUnits = settings.m_frequencyUnits; + } + if (settingsKeys.contains("showUnits")) { + m_showUnits = settings.m_showUnits; + } } diff --git a/plugins/feature/freqdisplay/freqdisplaysettings.h b/plugins/feature/freqdisplay/freqdisplaysettings.h index c4b339561..8af00aaa1 100644 --- a/plugins/feature/freqdisplay/freqdisplaysettings.h +++ b/plugins/feature/freqdisplay/freqdisplaysettings.h @@ -9,10 +9,17 @@ struct FreqDisplaySettings { enum DisplayMode { Frequency = 0, //!< Show channel centre frequency - Power = 1, //!< Show channel power in dBFS + Power = 1, //!< Show channel power in dB Both = 2 //!< Show frequency and power on two lines }; + enum FrequencyUnits { + Hz = 0, + kHz = 1, + MHz = 2, + GHz = 3 + }; + QString m_title; QString m_selectedChannel; int m_workspaceIndex; @@ -21,6 +28,8 @@ struct FreqDisplaySettings bool m_transparentBackground; DisplayMode m_displayMode; bool m_speechEnabled; + FrequencyUnits m_frequencyUnits; //!< Units to use when displaying frequency + bool m_showUnits; //!< Whether to append unit labels to displayed values FreqDisplaySettings(); ~FreqDisplaySettings() = default;