diff --git a/plugins/feature/freqdisplay/freqdisplaygui.cpp b/plugins/feature/freqdisplay/freqdisplaygui.cpp index fa20e4c02..b5b02288a 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.cpp +++ b/plugins/feature/freqdisplay/freqdisplaygui.cpp @@ -3,6 +3,7 @@ #include #include "channel/channelwebapiutils.h" +#include "gui/buttonswitch.h" #include "feature/featureuiset.h" @@ -82,6 +83,8 @@ FreqDisplayGUI::FreqDisplayGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, m_availableChannelOrFeatureHandler.scanAvailableChannelsAndFeatures(); connect(ui->channels, qOverload(&QComboBox::currentIndexChanged), this, &FreqDisplayGUI::on_channels_currentIndexChanged); + connect(ui->fontFamily, &QFontComboBox::currentFontChanged, this, &FreqDisplayGUI::on_fontFamily_currentFontChanged); + connect(ui->transparentBackground, &ButtonSwitch::toggled, this, &FreqDisplayGUI::on_transparentBackground_toggled); connect(&m_pollTimer, &QTimer::timeout, this, &FreqDisplayGUI::pollSelectedChannel); m_pollTimer.start(pollIntervalMs); @@ -105,6 +108,18 @@ void FreqDisplayGUI::displaySettings() setWindowTitle(m_settings.m_title); setTitle(m_settings.m_title); + // Populate font combo box with the saved font (or system default if empty) + ui->fontFamily->blockSignals(true); + if (!m_settings.m_fontName.isEmpty()) { + ui->fontFamily->setCurrentFont(QFont(m_settings.m_fontName)); + } + ui->fontFamily->blockSignals(false); + + ui->transparentBackground->blockSignals(true); + ui->transparentBackground->setChecked(m_settings.m_transparentBackground); + ui->transparentBackground->blockSignals(false); + + applyTransparency(); updateChannelList(); } @@ -119,6 +134,8 @@ void FreqDisplayGUI::applySettings(bool force) settingsKeys.append("selectedChannel"); settingsKeys.append("workspaceIndex"); settingsKeys.append("geometryBytes"); + settingsKeys.append("fontName"); + settingsKeys.append("transparentBackground"); m_freqDisplay->applySettings(m_settings, settingsKeys, force); } @@ -247,9 +264,14 @@ void FreqDisplayGUI::updateFrequencyFont() return; } + // Build a font with the user-chosen family (or the widget's current family if none saved) + QFont font = ui->frequencyValue->font(); + if (!m_settings.m_fontName.isEmpty()) { + font.setFamily(m_settings.m_fontName); + } + // 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); @@ -267,6 +289,36 @@ void FreqDisplayGUI::updateFrequencyFont() ui->frequencyValue->setFont(font); } +void FreqDisplayGUI::applyTransparency() +{ + if (m_settings.m_transparentBackground) + { + // Make the content area and frequency label fully transparent so that + // only the text is visible over whatever is behind the window. + ui->settingsContainer->setStyleSheet("background-color: transparent;"); + ui->frequencyValue->setStyleSheet("background-color: transparent;"); + } + else + { + ui->settingsContainer->setStyleSheet(QString()); + ui->frequencyValue->setStyleSheet(QString()); + } +} + +void FreqDisplayGUI::on_fontFamily_currentFontChanged(const QFont& font) +{ + m_settings.m_fontName = font.family(); + applySettings(); + updateFrequencyFont(); +} + +void FreqDisplayGUI::on_transparentBackground_toggled(bool checked) +{ + m_settings.m_transparentBackground = checked; + applyTransparency(); + applySettings(); +} + void FreqDisplayGUI::resizeEvent(QResizeEvent *event) { FeatureGUI::resizeEvent(event); diff --git a/plugins/feature/freqdisplay/freqdisplaygui.h b/plugins/feature/freqdisplay/freqdisplaygui.h index d6d122c29..f66a63311 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.h +++ b/plugins/feature/freqdisplay/freqdisplaygui.h @@ -2,6 +2,7 @@ #define INCLUDE_FEATURE_FREQDISPLAYGUI_H_ #include +#include #include "availablechannelorfeaturehandler.h" #include "feature/featuregui.h" @@ -56,10 +57,13 @@ private: void updateChannelList(); void updateFrequencyText(); void updateFrequencyFont(); + void applyTransparency(); private slots: void channelsOrFeaturesChanged(const QStringList& renameFrom, const QStringList& renameTo, const QStringList& removed, const QStringList& added); void on_channels_currentIndexChanged(int index); + void on_fontFamily_currentFontChanged(const QFont& font); + void on_transparentBackground_toggled(bool checked); void pollSelectedChannel(); }; diff --git a/plugins/feature/freqdisplay/freqdisplaygui.ui b/plugins/feature/freqdisplay/freqdisplaygui.ui index 4ed905304..eacc69dfe 100644 --- a/plugins/feature/freqdisplay/freqdisplaygui.ui +++ b/plugins/feature/freqdisplay/freqdisplaygui.ui @@ -68,6 +68,40 @@ + + + + + + Font + + + + + + + + 0 + 0 + + + + Select font family for the frequency display + + + + + + + Toggle transparent window background + + + T + + + + + @@ -94,6 +128,11 @@
gui/rollupcontents.h
1 + + ButtonSwitch + QToolButton +
gui/buttonswitch.h
+
diff --git a/plugins/feature/freqdisplay/freqdisplaysettings.cpp b/plugins/feature/freqdisplay/freqdisplaysettings.cpp index 2461e968c..635dd060b 100644 --- a/plugins/feature/freqdisplay/freqdisplaysettings.cpp +++ b/plugins/feature/freqdisplay/freqdisplaysettings.cpp @@ -13,6 +13,8 @@ void FreqDisplaySettings::resetToDefaults() m_selectedChannel.clear(); m_workspaceIndex = -1; m_geometryBytes.clear(); + m_fontName.clear(); + m_transparentBackground = false; } QByteArray FreqDisplaySettings::serialize() const @@ -23,6 +25,8 @@ QByteArray FreqDisplaySettings::serialize() const s.writeString(2, m_selectedChannel); s.writeS32(3, m_workspaceIndex); s.writeBlob(4, m_geometryBytes); + s.writeString(5, m_fontName); + s.writeBool(6, m_transparentBackground); return s.final(); } @@ -47,6 +51,8 @@ bool FreqDisplaySettings::deserialize(const QByteArray& data) d.readString(2, &m_selectedChannel, ""); d.readS32(3, &m_workspaceIndex, -1); d.readBlob(4, &m_geometryBytes); + d.readString(5, &m_fontName, ""); + d.readBool(6, &m_transparentBackground, false); return true; } @@ -65,4 +71,10 @@ void FreqDisplaySettings::applySettings(const QStringList& settingsKeys, const F if (settingsKeys.contains("geometryBytes")) { m_geometryBytes = settings.m_geometryBytes; } + if (settingsKeys.contains("fontName")) { + m_fontName = settings.m_fontName; + } + if (settingsKeys.contains("transparentBackground")) { + m_transparentBackground = settings.m_transparentBackground; + } } diff --git a/plugins/feature/freqdisplay/freqdisplaysettings.h b/plugins/feature/freqdisplay/freqdisplaysettings.h index 45575cd61..6ba38a921 100644 --- a/plugins/feature/freqdisplay/freqdisplaysettings.h +++ b/plugins/feature/freqdisplay/freqdisplaysettings.h @@ -11,6 +11,8 @@ struct FreqDisplaySettings QString m_selectedChannel; int m_workspaceIndex; QByteArray m_geometryBytes; + QString m_fontName; + bool m_transparentBackground; FreqDisplaySettings(); ~FreqDisplaySettings() = default;