1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-17 13:51:47 -05:00

New channel marker signal handling. Applied to channel analyzer

This commit is contained in:
f4exb 2017-11-14 00:06:42 +01:00
parent cf9c7eb8bb
commit 7b8b492bdd
7 changed files with 146 additions and 83 deletions

View File

@ -216,7 +216,7 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd)
m_settingsMutex.unlock(); m_settingsMutex.unlock();
qDebug() << " - MsgConfigureChannelAnalyzer: m_Bandwidth: " << m_Bandwidth qDebug() << "ChannelAnalyzer::handleMessage: MsgConfigureChannelAnalyzer: m_Bandwidth: " << m_Bandwidth
<< " m_LowCutoff: " << m_LowCutoff << " m_LowCutoff: " << m_LowCutoff
<< " m_spanLog2: " << m_spanLog2 << " m_spanLog2: " << m_spanLog2
<< " m_ssb: " << m_ssb; << " m_ssb: " << m_ssb;

View File

@ -92,6 +92,7 @@ QByteArray ChannelAnalyzerGUI::serialize() const
s.writeS32(6, ui->spanLog2->value()); s.writeS32(6, ui->spanLog2->value());
s.writeBool(7, ui->ssb->isChecked()); s.writeBool(7, ui->ssb->isChecked());
s.writeBlob(8, ui->scopeGUI->serialize()); s.writeBlob(8, ui->scopeGUI->serialize());
return s.final(); return s.final();
} }
@ -139,6 +140,7 @@ bool ChannelAnalyzerGUI::deserialize(const QByteArray& data)
blockApplySettings(false); blockApplySettings(false);
m_channelMarker.blockSignals(false); m_channelMarker.blockSignals(false);
m_channelMarker.emitChangedByAPI();
ui->BW->setValue(bw); ui->BW->setValue(bw);
ui->lowCut->setValue(lowCut); // does applySettings(); ui->lowCut->setValue(lowCut); // does applySettings();
@ -178,8 +180,11 @@ void ChannelAnalyzerGUI::handleInputMessages()
} }
} }
void ChannelAnalyzerGUI::viewChanged() void ChannelAnalyzerGUI::channelMarkerChangedByCursor()
{ {
ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0);
applySettings(); applySettings();
} }
@ -346,13 +351,14 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device
ui->glScope->connectTimer(MainWindow::getInstance()->getMasterTimer()); ui->glScope->connectTimer(MainWindow::getInstance()->getMasterTimer());
connect(&MainWindow::getInstance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); connect(&MainWindow::getInstance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
m_channelMarker.blockSignals(true);
m_channelMarker.setColor(Qt::gray); m_channelMarker.setColor(Qt::gray);
m_channelMarker.setBandwidth(m_rate); m_channelMarker.setBandwidth(m_rate);
m_channelMarker.setSidebands(ChannelMarker::usb); m_channelMarker.setSidebands(ChannelMarker::usb);
m_channelMarker.setCenterFrequency(0); m_channelMarker.setCenterFrequency(0);
m_channelMarker.setVisible(true); m_channelMarker.blockSignals(false);
m_channelMarker.setVisible(true); // activate signal on the last setting only
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged())); setTitleColor(m_channelMarker.getColor());
m_deviceUISet->registerRxChannelInstance(ChannelAnalyzer::m_channelID, this); m_deviceUISet->registerRxChannelInstance(ChannelAnalyzer::m_channelID, this);
m_deviceUISet->addChannelMarker(&m_channelMarker); m_deviceUISet->addChannelMarker(&m_channelMarker);
@ -361,6 +367,7 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum); ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope); ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
connect(&m_channelMarker, SIGNAL(changedByCursor()), this, SLOT(channelMarkerChangedByCursor()));
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
applySettings(); applySettings();
@ -450,10 +457,6 @@ void ChannelAnalyzerGUI::applySettings()
{ {
if (m_doApplySettings) if (m_doApplySettings)
{ {
setTitleColor(m_channelMarker.getColor());
ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0);
ChannelAnalyzer::MsgConfigureChannelizer *msg = ChannelAnalyzer::MsgConfigureChannelizer::create(m_channelMarker.getCenterFrequency()); ChannelAnalyzer::MsgConfigureChannelizer *msg = ChannelAnalyzer::MsgConfigureChannelizer::create(m_channelMarker.getCenterFrequency());
m_channelAnalyzer->getInputMessageQueue()->push(msg); m_channelAnalyzer->getInputMessageQueue()->push(msg);
@ -467,15 +470,11 @@ void ChannelAnalyzerGUI::applySettings()
void ChannelAnalyzerGUI::leaveEvent(QEvent*) void ChannelAnalyzerGUI::leaveEvent(QEvent*)
{ {
blockApplySettings(true);
m_channelMarker.setHighlighted(false); m_channelMarker.setHighlighted(false);
blockApplySettings(false);
} }
void ChannelAnalyzerGUI::enterEvent(QEvent*) void ChannelAnalyzerGUI::enterEvent(QEvent*)
{ {
blockApplySettings(true);
m_channelMarker.setHighlighted(true); m_channelMarker.setHighlighted(true);
blockApplySettings(false);
} }

View File

@ -53,17 +53,8 @@ public:
virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } virtual MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; }
virtual bool handleMessage(const Message& message); virtual bool handleMessage(const Message& message);
private slots: public slots:
void viewChanged(); void channelMarkerChangedByCursor();
void on_deltaFrequency_changed(quint64 value);
void on_deltaMinus_toggled(bool minus);
void on_BW_valueChanged(int value);
void on_lowCut_valueChanged(int value);
void on_spanLog2_valueChanged(int value);
void on_ssb_toggled(bool checked);
void onWidgetRolled(QWidget* widget, bool rollDown);
void handleInputMessages();
void tick();
private: private:
Ui::ChannelAnalyzerGUI* ui; Ui::ChannelAnalyzerGUI* ui;
@ -92,6 +83,17 @@ private:
void leaveEvent(QEvent*); void leaveEvent(QEvent*);
void enterEvent(QEvent*); void enterEvent(QEvent*);
private slots:
void on_deltaFrequency_changed(quint64 value);
void on_deltaMinus_toggled(bool minus);
void on_BW_valueChanged(int value);
void on_lowCut_valueChanged(int value);
void on_spanLog2_valueChanged(int value);
void on_ssb_toggled(bool checked);
void onWidgetRolled(QWidget* widget, bool rollDown);
void handleInputMessages();
void tick();
}; };
#endif // INCLUDE_CHANNELANALYZERGUI_H #endif // INCLUDE_CHANNELANALYZERGUI_H

