summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Daniel <cd@maintech.de>2013-09-27 23:17:53 +0200
committerChristian Daniel <cd@maintech.de>2013-09-27 23:17:53 +0200
commit391e47fed54d1f21252824531d15d3388d5d38a1 (patch)
tree5be316fe199ad0561f9e0c60b546e9890bb6d2c3
parent4db5f20216fd18469f286be8fa7b6508f644fb46 (diff)
RollupWidget, GLWidget, etc: automatic channel color assignment
-rw-r--r--include/dsp/channelmarker.h3
-rw-r--r--include/gui/basicchannelsettingswidget.h14
-rw-r--r--include/gui/rollupwidget.h6
-rw-r--r--plugins/channel/tcpsrc/tcpsrcgui.cpp19
-rw-r--r--plugins/channel/tcpsrc/tcpsrcgui.h2
-rw-r--r--sdrbase/dsp/channelmarker.cpp30
-rw-r--r--sdrbase/gui/basicchannelsettingswidget.cpp67
-rw-r--r--sdrbase/gui/basicchannelsettingswidget.ui25
-rw-r--r--sdrbase/gui/glspectrum.cpp6
-rw-r--r--sdrbase/gui/rollupwidget.cpp12
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 <QPainter>
+#include <QColorDialog>
#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 @@
</rect>
</property>
<property name="windowTitle">
- <string>Form</string>
+ <string>Title &amp; Color</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
@@ -22,6 +22,12 @@
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
<string>Title</string>
</property>
@@ -32,6 +38,12 @@
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
<string>Color</string>
</property>
@@ -45,7 +57,7 @@
</widget>
</item>
<item row="1" column="2">
- <widget class="QLabel" name="label_3">
+ <widget class="QLabel" name="color">
<property name="text">
<string>#ff0000</string>
</property>
@@ -53,6 +65,9 @@
</item>
<item row="2" column="1" colspan="2">
<widget class="QSlider" name="red">
+ <property name="maximum">
+ <number>255</number>
+ </property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -60,6 +75,9 @@
</item>
<item row="3" column="1" colspan="2">
<widget class="QSlider" name="green">
+ <property name="maximum">
+ <number>255</number>
+ </property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -67,6 +85,9 @@
</item>
<item row="4" column="1" colspan="2">
<widget class="QSlider" name="blue">
+ <property name="maximum">
+ <number>255</number>
+ </property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
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;
}
}