Move CSS used for book display title cells into book_details.css

Fixes #1999 (Fix book details rendering and customization)
This commit is contained in:
Kovid Goyal 2023-08-18 22:11:14 +05:30
parent d0a189e2a1
commit cd8af8ca11
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 18 additions and 16 deletions

View File

@ -29,7 +29,10 @@ table.fields td {
}
table.fields td.title {
font-weight: bold
font-weight: normal;
font-style: italic;
color: palette(placeholder-text);
text-align: right;
}
.series_name {

View File

@ -93,7 +93,7 @@ def mi_to_html(
mi,
field_list=None, default_author_link=None, use_roman_numbers=True,
rating_font='Liberation Serif', rtl=False, comments_heading_pos='hide',
for_qt=False, vertical_fields=(), show_links=True, gray='#7f7f7f',
for_qt=False, vertical_fields=(), show_links=True,
):
link_markup = '↗️'
@ -426,11 +426,7 @@ def mi_to_html(
classname(fieldl), html) for fieldl, html in ans]
# print '\n'.join(ans)
direction = 'rtl' if rtl else 'ltr'
rans = (
'<style>table.fields td { vertical-align:top} table.fields td.title {'
f'text-align: right; color: {gray}; font-style: italic; font-weight: normal '
'}</style>'
'<table class="fields" style="direction: %s; ' % direction)
rans = f'<table class="fields" style="direction: {direction}; '
if not for_qt:
# This causes wasted space at the edge of the table in Qt's rich text
# engine, see https://bugs.launchpad.net/calibre/+bug/1881488

View File

@ -292,15 +292,11 @@ def render_data(mi, use_roman_numbers=True, all_fields=False, pref_name='book_di
field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata),
pref_name=pref_name, mi=mi)
field_list = [(x, all_fields or display) for x, display in field_list]
gray = '#666'
app = QApplication.instance()
if app is not None and app.is_dark_theme:
gray = app.palette().color(QPalette.ColorRole.PlaceholderText).name()
return mi_to_html(
mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(),
rating_font=rating_font(), default_author_link=default_author_link(),
comments_heading_pos=gprefs['book_details_comments_heading_pos'], for_qt=True,
vertical_fields=vertical_fields, show_links=show_links, gray=gray
vertical_fields=vertical_fields, show_links=show_links
)
# }}}
@ -980,6 +976,10 @@ class BookInfo(HTMLDisplay):
html = render_html(mi, self.vertical, self.parent())
set_html(mi, html, self)
def process_external_css(self, css):
col = self.palette().color(QPalette.ColorRole.PlaceholderText).name() if QApplication.instance().is_dark_theme else '#666'
return css.replace('palette(placeholder-text)', col)
def mouseDoubleClickEvent(self, ev):
v = self.viewport()
if v.rect().contains(self.mapFromGlobal(ev.globalPos())):

View File

@ -288,7 +288,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
def __init__(self, parent=None):
QTextEdit.__init__(self, parent)
self.setTabChangesFocus(True)
self.document().setDefaultStyleSheet(css() + '\n\nli { margin-top: 0.5ex; margin-bottom: 0.5ex; }')
self.document().setDefaultStyleSheet(css().replace('palette(placeholder-text)', 'gray') + '\n\nli { margin-top: 0.5ex; margin-bottom: 0.5ex; }')
font = self.font()
f = QFontInfo(font)
delta = tweaks['change_book_details_font_size_by'] + 1

View File

@ -17,7 +17,7 @@ class Preview(HTMLDisplay):
def __init__(self, parent=None):
super().__init__(parent)
self.setDefaultStyleSheet(css())
self.setDefaultStyleSheet(css().replace('palette(placeholder-text)', 'gray'))
self.setTabChangesFocus(True)
self.base_url = None

View File

@ -547,7 +547,7 @@ class HTMLDisplay(QTextBrowser):
def setDefaultStyleSheet(self, css=''):
self.external_css = css
self.document().setDefaultStyleSheet(self.default_css + self.external_css)
self.document().setDefaultStyleSheet(self.default_css + self.process_external_css(self.external_css))
def palette_changed(self):
app = QApplication.instance()
@ -557,9 +557,12 @@ class HTMLDisplay(QTextBrowser):
self.default_css = 'a { color: %s }\n\n' % col.name(QColor.NameFormat.HexRgb)
else:
self.default_css = ''
self.document().setDefaultStyleSheet(self.default_css + self.external_css)
self.document().setDefaultStyleSheet(self.default_css + self.process_external_css(self.external_css))
self.setHtml(self.last_set_html)
def process_external_css(self, css):
return css
def on_anchor_clicked(self, qurl):
if not qurl.scheme() and qurl.hasFragment() and qurl.toString().startswith('#'):
frag = qurl.fragment(QUrl.ComponentFormattingOption.FullyDecoded)