mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Make drawing of annotations existence dot more robust in annots browser
This commit is contained in:
parent
d129c3b2a5
commit
9e74f75bee
@ -79,7 +79,7 @@ class AnnotsResultsDelegate(ResultsDelegate):
|
|||||||
|
|
||||||
def result_data(self, result):
|
def result_data(self, result):
|
||||||
if not isinstance(result, dict):
|
if not isinstance(result, dict):
|
||||||
return None, None, None, None
|
return None, None, None, None, None
|
||||||
full_text = result['text'].replace('\x1f', ' ')
|
full_text = result['text'].replace('\x1f', ' ')
|
||||||
parts = full_text.split('\x1d', 2)
|
parts = full_text.split('\x1d', 2)
|
||||||
before = after = ''
|
before = after = ''
|
||||||
@ -90,9 +90,7 @@ class AnnotsResultsDelegate(ResultsDelegate):
|
|||||||
before, text = parts
|
before, text = parts
|
||||||
else:
|
else:
|
||||||
text = parts[0]
|
text = parts[0]
|
||||||
if result.get('annotation', {}).get('notes'):
|
return False, before, text, after, bool(result.get('annotation', {}).get('notes'))
|
||||||
before = '•' + (before or '')
|
|
||||||
return False, before, text, after
|
|
||||||
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -19,13 +19,13 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def result_data(self, result):
|
def result_data(self, result):
|
||||||
if not hasattr(result, 'is_hidden'):
|
if not hasattr(result, 'is_hidden'):
|
||||||
return None, None, None, None
|
return None, None, None, None, None
|
||||||
return result.is_hidden, result.before, result.text, result.after
|
return result.is_hidden, result.before, result.text, result.after, False
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
QStyledItemDelegate.paint(self, painter, option, index)
|
QStyledItemDelegate.paint(self, painter, option, index)
|
||||||
result = index.data(Qt.ItemDataRole.UserRole)
|
result = index.data(Qt.ItemDataRole.UserRole)
|
||||||
is_hidden, result_before, result_text, result_after = self.result_data(result)
|
is_hidden, result_before, result_text, result_after, show_leading_dot = self.result_data(result)
|
||||||
if result_text is None:
|
if result_text is None:
|
||||||
return
|
return
|
||||||
painter.save()
|
painter.save()
|
||||||
@ -45,6 +45,8 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
|
|||||||
rect = option.rect.adjusted(option.decorationSize.width() + 4 if is_hidden else 0, 0, 0, 0)
|
rect = option.rect.adjusted(option.decorationSize.width() + 4 if 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:
|
||||||
|
before = '•' + before
|
||||||
before_width = 0
|
before_width = 0
|
||||||
if before:
|
if before:
|
||||||
before_width = painter.boundingRect(rect, flags, before).width()
|
before_width = painter.boundingRect(rect, flags, before).width()
|
||||||
@ -58,6 +60,8 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
|
|||||||
match_width = painter.boundingRect(rect, flags, text).width()
|
match_width = painter.boundingRect(rect, flags, text).width()
|
||||||
if match_width >= rect.width() - 3 * ellipsis_width:
|
if match_width >= rect.width() - 3 * ellipsis_width:
|
||||||
efm = QFontMetrics(emphasis_font)
|
efm = QFontMetrics(emphasis_font)
|
||||||
|
if show_leading_dot:
|
||||||
|
text = '•' + text
|
||||||
text = efm.elidedText(text, Qt.TextElideMode.ElideRight, rect.width())
|
text = efm.elidedText(text, Qt.TextElideMode.ElideRight, rect.width())
|
||||||
painter.drawText(rect, flags, text)
|
painter.drawText(rect, flags, text)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user