View File

@ -47,58 +47,75 @@ ChannelMarker::ChannelMarker(QObject* parent) :
setUDPAddress("127.0.0.1"); setUDPAddress("127.0.0.1");
} }
void ChannelMarker::emitChangedByAPI()
{
emit changedByAPI();
}
void ChannelMarker::setTitle(const QString& title) void ChannelMarker::setTitle(const QString& title)
{ {
m_title = title; m_title = title;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setCenterFrequency(int centerFrequency) void ChannelMarker::setCenterFrequency(int centerFrequency)
{ {
m_centerFrequency = centerFrequency; m_centerFrequency = centerFrequency;
emit changed(); emit changedByAPI();
}
void ChannelMarker::setCenterFrequencyByCursor(int centerFrequency)
{
m_centerFrequency = centerFrequency;
emit changedByCursor();
} }
void ChannelMarker::setBandwidth(int bandwidth) void ChannelMarker::setBandwidth(int bandwidth)
{ {
m_bandwidth = bandwidth; m_bandwidth = bandwidth;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setOppositeBandwidth(int bandwidth) void ChannelMarker::setOppositeBandwidth(int bandwidth)
{ {
m_oppositeBandwidth = bandwidth; m_oppositeBandwidth = bandwidth;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setLowCutoff(int lowCutoff) void ChannelMarker::setLowCutoff(int lowCutoff)
{ {
m_lowCutoff = lowCutoff; m_lowCutoff = lowCutoff;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setSidebands(sidebands_t sidebands) void ChannelMarker::setSidebands(sidebands_t sidebands)
{ {
m_sidebands = sidebands; m_sidebands = sidebands;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setVisible(bool visible) void ChannelMarker::setVisible(bool visible)
{ {
m_visible = visible; m_visible = visible;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setHighlighted(bool highlighted) void ChannelMarker::setHighlighted(bool highlighted)
{ {
m_highlighted = highlighted; m_highlighted = highlighted;
emit changed(); emit changedByAPI();
}
void ChannelMarker::setHighlightedByCursor(bool highlighted)
{
m_highlighted = highlighted;
emit highlightedByCursor();
} }
void ChannelMarker::setColor(const QColor& color) void ChannelMarker::setColor(const QColor& color)
{ {
m_color = color; m_color = color;
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setUDPAddress(const QString& udpAddress) void ChannelMarker::setUDPAddress(const QString& udpAddress)
@ -106,21 +123,21 @@ void ChannelMarker::setUDPAddress(const QString& udpAddress)
m_udpAddress = udpAddress; m_udpAddress = udpAddress;
m_displayAddressReceive = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort())); m_displayAddressReceive = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort()));
m_displayAddressReceive = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPReceivePort())); m_displayAddressReceive = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPReceivePort()));
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setUDPReceivePort(quint16 port) void ChannelMarker::setUDPReceivePort(quint16 port)
{ {
m_udpReceivePort = port; m_udpReceivePort = port;
m_displayAddressReceive = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPReceivePort())); m_displayAddressReceive = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPReceivePort()));
emit changed(); emit changedByAPI();
} }
void ChannelMarker::setUDPSendPort(quint16 port) void ChannelMarker::setUDPSendPort(quint16 port)
{ {
m_udpSendPort = port; m_udpSendPort = port;
m_displayAddressSend = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort())); m_displayAddressSend = QString(tr("%1:%2").arg(getUDPAddress()).arg(getUDPSendPort()));
emit changed(); emit changedByAPI();
} }
void ChannelMarker::resetToDefaults() void ChannelMarker::resetToDefaults()

