Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PPOCRLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ def get_str(str_id):
}
self.scrollArea = scroll
self.canvas.scrollRequest.connect(self.scrollRequest)
self.canvas.pixelScrollRequest.connect(self.pixelScrollRequest)

self.canvas.newShape.connect(partial(self.newShape, False))
self.canvas.shapeMoved.connect(self.updateBoxlist) # self.setDirty
Expand Down Expand Up @@ -2109,6 +2110,11 @@ def scrollRequest(self, delta, orientation):
bar = self.scrollBars[orientation]
bar.setValue(int(bar.value() + bar.singleStep() * units))

def pixelScrollRequest(self, dx, dy):
for orientation, delta in [(Qt.Horizontal, dx), (Qt.Vertical, dy)]:
bar = self.scrollBars[orientation]
bar.setValue(int(bar.value() - delta))

def setZoom(self, value):
self.actions.fitWidth.setChecked(False)
self.actions.fitWindow.setChecked(False)
Expand Down
23 changes: 13 additions & 10 deletions libs/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class Canvas(QWidget):
zoomRequest = pyqtSignal(int)
scrollRequest = pyqtSignal(int, int)
pixelScrollRequest = pyqtSignal(int, int)
newShape = pyqtSignal()
# selectionChanged = pyqtSignal(bool)
selectionChanged = pyqtSignal(list)
Expand Down Expand Up @@ -212,10 +213,11 @@ def mouseMoveEvent(self, ev):
self.movingShape = True
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.globalPos() - self.pan_initial_pos
if delta.x() != 0 or delta.y() != 0:
self.overrideCursor(CURSOR_MOVE)
self.pixelScrollRequest.emit(delta.x(), delta.y())
self.pan_initial_pos = ev.globalPos()
self.update()
return

Expand Down Expand Up @@ -282,7 +284,7 @@ def mousePressEvent(self, ev):
group_mode = int(ev.modifiers()) == Qt.ControlModifier
self.selectShapePoint(pos, multiple_selection_mode=group_mode)
self.prevPoint = pos
self.pan_initial_pos = pos
self.pan_initial_pos = ev.globalPos()

elif ev.button() == Qt.RightButton and self.editing():
group_mode = int(ev.modifiers()) == Qt.ControlModifier
Expand All @@ -306,13 +308,14 @@ def mouseReleaseEvent(self, ev):
else:
self.overrideCursor(CURSOR_GRAB)

elif ev.button() == Qt.LeftButton and not self.fourpoint:
pos = self.transformPos(ev.pos())
elif ev.button() == Qt.LeftButton:
if self.drawing():
self.handleDrawing(pos)
else:
if not self.fourpoint:
pos = self.transformPos(ev.pos())
self.handleDrawing(pos)
elif not self.selectedShapes:
# pan
QApplication.restoreOverrideCursor() # ?
self.overrideCursor(CURSOR_DEFAULT)

if self.movingShape and self.hShape:
if self.hShape in self.shapes:
Expand Down
Loading