Skip to content

Commit cb407ef

Browse files
Jacob Gilbertjacobagilbert
authored andcommitted
when increasing the FFT size, the plot should maintain the current center frequency
Signed-off-by: Jacob Gilbert <jacob.gilbert@protonmail.com>
1 parent 6a475d8 commit cb407ef

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/plotview.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,17 @@ void PlotView::setCursorSegments(int segments)
434434
selectedSamples.maximum = selectedSamples.minimum + (segments * sampPerSeg + 0.5f);
435435

436436
cursors.setSegments(segments);
437+
437438
updateView();
438439
emitTimeSelection();
439440
}
440441

441442
void PlotView::setFFTAndZoom(int size, int zoom)
442443
{
443444
auto oldSamplesPerColumn = samplesPerColumn();
445+
float oldPlotCenter = (verticalScrollBar()->value() + viewport()->height() / 2.0) / plotsHeight();
446+
if (verticalScrollBar()->maximum() == 0)
447+
oldPlotCenter = 0.5;
444448

445449
// Set new FFT size
446450
fftSize = size;
@@ -457,6 +461,10 @@ void PlotView::setFFTAndZoom(int size, int zoom)
457461
horizontalScrollBar()->setPageStep(100);
458462

459463
updateView(true, samplesPerColumn() < oldSamplesPerColumn);
464+
465+
// maintain the relative position of the vertical scroll bar
466+
if (verticalScrollBar()->maximum())
467+
verticalScrollBar()->setValue((int )(oldPlotCenter * plotsHeight() - viewport()->height() / 2.0 + 0.5f));
460468
}
461469

462470
void PlotView::setPowerMin(int power)
@@ -613,6 +621,7 @@ void PlotView::updateView(bool reCenter, bool expanding)
613621
}
614622
horizontalScrollBar()->setMaximum(std::max(0, sampleToColumn(mainSampleSource->count()) - width()));
615623
verticalScrollBar()->setMaximum(std::max(0, plotsHeight() - viewport()->height()));
624+
616625
if (expanding) {
617626
updateViewRange(reCenter);
618627
}

0 commit comments

Comments
 (0)