View File

@ -32,10 +32,13 @@ public:
ChannelMarker(QObject* parent = NULL); ChannelMarker(QObject* parent = NULL);
void emitChangedByAPI();
void setTitle(const QString& title); void setTitle(const QString& title);
const QString& getTitle() const { return m_title; } const QString& getTitle() const { return m_title; }
void setCenterFrequency(int centerFrequency); void setCenterFrequency(int centerFrequency);
void setCenterFrequencyByCursor(int centerFrequency);
int getCenterFrequency() const { return m_centerFrequency; } int getCenterFrequency() const { return m_centerFrequency; }
void setBandwidth(int bandwidth); void setBandwidth(int bandwidth);
@ -54,6 +57,7 @@ public:
bool getVisible() const { return m_visible; } bool getVisible() const { return m_visible; }
void setHighlighted(bool highlighted); void setHighlighted(bool highlighted);
void setHighlightedByCursor(bool highlighted);
bool getHighlighted() const { return m_highlighted; } bool getHighlighted() const { return m_highlighted; }
void setColor(const QColor& color); void setColor(const QColor& color);
@ -104,7 +108,9 @@ protected:
void resetToDefaults(); void resetToDefaults();
signals: signals:
void changed(); void changedByAPI();
void changedByCursor();
void highlightedByCursor();
}; };
#endif // INCLUDE_CHANNELMARKER_H #endif // INCLUDE_CHANNELMARKER_H

View File

