diff --git a/plotview.cpp b/plotview.cpp index 11240a9..6dd1bab 100644 --- a/plotview.cpp +++ b/plotview.cpp @@ -136,7 +136,7 @@ void PlotView::setFFTAndZoom(int size, int zoom) horizontalScrollBar()->setSingleStep(size * 10 / zoomLevel); horizontalScrollBar()->setPageStep(size * 100 / zoomLevel); - updateView(); + updateView(true); } void PlotView::setPowerMin(int power) @@ -207,13 +207,24 @@ void PlotView::scrollContentsBy(int dx, int dy) updateView(); } -void PlotView::updateView() +void PlotView::updateView(bool reCenter) { + // Store old view for recentering + auto oldViewRange = viewRange; + // Update current view viewRange = { horizontalScrollBar()->value(), horizontalScrollBar()->value() + width() * samplesPerLine() }; + + // Adjust time offset to zoom around central sample + if (reCenter) { + horizontalScrollBar()->setValue( + horizontalScrollBar()->value() + (oldViewRange.length() - viewRange.length()) / 2 + ); + } + horizontalScrollBar()->setMaximum(mainSampleSource->count() - ((width() - 1) * samplesPerLine())); verticalScrollBar()->setMaximum(std::max(0, plotsHeight() - viewport()->height())); diff --git a/plotview.h b/plotview.h index 08ec947..520f250 100644 --- a/plotview.h +++ b/plotview.h @@ -74,5 +74,5 @@ private: TracePlot* createQuadratureDemodPlot(SampleSource> *src); int plotsHeight(); off_t samplesPerLine(); - void updateView(); + void updateView(bool reCenter = false); }; \ No newline at end of file