Make drawing of annotations existence dot more robust in annots browser

This commit is contained in:
Kovid Goyal 2020-12-10 21:51:02 +05:30
parent d129c3b2a5
commit 9e74f75bee
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 7 deletions

View File

@ -79,7 +79,7 @@ class AnnotsResultsDelegate(ResultsDelegate):
def result_data(self, result):
if not isinstance(result, dict):
return None, None, None, None
return None, None, None, None, None
full_text = result['text'].replace('\x1f', ' ')
parts = full_text.split('\x1d', 2)
before = after = ''
@ -90,9 +90,7 @@ class AnnotsResultsDelegate(ResultsDelegate):
before, text = parts
else:
text = parts[0]
if result.get('annotation', {}).get('notes'):
before = '' + (before or '')
return False, before, text, after
return False, before, text, after, bool(result.get('annotation', {}).get('notes'))
# }}}

View File

@ -19,13 +19,13 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
def result_data(self, result):
if not hasattr(result, 'is_hidden'):
return None, None, None, None
return result.is_hidden, result.before, result.text, result.after
return None, None, None, None, None
return result.is_hidden, result.before, result.text, result.after, False
def paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, index)
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:
return
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)
painter.setClipRect(rect)
before = re.sub(r'\s+', ' ', result_before)
if show_leading_dot:
before = '' + before
before_width = 0
if before:
before_width = painter.boundingRect(rect, flags, before).width()
@ -58,6 +60,8 @@ class ResultsDelegate(QStyledItemDelegate): # {{{
match_width = painter.boundingRect(rect, flags, text).width()
if match_width >= rect.width() - 3 * ellipsis_width:
efm = QFontMetrics(emphasis_font)
if show_leading_dot:
text = '' + text
text = efm.elidedText(text, Qt.TextElideMode.ElideRight, rect.width())
painter.drawText(rect, flags, text)
else: