plotview: Zoom relative to centre of view

This commit is contained in:
Mike
2016-03-09 01:46:40 +00:00
parent 3c8f2b2701
commit 82494d501f
2 changed files with 14 additions and 3 deletions

View File

@@ -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()));