From f3f47d0ce77c0f0527fd4ccc6e2552820f81592f Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 1 Nov 2021 19:22:38 +0100 Subject: [PATCH] draw all line backgrounds first --- README.md | 4 +++- bigtext.py | 35 +++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e3e2130..ef3497e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ RavenLog is a viewer for text files of arbitrary length. * Case insensitive filtering enabled by default. * Filter matches are highlighted (can be disabled). * Filter results don't disappear when changing tabs. -* Colored highlighting of lines or matches based on regular expression. +* Colored highlighting based on regular expression filters. +* Different colors for line background and match. * Pleasing color palette. * Highlighters are automatically saved and restored. * Select arbitrary strings (not just fill lines). @@ -18,3 +19,4 @@ RavenLog is a viewer for text files of arbitrary length. * Triple click selects line. * Copy protection: Users is warned before creating a clipboard more than 5 MB in size. They can choose to copy the selection into a new file instead. +* Optionally open a new tab when saving selection as file. diff --git a/bigtext.py b/bigtext.py index e31104b..79276d3 100644 --- a/bigtext.py +++ b/bigtext.py @@ -373,11 +373,13 @@ class InnerBigText(QWidget): # draws over a character y_line_offset = self.char_height; for l in self.lines: + highlight_ranges = [] for h in highlighters: optional_highlight_range = h.compute_highlight(l) if optional_highlight_range: - for highlight in optional_highlight_range: - self.draw_highlight(highlight, painter, y_line_offset) + highlight_ranges = highlight_ranges + optional_highlight_range + + self.draw_highlights(highlight_ranges, painter, y_line_offset) y_line_offset = y_line_offset + self.char_height left_offset = -1 * self._left_offset * self.char_width @@ -388,21 +390,26 @@ class InnerBigText(QWidget): painter.end() - def draw_highlight(self, highlight: HighlightedRange, painter: QPainter, y_line_offset: int): - left_offset = -1 * self._left_offset * self.char_width - x1 = highlight.get_start() * self.char_width - width = highlight.get_width() * self.char_width + def draw_highlights(self, highlights: [HighlightedRange], painter: QPainter, y_line_offset: int): - y1 = y_line_offset - self.char_height + self.char_height / 7 - height = self.char_height + 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(left_offset, y1, full_width, height) + self.highlight_background(painter, rect, highlight.get_brush_full_line()) - if highlight.is_highlight_full_line(): - full_width = Settings.max_line_length() * self.char_width - rect = QRect(left_offset, y1, full_width, height) - self.highlight_background(painter, rect, highlight.get_brush_full_line()) + for highlight in highlights: + left_offset = -1 * self._left_offset * self.char_width + x1 = highlight.get_start() * self.char_width + width = highlight.get_width() * self.char_width + y1 = y_line_offset - self.char_height + self.char_height / 7 + height = self.char_height - rect = QRect(left_offset + x1, y1, width, height) - self.highlight_background(painter, rect, highlight.get_brush()) + rect = QRect(left_offset + x1, y1, width, height) + self.highlight_background(painter, rect, highlight.get_brush()) def highlight_background(self, painter: QPainter, rect: QRect, brush: QBrush): old_brush = painter.brush()