@ -49,6 +49,7 @@ void BasicChannelSettingsDialog::on_colorBtn_clicked()
void BasicChannelSettingsDialog::accept() void BasicChannelSettingsDialog::accept()
{ {
m_channelMarker->blockSignals(true);
m_channelMarker->setTitle(ui->title->text()); m_channelMarker->setTitle(ui->title->text());
if(m_color.isValid()) { if(m_color.isValid()) {
@ -74,9 +75,9 @@ void BasicChannelSettingsDialog::accept()
udpPort = 9999; udpPort = 9999;
} }
m_channelMarker->setUDPSendPort(udpPort);
m_channelMarker->setFrequencyScaleDisplayType((ChannelMarker::frequencyScaleDisplay_t) ui->fScaleDisplayType->currentIndex()); m_channelMarker->setFrequencyScaleDisplayType((ChannelMarker::frequencyScaleDisplay_t) ui->fScaleDisplayType->currentIndex());
m_channelMarker->blockSignals(false);
m_channelMarker->setUDPSendPort(udpPort); // activate signal on the last setting only
m_hasChanged = true; m_hasChanged = true;
QDialog::accept(); QDialog::accept();

View File

@ -280,7 +280,7 @@ void GLSpectrum::addChannelMarker(ChannelMarker* channelMarker)
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
connect(channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged())); connect(channelMarker, SIGNAL(changedByAPI()), this, SLOT(channelMarkerChanged()));
connect(channelMarker, SIGNAL(destroyed(QObject*)), this, SLOT(channelMarkerDestroyed(QObject*))); connect(channelMarker, SIGNAL(destroyed(QObject*)), this, SLOT(channelMarkerDestroyed(QObject*)));
m_channelMarkerStates.append(new ChannelMarkerState(channelMarker)); m_channelMarkerStates.append(new ChannelMarkerState(channelMarker));
m_changesPending = true; m_changesPending = true;
@ -1476,7 +1476,7 @@ void GLSpectrum::applyChanges()
switch (dv->m_channelMarker->getFrequencyScaleDisplayType()) switch (dv->m_channelMarker->getFrequencyScaleDisplayType())
{ {
case ChannelMarker::FScaleDisplay_freq: case ChannelMarker::FScaleDisplay_freq:
ftext = QString::number((m_centerFrequency + dv->m_channelMarker->getCenterFrequency())/1e6, 'f', 6); // TODO ftext = QString::number((m_centerFrequency + dv->m_channelMarker->getCenterFrequency())/1e6, 'f', 6);
break; break;
case ChannelMarker::FScaleDisplay_title: case ChannelMarker::FScaleDisplay_title:
ftext = dv->m_channelMarker->getTitle(); ftext = dv->m_channelMarker->getTitle();
@ -1597,45 +1597,73 @@ void GLSpectrum::mouseMoveEvent(QMouseEvent* event)
} }
} }
if(m_cursorState == CSSplitterMoving) { if (m_cursorState == CSSplitterMoving)
{
float newShare; float newShare;
if(!m_invertedWaterfall)
if (!m_invertedWaterfall) {
newShare = (float) (event->y() - m_frequencyScaleRect.height()) / (float) height(); newShare = (float) (event->y() - m_frequencyScaleRect.height()) / (float) height();
else newShare = 1.0 - (float)(event->y() + m_frequencyScaleRect.height()) / (float)height(); } else {
if(newShare < 0.1) newShare = 1.0 - (float) (event->y() + m_frequencyScaleRect.height()) / (float) height();
newShare = 0.1f;
else if(newShare > 0.8)
newShare = 0.8f;
m_waterfallShare = newShare;
m_changesPending = true;
update();
return;
} else if(m_cursorState == CSChannelMoving) {
Real freq = m_frequencyScale.getValueFromPos(event->x() - m_leftMarginPixmap.width() - 1) - m_centerFrequency;
if(m_channelMarkerStates[m_cursorChannel]->m_channelMarker->getMovable())
m_channelMarkerStates[m_cursorChannel]->m_channelMarker->setCenterFrequency(freq);
} }
if(m_displayWaterfall || m_displayHistogram || m_displayMaxHold || m_displayCurrent) { if (newShare < 0.1) {
for(int i = 0; i < m_channelMarkerStates.size(); ++i) { newShare = 0.1f;
if(m_channelMarkerStates[i]->m_rect.contains(event->pos())) { } else if (newShare > 0.8) {
if(m_cursorState == CSNormal) { newShare = 0.8f;
}
m_waterfallShare = newShare;
m_changesPending = true;
update();
return;
}
else if (m_cursorState == CSChannelMoving)
{
Real freq = m_frequencyScale.getValueFromPos(event->x() - m_leftMarginPixmap.width() - 1) - m_centerFrequency;
if (m_channelMarkerStates[m_cursorChannel]->m_channelMarker->getMovable())
{
m_channelMarkerStates[m_cursorChannel]->m_channelMarker->setCenterFrequencyByCursor(freq);
channelMarkerChanged();
}
}
if (m_displayWaterfall || m_displayHistogram || m_displayMaxHold || m_displayCurrent)
{
for (int i = 0; i < m_channelMarkerStates.size(); ++i)
{
if (m_channelMarkerStates[i]->m_rect.contains(event->pos()))
{
if (m_cursorState == CSNormal)
{
setCursor(Qt::SizeHorCursor); setCursor(Qt::SizeHorCursor);
m_cursorState = CSChannel; m_cursorState = CSChannel;
m_cursorChannel = i; m_cursorChannel = i;
m_channelMarkerStates[i]->m_channelMarker->setHighlighted(true); m_channelMarkerStates[i]->m_channelMarker->setHighlightedByCursor(true);
return; channelMarkerChanged();
} else if(m_cursorState == CSChannel) {
return; return;
} }
} else if (m_channelMarkerStates[i]->m_channelMarker->getHighlighted()) { else if (m_cursorState == CSChannel)
m_channelMarkerStates[i]->m_channelMarker->setHighlighted(false); {
return;
}
}
else if (m_channelMarkerStates[i]->m_channelMarker->getHighlighted())
{
m_channelMarkerStates[i]->m_channelMarker->setHighlightedByCursor(false);
channelMarkerChanged();
} }
} }
} }
if(m_cursorState == CSChannel) {
if(m_cursorState == CSChannel)
{
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
m_cursorState = CSNormal; m_cursorState = CSNormal;
return; return;
} }
} }
@ -1645,22 +1673,32 @@ void GLSpectrum::mousePressEvent(QMouseEvent* event)
if(event->button() != 1) if(event->button() != 1)
return; return;
if(m_cursorState == CSSplitter) { if(m_cursorState == CSSplitter)
{
grabMouse(); grabMouse();
m_cursorState = CSSplitterMoving; m_cursorState = CSSplitterMoving;
return; return;
} else if(m_cursorState == CSChannel) { }
else if(m_cursorState == CSChannel)
{
grabMouse(); grabMouse();
m_cursorState = CSChannelMoving; m_cursorState = CSChannelMoving;
return; return;
} else if((m_cursorState == CSNormal) && (m_channelMarkerStates.size() == 1)) { }
else if((m_cursorState == CSNormal) && (m_channelMarkerStates.size() == 1))
{
grabMouse(); grabMouse();
setCursor(Qt::SizeHorCursor); setCursor(Qt::SizeHorCursor);
m_cursorState = CSChannelMoving; m_cursorState = CSChannelMoving;
m_cursorChannel = 0; m_cursorChannel = 0;
Real freq = m_frequencyScale.getValueFromPos(event->x() - m_leftMarginPixmap.width() - 1) - m_centerFrequency; Real freq = m_frequencyScale.getValueFromPos(event->x() - m_leftMarginPixmap.width() - 1) - m_centerFrequency;
if(m_channelMarkerStates[m_cursorChannel]->m_channelMarker->getMovable()) if(m_channelMarkerStates[m_cursorChannel]->m_channelMarker->getMovable())
m_channelMarkerStates[m_cursorChannel]->m_channelMarker->setCenterFrequency(freq); {
m_channelMarkerStates[m_cursorChannel]->m_channelMarker->setCenterFrequencyByCursor(freq);
channelMarkerChanged();
}
return; return;
} }
} }