# HG changeset patch
# User Peter Demcak <
majs...@gmail.com>
# Date 1772737173 -3600
# Thu Mar 05 19:59:33 2026 +0100
# Node ID fe7f62674b3ee739f4dd06816712b5cd6ac7a4ac
# Parent 14c976e0c44030e3eb9c560d0428411a07888a3d
chunks: add dark theme support for margin and chunk markers
- Apply dark theme colors to Scintilla margin (background and foreground)
- Create custom 12x16 checkbox pixmaps on Windows where the margin is
narrower, using theme-aware colors instead of system defaults
- Set dark theme color for the vertical line marker separating chunks
- Reapply dark theme colors after setLexer() resets marker colors,
including the divider and selected chunk background
diff -r 14c976e0c440 -r fe7f62674b3e tortoisehg/hgqt/chunks.py
--- a/tortoisehg/hgqt/chunks.py Thu Mar 05 19:58:58 2026 +0100
+++ b/tortoisehg/hgqt/chunks.py Thu Mar 05 19:59:33 2026 +0100
@@ -9,6 +9,7 @@
import os
import re
+import sys
from . import qsci as Qsci
from .qtcore import (
@@ -29,6 +30,8 @@
QLabel,
QMenu,
QPainter,
+ QPixmap,
+ QPen,
QSplitter,
QStyle,
QToolBar,
@@ -61,6 +64,8 @@
visdiff,
)
+from .theme import THEME
+
# TODO
# Add support for tools like TortoiseMerge that help resolve rejected chunks
@@ -621,15 +626,32 @@
self.sci.setMarginSensitivity(1, True)
self.sci.marginClicked.connect(self.marginClicked)
- self._checkedpix = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_On,
+ if THEME.enabled:
+ # Dark theme colors for margin (line number / markers area)
+ self.sci.setMarginsBackgroundColor(THEME.backgroundLighter)
+ self.sci.setMarginsForegroundColor(THEME.control_text)
+
+ if THEME.enabled and sys.platform == 'win32':
+ # Draw custom checkboxes for Windows: the margin is 12px wide on this platform
+ # Not needed for Linux, as the margin is 16px wide
+ self._checkedpix = self._create_checkbox_pixmap(True)
+ self._uncheckedpix = self._create_checkbox_pixmap(False)
+ else:
+ self._checkedpix = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_On,
Qt.GlobalColor.gray, self)
+ self._uncheckedpix = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_Off,
+ Qt.GlobalColor.gray, self)
+
+
self.selected = self.sci.markerDefine(self._checkedpix, -1)
-
- self._uncheckedpix = qtlib.getcheckboxpixmap(QStyle.StateFlag.State_Off,
- Qt.GlobalColor.gray, self)
+
self.unselected = self.sci.markerDefine(self._uncheckedpix, -1)
self.vertical = self.sci.markerDefine(qsci.MarkerSymbol.VerticalLine, -1)
+
+ if THEME.enabled:
+ self.sci.setMarkerBackgroundColor(THEME.chunks_vertical_line, self.vertical)
+
self.divider = self.sci.markerDefine(qsci.MarkerSymbol.Background, -1)
self.selcolor = self.sci.markerDefine(qsci.MarkerSymbol.Background, -1)
self.sci.setMarkerBackgroundColor(QColor('#BBFFFF'), self.selcolor)
@@ -654,6 +676,32 @@
self.clearDisplay()
+ def _create_checkbox_pixmap(self, checked):
+ """Create a small checkbox pixmap (12x16) with optional checkmark"""
+ pm = QPixmap(12, 16)
+ pm.fill(Qt.GlobalColor.transparent)
+
+ painter = QPainter(pm)
+ painter.setRenderHint(qtlib.QtPainterRenderHint.Antialiasing, False)
+
+ # Draw rectangle for checkbox
+ color = THEME.diff_text
+ painter.setPen(QPen(color, 1))
+ painter.drawRect(0, 1, 11, 14)
+
+ # Draw checkmark if checked
+ if checked:
+ painter.setPen(QPen(color, 2))
+ painter.setRenderHint(qtlib.QtPainterRenderHint.Antialiasing, True)
+ painter.drawLine(3, 8, 5, 12)
+ painter.drawLine(5, 12, 9, 4)
+ painter.setRenderHint(qtlib.QtPainterRenderHint.Antialiasing, False)
+
+ painter.end()
+ return pm
+
+
+
def loadSettings(self, qs, prefix):
self.sci.loadSettings(qs, prefix)
@@ -816,6 +864,16 @@
self.toggleChunk(c)
self.updateSummary()
+ if THEME.enabled:
+ # Reapply dark theme colors because setLexer() resets marker colors to white
+
+ # Divider between margin and editor text
+ self.sci.setMarkerBackgroundColor(THEME.backgroundLighter, self.divider)
+
+ # Selected chunk background
+ self.sci.setMarkerBackgroundColor(THEME.diff_selected, self.selcolor)
+
+
@pyqtSlot(str, bool, bool, bool)
def find(self, exp, icase=True, wrap=False, forward=True):
self.sci.find(exp, icase, wrap, forward)