From a695572d31b32ae912a5e7c2157e6e0c08fc62b1 Mon Sep 17 00:00:00 2001 From: Jacob Gilbert Date: Sat, 24 Jul 2021 06:04:06 -0600 Subject: [PATCH] when increasing the FFT size, the plot should maintain the current center frequency Signed-off-by: Jacob Gilbert --- src/plotview.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plotview.cpp b/src/plotview.cpp index d1c6bea..33fd000 100644 --- a/src/plotview.cpp +++ b/src/plotview.cpp @@ -425,6 +425,7 @@ void PlotView::setCursorSegments(int segments) selectedSamples.maximum = selectedSamples.minimum + (segments * sampPerSeg + 0.5f); cursors.setSegments(segments); + updateView(); emitTimeSelection(); } @@ -432,6 +433,9 @@ void PlotView::setCursorSegments(int segments) void PlotView::setFFTAndZoom(int size, int zoom) { auto oldSamplesPerColumn = samplesPerColumn(); + float oldPlotCenter = (verticalScrollBar()->value() + viewport()->height() / 2.0) / plotsHeight(); + if (verticalScrollBar()->maximum() == 0) + oldPlotCenter = 0.5; // Set new FFT size fftSize = size; @@ -448,6 +452,10 @@ void PlotView::setFFTAndZoom(int size, int zoom) horizontalScrollBar()->setPageStep(100); updateView(true, samplesPerColumn() < oldSamplesPerColumn); + + // maintain the relative position of the vertical scroll bar + if (verticalScrollBar()->maximum()) + verticalScrollBar()->setValue((int )(oldPlotCenter * plotsHeight() - viewport()->height() / 2.0 + 0.5f)); } void PlotView::setPowerMin(int power) @@ -604,6 +612,7 @@ void PlotView::updateView(bool reCenter, bool expanding) } horizontalScrollBar()->setMaximum(std::max(0, sampleToColumn(mainSampleSource->count()) - width())); verticalScrollBar()->setMaximum(std::max(0, plotsHeight() - viewport()->height())); + if (expanding) { updateViewRange(reCenter); }