This commit is contained in:
iceman1001 2024-04-10 14:26:05 +02:00
commit 6a7e70ad26

View file

@ -149,6 +149,7 @@ void ProxGuiQT::_ShowPictureWindow(const QImage &img) {
);
pictureController->lbl_sz->setText(s);
pictureWidget->show();
}
void ProxGuiQT::_ShowBase64PictureWindow(char *b64) {
@ -203,6 +204,7 @@ void ProxGuiQT::_RepaintPictureWindow(void) {
return;
pictureWidget->update();
}
void ProxGuiQT::_HidePictureWindow(void) {
@ -516,7 +518,9 @@ int Plot::xCoordOf(int i, QRect r) {
int Plot::yCoordOf(int v, QRect r, int maxVal) {
int z = (r.bottom() - r.top()) / 2;
if (maxVal == 0) ++maxVal;
if (maxVal == 0) {
++maxVal;
}
return -(z * v) / maxVal + z;
}
@ -552,17 +556,27 @@ QColor Plot::getColor(int graphNum) {
}
void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) {
if (len == 0) return;
if (len == 0) {
return;
}
startMax = 0;
if (plotRect.right() >= plotRect.left() + 40) {
uint32_t t = (plotRect.right() - plotRect.left() - 40) / g_GraphPixelsPerPoint;
if (len >= t)
if (len >= t) {
startMax = len - t;
}
}
if (g_GraphStart > startMax) {
g_GraphStart = startMax;
}
if (g_GraphStart > len) return;
if (g_GraphStart > len) {
return;
}
int vMin = INT_MAX, vMax = INT_MIN;
uint32_t sample_index = g_GraphStart ;
for (; sample_index < len && xCoordOf(sample_index, plotRect) < plotRect.right() ; sample_index++) {
@ -573,14 +587,23 @@ void Plot::setMaxAndStart(int *buffer, size_t len, QRect plotRect) {
}
gs_absVMax = 0;
if (fabs((double) vMin) > gs_absVMax) gs_absVMax = (int)fabs((double) vMin);
if (fabs((double) vMax) > gs_absVMax) gs_absVMax = (int)fabs((double) vMax);
if (fabs((double) vMin) > gs_absVMax) {
gs_absVMax = (int)fabs((double) vMin);
}
if (fabs((double) vMax) > gs_absVMax) {
gs_absVMax = (int)fabs((double) vMax);
}
gs_absVMax = (int)(gs_absVMax * 1.25 + 1);
}
void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum, uint32_t plotOffset) {
if (len == 0 || g_PlotGridX <= 0) return;
//clock_t begin = clock();
if (len == 0 || g_PlotGridX <= 0) {
return;
}
QPainterPath penPath;
int grid_delta_x = g_PlotGridX;
@ -633,12 +656,15 @@ void Plot::PlotDemod(uint8_t *buffer, size_t len, QRect plotRect, QRect annotati
}
void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRect, QPainter *painter, int graphNum) {
if (len == 0) return;
// clock_t begin = clock();
if (len == 0) {
return;
}
QPainterPath penPath;
int vMin = INT_MAX, vMax = INT_MIN, v = 0;
int64_t vMean = 0;
uint32_t i = 0;
int vMin = INT_MAX, vMax = INT_MIN, v = 0;
int x = xCoordOf(g_GraphStart, plotRect);
int y = yCoordOf(buffer[g_GraphStart], plotRect, gs_absVMax);
penPath.moveTo(x, y);
@ -646,7 +672,6 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe
x = xCoordOf(i, plotRect);
v = buffer[i];
y = yCoordOf(v, plotRect, gs_absVMax);
penPath.lineTo(x, y);
@ -660,6 +685,7 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe
if (v > vMax) vMax = v;
vMean += v;
}
g_GraphStop = i;
vMean /= (g_GraphStop - g_GraphStart);
@ -681,7 +707,9 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe
int y0 = yCoordOf(v, plotRect, gs_absVMax);
int y1 = yCoordOf(-v, plotRect, gs_absVMax);
if (lasty0 - y0 < minYDist) continue;
if (lasty0 - y0 < minYDist) {
continue;
}
painter->drawLine(xo - 5, y0, xo + 5, y0);
@ -697,27 +725,38 @@ void Plot::PlotGraph(int *buffer, size_t len, QRect plotRect, QRect annotationRe
//Graph annotations
painter->drawPath(penPath);
char str[200];
snprintf(str, sizeof(str), "max=%d min=%d mean=%" PRId64 " n=%u/%zu CursorAVal=[%d] CursorBVal=[%d]",
vMax, vMin, vMean, g_GraphStop - g_GraphStart, len, buffer[CursorAPos], buffer[CursorBPos]);
snprintf(str, sizeof(str), "max=%d min=%d mean=%" PRId64 " n=%u/%zu CursorAVal=[%d] CursorBVal=[%d]"
, vMax
, vMin
, vMean
, g_GraphStop - g_GraphStart
, len
, buffer[CursorAPos]
, buffer[CursorBPos]
);
painter->drawText(20, annotationRect.bottom() - 23 - 20 * graphNum, str);
//clock_t end = clock();
//double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
//printf("Plot time %f\n", elapsed_secs);
}
void Plot::plotGridLines(QPainter *painter, QRect r) {
// set g_GridOffset
if (g_PlotGridX <= 0) return;
if (g_PlotGridX <= 0) {
return;
}
double offset = g_GridOffset;
if (g_GridLocked && g_PlotGridX) {
offset = g_GridOffset + g_PlotGridX - fmod(g_GraphStart, g_PlotGridX);
} else if (!g_GridLocked && g_GraphStart > 0 && g_PlotGridX) {
} else if (g_GridLocked == false && g_GraphStart > 0 && g_PlotGridX) {
offset = g_PlotGridX - fmod(g_GraphStart - offset, g_PlotGridX) + g_GraphStart - unlockStart;
}
offset = fmod(offset, g_PlotGridX);
if (offset < 0) offset += g_PlotGridX;
if (offset < 0) {
offset += g_PlotGridX;
}
double i;
double grid_delta_x = g_PlotGridX * g_GraphPixelsPerPoint;
@ -751,10 +790,13 @@ void Plot::paintEvent(QPaintEvent *event) {
if (CursorAPos > g_GraphTraceLen)
CursorAPos = 0;
if (CursorBPos > g_GraphTraceLen)
CursorBPos = 0;
if (g_CursorCPos > g_GraphTraceLen)
g_CursorCPos = 0;
if (g_CursorDPos > g_GraphTraceLen)
g_CursorDPos = 0;
@ -794,14 +836,17 @@ void Plot::paintEvent(QPaintEvent *event) {
painter.setPen(YELLOW);
painter.drawLine(xCoordOf(CursorAPos, plotRect), plotRect.top(), xCoordOf(CursorAPos, plotRect), plotRect.bottom());
}
if (CursorBPos > g_GraphStart && xCoordOf(CursorBPos, plotRect) < plotRect.right()) {
painter.setPen(PINK);
painter.drawLine(xCoordOf(CursorBPos, plotRect), plotRect.top(), xCoordOf(CursorBPos, plotRect), plotRect.bottom());
}
if (g_CursorCPos > g_GraphStart && xCoordOf(g_CursorCPos, plotRect) < plotRect.right()) {
painter.setPen(ORANGE);
painter.drawLine(xCoordOf(g_CursorCPos, plotRect), plotRect.top(), xCoordOf(g_CursorCPos, plotRect), plotRect.bottom());
}
if (g_CursorDPos > g_GraphStart && xCoordOf(g_CursorDPos, plotRect) < plotRect.right()) {
painter.setPen(LIGHTBLUE);
painter.drawLine(xCoordOf(g_CursorDPos, plotRect), plotRect.top(), xCoordOf(g_CursorDPos, plotRect), plotRect.bottom());
@ -810,6 +855,7 @@ void Plot::paintEvent(QPaintEvent *event) {
//Draw annotations
char str[200];
char scalestr[30] = {0};
if (g_CursorScaleFactor != 1) {
if (g_CursorScaleFactorUnit[0] == '\x00') {
snprintf(scalestr, sizeof(scalestr), "[%2.2f] ", ((int32_t)(CursorBPos - CursorAPos)) / g_CursorScaleFactor);
@ -817,7 +863,7 @@ void Plot::paintEvent(QPaintEvent *event) {
snprintf(scalestr, sizeof(scalestr), "[%2.2f %s] ", ((int32_t)(CursorBPos - CursorAPos)) / g_CursorScaleFactor, g_CursorScaleFactorUnit);
}
}
snprintf(str, sizeof(str), "@%u..%u dt=%i %szoom=%2.3f CursorAPos=%u CursorBPos=%u GridX=%lf GridY=%lf (%s) GridXoffset=%lf",
snprintf(str, sizeof(str), "@%u..%u dt=%zi %szoom=%2.3f CursorAPos=%zu CursorBPos=%zu GridX=%lf GridY=%lf (%s) GridXoffset=%lf",
g_GraphStart,
g_GraphStop,
CursorBPos - CursorAPos,
@ -902,7 +948,10 @@ void Plot::Zoom(double factor, uint32_t refX) {
}
void Plot::MoveTo(uint32_t pos) {
if (g_GraphTraceLen == 0) return;
if (g_GraphTraceLen == 0) {
return;
}
g_GraphStart = pos;
QObject *signalSender = sender();
@ -918,7 +967,10 @@ void Plot::MoveTo(int pos) {
}
void Plot::Move(int offset) {
if (g_GraphTraceLen == 0) return;
if (g_GraphTraceLen == 0) {
return;
}
if (offset > 0) { // Move right
if (g_GraphPixelsPerPoint < 20) {
g_GraphStart += offset;
@ -956,20 +1008,27 @@ void Plot::Trim(void) {
CursorBPos = 0;
}
} else {
lref = CursorAPos < CursorBPos ? CursorAPos : CursorBPos;
rref = CursorAPos < CursorBPos ? CursorBPos : CursorAPos;
// g_GraphPixelsPerPoint must remain a power of ZOOM_STEP
double GPPPtarget = g_GraphPixelsPerPoint * (g_GraphStop - g_GraphStart) / (rref - lref);
while (g_GraphPixelsPerPoint < GPPPtarget) {
g_GraphPixelsPerPoint *= ZOOM_STEP;
}
g_GraphPixelsPerPoint /= ZOOM_STEP;
CursorAPos -= lref;
CursorBPos -= lref;
}
g_DemodStartIdx -= lref;
for (uint32_t i = lref; i < rref; ++i)
for (uint32_t i = lref; i < rref; ++i) {
g_GraphBuffer[i - lref] = g_GraphBuffer[i];
}
g_GraphTraceLen = rref - lref;
g_GraphStart = 0;
}
@ -994,11 +1053,13 @@ void Plot::wheelEvent(QWheelEvent *event) {
x -= WIDTH_AXES;
x = (int)(x / g_GraphPixelsPerPoint);
x += g_GraphStart;
if (delta < 0) {
Zoom(ZOOM_STEP, x);
} else {
Zoom(1.0 / ZOOM_STEP, x);
}
} else {
Move(PageWidth * delta * move_offset / 120);
}
@ -1010,11 +1071,13 @@ void Plot::mouseMoveEvent(QMouseEvent *event) {
x -= WIDTH_AXES;
x = (int)(x / g_GraphPixelsPerPoint);
x += g_GraphStart;
if ((event->buttons() & Qt::LeftButton)) {
CursorAPos = x;
} else if (event->buttons() & Qt::RightButton) {
CursorBPos = x;
}
this->update();
}
@ -1022,16 +1085,18 @@ void Plot::keyPressEvent(QKeyEvent *event) {
uint32_t offset; // Left/right movement offset (in sample size)
if (event->modifiers() & Qt::ShiftModifier) {
if (g_PlotGridX)
if (g_PlotGridX) {
offset = PageWidth - fmod(PageWidth, g_PlotGridX);
else
offset = PageWidth;
} else {
if (event->modifiers() & Qt::ControlModifier)
offset = PageWidth;
}
} else {
if (event->modifiers() & Qt::ControlModifier) {
offset = 1;
else
} else {
offset = int(ZOOM_LIMIT / g_GraphPixelsPerPoint);
}
}
switch (event->key()) {
case Qt::Key_Down:
@ -1087,10 +1152,13 @@ void Plot::keyPressEvent(QKeyEvent *event) {
g_PlotGridX = 0;
g_PlotGridY = 0;
} else {
if (g_PlotGridXdefault < 0)
if (g_PlotGridXdefault < 0) {
g_PlotGridXdefault = 64;
if (g_PlotGridYdefault < 0)
}
if (g_PlotGridYdefault < 0) {
g_PlotGridYdefault = 0;
}
g_PlotGridX = g_PlotGridXdefault;
g_PlotGridY = g_PlotGridYdefault;
@ -1134,10 +1202,12 @@ void Plot::keyPressEvent(QKeyEvent *event) {
}
case Qt::Key_L:
g_GridLocked = !g_GridLocked;
if (g_GridLocked)
if (g_GridLocked) {
g_GridOffset += (g_GraphStart - unlockStart);
else
} else {
unlockStart = g_GraphStart;
}
break;
case Qt::Key_Q: