From 01eed29a6febec1e433149544018485845da3b03 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 24 Aug 2017 02:05:48 +0200 Subject: [PATCH] Implemented new basic channel settings dialog instead of widget inside rollup --- CMakeLists.txt | 3 + plugins/channelrx/demoddsd/dsddemodgui.cpp | 29 ++-- plugins/channelrx/demoddsd/dsddemodgui.h | 6 +- plugins/channeltx/udpsink/udpsinkgui.cpp | 25 +-- plugins/channeltx/udpsink/udpsinkgui.h | 5 +- sdrbase/gui/basicchannelsettingsdialog.cpp | 68 ++++++++ sdrbase/gui/basicchannelsettingsdialog.h | 32 ++++ sdrbase/gui/basicchannelsettingsdialog.ui | 172 +++++++++++++++++++++ sdrbase/gui/rollupwidget.cpp | 35 +++-- sdrbase/gui/rollupwidget.h | 2 - 10 files changed, 310 insertions(+), 67 deletions(-) create mode 100644 sdrbase/gui/basicchannelsettingsdialog.cpp create mode 100644 sdrbase/gui/basicchannelsettingsdialog.h create mode 100644 sdrbase/gui/basicchannelsettingsdialog.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index c2eccd23f..aefae43f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,6 +140,7 @@ set(sdrbase_SOURCES sdrbase/gui/aboutdialog.cpp sdrbase/gui/addpresetdialog.cpp sdrbase/gui/basicchannelsettingswidget.cpp + sdrbase/gui/basicchannelsettingsdialog.cpp sdrbase/gui/buttonswitch.cpp sdrbase/gui/channelwindow.cpp sdrbase/gui/clickablelabel.cpp @@ -261,6 +262,7 @@ set(sdrbase_HEADERS sdrbase/gui/aboutdialog.h sdrbase/gui/addpresetdialog.h sdrbase/gui/basicchannelsettingswidget.h + sdrbase/gui/basicchannelsettingsdialog.h sdrbase/gui/buttonswitch.h sdrbase/gui/channelwindow.h sdrbase/gui/colormapper.h @@ -329,6 +331,7 @@ set(sdrbase_FORMS sdrbase/gui/aboutdialog.ui sdrbase/gui/addpresetdialog.ui sdrbase/gui/basicchannelsettingswidget.ui + sdrbase/gui/basicchannelsettingsdialog.ui sdrbase/gui/cwkeyergui.ui sdrbase/gui/glscopegui.ui sdrbase/gui/glscopenggui.ui diff --git a/plugins/channelrx/demoddsd/dsddemodgui.cpp b/plugins/channelrx/demoddsd/dsddemodgui.cpp index 42429f247..6f2d9a10e 100644 --- a/plugins/channelrx/demoddsd/dsddemodgui.cpp +++ b/plugins/channelrx/demoddsd/dsddemodgui.cpp @@ -30,7 +30,7 @@ #include "plugin/pluginapi.h" #include "util/simpleserializer.h" #include "util/db.h" -#include "gui/basicchannelsettingswidget.h" +#include "gui/basicchannelsettingsdialog.h" #include "dsp/dspengine.h" #include "mainwindow.h" @@ -289,21 +289,12 @@ void DSDDemodGUI::onWidgetRolled(QWidget* widget __attribute__((unused)), bool r */ } -void DSDDemodGUI::onMenuDoubleClicked() +void DSDDemodGUI::onMenuDialogCalled(const QPoint &p) { - if (!m_basicSettingsShown) - { - m_basicSettingsShown = true; - m_bcsw = new BasicChannelSettingsWidget(&m_channelMarker, this); - m_bcsw->show(); - } - else - { - m_basicSettingsShown = false; - m_bcsw->hide(); - delete m_bcsw; - m_bcsw = 0; - } + //qDebug("DSDDemodGUI::onMenuDialogCalled: x: %d y: %d", p.x(), p.y()); + BasicChannelSettingsDialog dialog(&m_channelMarker, this); + dialog.move(p); + dialog.exec(); } DSDDemodGUI::DSDDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent) : @@ -312,7 +303,6 @@ DSDDemodGUI::DSDDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg m_pluginAPI(pluginAPI), m_deviceAPI(deviceAPI), m_channelMarker(this), - m_basicSettingsShown(false), m_doApplySettings(true), m_signalFormat(signalFormatNone), m_enableCosineFiltering(false), @@ -321,14 +311,13 @@ DSDDemodGUI::DSDDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg m_slot2On(false), m_tdmaStereo(false), m_squelchOpen(false), - m_tickCount(0), - m_bcsw(0) + m_tickCount(0) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); - connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); m_scopeVis = new ScopeVis(ui->glScope); m_dsdDemod = new DSDDemod(m_scopeVis); @@ -353,6 +342,7 @@ DSDDemodGUI::DSDDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg m_deviceAPI->addThreadedSink(m_threadedChannelizer); //m_channelMarker = new ChannelMarker(this); + m_channelMarker.setTitle(windowTitle()); m_channelMarker.setColor(Qt::cyan); m_channelMarker.setBandwidth(10000); m_channelMarker.setCenterFrequency(0); @@ -372,7 +362,6 @@ DSDDemodGUI::DSDDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg DSDDemodGUI::~DSDDemodGUI() { - if (m_bcsw) delete m_bcsw; m_deviceAPI->removeChannelInstance(this); m_deviceAPI->removeThreadedSink(m_threadedChannelizer); delete m_threadedChannelizer; diff --git a/plugins/channelrx/demoddsd/dsddemodgui.h b/plugins/channelrx/demoddsd/dsddemodgui.h index 65eafb3f5..2edcd40fd 100644 --- a/plugins/channelrx/demoddsd/dsddemodgui.h +++ b/plugins/channelrx/demoddsd/dsddemodgui.h @@ -28,7 +28,6 @@ class PluginAPI; class DeviceSourceAPI; -class BasicChannelSettingsWidget; class ThreadedBasebandSampleSink; class DownChannelizer; @@ -78,7 +77,7 @@ private slots: void on_audioMute_toggled(bool checked); void on_symbolPLLLock_toggled(bool checked); void onWidgetRolled(QWidget* widget, bool rollDown); - void onMenuDoubleClicked(); + void onMenuDialogCalled(const QPoint& p); void tick(); private: @@ -95,7 +94,6 @@ private: PluginAPI* m_pluginAPI; DeviceSourceAPI* m_deviceAPI; ChannelMarker m_channelMarker; - bool m_basicSettingsShown; bool m_doApplySettings; char m_formatStatusText[82+1]; //!< Fixed signal format dependent status text SignalFormat m_signalFormat; @@ -117,8 +115,6 @@ private: float m_myLatitude; float m_myLongitude; - BasicChannelSettingsWidget *m_bcsw; - explicit DSDDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent = NULL); virtual ~DSDDemodGUI(); diff --git a/plugins/channeltx/udpsink/udpsinkgui.cpp b/plugins/channeltx/udpsink/udpsinkgui.cpp index 84fe9aa79..881362b2f 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.cpp +++ b/plugins/channeltx/udpsink/udpsinkgui.cpp @@ -21,7 +21,7 @@ #include "dsp/dspengine.h" #include "util/simpleserializer.h" #include "util/db.h" -#include "gui/basicchannelsettingswidget.h" +#include "gui/basicchannelsettingsdialog.h" #include "plugin/pluginapi.h" #include "mainwindow.h" @@ -226,13 +226,11 @@ UDPSinkGUI::UDPSinkGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* m_inPowerAvg(4, 1e-10), m_tickCount(0), m_channelMarker(this), - m_basicSettingsShown(false), - m_bcsw(0), m_doApplySettings(true) { ui->setupUi(this); connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); - connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); + connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); setAttribute(Qt::WA_DeleteOnClose, true); m_spectrumVis = new SpectrumVis(ui->glSpectrum); @@ -279,7 +277,6 @@ UDPSinkGUI::UDPSinkGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* UDPSinkGUI::~UDPSinkGUI() { - if (m_bcsw) delete m_bcsw; m_deviceAPI->removeChannelInstance(this); m_deviceAPI->removeThreadedSource(m_threadedChannelizer); delete m_threadedChannelizer; @@ -543,21 +540,11 @@ void UDPSinkGUI::onWidgetRolled(QWidget* widget, bool rollDown) } } -void UDPSinkGUI::onMenuDoubleClicked() +void UDPSinkGUI::onMenuDialogCalled(const QPoint &p) { - if (!m_basicSettingsShown) - { - m_basicSettingsShown = true; - m_bcsw = new BasicChannelSettingsWidget(&m_channelMarker, this); - m_bcsw->show(); - } - else - { - m_basicSettingsShown = false; - m_bcsw->hide(); - delete m_bcsw; - m_bcsw = 0; - } + BasicChannelSettingsDialog dialog(&m_channelMarker, this); + dialog.move(p); + dialog.exec(); } void UDPSinkGUI::leaveEvent(QEvent*) diff --git a/plugins/channeltx/udpsink/udpsinkgui.h b/plugins/channeltx/udpsink/udpsinkgui.h index 88541990f..28169d27f 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.h +++ b/plugins/channeltx/udpsink/udpsinkgui.h @@ -31,7 +31,6 @@ class ThreadedBasebandSampleSource; class UpChannelizer; class UDPSink; class SpectrumVis; -class BasicChannelSettingsWidget; namespace Ui { class UDPSinkGUI; @@ -68,7 +67,7 @@ private slots: void on_amModPercent_textEdited(const QString& arg1); void on_applyBtn_clicked(); void onWidgetRolled(QWidget* widget, bool rollDown); - void onMenuDoubleClicked(); + void onMenuDialogCalled(const QPoint& p); void on_gain_valueChanged(int value); void on_squelch_valueChanged(int value); void on_squelchGate_valueChanged(int value); @@ -96,8 +95,6 @@ private: int m_fmDeviation; QString m_udpAddress; int m_udpPort; - bool m_basicSettingsShown; - BasicChannelSettingsWidget *m_bcsw; bool m_doApplySettings; explicit UDPSinkGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* parent = NULL); diff --git a/sdrbase/gui/basicchannelsettingsdialog.cpp b/sdrbase/gui/basicchannelsettingsdialog.cpp new file mode 100644 index 000000000..c44573abd --- /dev/null +++ b/sdrbase/gui/basicchannelsettingsdialog.cpp @@ -0,0 +1,68 @@ +#include + +#include "dsp/channelmarker.h" + +#include "basicchannelsettingsdialog.h" +#include "ui_basicchannelsettingsdialog.h" + +BasicChannelSettingsDialog::BasicChannelSettingsDialog(ChannelMarker* marker, QWidget *parent) : + QDialog(parent), + ui(new Ui::BasicChannelSettingsDialog), + m_channelMarker(marker) +{ + ui->setupUi(this); + ui->title->setText(m_channelMarker->getTitle()); + m_color = m_channelMarker->getColor(); + ui->udpAddress->setText(m_channelMarker->getUDPAddress()); + ui->udpPort->setText(QString("%1").arg(m_channelMarker->getUDPPort())); + paintColor(); +} + +BasicChannelSettingsDialog::~BasicChannelSettingsDialog() +{ + delete ui; +} + +void BasicChannelSettingsDialog::paintColor() +{ + QPixmap pm(24, 24); + pm.fill(m_color); + ui->colorBtn->setIcon(pm); + ui->colorText->setText(tr("#%1%2%3") + .arg(m_color.red(), 2, 16, QChar('0')) + .arg(m_color.green(), 2, 16, QChar('0')) + .arg(m_color.blue(), 2, 16, QChar('0'))); +} + +void BasicChannelSettingsDialog::on_colorBtn_clicked() +{ + QColor c = m_color; + c = QColorDialog::getColor(c, this, tr("Select Color for Channel")); + if(c.isValid()) { + m_color = c; + paintColor(); + } +} + +void BasicChannelSettingsDialog::accept() +{ + m_channelMarker->setTitle(ui->title->text()); + + if(m_color.isValid()) { + m_channelMarker->setColor(m_color); + } + + m_channelMarker->setUDPAddress(ui->udpAddress->text()); + + bool ok; + int udpPort = ui->udpPort->text().toInt(&ok); + + if((!ok) || (udpPort < 1024) || (udpPort > 65535)) + { + udpPort = 9999; + } + + m_channelMarker->setUDPPort(udpPort); + + QDialog::accept(); +} diff --git a/sdrbase/gui/basicchannelsettingsdialog.h b/sdrbase/gui/basicchannelsettingsdialog.h new file mode 100644 index 000000000..a0a8b71be --- /dev/null +++ b/sdrbase/gui/basicchannelsettingsdialog.h @@ -0,0 +1,32 @@ +#ifndef BASICCHANNELSETTINGSDIALOG_H +#define BASICCHANNELSETTINGSDIALOG_H + +#include + +namespace Ui { + class BasicChannelSettingsDialog; +} + +class ChannelMarker; + +class BasicChannelSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit BasicChannelSettingsDialog(ChannelMarker* marker, QWidget *parent = 0); + ~BasicChannelSettingsDialog(); + +private slots: + void on_colorBtn_clicked(); + void accept(); + +private: + Ui::BasicChannelSettingsDialog *ui; + ChannelMarker* m_channelMarker; + QColor m_color; + + void paintColor(); +}; + +#endif // BASICCHANNELSETTINGSDIALOG_H diff --git a/sdrbase/gui/basicchannelsettingsdialog.ui b/sdrbase/gui/basicchannelsettingsdialog.ui new file mode 100644 index 000000000..2384acc91 --- /dev/null +++ b/sdrbase/gui/basicchannelsettingsdialog.ui @@ -0,0 +1,172 @@ + + + BasicChannelSettingsDialog + + + + 0 + 0 + 400 + 131 + + + + Basic channel settings + + + + + + + + + 0 + 0 + + + + Title + + + + + + + Channel marker title + + + + + + + + + + + + 0 + 0 + + + + Color + + + + + + + Channel marker color + + + + + + + + + + #ff0000 + + + + + + + + + + + Addr + + + + + + + UDP address + + + 000.000.000.000 + + + 127.0.0.1 + + + + + + + Port + + + + + + + + 60 + 16777215 + + + + UDP port + + + 00000 + + + 9999 + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + BasicChannelSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + BasicChannelSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/sdrbase/gui/rollupwidget.cpp b/sdrbase/gui/rollupwidget.cpp index dafe315ea..0181594a1 100644 --- a/sdrbase/gui/rollupwidget.cpp +++ b/sdrbase/gui/rollupwidget.cpp @@ -100,23 +100,33 @@ int RollupWidget::arrangeRollups() QFontMetrics fm(font()); int pos = fm.height() + 4; - for(int i = 0; i < children().count(); ++i) { + for(int i = 0; i < children().count(); ++i) + { QWidget* r = qobject_cast(children()[i]); - if(r != NULL) { + if(r != NULL) + { pos += fm.height() + 2; - if(!r->isHidden()) { + + if(!r->isHidden() && (r->windowTitle() != "Basic channel settings")) + { r->move(2, pos + 3); int h = 0; - if(r->hasHeightForWidth()) + + if(r->hasHeightForWidth()) { h = r->heightForWidth(width() - 4); - else h = r->sizeHint().height(); + } else { + h = r->sizeHint().height(); + } + r->resize(width() - 4, h); pos += r->height() + 5; } } } + setMinimumHeight(pos); setMaximumHeight(pos); + return pos; } @@ -205,6 +215,8 @@ void RollupWidget::paintEvent(QPaintEvent*) int RollupWidget::paintRollup(QWidget* rollup, int pos, QPainter* p, bool last, const QColor& frame) { + if (rollup->windowTitle() == "Basic channel settings") return 0; + QFontMetrics fm(font()); int height = 1; @@ -270,7 +282,7 @@ void RollupWidget::mousePressEvent(QMouseEvent* event) // menu box left if(QRectF(3.5, 3.5, fm.ascent(), fm.ascent()).contains(event->pos())) { - emit customContextMenuRequested(event->pos()); + emit customContextMenuRequested(event->globalPos()); return; } @@ -305,17 +317,6 @@ void RollupWidget::mousePressEvent(QMouseEvent* event) } } -void RollupWidget::mouseDoubleClickEvent(QMouseEvent* event) -{ - QFontMetrics fm(font()); - - // menu box left - if(QRectF(3.5, 3.5, fm.ascent(), fm.ascent()).contains(event->pos())) { - emit menuDoubleClickEvent(); - return; - } -} - bool RollupWidget::event(QEvent* event) { if(event->type() == QEvent::ChildAdded) { diff --git a/sdrbase/gui/rollupwidget.h b/sdrbase/gui/rollupwidget.h index f695f395c..cfe657921 100644 --- a/sdrbase/gui/rollupwidget.h +++ b/sdrbase/gui/rollupwidget.h @@ -17,7 +17,6 @@ public: signals: void widgetRolled(QWidget* widget, bool rollDown); - void menuDoubleClickEvent(); protected: enum { @@ -33,7 +32,6 @@ protected: void resizeEvent(QResizeEvent* size); void mousePressEvent(QMouseEvent* event); - void mouseDoubleClickEvent(QMouseEvent* event); bool event(QEvent* event); bool eventFilter(QObject* object, QEvent* event);