mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-30 23:00:21 -04:00
Annotations browser: Add a color swatch in the results list to make seeing the type of highlight easier. See #2109496 (Custom organization of annotations and bookmarks)
This commit is contained in:
parent
041a64958d
commit
5ab3d72ed7
@ -210,6 +210,7 @@ class AnnotsResultsDelegate(ResultsDelegate):
|
|||||||
|
|
||||||
add_ellipsis = False
|
add_ellipsis = False
|
||||||
emphasize_text = False
|
emphasize_text = False
|
||||||
|
has_icons = True
|
||||||
|
|
||||||
def result_data(self, result):
|
def result_data(self, result):
|
||||||
if not isinstance(result, dict):
|
if not isinstance(result, dict):
|
||||||
@ -397,6 +398,8 @@ class ResultsList(QTreeWidget):
|
|||||||
self.currentItemChanged.connect(self.current_item_changed)
|
self.currentItemChanged.connect(self.current_item_changed)
|
||||||
self.number_of_results = 0
|
self.number_of_results = 0
|
||||||
self.item_map = []
|
self.item_map = []
|
||||||
|
self.icon_size = 12
|
||||||
|
self.setIconSize(QSize(self.icon_size, self.icon_size))
|
||||||
|
|
||||||
def show_context_menu(self, pos):
|
def show_context_menu(self, pos):
|
||||||
item = self.itemAt(pos)
|
item = self.itemAt(pos)
|
||||||
@ -438,6 +441,9 @@ class ResultsList(QTreeWidget):
|
|||||||
self.open_annotation.emit(r['book_id'], r['format'], r['annotation'])
|
self.open_annotation.emit(r['book_id'], r['format'], r['annotation'])
|
||||||
|
|
||||||
def set_results(self, results, emphasize_text):
|
def set_results(self, results, emphasize_text):
|
||||||
|
from calibre.gui2.viewer.highlights import decoration_for_style
|
||||||
|
is_dark = is_dark_theme()
|
||||||
|
dpr = self.devicePixelRatioF()
|
||||||
self.clear()
|
self.clear()
|
||||||
self.delegate.emphasize_text = emphasize_text
|
self.delegate.emphasize_text = emphasize_text
|
||||||
self.number_of_results = 0
|
self.number_of_results = 0
|
||||||
@ -463,6 +469,11 @@ class ResultsList(QTreeWidget):
|
|||||||
item.setData(0, Qt.ItemDataRole.UserRole, result)
|
item.setData(0, Qt.ItemDataRole.UserRole, result)
|
||||||
item.setData(0, Qt.ItemDataRole.UserRole + 1, self.number_of_results)
|
item.setData(0, Qt.ItemDataRole.UserRole + 1, self.number_of_results)
|
||||||
self.number_of_results += 1
|
self.number_of_results += 1
|
||||||
|
a = result.get('annotation')
|
||||||
|
if a and (s := a.get('style')):
|
||||||
|
dec = decoration_for_style(self.palette(), s, self.icon_size, dpr, is_dark)
|
||||||
|
if dec:
|
||||||
|
item.setData(0, Qt.ItemDataRole.DecorationRole, dec)
|
||||||
if self.item_map:
|
if self.item_map:
|
||||||
self.setCurrentItem(self.item_map[0])
|
self.setCurrentItem(self.item_map[0])
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
add_ellipsis = True
|
add_ellipsis = True
|
||||||
emphasize_text = True
|
emphasize_text = True
|
||||||
|
has_icons = False
|
||||||
|
|
||||||
def result_data(self, result):
|
def result_data(self, result):
|
||||||
if not hasattr(result, 'is_hidden'):
|
if not hasattr(result, 'is_hidden'):
|
||||||
@ -40,7 +41,7 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
|
|||||||
else:
|
else:
|
||||||
emphasis_font = font
|
emphasis_font = font
|
||||||
flags = Qt.AlignmentFlag.AlignTop | Qt.TextFlag.TextSingleLine | Qt.TextFlag.TextIncludeTrailingSpaces
|
flags = Qt.AlignmentFlag.AlignTop | Qt.TextFlag.TextSingleLine | Qt.TextFlag.TextIncludeTrailingSpaces
|
||||||
rect = option.rect.adjusted(option.decorationSize.width() + 4 if is_hidden else 0, 0, 0, 0)
|
rect = option.rect.adjusted(option.decorationSize.width() + (6 if self.has_icons else 4) if self.has_icons or is_hidden else 0, 0, 0, 0)
|
||||||
painter.setClipRect(rect)
|
painter.setClipRect(rect)
|
||||||
before = re.sub(r'\s+', ' ', result_before)
|
before = re.sub(r'\s+', ' ', result_before)
|
||||||
if show_leading_dot:
|
if show_leading_dot:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user