mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-05-14 21:32:41 -04:00
freqdisplay: fix hang on transparency exit; add units/showUnits; fix dB; fix Both mode fallback
Agent-Logs-Url: https://github.com/srcejon/sdrangel/sessions/ab287ce0-b7ef-4125-9e62-9054ab2ccd93 Co-authored-by: srcejon <57259258+srcejon@users.noreply.github.com>
This commit is contained in:
parent
2a41303bc0
commit
59504ea23d
@ -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<int>(&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<int>(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<qint64>(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<FreqDisplaySettings::FrequencyUnits>(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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -7,13 +7,13 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>520</width>
|
||||
<height>200</height>
|
||||
<height>220</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>420</width>
|
||||
<height>180</height>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -25,7 +25,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>520</width>
|
||||
<height>51</height>
|
||||
<height>75</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -148,13 +148,74 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="unitsLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="unitsLabel">
|
||||
<property name="text">
|
||||
<string>Units</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="frequencyUnits">
|
||||
<property name="toolTip">
|
||||
<string>Select units for the displayed frequency value</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Hz</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>kHz</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>MHz</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>GHz</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ButtonSwitch" name="showUnits">
|
||||
<property name="toolTip">
|
||||
<string>Show or hide unit labels in the display</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>U</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="unitsSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="horizontalWidget" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>70</y>
|
||||
<y>90</y>
|
||||
<width>501</width>
|
||||
<height>111</height>
|
||||
</rect>
|
||||
|
||||
@ -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<int>(m_displayMode));
|
||||
s.writeBool(8, m_speechEnabled);
|
||||
s.writeS32(9, static_cast<int>(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>(displayMode);
|
||||
d.readBool(8, &m_speechEnabled, false);
|
||||
int frequencyUnits = 0;
|
||||
d.readS32(9, &frequencyUnits, 0);
|
||||
m_frequencyUnits = static_cast<FrequencyUnits>(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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user