spacr.qt.widgets.zoom_view¶
One image view that fits, zooms, pans – and can be tied to another.
spaCR had a fit-on-load, wheel-zoom, drag-pan image canvas already: the QC
field browser’s own _FieldView. The raw-versus-enhanced window
needed the same thing twice over, and a third copy of “a QGraphicsView with
a pixmap in it” is how a codebase ends up with three that behave subtly
differently. So the field browser’s view moved here unchanged, under a name
that says it is shared, and the browser goes on using it under its old one.
WHAT IS NEW HERE IS THE TIE. Two views of the same region are only worth
putting side by side if they stay in register: a curator comparing a field
with its enhanced self is looking for a difference between them, and a
difference in where the two are pointing is the one difference that is not
information. ZoomableImageView.link_to() makes a group of views share
one zoom and one scroll position, so zooming or panning any of them moves
all of them.
The tie is on the VIEW and not on the window, because what has to match is the transform and the two scroll bars – the things a view owns. Views in a group must show images of the same size for the tie to mean anything; the compare window builds both of its pictures from one region, so they do.
Classes¶
Fit-on-load image canvas with wheel zoom and drag panning. |
Module Contents¶
- class spacr.qt.widgets.zoom_view.ZoomableImageView(parent=None)[source]¶
Bases:
PySide6.QtWidgets.QGraphicsViewFit-on-load image canvas with wheel zoom and drag panning.
- Parameters:
parent – parent widget; ownership only.
Build the view with its own scene, fitted on first load.
- link_to(other: ZoomableImageView) None[source]¶
Move with
other, and makeothermove with this one.Symmetric and transitive by construction: every view already in either group joins the other, so a group of three all follow each other however they were linked up.
- Parameters:
other – the view to tie this one to.
- resizeEvent(event) None[source]¶
Re-fit the image, unless the user has zoomed.
- Parameters:
event – the resize event.
- set_pixmap(pixmap: PySide6.QtGui.QPixmap) None[source]¶
Show a new image, fitted, and forget any zoom the user had applied.
- Parameters:
pixmap – the composite to show; a null one clears the view.
- wheelEvent(event) None[source]¶
Zoom on the wheel, and remember that the user did.
Once they have zoomed, a resize stops re-fitting – a view that snapped back to fit every time the splitter moved would undo the inspection the zoom was for.
- Parameters:
event – the wheel event.
- zoom_by(factor: float) None[source]¶
Zoom by
factorabout the view’s middle, and move the peers.The wheel zooms about the cursor (
AnchorUnderMouse); a button has no cursor position to speak of, so it zooms about the middle, which is what a person pressing + expects to keep in view.- Parameters:
factor – above 1 zooms in, below 1 zooms out.