consider scale when panning image (#892)

The previous variant calculates the delta by checking how many
"image pixels" the cursor was moved, and then emit an absolute
scrollbar move based on that. However, when zoomed in a single
image pixel can be multiple scroll bar units.

The effect was that panning a zoomed in image was very slow,
giving a rubber band kind of effect. Wiggling the mouse would emit
more deltas, eventually moving the image below the cursor again.

This PR uses the absolute coordinates instead, which keeps the
image closer to the cursor. There is still a slight rubber band
effect, probably due to slight differences between painter and
scroll bar positions/units.

The result is that panning a zoomed in image feels less sluggish.
This commit is contained in:
Stefan Breunig 2022-06-12 19:09:22 +02:00 committed by GitHub
parent efd90a481b
commit 981be1f9c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -204,10 +204,9 @@ class Canvas(QWidget):
'Width: %d, Height: %d / X: %d; Y: %d' % (current_width, current_height, pos.x(), pos.y()))
else:
# pan
delta_x = pos.x() - self.pan_initial_pos.x()
delta_y = pos.y() - self.pan_initial_pos.y()
self.scrollRequest.emit(delta_x, Qt.Horizontal)
self.scrollRequest.emit(delta_y, Qt.Vertical)
delta = ev.pos() - self.pan_initial_pos
self.scrollRequest.emit(delta.x(), Qt.Horizontal)
self.scrollRequest.emit(delta.y(), Qt.Vertical)
self.update()
return
@ -269,7 +268,7 @@ class Canvas(QWidget):
if selection is None:
# pan
QApplication.setOverrideCursor(QCursor(Qt.OpenHandCursor))
self.pan_initial_pos = pos
self.pan_initial_pos = ev.pos()
elif ev.button() == Qt.RightButton and self.editing():
self.select_shape_point(pos)