From 6ccd8732d5e67919f3efd3c9c2d36895d4377afe Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 19 Jul 2015 18:43:48 +0200 Subject: [PATCH] Experimental reverse video frequency dial implmented for NFM --- CMakeLists.txt | 2 ++ include-gpl/gui/colormapper.h | 41 ++++++++++++++++++++++ include-gpl/gui/valuedial.h | 7 +++- plugins/channel/nfm/nfmdemodgui.cpp | 3 ++ sdrbase/gui/colormapper.cpp | 53 +++++++++++++++++++++++++++++ sdrbase/gui/valuedial.cpp | 49 +++++++++++++++++++++----- 6 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 include-gpl/gui/colormapper.h create mode 100644 sdrbase/gui/colormapper.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ecbdc0b16..89f67de79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,7 @@ set(sdrbase_SOURCES sdrbase/gui/basicchannelsettingswidget.cpp sdrbase/gui/buttonswitch.cpp sdrbase/gui/channelwindow.cpp + sdrbase/gui/colormapper.cpp sdrbase/gui/glscope.cpp sdrbase/gui/glscopegui.cpp sdrbase/gui/glspectrum.cpp @@ -147,6 +148,7 @@ set(sdrbase_HEADERS include/gui/basicchannelsettingswidget.h include-gpl/gui/buttonswitch.h include-gpl/gui/channelwindow.h + include-gpl/gui/colormapper.h include-gpl/gui/glscope.h include-gpl/gui/glscopegui.h include-gpl/gui/glspectrum.h diff --git a/include-gpl/gui/colormapper.h b/include-gpl/gui/colormapper.h new file mode 100644 index 000000000..336a2aa7c --- /dev/null +++ b/include-gpl/gui/colormapper.h @@ -0,0 +1,41 @@ +/* + * colormap.h + * + * Created on: Jul 19, 2015 + * Author: f4exb + */ +#ifndef INCLUDE_GPL_GUI_COLORMAPPER_H_ +#define INCLUDE_GPL_GUI_COLORMAPPER_H_ + +#include +#include +#include +#include "util/export.h" + +class SDRANGELOVE_API ColorMapper +{ +public: + enum Theme { + Normal, + ReverseGold, + }; + + typedef std::vector > colormap; + + ColorMapper(Theme theme = Normal); + ~ColorMapper(); + + const colormap& getDialBackgroundColorMap() const { return m_dialBackgroundcolorMap; }; + const QColor& getForegroundColor() const { return m_foregroundColor; }; + const QColor& getSecondaryForegroundColor() const { return m_secondaryForegroundColor; }; + const QColor& getHighlightColor() const { return m_highlightColor; }; + +private: + Theme m_theme; + std::vector > m_dialBackgroundcolorMap; + QColor m_foregroundColor; + QColor m_secondaryForegroundColor; + QColor m_highlightColor; +}; + +#endif /* INCLUDE_GPL_GUI_COLORMAPPER_H_ */ diff --git a/include-gpl/gui/valuedial.h b/include-gpl/gui/valuedial.h index a04825da8..0f58e024f 100644 --- a/include-gpl/gui/valuedial.h +++ b/include-gpl/gui/valuedial.h @@ -17,17 +17,20 @@ #include #include +#include "gui/colormapper.h" #include "util/export.h" class SDRANGELOVE_API ValueDial : public QWidget { Q_OBJECT public: - ValueDial(QWidget* parent = NULL); + ValueDial(QWidget* parent = NULL, ColorMapper colorMapper = ColorMapper(ColorMapper::Normal)); void setValue(quint64 value); void setValueRange(uint numDigits, quint64 min, quint64 max); void setFont(const QFont& font); + void setBold(bool bold); + void setColorMapper(ColorMapper colorMapper); signals: void changed(quint64 value); @@ -52,6 +55,8 @@ private: QTimer m_animationTimer; QTimer m_blinkTimer; + ColorMapper m_colorMapper; + quint64 findExponent(int digit); QChar digitNeigh(QChar c, bool dir); QString formatText(quint64 value); diff --git a/plugins/channel/nfm/nfmdemodgui.cpp b/plugins/channel/nfm/nfmdemodgui.cpp index 6346c98c3..06350ec0e 100644 --- a/plugins/channel/nfm/nfmdemodgui.cpp +++ b/plugins/channel/nfm/nfmdemodgui.cpp @@ -209,6 +209,9 @@ NFMDemodGUI::NFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) : ui->ctcss->addItem(QString("%1").arg(ctcss_tones[i])); } + ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); + //ui->deltaFrequency->setBold(true); + m_channelizer = new Channelizer(m_nfmDemod); m_threadedSampleSink = new ThreadedSampleSink(m_channelizer); m_pluginAPI->addAudioSource(m_audioFifo); diff --git a/sdrbase/gui/colormapper.cpp b/sdrbase/gui/colormapper.cpp new file mode 100644 index 000000000..cc36c8788 --- /dev/null +++ b/sdrbase/gui/colormapper.cpp @@ -0,0 +1,53 @@ +/* + * colormap.cpp + * + * Created on: Jul 19, 2015 + * Author: f4exb + */ + +#include + +ColorMapper::ColorMapper(Theme theme) : + m_theme(theme) +{ + switch (m_theme) + { + case ReverseGold: + /* + m_dialBackgroundcolorMap.push_back(std::pair(0.0, QColor(0x97, 0x54, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.1, QColor(0x5e, 0x34, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.2, QColor(0x2e, 0x19, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.5, QColor(0x00, 0x00, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.8, QColor(0x0f, 0x08, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.9, QColor(0x40, 0x23, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(1.0, QColor(0x97, 0x54, 0x00))); + */ + m_dialBackgroundcolorMap.push_back(std::pair(0.0, QColor(0x97, 0x54, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.1, QColor(0x5e, 0x34, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.2, QColor(0x5e, 0x34, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.5, QColor(0x00, 0x00, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.8, QColor(0x5e, 0x34, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(0.9, QColor(0x40, 0x23, 0x00))); + m_dialBackgroundcolorMap.push_back(std::pair(1.0, QColor(0x97, 0x54, 0x00))); + m_foregroundColor = QColor(0xff, 0x8b, 0x00); + m_secondaryForegroundColor = QColor(0xff, 0xc5, 0x80); + m_highlightColor = QColor(0xbf, 0x69, 0x00, 0x80); + break; + case Normal: + default: + m_dialBackgroundcolorMap.push_back(std::pair(0.0, QColor(0x40, 0x40, 0x40))); + m_dialBackgroundcolorMap.push_back(std::pair(0.1, QColor(0xc0, 0xc0, 0xc0))); + m_dialBackgroundcolorMap.push_back(std::pair(0.2, QColor(0xf0, 0xf0, 0xf0))); + m_dialBackgroundcolorMap.push_back(std::pair(0.5, QColor(0xff, 0xff, 0xff))); + m_dialBackgroundcolorMap.push_back(std::pair(0.8, QColor(0xd0, 0xd0, 0xd0))); + m_dialBackgroundcolorMap.push_back(std::pair(0.9, QColor(0xa0, 0xa0, 0xa0))); + m_dialBackgroundcolorMap.push_back(std::pair(1.0, QColor(0x40, 0x40, 0x40))); + m_foregroundColor = QColor(0x00, 0x00, 0x00); + m_secondaryForegroundColor = QColor(0x10, 0x10, 0x10); + m_highlightColor = QColor(0xff, 0x00, 0x00, 0x20); + } +} + +ColorMapper::~ColorMapper() +{ +} diff --git a/sdrbase/gui/valuedial.cpp b/sdrbase/gui/valuedial.cpp index 79268fc79..3c59f58ae 100644 --- a/sdrbase/gui/valuedial.cpp +++ b/sdrbase/gui/valuedial.cpp @@ -21,9 +21,10 @@ #include #include "gui/valuedial.h" -ValueDial::ValueDial(QWidget* parent) : +ValueDial::ValueDial(QWidget* parent, ColorMapper colorMapper) : QWidget(parent), - m_animationState(0) + m_animationState(0), + m_colorMapper(colorMapper) { setAutoFillBackground(false); setAttribute(Qt::WA_OpaquePaintEvent, true); @@ -35,6 +36,14 @@ ValueDial::ValueDial(QWidget* parent) : m_background.setFinalStop(0, 1); m_background.setCoordinateMode(QGradient::ObjectBoundingMode); + ColorMapper::colormap::const_iterator cmit = m_colorMapper.getDialBackgroundColorMap().begin(); + ColorMapper::colormap::const_iterator cmitEnd = m_colorMapper.getDialBackgroundColorMap().end(); + + for (; cmit != cmitEnd; ++ cmit) { + m_background.setColorAt(cmit->first, cmit->second); + } + + /* m_background.setColorAt(0.0, QColor(0x40, 0x40, 0x40)); m_background.setColorAt(0.1, QColor(0xc0, 0xc0, 0xc0)); m_background.setColorAt(0.2, QColor(0xf0, 0xf0, 0xf0)); @@ -42,6 +51,7 @@ ValueDial::ValueDial(QWidget* parent) : m_background.setColorAt(0.8, QColor(0xd0, 0xd0, 0xd0)); m_background.setColorAt(0.9, QColor(0xa0, 0xa0, 0xa0)); m_background.setColorAt(1.0, QColor(0x40, 0x40, 0x40)); + */ m_value = 0; m_valueMin = 0; @@ -71,6 +81,26 @@ void ValueDial::setFont(const QFont& font) setFixedHeight(m_digitHeight * 2 + 2); } +void ValueDial::setBold(bool bold) +{ + QFont f = font(); + f.setBold(bold); + setFont(f); +} + +void ValueDial::setColorMapper(ColorMapper colorMapper) +{ + m_colorMapper = colorMapper; + + ColorMapper::colormap::const_iterator cmit = m_colorMapper.getDialBackgroundColorMap().begin(); + ColorMapper::colormap::const_iterator cmitEnd = m_colorMapper.getDialBackgroundColorMap().end(); + + for (; cmit != cmitEnd; ++ cmit) { + m_background.setColorAt(cmit->first, cmit->second); + } +} + + void ValueDial::setValue(quint64 value) { m_valueNew = value; @@ -158,16 +188,17 @@ void ValueDial::paintEvent(QPaintEvent*) if(m_hightlightedDigit >= 0) { painter.setPen(Qt::NoPen); painter.setBrush(QColor(0xff, 0x00, 0x00, 0x20)); + painter.setBrush(m_colorMapper.getHighlightColor()); painter.drawRect(2 + m_hightlightedDigit * m_digitWidth, 1, m_digitWidth - 1, height() - 1); } if(m_animationState == 0) { for(int i = 0; i < m_text.length(); i++) { painter.setClipRect(1 + i * m_digitWidth, 1, m_digitWidth, m_digitHeight * 2); - painter.setPen(QColor(0x10, 0x10, 0x10)); + painter.setPen(m_colorMapper.getSecondaryForegroundColor()); painter.drawText(QRect(1 + i * m_digitWidth, m_digitHeight * 0.6, m_digitWidth, m_digitHeight), Qt::AlignCenter, m_text.mid(i, 1)); if(m_text[i] != QChar('.')) { - painter.setPen(QColor(0x00, 0x00, 0x00)); + painter.setPen(m_colorMapper.getForegroundColor()); painter.drawText(QRect(1 + i * m_digitWidth, m_digitHeight * -0.7, m_digitWidth, m_digitHeight), Qt::AlignCenter, digitNeigh(m_text[i], true)); painter.drawText(QRect(1 + i * m_digitWidth, m_digitHeight * 1.9, m_digitWidth, m_digitHeight), Qt::AlignCenter, digitNeigh(m_text[i], false)); } @@ -175,7 +206,7 @@ void ValueDial::paintEvent(QPaintEvent*) painter.setClipping(false); if((m_cursor >= 0) && (m_cursorState)) { painter.setPen(Qt::NoPen); - painter.setBrush(QColor(0x10, 0x10, 0x10)); + painter.setBrush(m_colorMapper.getSecondaryForegroundColor()); painter.drawRect(4 + m_cursor * m_digitWidth, 1 + m_digitHeight * 1.5, m_digitWidth - 5, m_digitHeight / 6); } } else { @@ -183,20 +214,20 @@ void ValueDial::paintEvent(QPaintEvent*) for(int i = 0; i < m_text.length(); i++) { if(m_text[i] == m_textNew[i]) { painter.setClipRect(1 + i * m_digitWidth, 1, m_digitWidth, m_digitHeight * 2); - painter.setPen(QColor(0x10, 0x10, 0x10)); + painter.setPen(m_colorMapper.getSecondaryForegroundColor()); painter.drawText(QRect(1 + i * m_digitWidth, m_digitHeight * 0.6, m_digitWidth, m_digitHeight), Qt::AlignCenter, m_text.mid(i, 1)); if(m_text[i] != QChar('.')) { - painter.setPen(QColor(0x00, 0x00, 0x00)); + painter.setPen(m_colorMapper.getForegroundColor()); painter.drawText(QRect(1 + i * m_digitWidth, m_digitHeight * -0.7, m_digitWidth, m_digitHeight), Qt::AlignCenter, digitNeigh(m_text[i], true)); painter.drawText(QRect(1 + i * m_digitWidth, m_digitHeight * 1.9, m_digitWidth, m_digitHeight), Qt::AlignCenter, digitNeigh(m_text[i], false)); } } else { int h = m_digitHeight * 0.6 + m_digitHeight * m_animationState / 2.0; painter.setClipRect(1 + i * m_digitWidth, 1, m_digitWidth, m_digitHeight * 2); - painter.setPen(QColor(0x10, 0x10, 0x10)); + painter.setPen(m_colorMapper.getSecondaryForegroundColor()); painter.drawText(QRect(1 + i * m_digitWidth, h, m_digitWidth, m_digitHeight), Qt::AlignCenter, m_text.mid(i, 1)); if(m_text[i] != QChar('.')) { - painter.setPen(QColor(0x00, 0x00, 0x00)); + painter.setPen(m_colorMapper.getForegroundColor()); painter.drawText(QRect(1 + i * m_digitWidth, h + m_digitHeight * -0.7, m_digitWidth, m_digitHeight), Qt::AlignCenter, digitNeigh(m_text[i], true)); painter.drawText(QRect(1 + i * m_digitWidth, h + m_digitHeight * 1.9, m_digitWidth, m_digitHeight), Qt::AlignCenter, digitNeigh(m_text[i], false)); }