[PATCH 7 of 8 DarkThemeSeries 1] fileview: dark diff/file view colors, lexer styling and chunk checkboxes

0 views
Skip to first unread message

Peter Demcak

unread,
Mar 7, 2026, 1:26:41 PM (3 days ago) Mar 7
to thg...@googlegroups.com
# HG changeset patch
# User Peter Demcak <majs...@gmail.com>
# Date 1772737052 -3600
# Thu Mar 05 19:57:32 2026 +0100
# Node ID 02f645a75099443fb46fdec53801adeed4a0b90d
# Parent 850aefde16bddd4e7fc59327e62edd433d78efcf
fileview: dark diff/file view colors, lexer styling and chunk checkboxes

- Apply THEME marker colors in _DiffViewControl for chunk start markers
and configure Scintilla styles for diff syntax (added/removed/header)
- Use THEME colors for inserted/replaced line markers in _FileViewControl
- Set lexer default paper and text color to THEME values in file view
- Modify chunk-selection checkboxes via _patch_checkbox_pixmap() to avoid
clipping: the margin width is 14px while the default checkbox is 16px.
- Use THEME colors for excluded line markers in _ChunkSelectionViewControl
- Include THEME.enabled in _AnnotateViewControl._isdarktheme flag

diff -r 850aefde16bd -r 02f645a75099 tortoisehg/hgqt/fileview.py
--- a/tortoisehg/hgqt/fileview.py Thu Mar 05 19:57:02 2026 +0100
+++ b/tortoisehg/hgqt/fileview.py Thu Mar 05 19:57:32 2026 +0100
@@ -39,7 +39,9 @@
QKeySequence,
QLabel,
QMouseEvent,
+ QPainter,
QPalette,
+ QPen,
QShortcut,
QStyle,
QToolBar,
@@ -801,7 +803,10 @@

def open(self):
self._sci.markerDefine(qsci.MarkerSymbol.Background, _ChunkStartMarker)
- if qtlib.isDarkTheme(self._sci.palette()):
+
+ if THEME.enabled:
+ self._sci.setMarkerBackgroundColor(THEME.backgroundLighter, _ChunkStartMarker)
+ elif qtlib.isDarkTheme(self._sci.palette()):
self._sci.setMarkerBackgroundColor(QColor('#204820'),
_ChunkStartMarker)
else:
@@ -879,7 +884,10 @@
# define markers for colorize zones of diff
self._sci.markerDefine(qsci.MarkerSymbol.Background, _InsertedLineMarker)
self._sci.markerDefine(qsci.MarkerSymbol.Background, _ReplacedLineMarker)
- if qtlib.isDarkTheme(self._sci.palette()):
+ if THEME.enabled:
+ self._sci.setMarkerBackgroundColor(THEME.diff_added_bg, _InsertedLineMarker)
+ self._sci.setMarkerBackgroundColor(THEME.diff_added2_bg, _ReplacedLineMarker)
+ elif qtlib.isDarkTheme(self._sci.palette()):
self._sci.setMarkerBackgroundColor(QColor('#204820'),
_InsertedLineMarker)
self._sci.setMarkerBackgroundColor(QColor('#202050'),
@@ -935,6 +943,11 @@
lexer = lexers.getlexer(self._ui, filename, fd.contents, self)
newFont = qtlib.getfont('fontlog').font()

+ if THEME.enabled:
+ if lexer:
+ lexer.setDefaultPaper(THEME.background)
+ lexer.setDefaultColor(THEME.text)
+
self._sci.setFont(newFont)
self._sci.setLexer(lexer)
self._sci.setFont(newFont)
@@ -1101,7 +1114,7 @@
self._initAnnotateOptionActions()
self._loadAnnotateSettings()

- self._isdarktheme = qtlib.isDarkTheme(self._sci.palette())
+ self._isdarktheme = THEME.enabled or qtlib.isDarkTheme(self._sci.palette())

def open(self):
self._sci.viewport().installEventFilter(self)
@@ -1429,8 +1442,21 @@
p = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_Off, QColor('#B0FFA0'), sci)
self._sci.markerDefine(p, _ExcludedChunkStartMarker)

+ if THEME.enabled:
+ # Fix rendering of checkboxes in diff view. Default checkboxes are clipped by the margin
+ # width which is 14px, but the actual checkbox pixmap is 16px.
+ p = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_On, THEME.background, sci)
+ self._patch_checkbox_pixmap(p)
+ self._sci.markerDefine(p, _IncludedChunkStartMarker)
+
+ p = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_Off, THEME.background, sci)
+ self._patch_checkbox_pixmap(p)
+ self._sci.markerDefine(p, _ExcludedChunkStartMarker)
+
self._sci.markerDefine(qsci.MarkerSymbol.Background, _ExcludedLineMarker)
- if qtlib.isDarkTheme(self._sci.palette()):
+ if THEME.enabled:
+ bg, fg = THEME.diff_selected, THEME.diff_text
+ elif qtlib.isDarkTheme(self._sci.palette()):
bg, fg = QColor(44, 44, 44), QColor(86, 86, 86)
else:
bg, fg = QColor('lightgrey'), QColor('darkgrey')
@@ -1460,6 +1486,15 @@
self._fd = fd
self._chunkatline = {}

+ def _patch_checkbox_pixmap(self, pm):
+ painter = QPainter(pm)
+ painter.setRenderHint(qtlib.QtPainterRenderHint.Antialiasing, False)
+
+ painter.setPen(QPen(THEME.diff_text))
+ painter.drawRect(1, 0, pm.width() - 1 - 2, pm.height() - 1)
+
+ painter.end()
+
def open(self):
self._sci.setMarginWidth(_ChunkSelectionMargin, 15)
self._toggleshortcut.setEnabled(True)

Reply all
Reply to author
Forward
0 new messages