From ef7694fdc6738f1ccaed568f90bd76d50c6488d0 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 18 Dec 2022 19:23:14 +0100 Subject: [PATCH 1/5] only draw visible text --- src/ui/bigtext/bigtext.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/bigtext/bigtext.py b/src/ui/bigtext/bigtext.py index c4a3207..719bb64 100644 --- a/src/ui/bigtext/bigtext.py +++ b/src/ui/bigtext/bigtext.py @@ -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,12 +504,17 @@ 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 - 1) + 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): From d0fb7d43621e5dd114ab03f9c372efe46eb01bd0 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 18 Dec 2022 19:26:02 +0100 Subject: [PATCH 2/5] only draw visible full line background instead of maximal possible width --- src/ui/bigtext/bigtext.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ui/bigtext/bigtext.py b/src/ui/bigtext/bigtext.py index 719bb64..345a848 100644 --- a/src/ui/bigtext/bigtext.py +++ b/src/ui/bigtext/bigtext.py @@ -520,11 +520,9 @@ class InnerBigText(QWidget): 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: From addca937c501cc57345d7c41fc857e3c1a380be4 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 18 Dec 2022 19:37:36 +0100 Subject: [PATCH 3/5] only draw visible highlight --- src/ui/bigtext/bigtext.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ui/bigtext/bigtext.py b/src/ui/bigtext/bigtext.py index 345a848..38f5b30 100644 --- a/src/ui/bigtext/bigtext.py +++ b/src/ui/bigtext/bigtext.py @@ -504,7 +504,7 @@ class InnerBigText(QWidget): y_line_offset = self.char_height for line in self.lines: text = line.line_prepared_for_display() - leftmost_visible_char_index = line.column_to_char(self._left_offset - 1) + 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 @@ -532,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): From 493649dad5ef7e1914ada7598fd03ff9d3491891 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 18 Dec 2022 19:57:45 +0100 Subject: [PATCH 4/5] skip highlighter when query is empty --- src/ui/bigtext/highlight_regex.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ui/bigtext/highlight_regex.py b/src/ui/bigtext/highlight_regex.py index 543f6d7..7e840a4 100644 --- a/src/ui/bigtext/highlight_regex.py +++ b/src/ui/bigtext/highlight_regex.py @@ -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: From 209ad71235763d100176bfcf33af8a76cda8e6ac Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 19 Dec 2022 16:18:39 +0100 Subject: [PATCH 5/5] don't use anti aliasing for horizontal line when drawing handle --- src/ui/rangeslider.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/rangeslider.py b/src/ui/rangeslider.py index 9b2e403..950e4ca 100644 --- a/src/ui/rangeslider.py +++ b/src/ui/rangeslider.py @@ -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)))