diff --git a/artiq/gui/dndwidgets.py b/artiq/gui/dndwidgets.py index 43cc20d4b..46572e57c 100644 --- a/artiq/gui/dndwidgets.py +++ b/artiq/gui/dndwidgets.py @@ -59,7 +59,6 @@ class DragDropSplitter(QtWidgets.QSplitter): class VDragScrollArea(QtWidgets.QScrollArea): def __init__(self, parent): QtWidgets.QScrollArea.__init__(self, parent) - self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.installEventFilter(self) self._margin = 40 self._timer = QtCore.QTimer(self) @@ -68,31 +67,32 @@ class VDragScrollArea(QtWidgets.QScrollArea): self._direction = 0 self._speed = 10 + def setAutoScrollMargin(self, margin): + self._margin = margin + + def setAutoScrollSpeed(self, speed): + self._speed = speed + def eventFilter(self, obj, e): if e.type() == QtCore.QEvent.DragMove: val = self.verticalScrollBar().value() - vp_height = self.viewport().height() - pos = e.pos() - if pos.y() < val + self._margin: + height = self.viewport().height() + y = e.pos().y() + self._direction = 0 + if y < val + self._margin: self._direction = -1 - elif pos.y() > vp_height + val - self._margin: + elif y > height + val - self._margin: self._direction = 1 - else: - self._direction = 0 if not self._timer.isActive(): self._timer.start() elif e.type() in (QtCore.QEvent.Drop, QtCore.QEvent.DragLeave): self._timer.stop() return False - def setAutoScrollMargin(self, margin): - self._margin = margin - def _on_auto_scroll(self): val = self.verticalScrollBar().value() - mini = self.verticalScrollBar().minimum() - maxi = self.verticalScrollBar().maximum() - dx = self._direction * self._speed - new_val = min(maxi, max(mini, val + dx)) + mn = self.verticalScrollBar().minimum() + mx = self.verticalScrollBar().maximum() + dy = self._direction * self._speed + new_val = min(mx, max(mn, val + dy)) self.verticalScrollBar().setValue(new_val) -