scroll by wheel

This commit is contained in:
2021-10-24 20:02:11 +02:00
parent 6e831c66be
commit b99fb35727
2 changed files with 58 additions and 17 deletions

View File

@@ -20,6 +20,7 @@ from settings import Settings
class BigText(QWidget):
_byte_offset = 0
_left_offset = 0
scroll_lines = 0
highlights: [Highlight] = []
@@ -42,6 +43,14 @@ class BigText(QWidget):
def paintEvent(self, event: QPaintEvent) -> None:
self.draw()
def wheelEvent(self, event: QWheelEvent):
direction = 1 if event.angleDelta().y() > 0 else -1
#print("wheel event fired :) %s" % (direction))
self.scroll_lines = direction * 3
self.update()
#self.draw(direction * 3)
#self._vscrollbar.setValue(self._byte_offset)
def mousePressEvent(self, e: QMouseEvent) -> None:
if e.buttons() == Qt.MouseButton.LeftButton:
offset = self.to_byte_offset(e)
@@ -80,7 +89,9 @@ class BigText(QWidget):
self.update_font_metrics(painter)
lines_to_show = self.height() / (self.fontMetrics().height())
self.lines = self.model.data(self._byte_offset, lines_to_show)
self.lines = self.model.data(self._byte_offset, self.scroll_lines, lines_to_show)
self.scroll_lines=0
self._byte_offset = self.lines[0].byte_offset()
# draw hightlights first - some characters may overlap to the next line
# by drawing the background hightlights first we prevent that the hightlight