pscan: Fix the Alt-L paper-size toggle not reaching the scanner - #89
Open
sjg20 wants to merge 2 commits into
Open
pscan: Fix the Alt-L paper-size toggle not reaching the scanner#89sjg20 wants to merge 2 commits into
sjg20 wants to merge 2 commits into
Conversation
Pressing Alt-L to toggle between Letter and Legal updates the page-size combo but leaves the scanner on the previous size: the first toggle works, but toggling back changes the combo to Letter while the scanner stays on Legal. Applying a size makes the preview widget rebuild its list of predefined sizes (the scan range changes, so a different set of sizes fits) and this shifts the list indices. Pscan caches the Letter, Legal and A4 indices just once when the dialog is built, so after the first toggle those cached indices no longer point at the sizes they name, and the next toggle hands the wrong index to the preview, sending the wrong size to the scanner. Look the indices up fresh from the preview widget each time, decide the toggle direction from the size name currently shown, and mirror the choice back into our own combo by name rather than by index. Route selectA4() through the same helper so it cannot go stale either. Add a test driving the toggle against the simulated scanner, checking that the size actually pushed to the scanner matches the size shown in the combo across repeated toggles. Co-developed-by: Claude <noreply@anthropic.com>
Choosing a paper size (including the Alt-L Letter/Legal toggle) updated the page-size combo but left the scanner scanning the previous size: pick Letter after Legal and the page-height option reads 279mm while the scan area's bottom-right y stays at 356mm, so the scan still comes out Legal-length. Two things go wrong in slotSetPredefinedSize(). First, setting the page size reloads the options and rebuilds the preview, which re-enters the slot with a stale size and undoes the scan area just applied; guard against that re-entrancy as slotReloadOptions() already does. Second, the scan area is only nudged through the scroll-bar widgets as a percentage. When the page shrinks, reloading pins the slider at its new maximum, so re-applying 100% produces no valueChanged() and nothing reaches the scanner. Push the four scan-area options to the scanner explicitly so the scan window always matches the selected size. Give the simulated scanner an 8.6x14.5in bed so it can represent Letter and Legal (216mm wide, 356mm tall), and add a test that toggles the paper size and checks the scanner's bottom-right y follows it. Also drop some stray debug printf()s (the size dump, the A4 dump and the missing-x/yres warnings) that spammed the console during scanning. Co-developed-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix the Alt-L paper-size toggle not reaching the scanner
Toggling paper size (Alt-L for Letter/Legal, or picking a size in the
combo) updated the on-screen combo but left the scanner on the
previous size. In the report, the page-height option showed 279 mm
(Letter) while the scan area's bottom-right y stayed at 356 mm (Legal),
so a "Letter" scan still came out Legal-length. The console also spammed
0.00 0.00 1.00 1.00, valid=0andWarning - no yres.Root causes (found by reproducing on the simulated scanner)
slotSetPredefinedSize()sets the page size,which reloads options and rebuilds the preview; that re-enters the
slot with a stale size and undoes the scan area just applied. Guarded
against re-entrancy, like
slotReloadOptions()already is.scroll-bar widgets as a percentage. When the page shrinks, reloading
pins the slider at its new maximum, so re-applying 100% yields no
valueChanged()and nothing reaches the scanner. Now the fourscan-area options are pushed to the scanner explicitly.
Pscancached the Letter/Legal/A4 indicesonce; applying a size rebuilds the preview list and shifts them.
toggleLetter()/selectA4()now look the indices up fresh and matchby name.
Tests
TestQscanner::testPscanPaperToggletoggles the paper size against thesimulated scanner and asserts the scanner's bottom-right y follows the
selection (Legal scans clearly taller than Letter). The simulated scanner
now advertises an 8.6×14.5 in bed so it can represent Letter and Legal.
Verified the test fails without the fix and passes with it.
Also removes stray debug
printf()s (size dump, A4 dump, missingx/yres warnings) that spammed the console during scanning.
Note on local testing
This was reproduced and fixed against a real local build: installing the
Qt5 dev packages lets the whole app + test suite build and run here
(
QT_QPA_PLATFORM=offscreen ./paperman -t TestQscanner), which the Qt6sandbox could not do (missing QtStateMachine headers).