From 219c880cde7685ab081ad64b48b73a196d9c4c82 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Wed, 21 Jan 2026 08:48:28 +0100 Subject: [PATCH] Bookshelf: make outline colors customisable --- src/calibre/gui2/library/bookshelf_view.py | 12 +++++++----- .../preferences/look_feel_tabs/bookshelf_view.py | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/library/bookshelf_view.py b/src/calibre/gui2/library/bookshelf_view.py index 2fc86ff18b..95d11054aa 100644 --- a/src/calibre/gui2/library/bookshelf_view.py +++ b/src/calibre/gui2/library/bookshelf_view.py @@ -224,6 +224,8 @@ class WoodTheme(NamedTuple): class ColorTheme(NamedTuple): text_color_for_dark_background: QColor text_color_for_light_background: QColor + outline_color_for_dark_background: QColor + outline_color_for_light_background: QColor # Divider colors divider_text_color: QColor @@ -240,6 +242,8 @@ class ColorTheme(NamedTuple): return ColorTheme( text_color_for_dark_background=dark_palette().color(QPalette.ColorRole.WindowText), text_color_for_light_background=light_palette().color(QPalette.ColorRole.WindowText), + outline_color_for_dark_background=QColor(0, 0, 0), + outline_color_for_light_background=QColor(255, 255, 255), divider_text_color=palette.color(QPalette.ColorRole.WindowText), current_selected_color=palette.color(QPalette.ColorRole.LinkVisited), current_color=palette.color(QPalette.ColorRole.Mid), @@ -1421,8 +1425,6 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): def __init__(self, gui): super().__init__(gui) - self.text_color_for_dark_background = QColor() - self.text_color_for_light_background = QColor() self.auto_scroll = True self.scroll_to_current_after_layout: bool = False self.theme: ColorTheme = None @@ -2245,11 +2247,11 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): def get_contrasting_text_color(self, background_color: QColor) -> tuple[QColor, QColor]: if not background_color or not background_color.isValid(): - return self.theme.text_color_for_light_background, self.theme.text_color_for_dark_background + return self.theme.text_color_for_light_background, self.theme.outline_color_for_light_background if (contrast_ratio(background_color, self.theme.text_color_for_dark_background) > contrast_ratio(background_color, self.theme.text_color_for_light_background)): - return self.theme.text_color_for_dark_background, self.theme.text_color_for_light_background - return self.theme.text_color_for_light_background, self.theme.text_color_for_dark_background + return self.theme.text_color_for_dark_background, self.theme.outline_color_for_dark_background + return self.theme.text_color_for_light_background, self.theme.outline_color_for_light_background # Selection methods (required for AlternateViews integration) diff --git a/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py b/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py index 50ece28d69..db7527b2ad 100644 --- a/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py +++ b/src/calibre/gui2/preferences/look_feel_tabs/bookshelf_view.py @@ -261,8 +261,10 @@ def evaluate(book, context): @lru_cache(maxsize=2) def color_label_map(self) -> dict[str, str]: return { - 'text_color_for_dark_background': _('Text on &dark spine background'), 'text_color_for_light_background': _('Text on &light spine background'), + 'text_color_for_dark_background': _('Text on &dark spine background'), + 'outline_color_for_light_background': _('&Outline on light spine background'), + 'outline_color_for_dark_background': _('Outli&ne on dark spine background'), 'divider_background_color': _('Divider &background'), 'divider_line_color': _('&Line on the divider'), 'divider_text_color': _('Text on the ÷r'),