From d9f88d963264248c230482993e030aa385f7c0cb Mon Sep 17 00:00:00 2001 From: "Edson W. R. Pereira" Date: Tue, 16 Jul 2013 21:16:57 +0000 Subject: [PATCH] Added new meter widget. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3489 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- mainwindow.cpp | 22 ++++-- mainwindow.h | 4 +- mainwindow.ui | 199 ++++++++++++++++++++---------------------------- meterwidget.cpp | 51 +++++++++++++ meterwidget.h | 30 ++++++++ signalmeter.cpp | 53 +++++++++++++ signalmeter.h | 32 ++++++++ wsjtx.pro | 8 +- 8 files changed, 271 insertions(+), 128 deletions(-) create mode 100644 meterwidget.cpp create mode 100644 meterwidget.h create mode 100644 signalmeter.cpp create mode 100644 signalmeter.h diff --git a/mainwindow.cpp b/mainwindow.cpp index 0f2c79a6a..a50b5e9e5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -191,8 +191,14 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : m_CATerror=false; decodeBusy(false); - ui->xThermo->setMaximumWidth(12); - ui->xThermo->setTextVisible(false); + //ui->xThermo->setMaximumWidth(12); + //ui->xThermo->setTextVisible(false); + + signalMeter = new SignalMeter(ui->meterFrame); + signalMeter->resize(50, 160); + + qDebug() << signalMeter->size(); + ui->labAz->setStyleSheet("border: 0px;"); ui->labDist->setStyleSheet("border: 0px;"); @@ -639,7 +645,8 @@ void MainWindow::dataSink(int k) m_pctZap=nzap*100.0/m_nsps; t.sprintf(" Rx noise: %5.1f ",px); lab2->setText(t); - ui->xThermo->setValue((double)px); //Update thermometer + //ui->xThermo->setValue((double)px); //Update thermometer + signalMeter->setValue(px); // Update thermometer if(m_monitoring || m_diskData) { g_pWideGraph->dataSink2(s,df3,ihsym,m_diskData); } @@ -1729,7 +1736,8 @@ void MainWindow::guiUpdate() m_msgSent0=t; } - ui->xThermo->setValue(0.0); //Set Thermo to zero + //ui->xThermo->setValue(0.0); //Set Thermo to zero + signalMeter->setValue(0); m_monitoring=false; soundInThread.setMonitoring(false); btxok=true; @@ -1802,7 +1810,8 @@ void MainWindow::guiUpdate() t.time().toString() + " "; ui->labUTC->setText(utc); if(!m_monitoring and !m_diskData) { - ui->xThermo->setValue(0.0); + //ui->xThermo->setValue(0.0); + signalMeter->setValue(0); } if(m_catEnabled and m_poll>0 and (nsec%m_poll)==0 and !m_decoderBusy) { @@ -1868,7 +1877,8 @@ void MainWindow::startTx2() soundOutThread.setTxSNR(snr); soundOutThread.m_modeTx=m_modeTx; soundOutThread.start(QThread::HighestPriority); - ui->xThermo->setValue(0.0); //Set Thermo to zero + //ui->xThermo->setValue(0.0); //Set Thermo to zero + signalMeter->setValue(0); m_monitoring=false; soundInThread.setMonitoring(false); btxok=true; diff --git a/mainwindow.h b/mainwindow.h index 438834a15..04ddcaf0d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -12,6 +12,7 @@ #include "commons.h" #include "psk_reporter.h" #include "rigclass.h" +#include "signalmeter.h" #ifdef WIN32 #include "PSKReporter.h" @@ -330,10 +331,9 @@ private: SoundInThread soundInThread; //Instantiate the audio threads SoundOutThread soundOutThread; - QSharedMemory *mem_jt9; - PSK_Reporter *psk_Reporter; + SignalMeter *signalMeter; //---------------------------------------------------- private functions void readSettings(); diff --git a/mainwindow.ui b/mainwindow.ui index 3856aa953..60abbeff5 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -84,7 +84,7 @@ <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Courier New'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> false @@ -526,7 +526,57 @@ p, li { white-space: pre-wrap; } - + + + + + 50 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 23 + + + + true + + + + + + Qt::AlignCenter + + + 4 + + + + Select operating band @@ -616,7 +666,7 @@ p, li { white-space: pre-wrap; } - + @@ -632,7 +682,7 @@ p, li { white-space: pre-wrap; } - + @@ -670,7 +720,7 @@ p, li { white-space: pre-wrap; } - + @@ -692,7 +742,7 @@ p, li { white-space: pre-wrap; } - + @@ -707,7 +757,7 @@ p, li { white-space: pre-wrap; } - QFrame::StyledPanel + QFrame::NoFrame QFrame::Plain @@ -743,7 +793,7 @@ p, li { white-space: pre-wrap; } QTabWidget::Triangular - 1 + 0 @@ -819,7 +869,7 @@ p, li { white-space: pre-wrap; } - buttonGroup + buttonGroup @@ -853,7 +903,7 @@ p, li { white-space: pre-wrap; } true - buttonGroup + buttonGroup @@ -884,7 +934,7 @@ p, li { white-space: pre-wrap; } - buttonGroup + buttonGroup @@ -1052,7 +1102,7 @@ p, li { white-space: pre-wrap; } - buttonGroup + buttonGroup @@ -1200,7 +1250,7 @@ p, li { white-space: pre-wrap; } - buttonGroup + buttonGroup @@ -1231,7 +1281,7 @@ p, li { white-space: pre-wrap; } - buttonGroup + buttonGroup @@ -1493,14 +1543,14 @@ p, li { white-space: pre-wrap; } - + +2 kHz - + @@ -1592,7 +1642,7 @@ p, li { white-space: pre-wrap; } - + @@ -1690,7 +1740,7 @@ p, li { white-space: pre-wrap; } - + false @@ -1701,40 +1751,6 @@ p, li { white-space: pre-wrap; } - - - - 0 - 0 - - - - - 0 - 160 - - - - - 15 - 160 - - - - 60 - - - 0 - - - false - - - Qt::Vertical - - - - @@ -1768,7 +1784,7 @@ p, li { white-space: pre-wrap; } - + @@ -1799,7 +1815,7 @@ p, li { white-space: pre-wrap; } - + @@ -1830,7 +1846,7 @@ p, li { white-space: pre-wrap; } - + @@ -1871,40 +1887,6 @@ p, li { white-space: pre-wrap; } - - - - 0 - 0 - - - - - 0 - 23 - - - - - 16777215 - 23 - - - - true - - - - - - Qt::AlignCenter - - - 4 - - - - @@ -1932,7 +1914,7 @@ p, li { white-space: pre-wrap; } - + Qt::Horizontal @@ -1948,7 +1930,7 @@ p, li { white-space: pre-wrap; } - + @@ -1979,7 +1961,7 @@ p, li { white-space: pre-wrap; } - + Qt::Horizontal @@ -1995,26 +1977,7 @@ p, li { white-space: pre-wrap; } - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - dB - - - - + @@ -2036,7 +1999,7 @@ p, li { white-space: pre-wrap; } - + @@ -2058,7 +2021,7 @@ p, li { white-space: pre-wrap; } - + 5 @@ -2112,7 +2075,7 @@ p, li { white-space: pre-wrap; } - + @@ -2157,14 +2120,14 @@ p, li { white-space: pre-wrap; } - + Lock Tx=Rx - + 5 @@ -2228,7 +2191,7 @@ p, li { white-space: pre-wrap; } 0 0 760 - 21 + 25 diff --git a/meterwidget.cpp b/meterwidget.cpp new file mode 100644 index 000000000..b48aa65d0 --- /dev/null +++ b/meterwidget.cpp @@ -0,0 +1,51 @@ +// Simple bargraph meter +// Implemented by Edson Pereira PY2SDR + +#include "meterwidget.h" + +MeterWidget::MeterWidget(QWidget *parent) : + QWidget(parent), + m_signal(0) +{ + for ( int i = 0; i < 10; i++ ) { + signalQueue.enqueue(0); + } +} + +void MeterWidget::setValue(int value) +{ + m_signal = value; + signalQueue.enqueue(value); + signalQueue.dequeue(); + + // Get signal peak + int tmp = 0; + for (int i = 0; i < signalQueue.size(); ++i) { + if (signalQueue.at(i) > tmp) + tmp = signalQueue.at(i); + } + m_sigPeak = tmp; + + update(); +} + +void MeterWidget::paintEvent( QPaintEvent * ) +{ + int pos; + QPainter p; + + p.begin(this); + + // Sanitize + m_signal = m_signal < 0 ? 0 : m_signal; + m_signal = m_signal > 60 ? 60 : m_signal; + + pos = m_signal * 2; + QRect r(0, height() - pos, width(), pos ); + p.fillRect(r, QColor( 255, 150, 0 )); + + // Draw peak hold indicator + p.setPen(Qt::black); + pos = m_sigPeak * 2; + p.drawLine(0, height() - pos, 10, height() - pos); +} diff --git a/meterwidget.h b/meterwidget.h new file mode 100644 index 000000000..7b51efb65 --- /dev/null +++ b/meterwidget.h @@ -0,0 +1,30 @@ +#ifndef METERWIDGET_H +#define METERWIDGET_H + +#include +#include +#include + +class MeterWidget : public QWidget +{ + Q_OBJECT +public: + explicit MeterWidget(QWidget *parent = 0); + +signals: + +public slots: + void setValue(int value); + +private: + QQueue signalQueue; + + int m_signal; + int m_sigPeak; + +protected: + void paintEvent( QPaintEvent * ); + +}; + +#endif // METERWIDGET_H diff --git a/signalmeter.cpp b/signalmeter.cpp new file mode 100644 index 000000000..537b900f8 --- /dev/null +++ b/signalmeter.cpp @@ -0,0 +1,53 @@ +// Simple bargraph dB meter +// Implemented by Edson Pereira PY2SDR +// +// Limits and geometry are hardcded for now. + +#include "signalmeter.h" + +SignalMeter::SignalMeter(QWidget *parent) : + QWidget(parent) +{ + resize(parent->size()); + + m_meter = new MeterWidget(this); + m_meter->setGeometry(10, 10, 10, 120); + + m_label = new QLabel(this); + m_label->setGeometry(10, 135, 20, 20); + + QLabel *dbLabel = new QLabel(this); + dbLabel->setText("dB"); + dbLabel->setGeometry(30, 135, 20, 20); +} + +SignalMeter::~SignalMeter() +{ + +} + +void SignalMeter::paintEvent( QPaintEvent * ) +{ + QPainter p; + p.begin(this); + p.drawLine(22, 10, 22, 130); + + for ( int i = 0; i <= 60; i += 10 ) { + p.drawLine(22, i*2 + 10, 25, i*2 + 10); + } + + for ( int i = 10; i < 60; i += 10 ) { + p.drawText(30, i*2 + 15, QString::number(60 - i)); + } +} + +void SignalMeter::setValue(int value) +{ + m_meter->setValue(value); + m_label->setText(QString::number(value)); +} + +void SignalMeter::resizeEvent(QResizeEvent *s) +{ + resize(s->size()); +} diff --git a/signalmeter.h b/signalmeter.h new file mode 100644 index 000000000..ea1aa6295 --- /dev/null +++ b/signalmeter.h @@ -0,0 +1,32 @@ +#ifndef SIGNALMETER_H +#define SIGNALMETER_H + +#include +#include +#include + +class SignalMeter : public QWidget +{ + Q_OBJECT + +public: + explicit SignalMeter(QWidget *parent = 0); + ~SignalMeter(); + +public slots: + void setValue(int value); + +private: + MeterWidget *m_meter; + + QLabel *m_label; + + int m_signal; + int m_sigPeak; + +protected: + void paintEvent( QPaintEvent * ); + void resizeEvent(QResizeEvent *s); +}; + +#endif // SIGNALMETER_H diff --git a/wsjtx.pro b/wsjtx.pro index 6e4272e1c..92270a544 100644 --- a/wsjtx.pro +++ b/wsjtx.pro @@ -36,7 +36,9 @@ QMAKE_EXTRA_COMPILERS += gfortran SOURCES += main.cpp mainwindow.cpp plotter.cpp about.cpp \ soundin.cpp soundout.cpp devsetup.cpp widegraph.cpp \ getfile.cpp displaytext.cpp getdev.cpp logqso.cpp \ - psk_reporter.cpp rigclass.cpp + psk_reporter.cpp rigclass.cpp \ + signalmeter.cpp \ + meterwidget.cpp win32 { SOURCES += killbyname.cpp @@ -45,7 +47,9 @@ SOURCES += killbyname.cpp HEADERS += mainwindow.h plotter.h soundin.h soundout.h \ about.h devsetup.h widegraph.h getfile.h \ commons.h sleep.h displaytext.h logqso.h \ - psk_reporter.h rigclass.h + psk_reporter.h rigclass.h \ + signalmeter.h \ + meterwidget.h # (Is the following really needed???) #DEFINES += __cplusplus