Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisslav2011 committed Mar 29, 2024
1 parent 243e6a2 commit 83817e1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/qtgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ add_source_files(SRCS_LIST
nb_options.h
plotter.cpp
plotter.h
plotter2.cpp
plotter2.h
qtcolorpicker.cpp
qtcolorpicker.h
)
Expand Down
1 change: 1 addition & 0 deletions src/qtgui/dockprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ DockProbe::DockProbe(QWidget *parent) :
ui->spectrum->setFreqDigits(1);

grid_init(ui->gridLayout,ui->gridLayout->rowCount(),0/*ui->gridLayout->columnCount()*/);
ui->plot->setVisible(false);
}

DockProbe::~DockProbe()
Expand Down
37 changes: 37 additions & 0 deletions src/qtgui/dockprobe.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,37 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="CPlotter2" name="plot">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Audio spectrum</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
Expand All @@ -81,6 +112,12 @@
<header>qtgui/plotter.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CPlotter2</class>
<extends>QFrame</extends>
<header>qtgui/plotter2.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../resources/icons.qrc"/>
Expand Down
49 changes: 19 additions & 30 deletions src/qtgui/plotter2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <QToolTip>
#include "plotter2.h"

Q_LOGGING_CATEGORY(plotter, "plotter2")
Q_LOGGING_CATEGORY(plotter2, "plotter2")

#define CUR_CUT_DELTA 5 //cursor capture delta in pixels

Expand All @@ -54,7 +54,7 @@ Q_LOGGING_CATEGORY(plotter, "plotter2")
#define HOR_MARGIN 5
#define VER_MARGIN 5

int F2B(float f)
static int F2B(float f)
{
int b = (f >= 1.0 ? 255 : (f <= 0.0 ? 0 : (int)floor(f * 256.0)));
return b;
Expand All @@ -65,13 +65,6 @@ static inline bool val_is_out_of_range(float val, float min, float max)
return (val < min || val > max);
}

static inline bool out_of_range(float min, float max)
{
return (val_is_out_of_range(min, FFT_MIN_DB, FFT_MAX_DB) ||
val_is_out_of_range(max, FFT_MIN_DB, FFT_MAX_DB) ||
max < min + 10.f);
}

#define STATUS_TIP \
"Click, drag or scroll on spectrum to tune. " \
"Drag and scroll X and Y axes for pan and zoom. " \
Expand Down Expand Up @@ -115,9 +108,9 @@ void CPlotter2::mouseMoveEvent(QMouseEvent* event)
if (event->buttons() == Qt::NoButton)
{
if (m_TooltipsEnabled)
showToolTip(event, QString("Current demod %1: %2 kHz")
.arg(m_currentVfo)
.arg(m_DemodCenterFreq/1.e3, 0, 'f', 3));
showToolTip(event, QString("S: %1 M: %2")
.arg(0.f, 0, 'f', 3)
.arg(0.f, 0, 'f', 3));
}
setCursor(QCursor(Qt::ArrowCursor));
}
Expand Down Expand Up @@ -168,7 +161,6 @@ void CPlotter2::resizeEvent(QResizeEvent* )
// if changed, resize pixmaps to new screensize
m_Size = size();
m_DPR = devicePixelRatio();
fft_plot_height = m_Percent2DScreen * m_Size.height() / 100;
{
m_OverlayPixmap = QPixmap(m_Size.width() * m_DPR, m_Size.height() * m_DPR);
m_OverlayPixmap.setDevicePixelRatio(m_DPR);
Expand Down Expand Up @@ -200,6 +192,7 @@ void CPlotter2::draw()
int w;
int h;
int xmin, xmax;
QPointF LineBuf[MAX_SCREENSIZE];

if (m_DrawOverlay)
{
Expand All @@ -208,10 +201,6 @@ void CPlotter2::draw()
}


if (!m_Running)
return;


// get/draw the 2D spectrum
w = m_2DPixmap.width() / m_DPR;
h = m_2DPixmap.height() / m_DPR;
Expand All @@ -229,7 +218,7 @@ void CPlotter2::draw()
for (i = 0; i < n; i++)
{
LineBuf[i].setX(i + xmin + 0.5);
LineBuf[i].setY(m_fftbuf[i + xmin] + 0.5);
LineBuf[i].setY(m_data[i + xmin] + 0.5);
}
painter2.setPen(m_PlotColor);
painter2.drawPolyline(LineBuf, n);
Expand Down Expand Up @@ -294,6 +283,7 @@ void CPlotter2::drawOverlay()
int fLabelTop = xAxisTop + VER_MARGIN;


#if 0
if (m_CenterLineEnabled)
{
x = xFromFreq(m_CenterFreq);
Expand All @@ -303,7 +293,7 @@ void CPlotter2::drawOverlay()
painter.drawLine(x, 0, x, xAxisTop);
}
}

