Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain the current scroll position when zooming #172

Merged
merged 1 commit into from
Oct 1, 2020

Conversation

argilo
Copy link
Contributor

@argilo argilo commented Oct 1, 2020

Fixes #157.

When the "Zoom" slider or "FFT size" slider is moved, Inspectrum jumps either to the end of the file or to the last location that was zoomed with Ctrl+scrollwheel. This happens because the code that tracks where the center of the window is was commented out in #131.

The change in #131 also reordered PlotView::updateView in an attempt to work around a zoom bug, but it only moved the problem. The underlying issue is that when zooming or changing the FFT size, horizontalScrollBar()->setMaximum() and horizontalScrollBar()->setValue() must be called in the correct order. When the total width of the FFT data expands, the scroll maximum must be increased before the scroll value, or else the value might be clipped. Conversely, when the total width of the FFT data shrinks, the scroll value must be decreased before the scroll maximum. I've accomplished that here by having PlotView::setFFTAndZoom() determine whether the total width is expanding and pass that information into PlotView::updateViewRange(), which can then perform the two steps in the correct order.

@@ -71,7 +71,7 @@ public slots:
size_t zoomSample;

int fftSize = 1024;
int zoomLevel = 0;
int zoomLevel = 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to 1 because 0 is invalid and causes PlotView::samplesPerColumn() to crash due to a division by zero.

@schneider42
Copy link
Collaborator

Thank you soooo much!

@miek miek merged commit 32409be into miek:master Oct 1, 2020
@miek
Copy link
Owner

miek commented Oct 1, 2020

Thanks!

@argilo argilo deleted the fix-zoom-scrolling branch October 1, 2020 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zoom slider weirdness
3 participants