Now have gradient fill in 2D spectrum, and 30% height.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@2621 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Joe Taylor 2012-09-30 01:03:18 +00:00
parent 64eeef06d0
commit 6d2e429144
3 changed files with 101 additions and 38 deletions

View File

@ -1,4 +1,4 @@
//---------------------------------------------------------------- MainWindow //--------------------------------------------------------------- MainWindow
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "devsetup.h" #include "devsetup.h"

View File

@ -25,12 +25,14 @@ CPlotter::CPlotter(QWidget *parent) : //CPlotter Constructor
m_WaterfallPixmap = QPixmap(0,0); m_WaterfallPixmap = QPixmap(0,0);
m_2DPixmap = QPixmap(0,0); m_2DPixmap = QPixmap(0,0);
m_ScalePixmap = QPixmap(0,0); m_ScalePixmap = QPixmap(0,0);
m_LowerScalePixmap = QPixmap(0,0); m_OverlayPixmap = QPixmap(0,0);
m_Size = QSize(0,0); m_Size = QSize(0,0);
m_fQSO = 125; m_fQSO = 125;
m_line = 0; m_line = 0;
m_fSample = 12000; m_fSample = 12000;
m_nsps=6912; m_nsps=6912;
m_dBStepSize=10;
m_Percent2DScreen = 30; //percent of screen used for 2D display
} }
CPlotter::~CPlotter() { } // Destructor CPlotter::~CPlotter() { } // Destructor
@ -48,19 +50,23 @@ QSize CPlotter::sizeHint() const
void CPlotter::resizeEvent(QResizeEvent* ) //resizeEvent() void CPlotter::resizeEvent(QResizeEvent* ) //resizeEvent()
{ {
if(!size().isValid()) return; if(!size().isValid()) return;
if( m_Size != size() ) { if( m_Size != size() ) { //if changed, resize pixmaps to new screensize
//if changed, resize pixmaps to new screensize
m_Size = size(); m_Size = size();
int w = m_Size.width(); m_w = m_Size.width();
int h = (m_Size.height()-60)/2; m_h = m_Size.height();
m_WaterfallPixmap = QPixmap(w,h); m_h1 = (100-m_Percent2DScreen)*(m_Size.height()-30)/100;
m_2DPixmap = QPixmap(w,h); m_h2 = (m_Percent2DScreen)*(m_Size.height()-30)/100;
m_2DPixmap = QPixmap(m_Size.width(), m_h2);
m_2DPixmap.fill(Qt::black);
m_WaterfallPixmap = QPixmap(m_Size.width(), m_h1);
m_OverlayPixmap = QPixmap(m_Size.width(), m_h2);
m_OverlayPixmap.fill(Qt::black);
m_WaterfallPixmap.fill(Qt::black); m_WaterfallPixmap.fill(Qt::black);
m_2DPixmap.fill(Qt::black); m_2DPixmap.fill(Qt::black);
m_ScalePixmap = QPixmap(w,30); m_ScalePixmap = QPixmap(m_w,30);
m_LowerScalePixmap = QPixmap(w,30); //(no change on resize...)
m_ScalePixmap.fill(Qt::white); m_ScalePixmap.fill(Qt::white);
m_LowerScalePixmap.fill(Qt::yellow);
} }
DrawOverlay(); DrawOverlay();
} }
@ -72,44 +78,37 @@ void CPlotter::paintEvent(QPaintEvent *) // paintEvent()
if(m_paintEventBusy) return; if(m_paintEventBusy) return;
m_paintEventBusy=true; m_paintEventBusy=true;
QPainter painter(this); QPainter painter(this);
int w = m_Size.width();
int h = (m_Size.height()-60)/2;
painter.drawPixmap(0,0,m_ScalePixmap); painter.drawPixmap(0,0,m_ScalePixmap);
painter.drawPixmap(0,30,m_WaterfallPixmap); painter.drawPixmap(0,30,m_WaterfallPixmap);
painter.drawPixmap(0,h+30,m_ScalePixmap); painter.drawPixmap(0,m_h1,m_2DPixmap);
painter.drawPixmap(0,h+60,m_2DPixmap);
m_paintEventBusy=false; m_paintEventBusy=false;
} }
void CPlotter::draw(float swide[], int i0, float splot[]) //draw() void CPlotter::draw(float swide[], int i0, float splot[]) //draw()
{ {
int i,j,w,h; int j;
float y; float y;
m_i0=i0; m_i0=i0;
w = m_WaterfallPixmap.width();
h = m_WaterfallPixmap.height();
double gain = pow(10.0,0.05*(m_plotGain+7)); double gain = pow(10.0,0.05*(m_plotGain+7));
//move current data down one line //move current data down one line (must do this before attaching a QPainter object)
//(must do this before attaching a QPainter object) m_WaterfallPixmap.scroll(0,1,0,0,m_w,m_h1);
m_WaterfallPixmap.scroll(0,1,0,0,w,h);
QPainter painter1(&m_WaterfallPixmap); QPainter painter1(&m_WaterfallPixmap);
m_2DPixmap = m_OverlayPixmap.copy(0,0,m_w,m_h2);
QPainter painter2D(&m_2DPixmap); QPainter painter2D(&m_2DPixmap);
for(i=0; i<256; i++) { //Zero the histograms for(int i=0; i<256; i++) { //Zero the histograms
m_hist1[i]=0; m_hist1[i]=0;
} }
painter2D.setPen(Qt::green); painter2D.setPen(Qt::green);
QRect tmp(0,0,w,h);
painter2D.fillRect(tmp,Qt::black);
QPoint LineBuf[MAX_SCREENSIZE]; QPoint LineBuf[MAX_SCREENSIZE];
j=0; j=0;
bool strong0=false; bool strong0=false;
bool strong=false; bool strong=false;
for(i=0; i<w; i++) { for(int i=0; i<m_w; i++) {
strong=false; strong=false;
if(swide[i]<0) { if(swide[i]<0) {
strong=true; strong=true;
@ -127,7 +126,7 @@ void CPlotter::draw(float swide[], int i0, float splot[]) //draw()
if (y2<0) y2=0; if (y2<0) y2=0;
if (y2>254) y2=254; if (y2>254) y2=254;
if (swide[i]>1.e29) y2=255; if (swide[i]>1.e29) y2=255;
if(strong != strong0 or i==w-1) { if(strong != strong0 or i==m_w-1) {
painter2D.drawPolyline(LineBuf,j); painter2D.drawPolyline(LineBuf,j);
j=0; j=0;
strong0=strong; strong0=strong;
@ -135,7 +134,7 @@ void CPlotter::draw(float swide[], int i0, float splot[]) //draw()
if(!strong0) painter2D.setPen(Qt::green); if(!strong0) painter2D.setPen(Qt::green);
} }
LineBuf[j].setX(i); LineBuf[j].setX(i);
LineBuf[j].setY(h-y2); LineBuf[j].setY(m_h-y2-320);
j++; j++;
} }
@ -168,12 +167,68 @@ void CPlotter::UTCstr()
void CPlotter::DrawOverlay() //DrawOverlay() void CPlotter::DrawOverlay() //DrawOverlay()
{ {
if(m_OverlayPixmap.isNull()) return;
if(m_WaterfallPixmap.isNull()) return; if(m_WaterfallPixmap.isNull()) return;
int w = m_WaterfallPixmap.width(); int w = m_WaterfallPixmap.width();
int x,y; int x,y;
int nHzDiv[11]={0,50,100,200,200,200,500,500,500,500,500}; int nHzDiv[11]={0,50,100,200,200,200,500,500,500,500,500};
float pixperdiv; float pixperdiv;
//###
QRect rect;
QPainter painter(&m_OverlayPixmap);
painter.initFrom(this);
QLinearGradient gradient(0, 0, 0 ,m_h2); //fill background with gradient
gradient.setColorAt(1, Qt::black);
gradient.setColorAt(0, Qt::darkBlue);
painter.setBrush(gradient);
painter.drawRect(0, 0, m_w, m_h2);
painter.setBrush(Qt::SolidPattern);
//draw vertical grids
double df = m_binsPerPixel*m_fftBinWidth;
pixperdiv = m_freqPerDiv/df;
y = m_h2 - m_h2/VERT_DIVS;
for( int i=1; i<m_hdivs; i++)
{
x = (int)( (float)i*pixperdiv );
painter.setPen(QPen(Qt::white, 1,Qt::DotLine));
painter.drawLine(x, 0, x , y);
painter.drawLine(x, m_h2-5, x , m_h2);
}
//draw horizontal grids
pixperdiv = (float)m_h2 / (float)VERT_DIVS;
painter.setPen(QPen(Qt::white, 1,Qt::DotLine));
for( int i=1; i<VERT_DIVS; i++)
{
y = (int)( (float)i*pixperdiv );
painter.drawLine(0, y, w, y);
}
//draw amplitude values
painter.setPen(Qt::yellow);
// Font.setWeight(QFont::Light);
// painter.setFont(Font);
// int dB = m_MaxdB;
int dB = 50;
for( int i=0; i<VERT_DIVS-1; i++)
{
y = (int)( (float)i*pixperdiv );
painter.drawStaticText(5, y-1, QString::number(dB)+" dB");
dB -= m_dBStepSize;
}
// m_MindB = m_MaxdB - (VERT_DIVS)*m_dBStepSize;
if(!m_Running)
{ //if not running so is no data updates to draw to screen
//copy into 2Dbitmap the overlay bitmap.
m_2DPixmap = m_OverlayPixmap.copy(0,0,m_w,m_h2);
//trigger a new paintEvent
update();
}
//###
QRect rect0; QRect rect0;
QPainter painter0(&m_ScalePixmap); QPainter painter0(&m_ScalePixmap);
painter0.initFrom(this); painter0.initFrom(this);
@ -188,7 +243,6 @@ void CPlotter::DrawOverlay() //DrawOverlay()
m_fftBinWidth=12000.0/m_nsps; m_fftBinWidth=12000.0/m_nsps;
if(m_binsPerPixel < 1) m_binsPerPixel=1; if(m_binsPerPixel < 1) m_binsPerPixel=1;
double df = m_binsPerPixel*m_fftBinWidth;
m_fSpan = w*df; m_fSpan = w*df;
int n=m_fSpan/10; int n=m_fSpan/10;
m_freqPerDiv=10; m_freqPerDiv=10;
@ -251,31 +305,32 @@ void CPlotter::DrawOverlay() //DrawOverlay()
// Now make the lower scale, using m_LowerScalePixmap and painter3 // Now make the lower scale, using m_LowerScalePixmap and painter3
QRect rect1; QRect rect1;
QPainter painter3(&m_LowerScalePixmap); // QPainter painter3(&m_LowerScalePixmap);
painter3.initFrom(this); // painter3.initFrom(this);
painter3.setFont(Font); // painter3.setFont(Font);
painter3.setPen(Qt::black); // painter3.setPen(Qt::black);
df = 12000.0/m_nsps; df = 12000.0/m_nsps;
int nlabs=df*w/m_freqPerDiv + 1.0; int nlabs=df*w/m_freqPerDiv + 1.0;
m_LowerScalePixmap.fill(Qt::white); // m_LowerScalePixmap.fill(Qt::white);
painter3.drawRect(0, 0, w, 30); // painter3.drawRect(0, 0, w, 30);
pixperdiv = m_freqPerDiv/df; pixperdiv = m_freqPerDiv/df;
for( int i=0; i<10*nlabs; i++) { for( int i=0; i<10*nlabs; i++) {
x = i*pixperdiv/10; x = i*pixperdiv/10;
y=24; y=24;
if ((i%10) == 0) y=18; if ((i%10) == 0) y=18;
painter3.drawLine(x,y,x,30); // painter3.drawLine(x,y,x,30);
} }
/*
//draw frequency values //draw frequency values
MakeFrequencyStrs(); MakeFrequencyStrs();
for( int i=0; i<=nlabs; i++) { for( int i=0; i<=nlabs; i++) {
x = (int)( (float)i*pixperdiv - pixperdiv/2); x = (int)( (float)i*pixperdiv - pixperdiv/2);
rect1.setRect(x,0, (int)pixperdiv, 20); rect1.setRect(x,0, (int)pixperdiv, 20);
painter3.drawText(rect1, Qt::AlignHCenter|Qt::AlignVCenter, // painter3.drawText(rect1, Qt::AlignHCenter|Qt::AlignVCenter,m_HDivText[i]);
m_HDivText[i]);
} }
*/
} }
void CPlotter::MakeFrequencyStrs() //MakeFrequencyStrs void CPlotter::MakeFrequencyStrs() //MakeFrequencyStrs

View File

@ -61,6 +61,8 @@ public:
void setFsample(int n); void setFsample(int n);
void setNsps(int n); void setNsps(int n);
double fGreen(); double fGreen();
void SetPercent2DScreen(int percent){m_Percent2DScreen=percent;}
signals: signals:
void freezeDecode0(int n); void freezeDecode0(int n);
@ -82,7 +84,8 @@ private:
QPixmap m_WaterfallPixmap; QPixmap m_WaterfallPixmap;
QPixmap m_2DPixmap; QPixmap m_2DPixmap;
QPixmap m_ScalePixmap; QPixmap m_ScalePixmap;
QPixmap m_LowerScalePixmap; QPixmap m_OverlayPixmap;
// QPixmap m_LowerScalePixmap;
QSize m_Size; QSize m_Size;
QString m_Str; QString m_Str;
QString m_HDivText[483]; QString m_HDivText[483];
@ -105,6 +108,11 @@ private:
qint32 m_xClick; qint32 m_xClick;
qint32 m_freqPerDiv; qint32 m_freqPerDiv;
qint32 m_nsps; qint32 m_nsps;
qint32 m_Percent2DScreen;
qint32 m_w;
qint32 m_h;
qint32 m_h1;
qint32 m_h2;
private slots: private slots:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);