// Frequency grid
qint64 StartFreq = m_CenterFreq + m_FftCenter - m_Span / 2;
QString label;
Expand Down Expand Up @@ -375,7 +365,7 @@ void CPlotter2::drawOverlay()
painter.drawText(rect, Qt::AlignRight|Qt::AlignVCenter, QString::number(dB));
}
}

#endif

painter.end();
}
Expand All @@ -388,6 +378,7 @@ void CPlotter2::drawOverlay()
// Keeps all strings the same fractional length
void CPlotter2::makeFrequencyStrs()
{
#if 0
qint64 StartFreq = m_StartFreqAdj;
double freq;
int i,j;
Expand Down Expand Up @@ -434,24 +425,22 @@ void CPlotter2::makeFrequencyStrs()
m_HDivText[i].setNum(freq,'f', max);
StartFreq += m_FreqPerDiv;
}
#endif
}


// Ensure overlay is updated by either scheduling or forcing a redraw
void CPlotter2::updateOverlay()
{
if (m_Running)
m_DrawOverlay = true;
else
drawOverlay();
drawOverlay();
}


void CPlotter2::calcDivSize (qint64 low, qint64 high, int divswanted, qint64 &adjlow, qint64 &step, int& divs)
{
qCDebug(plotter) << "low:" << low;
qCDebug(plotter) << "high:" << high;
qCDebug(plotter) << "divswanted:" << divswanted;
qCDebug(plotter2) << "low:" << low;
qCDebug(plotter2) << "high:" << high;
qCDebug(plotter2) << "divswanted:" << divswanted;

if (divswanted == 0)
return;
Expand Down Expand Up @@ -479,9 +468,9 @@ void CPlotter2::calcDivSize (qint64 low, qint64 high, int divswanted, qint64 &ad
if (adjlow < low)
adjlow += step;

qCDebug(plotter) << "adjlow:" << adjlow;
qCDebug(plotter) << "step:" << step;
qCDebug(plotter) << "divs:" << divs;
qCDebug(plotter2) << "adjlow:" << adjlow;
qCDebug(plotter2) << "step:" << step;
qCDebug(plotter2) << "divs:" << divs;
}

void CPlotter2::showToolTip(QMouseEvent* event, QString toolTipText)
Expand Down
7 changes: 6 additions & 1 deletion src/qtgui/plotter2.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CPlotter2 : public QFrame
QSize sizeHint() const override;

void draw(); //call to draw new fft data onto screen plot
void setRunningState(bool running) { m_Running = running; }
void setTooltipsEnabled(bool enabled) { m_TooltipsEnabled = enabled; }

void setNewData(float *data, int size);

Expand All @@ -55,14 +55,17 @@ public slots:
void showToolTip(QMouseEvent* event, QString toolTipText);

float *m_data{};
int m_dataSize;
QPixmap m_2DPixmap;
QPixmap m_OverlayPixmap;
QColor m_PlotColor{255,255,255};
QSize m_Size;
qreal m_DPR{};
QString m_HDivText[HORZ_DIVS_MAX+1];
bool m_DrawOverlay;
bool m_TooltipsEnabled{}; /*!< Tooltips enabled */
bool m_InvertScrolling;
bool m_polar{false};
int m_CursorCaptureDelta;
int m_GrabPosition;

Expand All @@ -72,6 +75,8 @@ public slots:
int m_FHiCmax;
bool m_symetric;

int m_XAxisYCenter{};
int m_YAxisWidth{};
int m_HorDivs; /*!< Current number of horizontal divisions. Calculated from width. */
int m_VerDivs; /*!< Current number of vertical divisions. Calculated from height. */

Expand Down

0 comments on commit 83817e1

Please sign in to comment.