mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-05-14 05:12:09 -04:00
freqdisplay: add font family combo box and transparent background toggle
Agent-Logs-Url: https://github.com/srcejon/sdrangel/sessions/b4da7187-ba56-4943-ae14-800f326fb72b Co-authored-by: srcejon <57259258+srcejon@users.noreply.github.com>
This commit is contained in:
parent
5df45136f7
commit
f5a3dce168
@ -3,6 +3,7 @@
|
||||
#include <QResizeEvent>
|
||||
|
||||
#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<int>(&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);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define INCLUDE_FEATURE_FREQDISPLAYGUI_H_
|
||||
|
||||
#include <QTimer>
|
||||
#include <QFontComboBox>
|
||||
|
||||
#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();
|
||||
};
|
||||
|
||||
|
||||
@ -68,6 +68,40 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="fontLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="fontLabel">
|
||||
<property name="text">
|
||||
<string>Font</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFontComboBox" name="fontFamily">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Select font family for the frequency display</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ButtonSwitch" name="transparentBackground">
|
||||
<property name="toolTip">
|
||||
<string>Toggle transparent window background</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>T</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="frequencyValue">
|
||||
<property name="sizePolicy">
|
||||
@ -94,6 +128,11 @@
|
||||
<header>gui/rollupcontents.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ButtonSwitch</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>gui/buttonswitch.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ struct FreqDisplaySettings
|
||||
QString m_selectedChannel;
|
||||
int m_workspaceIndex;
|
||||
QByteArray m_geometryBytes;
|
||||
QString m_fontName;
|
||||
bool m_transparentBackground;
|
||||
|
||||
FreqDisplaySettings();
|
||||
~FreqDisplaySettings() = default;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user