Automatically adjust number of vertical divisions according to window size (seems to break HDIVS).

This commit is contained in:
Alexandru Csete 2012-04-12 23:37:01 +02:00
parent 07fd3ee323
commit 96418ac93c
2 changed files with 27 additions and 16 deletions

View File

@ -28,6 +28,7 @@
*/ */
#include "plotter.h" #include "plotter.h"
#include <stdlib.h> #include <stdlib.h>
#include <cmath>
#include <QDebug> #include <QDebug>
@ -86,9 +87,12 @@ CPlotter::CPlotter(QWidget *parent) :
m_CursorCaptureDelta = CUR_CUT_DELTA; m_CursorCaptureDelta = CUR_CUT_DELTA;
m_Span = 96000; m_Span = 96000;
m_VertDivs = 6;
m_MaxdB = 0; m_MaxdB = 0;
m_MindB = -120; m_MindB = -120;
m_dBStepSize = 20; m_dBStepSize = abs(m_MaxdB-m_MindB)/m_VertDivs;
m_FreqUnits = 1000000; m_FreqUnits = 1000000;
m_CursorCaptured = NONE; m_CursorCaptured = NONE;
m_Running = false; m_Running = false;
@ -501,7 +505,8 @@ void CPlotter::GetScreenIntegerFFTData(qint32 MaxHeight, qint32 MaxWidth,
qint32 xprev = -1; qint32 xprev = -1;
qint32 maxbin; qint32 maxbin;
double dBmaxOffset = 0.0;//MaxdB/10.0; FIXME double dBmaxOffset = 0.0;//MaxdB/10.0; FIXME
double dBGainFactor = 1.0/MindB;//-1.0/(MaxdB-MindB); FIXME //double dBGainFactor = 1.0/MindB;//-1.0/(MaxdB-MindB); FIXME
double dBGainFactor = ((double)MaxHeight)/abs(MaxdB-MindB);
qint32 m_PlotWidth = MaxWidth; qint32 m_PlotWidth = MaxWidth;
@ -553,7 +558,10 @@ void CPlotter::GetScreenIntegerFFTData(qint32 MaxHeight, qint32 MaxWidth,
if (m_Invert) if (m_Invert)
y = (qint32)((double)MaxHeight*dBGainFactor*(m_pFFTAveBuf[(m-i)] - dBmaxOffset)); y = (qint32)((double)MaxHeight*dBGainFactor*(m_pFFTAveBuf[(m-i)] - dBmaxOffset));
else else
y = (qint32)((double)MaxHeight*dBGainFactor*(m_pFFTAveBuf[i] - dBmaxOffset)); {
//y = (qint32)((double)MaxHeight*dBGainFactor*(m_pFFTAveBuf[i] - dBmaxOffset));
y = (qint32)(dBGainFactor*(MaxdB-m_pFFTAveBuf[i]));
}
if (y < 0) if (y < 0)
y = 0; y = 0;
@ -655,7 +663,7 @@ void CPlotter::DrawOverlay()
Font.setPointSize(9); Font.setPointSize(9);
QFontMetrics metrics(Font); QFontMetrics metrics(Font);
y = h/VERT_DIVS; y = h/m_VertDivs;
//if (y < metrics.height()) //if (y < metrics.height())
// Font.setPixelSize(y); // Font.setPixelSize(y);
Font.setWeight(QFont::Normal); Font.setWeight(QFont::Normal);
@ -663,7 +671,7 @@ void CPlotter::DrawOverlay()
//draw vertical grids //draw vertical grids
pixperdiv = (float)w / (float)HORZ_DIVS; pixperdiv = (float)w / (float)HORZ_DIVS;
y = h - h/VERT_DIVS/2; y = h - h/m_VertDivs/2;
for (int i = 1; i < HORZ_DIVS; i++) for (int i = 1; i < HORZ_DIVS; i++)
{ {
x = (int)((float)i*pixperdiv); x = (int)((float)i*pixperdiv);
@ -680,8 +688,8 @@ void CPlotter::DrawOverlay()
//draw frequency values //draw frequency values
MakeFrequencyStrs(); MakeFrequencyStrs();
painter.setPen(QColor(0xD8,0xBA,0xA1,0xFF)); painter.setPen(QColor(0xD8,0xBA,0xA1,0xFF));
y = h - (h/VERT_DIVS); y = h - (h/m_VertDivs);
for (int i = 1; i < HORZ_DIVS; i++) for (int i = 1; i < m_VertDivs; i++)
{ {
//if ((i==0) || (i==HORZ_DIVS)) //if ((i==0) || (i==HORZ_DIVS))
//{ //left justify the leftmost text //{ //left justify the leftmost text
@ -698,15 +706,17 @@ void CPlotter::DrawOverlay()
//else //else
//{ //center justify the rest of the text //{ //center justify the rest of the text
x = (int)((float)i*pixperdiv - pixperdiv/2); x = (int)((float)i*pixperdiv - pixperdiv/2);
rect.setRect(x, y, (int)pixperdiv, h/VERT_DIVS); rect.setRect(x, y, (int)pixperdiv, h/m_VertDivs);
painter.drawText(rect, Qt::AlignHCenter|Qt::AlignBottom, m_HDivText[i]); painter.drawText(rect, Qt::AlignHCenter|Qt::AlignBottom, m_HDivText[i]);
//} //}
} }
//draw horizontal grids // horizontal grids (size and grid calcs could be moved to resize)
pixperdiv = (float)h / (float)VERT_DIVS; m_VertDivs = h/VDIV_DELTA+1;
m_dBStepSize = abs(m_MaxdB-m_MindB)/(double)m_VertDivs;
pixperdiv = (float)h / (float)m_VertDivs;
painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0x30), 1,Qt::DotLine)); painter.setPen(QPen(QColor(0xF0,0xF0,0xF0,0x30), 1,Qt::DotLine));
for (int i = 1; i < VERT_DIVS; i++) for (int i = 1; i < m_VertDivs; i++)
{ {
y = (int)((float) i*pixperdiv); y = (int)((float) i*pixperdiv);
painter.drawLine(5*metrics.width("0",-1), y, w, y); painter.drawLine(5*metrics.width("0",-1), y, w, y);
@ -718,7 +728,7 @@ void CPlotter::DrawOverlay()
painter.setFont(Font); painter.setFont(Font);
int dB = m_MaxdB; int dB = m_MaxdB;
m_YAxisWidth = metrics.width("-120 "); m_YAxisWidth = metrics.width("-120 ");
for (int i = 1; i < VERT_DIVS; i++) for (int i = 1; i < m_VertDivs; i++)
{ {
dB -= m_dBStepSize; /* move to end if want to include maxdb */ dB -= m_dBStepSize; /* move to end if want to include maxdb */
y = (int)((float)i*pixperdiv); y = (int)((float)i*pixperdiv);
@ -726,8 +736,6 @@ void CPlotter::DrawOverlay()
painter.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, QString::number(dB)); painter.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, QString::number(dB));
} }
m_MindB = m_MaxdB - (VERT_DIVS)*m_dBStepSize;
if (!m_Running) if (!m_Running)
{ //if not running so is no data updates to draw to screen { //if not running so is no data updates to draw to screen
//copy into 2Dbitmap the overlay bitmap. //copy into 2Dbitmap the overlay bitmap.

View File

@ -6,9 +6,11 @@
#include <QFrame> #include <QFrame>
#include <QImage> #include <QImage>
#define VERT_DIVS 6 //specify grid screen divisions //#define VERT_DIVS 6 //specify grid screen divisions
#define HORZ_DIVS 12 #define HORZ_DIVS 12
#define MAX_SCREENSIZE 4096 #define MAX_SCREENSIZE 4096
#define VDIV_DELTA 40 // Minimum distance in pixels between two horizontal grid lines (vertical division)
#define HDIV_DELTA 60 // Minimum distance in pixels between two vertical grid lines (horizontal division)
class CPlotter : public QFrame class CPlotter : public QFrame
{ {
@ -131,10 +133,11 @@ private:
int m_FHiCmax; int m_FHiCmax;
bool m_symetric; bool m_symetric;
qint32 m_Span; qint32 m_VertDivs; /*!< Current number of vertical divisions. Calculated from height. */
qint32 m_MaxdB; qint32 m_MaxdB;
qint32 m_MindB; qint32 m_MindB;
qint32 m_dBStepSize; qint32 m_dBStepSize;
qint32 m_Span;
qint32 m_FreqUnits; qint32 m_FreqUnits;
int m_ClickResolution; int m_ClickResolution;
int m_FilterClickResolution; int m_FilterClickResolution;