diff options
| author | Iain R. Learmonth <irl@debian.org> | 2015-10-18 18:51:00 +0100 |
|---|---|---|
| committer | Iain R. Learmonth <irl@debian.org> | 2015-10-18 18:51:00 +0100 |
| commit | d63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch) | |
| tree | b9c1f6245147a310aac3762630bad389bbb57335 /widegraph.cpp | |
| parent | c720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff) | |
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'widegraph.cpp')
| -rw-r--r-- | widegraph.cpp | 269 |
1 files changed, 174 insertions, 95 deletions
diff --git a/widegraph.cpp b/widegraph.cpp index 3efa1f29..7271eee5 100644 --- a/widegraph.cpp +++ b/widegraph.cpp @@ -1,19 +1,37 @@ #include "widegraph.h" + +#include <QApplication> +#include <QSettings> + #include "ui_widegraph.h" #include "commons.h" +#include "Configuration.hpp" + +#include "moc_widegraph.cpp" + +#define MAX_SCREENSIZE 2048 + +namespace +{ + auto user_defined = QObject::tr ("User Defined"); +} -WideGraph::WideGraph(QWidget *parent) : +WideGraph::WideGraph(QSettings * settings, QWidget *parent) : QDialog(parent), - ui(new Ui::WideGraph) + ui(new Ui::WideGraph), + m_settings (settings), + m_palettes_path {":/Palettes"} { ui->setupUi(this); - this->setWindowFlags(Qt::Dialog); - this->installEventFilter(parent); //Installing the filter + + setWindowTitle (QApplication::applicationName () + " - " + tr ("Wide Graph")); + setWindowFlags (Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint); + setMaximumWidth (MAX_SCREENSIZE); + setMaximumHeight (880); + ui->widePlot->setCursor(Qt::CrossCursor); - this->setMaximumWidth(2048); - this->setMaximumHeight(880); ui->widePlot->setMaximumHeight(800); - ui->widePlot->m_bCurrent=false; + ui->widePlot->setCurrent(false); connect(ui->widePlot, SIGNAL(freezeDecode1(int)),this, SLOT(wideFreezeDecode(int))); @@ -21,68 +39,99 @@ WideGraph::WideGraph(QWidget *parent) : connect(ui->widePlot, SIGNAL(setFreq1(int,int)),this, SLOT(setFreq2(int,int))); - m_fMin=3000; - ui->fMinSpinBox->setValue(m_fMin); - //Restore user's settings - QString inifile(QApplication::applicationDirPath()); - inifile += "/wsjtx.ini"; - QSettings settings(inifile, QSettings::IniFormat); - - settings.beginGroup("WideGraph"); - ui->widePlot->setPlotZero(settings.value("PlotZero", 0).toInt()); - ui->widePlot->setPlotGain(settings.value("PlotGain", 0).toInt()); + m_settings->beginGroup("WideGraph"); + restoreGeometry (m_settings->value ("geometry", saveGeometry ()).toByteArray ()); + ui->widePlot->setPlotZero(m_settings->value("PlotZero", 0).toInt()); + ui->widePlot->setPlotGain(m_settings->value("PlotGain", 0).toInt()); ui->zeroSpinBox->setValue(ui->widePlot->getPlotZero()); ui->gainSpinBox->setValue(ui->widePlot->getPlotGain()); - int n = settings.value("FreqSpan",2).toInt(); - int w = settings.value("PlotWidth",1000).toInt(); - ui->widePlot->m_w=w; + int n = m_settings->value("FreqSpan",2).toInt(); + m_bFlatten=m_settings->value("Flatten",true).toBool(); + ui->cbFlatten->setChecked(m_bFlatten); + ui->widePlot->setFlatten(m_bFlatten); + ui->widePlot->setBreadth(m_settings->value("PlotWidth",1000).toInt()); ui->freqSpanSpinBox->setValue(n); ui->widePlot->setNSpan(n); - m_waterfallAvg = settings.value("WaterfallAvg",5).toInt(); + m_waterfallAvg = m_settings->value("WaterfallAvg",5).toInt(); ui->waterfallAvgSpinBox->setValue(m_waterfallAvg); - ui->widePlot->m_bCurrent=settings.value("Current",false).toBool(); - ui->widePlot->m_bCumulative=settings.value("Cumulative",true).toBool(); - if(ui->widePlot->m_bCurrent) ui->spec2dComboBox->setCurrentIndex(0); - if(ui->widePlot->m_bCumulative) ui->spec2dComboBox->setCurrentIndex(1); - int nbpp=settings.value("BinsPerPixel",2).toInt(); + ui->widePlot->setCurrent(m_settings->value("Current",false).toBool()); + ui->widePlot->setCumulative(m_settings->value("Cumulative",true).toBool()); + ui->widePlot->setLinearAvg(m_settings->value("LinearAvg",false).toBool()); + if(ui->widePlot->current()) ui->spec2dComboBox->setCurrentIndex(0); + if(ui->widePlot->cumulative()) ui->spec2dComboBox->setCurrentIndex(1); + if(ui->widePlot->linearAvg()) ui->spec2dComboBox->setCurrentIndex(2); + int nbpp=m_settings->value("BinsPerPixel",2).toInt(); ui->widePlot->setBinsPerPixel(nbpp); - m_slope=settings.value("Slope",0.0).toDouble(); - ui->slopeSpinBox->setValue(m_slope); - settings.endGroup(); + ui->widePlot->setStartFreq(m_settings->value("StartFreq",0).toInt()); + ui->fStartSpinBox->setValue(ui->widePlot->startFreq()); + m_waterfallPalette=m_settings->value("WaterfallPalette","Default").toString(); + m_userPalette = WFPalette {m_settings->value("UserPalette").value<WFPalette::Colours> ()}; + int m_fMin = m_settings->value ("fMin", 2500).toInt (); + ui->fMinSpinBox->setValue (m_fMin); + setRxRange (m_fMin); + m_settings->endGroup(); + + saveSettings (); // update config with defaults + + QStringList allFiles = m_palettes_path.entryList(QDir::NoDotAndDotDot | + QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, + QDir::DirsFirst); + int index=0; + foreach(QString file, allFiles) { + QString t=file.mid(0,file.length()-4); + ui->paletteComboBox->addItem(t); + if(t==m_waterfallPalette) { + ui->paletteComboBox->setCurrentIndex(index); + } + index++; + } + ui->paletteComboBox->addItem (user_defined); + if (user_defined == m_waterfallPalette) + { + ui->paletteComboBox->setCurrentIndex(index); + } + readPalette (); + + // ui->paletteComboBox->lineEdit()->setAlignment(Qt::AlignHCenter); } -WideGraph::~WideGraph() +WideGraph::~WideGraph () { - saveSettings(); - delete ui; } -void WideGraph::saveSettings() +void WideGraph::closeEvent (QCloseEvent * e) { - //Save user's settings - QString inifile(QApplication::applicationDirPath()); - inifile += "/wsjtx.ini"; - QSettings settings(inifile, QSettings::IniFormat); + saveSettings (); + QDialog::closeEvent (e); +} - settings.beginGroup("WideGraph"); - settings.setValue("PlotZero",ui->widePlot->m_plotZero); - settings.setValue("PlotGain",ui->widePlot->m_plotGain); - settings.setValue("PlotWidth",ui->widePlot->plotWidth()); - settings.setValue("FreqSpan",ui->freqSpanSpinBox->value()); - settings.setValue("WaterfallAvg",ui->waterfallAvgSpinBox->value()); - settings.setValue("Current",ui->widePlot->m_bCurrent); - settings.setValue("Cumulative",ui->widePlot->m_bCumulative); - settings.setValue("BinsPerPixel",ui->widePlot->binsPerPixel()); - settings.setValue("Slope",m_slope); - settings.endGroup(); +void WideGraph::saveSettings() +{ + m_settings->beginGroup ("WideGraph"); + m_settings->setValue ("geometry", saveGeometry ()); + m_settings->setValue ("PlotZero", ui->widePlot->getPlotZero()); + m_settings->setValue ("PlotGain", ui->widePlot->getPlotGain()); + m_settings->setValue ("PlotWidth", ui->widePlot->plotWidth ()); + m_settings->setValue ("FreqSpan", ui->freqSpanSpinBox->value ()); + m_settings->setValue ("WaterfallAvg", ui->waterfallAvgSpinBox->value ()); + m_settings->setValue ("Current", ui->widePlot->current()); + m_settings->setValue ("Cumulative", ui->widePlot->cumulative()); + m_settings->setValue ("LinearAvg", ui->widePlot->linearAvg()); + m_settings->setValue ("BinsPerPixel", ui->widePlot->binsPerPixel ()); + m_settings->setValue ("StartFreq", ui->widePlot->startFreq ()); + m_settings->setValue ("WaterfallPalette", m_waterfallPalette); + m_settings->setValue ("UserPalette", QVariant::fromValue (m_userPalette.colours ())); + m_settings->setValue ("Fmin", m_fMin); + m_settings->setValue("Flatten",m_bFlatten); + m_settings->endGroup (); } void WideGraph::dataSink2(float s[], float df3, int ihsym, int ndiskdata) { static float splot[NSMAX]; - static float swide[2048]; + static float swide[MAX_SCREENSIZE]; int nbpp = ui->widePlot->binsPerPixel(); static int n=0; @@ -100,16 +149,13 @@ void WideGraph::dataSink2(float s[], float df3, int ihsym, for (int i=0; i<NSMAX; i++) splot[i] /= n; //Normalize the average n=0; - -// int w=ui->widePlot->plotWidth(); - int i0=-1; //### - int i=i0; + int i=int(ui->widePlot->startFreq()/df3 + 0.5); int jz=5000.0/(nbpp*df3); + if(jz>MAX_SCREENSIZE) jz=MAX_SCREENSIZE; for (int j=0; j<jz; j++) { float sum=0; for (int k=0; k<nbpp; k++) { - i++; - sum += splot[i]; + sum += splot[i++]; } swide[j]=sum; } @@ -123,7 +169,7 @@ void WideGraph::dataSink2(float s[], float df3, int ihsym, } } m_ntr0=ntr; - ui->widePlot->draw(swide,i0); + ui->widePlot->draw(swide); } } @@ -163,15 +209,14 @@ void WideGraph::keyPressEvent(QKeyEvent *e) emit f11f12(n); break; default: - e->ignore(); + QDialog::keyPressEvent (e); } } void WideGraph::setRxFreq(int n) { - m_rxFreq=n; - ui->widePlot->setRxFreq(m_rxFreq,true); - if(m_lockTxFreq) setTxFreq(m_rxFreq); + ui->widePlot->setRxFreq(n); + if(m_lockTxFreq) setTxFreq(n); } int WideGraph::rxFreq() @@ -181,12 +226,12 @@ int WideGraph::rxFreq() int WideGraph::nSpan() { - return ui->widePlot->m_nSpan; + return ui->widePlot->nSpan(); } float WideGraph::fSpan() { - return ui->widePlot->m_fSpan; + return ui->widePlot->fSpan(); } int WideGraph::nStartFreq() @@ -218,18 +263,6 @@ int WideGraph::getFmax() return n; } -void WideGraph::setFmin(int n) -{ - m_fMin = n; - ui->fMinSpinBox->setValue(n); - setRxRange(m_fMin); -} - -void WideGraph::setPalette(QString palette) -{ - ui->widePlot->setPalette(palette); -} - double WideGraph::fGreen() { return ui->widePlot->fGreen(); @@ -267,10 +300,12 @@ void WideGraph::setModeTx(QString modeTx) void WideGraph::on_spec2dComboBox_currentIndexChanged(const QString &arg1) { - ui->widePlot->m_bCurrent=false; - ui->widePlot->m_bCumulative=false; - if(arg1=="Current") ui->widePlot->m_bCurrent=true; - if(arg1=="Cumulative") ui->widePlot->m_bCumulative=true; + ui->widePlot->setCurrent(false); + ui->widePlot->setCumulative(false); + ui->widePlot->setLinearAvg(false); + if(arg1=="Current") ui->widePlot->setCurrent(true); + if(arg1=="Cumulative") ui->widePlot->setCumulative(true); + if(arg1=="Linear Avg") ui->widePlot->setLinearAvg(true); } void WideGraph::on_fMinSpinBox_valueChanged(int n) @@ -279,36 +314,80 @@ void WideGraph::on_fMinSpinBox_valueChanged(int n) setRxRange(m_fMin); } -void WideGraph::on_slopeSpinBox_valueChanged(double d) +void WideGraph::setLockTxFreq(bool b) { - m_slope=d; + m_lockTxFreq=b; + ui->widePlot->setLockTxFreq(b); } -void WideGraph::setSlope(double d) +void WideGraph::setFreq2(int rxFreq, int txFreq) { - m_slope=d; - ui->slopeSpinBox->setValue(d); + emit setFreq3(rxFreq,txFreq); } -void WideGraph::setLockTxFreq(bool b) +void WideGraph::setDialFreq(double d) { - m_lockTxFreq=b; - ui->widePlot->m_lockTxFreq=b; + ui->widePlot->setDialFreq(d); } -double WideGraph::getSlope() + +void WideGraph::on_fStartSpinBox_valueChanged(int n) { - return m_slope; + ui->widePlot->setStartFreq(n); } -void WideGraph::setFreq2(int rxFreq, int txFreq) +void WideGraph::readPalette () { - m_rxFreq=rxFreq; - m_txFreq=txFreq; - emit setFreq3(rxFreq,txFreq); + try + { + if (user_defined == m_waterfallPalette) + { + ui->widePlot->setColours (WFPalette {m_userPalette}.interpolate ()); + } + else + { + ui->widePlot->setColours (WFPalette {m_palettes_path.absoluteFilePath (m_waterfallPalette + ".pal")}.interpolate()); + } + } + catch (std::exception const& e) + { + QMessageBox msgBox0; + msgBox0.setText(e.what()); + msgBox0.exec(); + } } -void WideGraph::setDialFreq(double d) +void WideGraph::on_paletteComboBox_activated (QString const& palette) { - m_dialFreq=d; - ui->widePlot->setDialFreq(d); + m_waterfallPalette = palette; + readPalette(); +} + +void WideGraph::on_cbFlatten_toggled(bool b) +{ + m_bFlatten=b; + ui->widePlot->setFlatten(m_bFlatten); +} + +void WideGraph::on_adjust_palette_push_button_clicked (bool) +{ + try + { + if (m_userPalette.design ()) + { + m_waterfallPalette = user_defined; + ui->paletteComboBox->setCurrentText (m_waterfallPalette); + readPalette (); + } + } + catch (std::exception const& e) + { + QMessageBox msgBox0; + msgBox0.setText(e.what()); + msgBox0.exec(); + } +} + +bool WideGraph::flatten() +{ + return m_bFlatten; } |
