mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-05-14 13:22:16 -04:00
freqdisplay: add text color picker button saved as setting, default white
Agent-Logs-Url: https://github.com/srcejon/sdrangel/sessions/6d0cceb4-1d01-4c8e-95aa-f203715615cc Co-authored-by: srcejon <57259258+srcejon@users.noreply.github.com>
This commit is contained in:
parent
1f41715197
commit
6b67959774
@ -16,11 +16,14 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QFont>
|
||||
#include <QLabel>
|
||||
#include <QLocale>
|
||||
#include <QMenu>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
#include <QSpinBox>
|
||||
#include <QTimer>
|
||||
@ -76,7 +79,6 @@ FreqDisplayOverlay::FreqDisplayOverlay(QWidget* parent)
|
||||
m_label = new QLabel(this);
|
||||
m_label->setAlignment(Qt::AlignCenter);
|
||||
m_label->setWordWrap(true);
|
||||
m_label->setStyleSheet("color: white;");
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
@ -269,7 +271,9 @@ void FreqDisplayGUI::displaySettings()
|
||||
// Must come after frequencyUnits is set so the range/enabled state is correct
|
||||
updateFreqDecimalSpinbox();
|
||||
|
||||
updateTextColorButton();
|
||||
applyTransparency();
|
||||
applyTextColor();
|
||||
applySpeech();
|
||||
updateChannelList();
|
||||
}
|
||||
@ -293,6 +297,7 @@ void FreqDisplayGUI::applySettings(bool force)
|
||||
settingsKeys.append("showUnits");
|
||||
settingsKeys.append("freqDecimalPlaces");
|
||||
settingsKeys.append("powerDecimalPlaces");
|
||||
settingsKeys.append("textColor");
|
||||
m_freqDisplay->applySettings(m_settings, settingsKeys, force);
|
||||
}
|
||||
|
||||
@ -561,6 +566,7 @@ void FreqDisplayGUI::applyTransparency()
|
||||
// Position the overlay at the current screen position of FreqDisplayGUI.
|
||||
m_overlay->move(mapToGlobal(QPoint(0, 0)));
|
||||
m_overlay->resize(size());
|
||||
applyTextColor();
|
||||
m_overlay->show();
|
||||
}
|
||||
hide();
|
||||
@ -579,6 +585,7 @@ void FreqDisplayGUI::applyTransparency()
|
||||
m_overlay = nullptr;
|
||||
}
|
||||
show();
|
||||
applyTextColor();
|
||||
updateFrequencyFont();
|
||||
}
|
||||
}
|
||||
@ -594,6 +601,36 @@ void FreqDisplayGUI::applySpeech()
|
||||
#endif
|
||||
}
|
||||
|
||||
void FreqDisplayGUI::applyTextColor()
|
||||
{
|
||||
const QString styleSheet = QString("color: %1;").arg(m_settings.m_textColor.name());
|
||||
if (m_overlay) {
|
||||
m_overlay->label()->setStyleSheet(styleSheet);
|
||||
} else {
|
||||
ui->frequencyValue->setStyleSheet(styleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
void FreqDisplayGUI::updateTextColorButton()
|
||||
{
|
||||
QPixmap pm(16, 16);
|
||||
pm.fill(m_settings.m_textColor);
|
||||
ui->textColor->setIcon(pm);
|
||||
}
|
||||
|
||||
void FreqDisplayGUI::on_textColor_clicked()
|
||||
{
|
||||
const QColor color = QColorDialog::getColor(
|
||||
m_settings.m_textColor, this, tr("Select text color"), QColorDialog::DontUseNativeDialog);
|
||||
if (color.isValid())
|
||||
{
|
||||
m_settings.m_textColor = color;
|
||||
updateTextColorButton();
|
||||
applyTextColor();
|
||||
applySettings();
|
||||
}
|
||||
}
|
||||
|
||||
void FreqDisplayGUI::on_displayMode_currentIndexChanged(int index)
|
||||
{
|
||||
m_settings.m_displayMode = static_cast<FreqDisplaySettings::DisplayMode>(index);
|
||||
|
||||
@ -120,6 +120,8 @@ private:
|
||||
void updateFreqDecimalSpinbox();
|
||||
void applyTransparency();
|
||||
void applySpeech();
|
||||
void applyTextColor();
|
||||
void updateTextColorButton();
|
||||
QString formatFrequency(qint64 frequencyHz) const;
|
||||
|
||||
private slots:
|
||||
@ -133,6 +135,7 @@ private slots:
|
||||
void on_showUnits_toggled(bool checked);
|
||||
void on_freqDecimalPlaces_valueChanged(int value);
|
||||
void on_powerDecimalPlaces_valueChanged(int value);
|
||||
void on_textColor_clicked();
|
||||
void pollSelectedChannel();
|
||||
void onExitTransparentMode();
|
||||
#ifdef QT_TEXTTOSPEECH_FOUND
|
||||
|
||||
@ -270,6 +270,22 @@ When in transparent mode:
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="textColor">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Select color for the frequency / power text</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
@ -16,6 +16,8 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include "util/simpleserializer.h"
|
||||
|
||||
#include "freqdisplaysettings.h"
|
||||
@ -39,6 +41,7 @@ void FreqDisplaySettings::resetToDefaults()
|
||||
m_showUnits = true;
|
||||
m_freqDecimalPlaces = 3;
|
||||
m_powerDecimalPlaces = 1;
|
||||
m_textColor = Qt::white;
|
||||
}
|
||||
|
||||
QByteArray FreqDisplaySettings::serialize() const
|
||||
@ -57,6 +60,7 @@ QByteArray FreqDisplaySettings::serialize() const
|
||||
s.writeBool(10, m_showUnits);
|
||||
s.writeS32(11, m_freqDecimalPlaces);
|
||||
s.writeS32(12, m_powerDecimalPlaces);
|
||||
s.writeU32(13, m_textColor.rgba());
|
||||
|
||||
return s.final();
|
||||
}
|
||||
@ -93,6 +97,9 @@ bool FreqDisplaySettings::deserialize(const QByteArray& data)
|
||||
d.readBool(10, &m_showUnits, true);
|
||||
d.readS32(11, &m_freqDecimalPlaces, 3);
|
||||
d.readS32(12, &m_powerDecimalPlaces, 1);
|
||||
quint32 rgba = QColor(Qt::white).rgba();
|
||||
d.readU32(13, &rgba, QColor(Qt::white).rgba());
|
||||
m_textColor = QColor::fromRgba(rgba);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -135,4 +142,7 @@ void FreqDisplaySettings::applySettings(const QStringList& settingsKeys, const F
|
||||
if (settingsKeys.contains("powerDecimalPlaces")) {
|
||||
m_powerDecimalPlaces = settings.m_powerDecimalPlaces;
|
||||
}
|
||||
if (settingsKeys.contains("textColor")) {
|
||||
m_textColor = settings.m_textColor;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#define INCLUDE_FEATURE_FREQDISPLAYSETTINGS_H_
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QColor>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
@ -50,6 +51,7 @@ struct FreqDisplaySettings
|
||||
bool m_showUnits; //!< Whether to append unit labels to displayed values
|
||||
int m_freqDecimalPlaces; //!< Decimal places for frequency value (max depends on units: kHz→3, MHz→6, GHz→9)
|
||||
int m_powerDecimalPlaces; //!< Decimal places for power value (0–3)
|
||||
QColor m_textColor; //!< Color of the frequency / power text
|
||||
|
||||
FreqDisplaySettings();
|
||||
~FreqDisplaySettings() = default;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user