mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Annotations browser: Show highlight color in the preview panel. Fixes #1934204 [Enhancement Request: Display highlight colour in Annotation Browser](https://bugs.launchpad.net/calibre/+bug/1934204)
This commit is contained in:
parent
ae81ae2b72
commit
e9ea68aee2
@ -17,10 +17,14 @@ from qt.core import (
|
|||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from calibre import prepare_string_for_xml
|
from calibre import prepare_string_for_xml
|
||||||
|
from calibre.constants import (
|
||||||
|
builtin_colors_dark, builtin_colors_light, builtin_decorations
|
||||||
|
)
|
||||||
from calibre.db.backend import FTSQueryError
|
from calibre.db.backend import FTSQueryError
|
||||||
from calibre.ebooks.metadata import authors_to_string, fmt_sidx
|
from calibre.ebooks.metadata import authors_to_string, fmt_sidx
|
||||||
from calibre.gui2 import (
|
from calibre.gui2 import (
|
||||||
Application, choose_save_file, config, error_dialog, gprefs, safe_open_url
|
Application, choose_save_file, config, error_dialog, gprefs, is_dark_theme,
|
||||||
|
safe_open_url
|
||||||
)
|
)
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
||||||
@ -184,6 +188,35 @@ def sorted_items(items):
|
|||||||
return sorted(items, key=sort_key)
|
return sorted(items, key=sort_key)
|
||||||
|
|
||||||
|
|
||||||
|
def css_for_highlight_style(style):
|
||||||
|
is_dark = is_dark_theme()
|
||||||
|
kind = style.get('kind')
|
||||||
|
ans = ''
|
||||||
|
if kind == 'color':
|
||||||
|
key = 'dark' if is_dark else 'light'
|
||||||
|
val = style.get(key)
|
||||||
|
if val is None:
|
||||||
|
which = style.get('which')
|
||||||
|
val = (builtin_colors_dark if is_dark else builtin_colors_light).get(which)
|
||||||
|
if val is None:
|
||||||
|
val = style.get('background-color')
|
||||||
|
if val is not None:
|
||||||
|
ans = f'background-color: {val}'
|
||||||
|
elif 'background-color' in style:
|
||||||
|
ans = 'background-color: ' + style['background-color']
|
||||||
|
if 'color' in style:
|
||||||
|
ans += '; color: ' + style["color"]
|
||||||
|
elif kind == 'decoration':
|
||||||
|
which = style.get('which')
|
||||||
|
if which is not None:
|
||||||
|
q = builtin_decorations.get(which)
|
||||||
|
if q is not None:
|
||||||
|
ans = q
|
||||||
|
else:
|
||||||
|
ans = '; '.join(f'{k}: {v}' for k, v in style.items())
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
class Export(Dialog): # {{{
|
class Export(Dialog): # {{{
|
||||||
|
|
||||||
prefs = gprefs
|
prefs = gprefs
|
||||||
@ -800,6 +833,7 @@ class DetailsPanel(QWidget):
|
|||||||
book_format = r['format']
|
book_format = r['format']
|
||||||
annot_text = ''
|
annot_text = ''
|
||||||
a = prepare_string_for_xml
|
a = prepare_string_for_xml
|
||||||
|
highlight_css = ''
|
||||||
|
|
||||||
paras = []
|
paras = []
|
||||||
|
|
||||||
@ -819,6 +853,8 @@ class DetailsPanel(QWidget):
|
|||||||
else:
|
else:
|
||||||
paras.append('<p><a title="{}" href="calibre://edit_result">{}</a></p>'.format(
|
paras.append('<p><a title="{}" href="calibre://edit_result">{}</a></p>'.format(
|
||||||
_('Add notes to this highlight'), _('Add notes')))
|
_('Add notes to this highlight'), _('Add notes')))
|
||||||
|
if 'style' in annot:
|
||||||
|
highlight_css = css_for_highlight_style(annot['style'])
|
||||||
|
|
||||||
annot_text += '\n'.join(paras)
|
annot_text += '\n'.join(paras)
|
||||||
date = QDateTime.fromString(annot['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(Qt.DateFormat.SystemLocaleShortDate)
|
date = QDateTime.fromString(annot['timestamp'], Qt.DateFormat.ISODate).toLocalTime().toString(Qt.DateFormat.SystemLocaleShortDate)
|
||||||
@ -830,6 +866,7 @@ class DetailsPanel(QWidget):
|
|||||||
<div style="text-align: center">{series}</div>
|
<div style="text-align: center">{series}</div>
|
||||||
<div> </div>
|
<div> </div>
|
||||||
<div> </div>
|
<div> </div>
|
||||||
|
|
||||||
<div>{dt}: {date}</div>
|
<div>{dt}: {date}</div>
|
||||||
<div>{ut}: {user}</div>
|
<div>{ut}: {user}</div>
|
||||||
<div>
|
<div>
|
||||||
@ -837,12 +874,12 @@ class DetailsPanel(QWidget):
|
|||||||
<span>\xa0\xa0\xa0</span>
|
<span>\xa0\xa0\xa0</span>
|
||||||
<a title="{sictt}" href="calibre://show_in_library">{sic}</a>
|
<a title="{sictt}" href="calibre://show_in_library">{sic}</a>
|
||||||
</div>
|
</div>
|
||||||
<h3 style="text-align: left">{atype}</h3>
|
<h3 style="text-align: left; {highlight_css}">{atype}</h3>
|
||||||
{text}
|
{text}
|
||||||
'''.format(
|
'''.format(
|
||||||
title=a(title), authors=a(authors), series=a(series_text), book_format=a(book_format),
|
title=a(title), authors=a(authors), series=a(series_text), book_format=a(book_format),
|
||||||
atype=a(atype), text=annot_text, dt=_('Date'), date=a(date), ut=a(_('User')),
|
atype=a(atype), text=annot_text, dt=_('Date'), date=a(date), ut=a(_('User')),
|
||||||
user=a(friendly_username(r['user_type'], r['user'])),
|
user=a(friendly_username(r['user_type'], r['user'])), highlight_css=highlight_css,
|
||||||
ov=a(_('Open in viewer')), sic=a(_('Show in calibre')),
|
ov=a(_('Open in viewer')), sic=a(_('Show in calibre')),
|
||||||
ovtt=a(_('Open the book at this annotation in the calibre E-book viewer')),
|
ovtt=a(_('Open the book at this annotation in the calibre E-book viewer')),
|
||||||
sictt=(_('Show this book in the main calibre book list')),
|
sictt=(_('Show this book in the main calibre book list')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user