Skip to content

pscan: Fix the Alt-L paper-size toggle not reaching the scanner - #89

Open
sjg20 wants to merge 2 commits into
masterfrom
fix-legal-toggle
Open

pscan: Fix the Alt-L paper-size toggle not reaching the scanner#89
sjg20 wants to merge 2 commits into
masterfrom
fix-legal-toggle

Conversation

@sjg20

@sjg20 sjg20 commented Jul 16, 2026

Copy link
Copy Markdown
Owner

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=0 and Warning - no yres.

Root causes (found by reproducing on the simulated scanner)

  1. Re-entrancy storm. 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.
  2. Scan area never pushed. The scan area is only nudged via the
    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 four
    scan-area options are pushed to the scanner explicitly.
  3. Stale combo indices. Pscan cached the Letter/Legal/A4 indices
    once; applying a size rebuilds the preview list and shifts them.
    toggleLetter()/selectA4() now look the indices up fresh and match
    by name.

Tests

TestQscanner::testPscanPaperToggle toggles the paper size against the
simulated 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, missing
x/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 Qt6
sandbox could not do (missing QtStateMachine headers).

sjg20 added 2 commits July 16, 2026 07:31
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>
@sjg20 sjg20 changed the title pscan: Fix Alt-L paper-size toggle desyncing from the scanner pscan: Fix the Alt-L paper-size toggle not reaching the scanner Jul 16, 2026
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.

1 participant