vertical scroll by keys
This commit is contained in:
26
bigtext.py
26
bigtext.py
@@ -63,6 +63,8 @@ class InnerBigText(QWidget):
|
||||
super(InnerBigText, self).__init__()
|
||||
self.model = model
|
||||
self.parent = parent
|
||||
self.setFocusPolicy(Qt.FocusPolicy.StrongFocus)
|
||||
|
||||
self.font = QFont("monospace", 12)
|
||||
self.update_font_metrics(QPainter(self))
|
||||
self.lines = []
|
||||
@@ -79,10 +81,24 @@ class InnerBigText(QWidget):
|
||||
def paintEvent(self, event: QPaintEvent) -> None:
|
||||
self.draw()
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
lines_to_scroll = math.floor(self.lines_shown()) -1
|
||||
if e.key() == Qt.Key.Key_PageUp:
|
||||
self.scroll_by_lines(lines_to_scroll)
|
||||
if e.key() == Qt.Key.Key_PageDown:
|
||||
self.scroll_by_lines(-lines_to_scroll)
|
||||
if e.key() == 16777235:
|
||||
self.scroll_by_lines(3)
|
||||
if e.key() == 16777237:
|
||||
self.scroll_by_lines(-3)
|
||||
|
||||
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.scroll_by_lines(direction * 3)
|
||||
|
||||
def scroll_by_lines(self, scroll_lines: int):
|
||||
self.scroll_lines = scroll_lines
|
||||
self.update()
|
||||
self.parent.v_scroll_bar.setValue(self._byte_offset)
|
||||
|
||||
@@ -133,14 +149,16 @@ class InnerBigText(QWidget):
|
||||
current_byte = self.model.byte_count()
|
||||
return current_byte
|
||||
|
||||
def lines_shown(self):
|
||||
return self.height() / float(self.char_height)
|
||||
|
||||
def draw(self):
|
||||
painter = QPainter()
|
||||
painter.begin(self)
|
||||
painter = QPainter(self)
|
||||
painter.setFont(self.font)
|
||||
painter.setPen(QColor(0, 0, 0))
|
||||
self.update_font_metrics(painter)
|
||||
|
||||
lines_to_show = self.height() / float(self.char_height)
|
||||
lines_to_show = self.lines_shown()
|
||||
#print("%s / %s = %s" %(self.height(), float(self.char_height), lines_to_show))
|
||||
|
||||
self.lines = self.model.data(self._byte_offset, self.scroll_lines, lines_to_show)
|
||||
|
||||
@@ -17,7 +17,7 @@ class LogFileModel:
|
||||
lines_before_offset: List[Line] = []
|
||||
lines_after_offset: List[Line] = []
|
||||
result: List[Line] = []
|
||||
lines_to_find = lines # + -1 * scroll_lines
|
||||
lines_to_find = lines + abs(scroll_lines)
|
||||
|
||||
with self._lock:
|
||||
# TODO handle lines longer than 4096 bytes
|
||||
|
||||
Reference in New Issue
Block a user