From 391e47fed54d1f21252824531d15d3388d5d38a1 Mon Sep 17 00:00:00 2001 From: Christian Daniel Date: Fri, 27 Sep 2013 23:17:53 +0200 Subject: RollupWidget, GLWidget, etc: automatic channel color assignment --- include/dsp/channelmarker.h | 3 ++ include/gui/basicchannelsettingswidget.h | 14 ++++++- include/gui/rollupwidget.h | 6 ++- plugins/channel/tcpsrc/tcpsrcgui.cpp | 19 ++++++++- plugins/channel/tcpsrc/tcpsrcgui.h | 2 + sdrbase/dsp/channelmarker.cpp | 30 ++++++++++++- sdrbase/gui/basicchannelsettingswidget.cpp | 67 +++++++++++++++++++++++++++++- sdrbase/gui/basicchannelsettingswidget.ui | 25 ++++++++++- sdrbase/gui/glspectrum.cpp | 6 +-- sdrbase/gui/rollupwidget.cpp | 12 +++++- 10 files changed, 171 insertions(+), 13 deletions(-) diff --git a/include/dsp/channelmarker.h b/include/dsp/channelmarker.h index 06cd5b9..df9c173 100644 --- a/include/dsp/channelmarker.h +++ b/include/dsp/channelmarker.h @@ -27,6 +27,9 @@ public: const QColor& getColor() const { return m_color; } protected: + static QRgb m_colorTable[]; + static int m_nextColor; + QString m_title; int m_centerFrequency; int m_bandwidth; diff --git a/include/gui/basicchannelsettingswidget.h b/include/gui/basicchannelsettingswidget.h index 003b923..072cda1 100644 --- a/include/gui/basicchannelsettingswidget.h +++ b/include/gui/basicchannelsettingswidget.h @@ -7,15 +7,27 @@ namespace Ui { class BasicChannelSettingsWidget; } +class ChannelMarker; + class BasicChannelSettingsWidget : public QWidget { Q_OBJECT public: - explicit BasicChannelSettingsWidget(QWidget* parent = NULL); + explicit BasicChannelSettingsWidget(ChannelMarker* marker, QWidget* parent = NULL); ~BasicChannelSettingsWidget(); +private slots: + void on_title_textChanged(const QString& text); + void on_colorBtn_clicked(); + void on_red_valueChanged(int value); + void on_green_valueChanged(int value); + void on_blue_valueChanged(int value); + private: Ui::BasicChannelSettingsWidget* ui; + ChannelMarker* m_channelMarker; + + void paintColor(); }; #endif // INCLUDE_BASICCHANNELSETTINGSWIDGET_H diff --git a/include/gui/rollupwidget.h b/include/gui/rollupwidget.h index 60966ac..d34085c 100644 --- a/include/gui/rollupwidget.h +++ b/include/gui/rollupwidget.h @@ -13,15 +13,19 @@ public: QByteArray saveState(int version = 0) const; bool restoreState(const QByteArray& state, int version = 0); + void setTitleColor(const QColor& c); + signals: void widgetRolled(QWidget* widget, bool rollDown); - void menuDoubleClickEvent(const QPoint& position); + void menuDoubleClickEvent(); protected: enum { VersionMarker = 0xff }; + QColor m_titleColor; + int arrangeRollups(); void paintEvent(QPaintEvent*); diff --git a/plugins/channel/tcpsrc/tcpsrcgui.cpp b/plugins/channel/tcpsrc/tcpsrcgui.cpp index 92f210e..bf33167 100644 --- a/plugins/channel/tcpsrc/tcpsrcgui.cpp +++ b/plugins/channel/tcpsrc/tcpsrcgui.cpp @@ -5,6 +5,7 @@ #include "dsp/spectrumvis.h" #include "dsp/threadedsamplesink.h" #include "util/simpleserializer.h" +#include "gui/basicchannelsettingswidget.h" #include "ui_tcpsrcgui.h" TCPSrcGUI* TCPSrcGUI::create(PluginAPI* pluginAPI) @@ -43,6 +44,7 @@ QByteArray TCPSrcGUI::serialize() const s.writeReal(5, m_rfBandwidth); s.writeS32(6, m_tcpPort); s.writeBlob(7, ui->spectrumGUI->serialize()); + s.writeU32(8, m_channelMarker->getColor().rgb()); return s.final(); } @@ -58,6 +60,7 @@ bool TCPSrcGUI::deserialize(const QByteArray& data) if(d.getVersion() == 1) { QByteArray bytetmp; qint32 s32tmp; + quint32 u32tmp; Real realtmp; d.readBlob(1, &bytetmp); restoreState(bytetmp); @@ -83,6 +86,8 @@ bool TCPSrcGUI::deserialize(const QByteArray& data) ui->tcpPort->setText(QString("%1").arg(s32tmp)); d.readBlob(7, &bytetmp); ui->spectrumGUI->deserialize(bytetmp); + if(d.readU32(8, &u32tmp)) + m_channelMarker->setColor(u32tmp); applySettings(); return true; } else { @@ -119,6 +124,7 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) : ui->setupUi(this); ui->connectedClientsBox->hide(); connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); + connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); setAttribute(Qt::WA_DeleteOnClose, true); m_spectrumVis = new SpectrumVis(ui->glSpectrum); @@ -134,7 +140,6 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) : m_spectrumVis->configure(m_threadedSampleSink->getMessageQueue(), 64, 10, FFTWindow::BlackmanHarris); m_channelMarker = new ChannelMarker(this); - m_channelMarker->setColor(Qt::red); m_channelMarker->setBandwidth(25000); m_channelMarker->setCenterFrequency(0); m_channelMarker->setVisible(true); @@ -143,6 +148,8 @@ TCPSrcGUI::TCPSrcGUI(PluginAPI* pluginAPI, QWidget* parent) : ui->spectrumGUI->setBuddies(m_threadedSampleSink->getMessageQueue(), m_spectrumVis, ui->glSpectrum); + m_basicSettingsShown = false; + applySettings(); } @@ -172,6 +179,7 @@ void TCPSrcGUI::applySettings() if((!ok) || (tcpPort < 1) || (tcpPort > 65535)) tcpPort = 9999; + setTitleColor(m_channelMarker->getColor()); ui->sampleRate->setText(QString("%1").arg(outputSampleRate, 0)); ui->rfBandwidth->setText(QString("%1").arg(rfBandwidth, 0)); ui->tcpPort->setText(QString("%1").arg(tcpPort)); @@ -242,6 +250,15 @@ void TCPSrcGUI::onWidgetRolled(QWidget* widget, bool rollDown) m_tcpSrc->setSpectrum(m_threadedSampleSink->getMessageQueue(), rollDown); } +void TCPSrcGUI::onMenuDoubleClicked() +{ + if(!m_basicSettingsShown) { + m_basicSettingsShown = true; + BasicChannelSettingsWidget* bcsw = new BasicChannelSettingsWidget(m_channelMarker, this); + bcsw->show(); + } +} + void TCPSrcGUI::addConnection(quint32 id, const QHostAddress& peerAddress, int peerPort) { QStringList l; diff --git a/plugins/channel/tcpsrc/tcpsrcgui.h b/plugins/channel/tcpsrc/tcpsrcgui.h index c2c1614..b5a4dc0 100644 --- a/plugins/channel/tcpsrc/tcpsrcgui.h +++ b/plugins/channel/tcpsrc/tcpsrcgui.h @@ -40,6 +40,7 @@ private slots: void on_tcpPort_textEdited(const QString& arg1); void on_applyBtn_clicked(); void onWidgetRolled(QWidget* widget, bool rollDown); + void onMenuDoubleClicked(); private: Ui::TCPSrcGUI* ui; @@ -51,6 +52,7 @@ private: Real m_outputSampleRate; Real m_rfBandwidth; int m_tcpPort; + bool m_basicSettingsShown; // RF path ThreadedSampleSink* m_threadedSampleSink; diff --git a/sdrbase/dsp/channelmarker.cpp b/sdrbase/dsp/channelmarker.cpp index a39ae63..97d1e73 100644 --- a/sdrbase/dsp/channelmarker.cpp +++ b/sdrbase/dsp/channelmarker.cpp @@ -1,12 +1,40 @@ #include "dsp/channelmarker.h" +QRgb ChannelMarker::m_colorTable[] = { + qRgb(0xc0, 0x00, 0x00), + qRgb(0x00, 0xc0, 0x00), + qRgb(0x00, 0x00, 0xc0), + + qRgb(0xc0, 0xc0, 0x00), + qRgb(0xc0, 0x00, 0xc0), + qRgb(0x00, 0xc0, 0xc0), + + qRgb(0xc0, 0x60, 0x00), + qRgb(0xc0, 0x00, 0x60), + qRgb(0x60, 0x00, 0xc0), + + qRgb(0x60, 0x00, 0x00), + qRgb(0x00, 0x60, 0x00), + qRgb(0x00, 0x00, 0x60), + + qRgb(0x60, 0x60, 0x00), + qRgb(0x60, 0x00, 0x60), + qRgb(0x00, 0x60, 0x60), + + 0 +}; +int ChannelMarker::m_nextColor = 0; + ChannelMarker::ChannelMarker(QObject* parent) : QObject(parent), m_centerFrequency(0), m_bandwidth(0), m_visible(false), - m_color(Qt::red) + m_color(m_colorTable[m_nextColor]) { + ++m_nextColor; + if(m_colorTable[m_nextColor] == 0) + m_nextColor = 0; } void ChannelMarker::setTitle(const QString& title) diff --git a/sdrbase/gui/basicchannelsettingswidget.cpp b/sdrbase/gui/basicchannelsettingswidget.cpp index 3103a25..77f607e 100644 --- a/sdrbase/gui/basicchannelsettingswidget.cpp +++ b/sdrbase/gui/basicchannelsettingswidget.cpp @@ -1,14 +1,77 @@ +#include +#include #include "gui/basicchannelsettingswidget.h" +#include "dsp/channelmarker.h" #include "ui_basicchannelsettingswidget.h" -BasicChannelSettingsWidget::BasicChannelSettingsWidget(QWidget* parent) : +BasicChannelSettingsWidget::BasicChannelSettingsWidget(ChannelMarker* marker, QWidget* parent) : QWidget(parent), - ui(new Ui::BasicChannelSettingsWidget) + ui(new Ui::BasicChannelSettingsWidget), + m_channelMarker(marker) { ui->setupUi(this); + ui->title->setText(m_channelMarker->getTitle()); + paintColor(); + ui->red->setValue(m_channelMarker->getColor().red()); + ui->green->setValue(m_channelMarker->getColor().green()); + ui->blue->setValue(m_channelMarker->getColor().blue()); } BasicChannelSettingsWidget::~BasicChannelSettingsWidget() { delete ui; } + +void BasicChannelSettingsWidget::on_title_textChanged(const QString& text) +{ + m_channelMarker->setTitle(text); +} + +void BasicChannelSettingsWidget::on_colorBtn_clicked() +{ + QColor c = m_channelMarker->getColor(); + c = QColorDialog::getColor(c, this, tr("Select Color for Channel")); + if(c.isValid()) { + m_channelMarker->setColor(c); + paintColor(); + ui->red->setValue(m_channelMarker->getColor().red()); + ui->green->setValue(m_channelMarker->getColor().green()); + ui->blue->setValue(m_channelMarker->getColor().blue()); + } +} + +void BasicChannelSettingsWidget::paintColor() +{ + QColor c(m_channelMarker->getColor()); + QPixmap pm(24, 24); + pm.fill(c); + ui->colorBtn->setIcon(pm); + ui->color->setText(tr("#%1%2%3") + .arg(c.red(), 2, 16, QChar('0')) + .arg(c.green(), 2, 16, QChar('0')) + .arg(c.blue(), 2, 16, QChar('0'))); +} + +void BasicChannelSettingsWidget::on_red_valueChanged(int value) +{ + QColor c(m_channelMarker->getColor()); + c.setRed(value); + m_channelMarker->setColor(c); + paintColor(); +} + +void BasicChannelSettingsWidget::on_green_valueChanged(int value) +{ + QColor c(m_channelMarker->getColor()); + c.setGreen(value); + m_channelMarker->setColor(c); + paintColor(); +} + +void BasicChannelSettingsWidget::on_blue_valueChanged(int value) +{ + QColor c(m_channelMarker->getColor()); + c.setBlue(value); + m_channelMarker->setColor(c); + paintColor(); +} diff --git a/sdrbase/gui/basicchannelsettingswidget.ui b/sdrbase/gui/basicchannelsettingswidget.ui index 25d72e2..d8c61ff 100644 --- a/sdrbase/gui/basicchannelsettingswidget.ui +++ b/sdrbase/gui/basicchannelsettingswidget.ui @@ -11,7 +11,7 @@ - Form + Title & Color @@ -22,6 +22,12 @@ + + + 0 + 0 + + Title @@ -32,6 +38,12 @@ + + + 0 + 0 + + Color @@ -45,7 +57,7 @@ - + #ff0000 @@ -53,6 +65,9 @@ + + 255 + Qt::Horizontal @@ -60,6 +75,9 @@ + + 255 + Qt::Horizontal @@ -67,6 +85,9 @@ + + 255 + Qt::Horizontal diff --git a/sdrbase/gui/glspectrum.cpp b/sdrbase/gui/glspectrum.cpp index 4352c2c..f05400b 100644 --- a/sdrbase/gui/glspectrum.cpp +++ b/sdrbase/gui/glspectrum.cpp @@ -466,7 +466,7 @@ void GLSpectrum::paintGL() if(dv->m_channelMarker->getVisible()) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.15f); + glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f); glPushMatrix(); glTranslatef(dv->m_glRect.x(), dv->m_glRect.y(), 0); glScalef(dv->m_glRect.width(), dv->m_glRect.height(), 1); @@ -546,7 +546,7 @@ void GLSpectrum::paintGL() if(dv->m_channelMarker->getVisible()) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.15f); + glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f); glPushMatrix(); glTranslatef(dv->m_glRect.x(), dv->m_glRect.y(), 0); glScalef(dv->m_glRect.width(), dv->m_glRect.height(), 1); @@ -646,7 +646,7 @@ void GLSpectrum::paintGL() if(dv->m_channelMarker->getVisible()) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.3f); + glColor4f(dv->m_channelMarker->getColor().redF(), dv->m_channelMarker->getColor().greenF(), dv->m_channelMarker->getColor().blueF(), 0.5f); glPushMatrix(); glTranslatef(dv->m_glRect.x(), dv->m_glRect.y(), 0); glScalef(dv->m_glRect.width(), dv->m_glRect.height(), 1); diff --git a/sdrbase/gui/rollupwidget.cpp b/sdrbase/gui/rollupwidget.cpp index 61532b4..dafe315 100644 --- a/sdrbase/gui/rollupwidget.cpp +++ b/sdrbase/gui/rollupwidget.cpp @@ -13,6 +13,8 @@ RollupWidget::RollupWidget(QWidget* parent) : setAutoFillBackground(false); setAttribute(Qt::WA_OpaquePaintEvent, true); + + m_titleColor = palette().highlight().color(); } QByteArray RollupWidget::saveState(int version) const @@ -87,6 +89,12 @@ bool RollupWidget::restoreState(const QByteArray& state, int version) return true; } +void RollupWidget::setTitleColor(const QColor& c) +{ + m_titleColor = c; + update(); +} + int RollupWidget::arrangeRollups() { QFontMetrics fm(font()); @@ -139,7 +147,7 @@ void RollupWidget::paintEvent(QPaintEvent*) // Titel-Hintergrund p.setPen(Qt::NoPen); - p.setBrush(palette().highlight()); + p.setBrush(m_titleColor); QPainterPath path; path.moveTo(1.5, fm.height() + 2.5); path.lineTo(width() - 1.5, fm.height() + 2.5); @@ -303,7 +311,7 @@ void RollupWidget::mouseDoubleClickEvent(QMouseEvent* event) // menu box left if(QRectF(3.5, 3.5, fm.ascent(), fm.ascent()).contains(event->pos())) { - emit menuDoubleClickEvent(event->pos()); + emit menuDoubleClickEvent(); return; } } -- cgit v1.2.3