Merge pull request 'only-draw-visible-stuff' (#2) from only-draw-visible-stuff into master

Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2022-12-19 17:00:19 +00:00
3 changed files with 24 additions and 8 deletions

View File

@@ -131,7 +131,7 @@ class BigText(QWidget):
# noinspection PyArgumentList,PyTypeChecker
class InnerBigText(QWidget):
_byte_offset = 0
_left_offset = 0
_left_offset = 0 # number of characters the horizontal scrollbar was moved to the right
scroll_lines = 0
longest_line = 0
@@ -504,22 +504,25 @@ class InnerBigText(QWidget):
y_line_offset = self.char_height
for line in self.lines:
text = line.line_prepared_for_display()
painter.drawText(left_offset, y_line_offset, text)
leftmost_visible_char_index = line.column_to_char(self._left_offset)
rightmost_visible_char_index = line.column_to_char(self._left_offset + math.ceil(self.columns_shown()))
text = text[
leftmost_visible_char_index:rightmost_visible_char_index] # reduce string to the visible section before drawing
painter.drawText(0, y_line_offset, text)
# painter.drawText(left_offset, y_line_offset, text)
y_line_offset = y_line_offset + self.char_height
painter.end()
end_ns = time.process_time_ns()
#print(f"paint took {(end_ns - start_ns) / 1000000.0}")
print(f"paint took {(end_ns - start_ns) / 1000000.0}")
def draw_highlights(self, highlights: [HighlightedRange], painter: QPainter, y_line_offset: int):
for highlight in highlights:
if highlight.is_highlight_full_line():
left_offset = -1 * self._left_offset * self.char_width
y1 = y_line_offset - self.char_height + self.char_height / 7
height = self.char_height
full_width = Settings.max_line_length() * self.char_width
rect = QRect(round(left_offset), round(y1), round(full_width), round(height))
rect = QRect(0, round(y1), self.width(), round(height))
self.highlight_background(painter, rect, highlight.get_brush_full_line())
for highlight in highlights:
@@ -529,7 +532,13 @@ class InnerBigText(QWidget):
y1 = y_line_offset - self.char_height + self.char_height / 7
height = self.char_height
rect = QRect(round(x1 - left_offset), round(y1), round(width), round(height))
left = round(x1 - left_offset)
if x1 + width < left_offset \
or x1 > left_offset + self.width():
# too far left or too far right
continue
rect = QRect(left, round(y1), round(width), round(height))
self.highlight_background(painter, rect, highlight.get_brush())
def highlight_background(self, painter: QPainter, rect: QRect, brush: QBrush):

View File

@@ -35,6 +35,12 @@ class HighlightRegex(Highlight):
def compute_highlight(self, line: Line) -> Optional[List[HighlightedRange]]:
result = []
if len(self.query) == 0:
# query is empty - this would result in many hits and is quite expensive
# This happens with the highlighter we use for the selected text and maybe for the current filter query.
return result
# print("execute regex: %s in %s" % (self.regex, line.line()))
match_iter = re.finditer(self.regex, line.line())
for match in match_iter:

View File

@@ -101,8 +101,9 @@ class RangeSlider(QWidget):
painter.setBrush(to_qcolor("dddddd"))
painter.setPen(to_qcolor("444444"))
painter.setRenderHint(PySide6.QtGui.QPainter.RenderHint.Antialiasing, True)
painter.setRenderHint(PySide6.QtGui.QPainter.RenderHint.Antialiasing, False)
painter.drawLine(2, y_pixel, 18, y_pixel)
painter.setRenderHint(PySide6.QtGui.QPainter.RenderHint.Antialiasing, True)
painter.drawPolygon(
(QPoint(10, y_pixel), QPoint(18, y_pixel + 12 * direction), QPoint(2, y_pixel + 12 * direction)))