Skip to content

Maintain the current scroll position when zooming#172

Merged
miek merged 1 commit intomiek:masterfrom
argilo:fix-zoom-scrolling
Oct 1, 2020
Merged

Maintain the current scroll position when zooming#172
miek merged 1 commit intomiek:masterfrom
argilo:fix-zoom-scrolling

Conversation

@argilo
Copy link
Copy Markdown
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.


int fftSize = 1024;
int zoomLevel = 0;
int zoomLevel = 1;
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Thank you soooo much!

@miek miek merged commit 32409be into miek:master Oct 1, 2020
@miek
Copy link
Copy Markdown
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