mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
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:
parent
d0a189e2a1
commit
cd8af8ca11
@ -29,7 +29,10 @@ table.fields td {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table.fields td.title {
|
table.fields td.title {
|
||||||
font-weight: bold
|
font-weight: normal;
|
||||||
|
font-style: italic;
|
||||||
|
color: palette(placeholder-text);
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.series_name {
|
.series_name {
|
||||||
|
@ -93,7 +93,7 @@ def mi_to_html(
|
|||||||
mi,
|
mi,
|
||||||
field_list=None, default_author_link=None, use_roman_numbers=True,
|
field_list=None, default_author_link=None, use_roman_numbers=True,
|
||||||
rating_font='Liberation Serif', rtl=False, comments_heading_pos='hide',
|
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 = '↗️'
|
link_markup = '↗️'
|
||||||
@ -426,11 +426,7 @@ def mi_to_html(
|
|||||||
classname(fieldl), html) for fieldl, html in ans]
|
classname(fieldl), html) for fieldl, html in ans]
|
||||||
# print '\n'.join(ans)
|
# print '\n'.join(ans)
|
||||||
direction = 'rtl' if rtl else 'ltr'
|
direction = 'rtl' if rtl else 'ltr'
|
||||||
rans = (
|
rans = f'<table class="fields" style="direction: {direction}; '
|
||||||
'<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)
|
|
||||||
if not for_qt:
|
if not for_qt:
|
||||||
# This causes wasted space at the edge of the table in Qt's rich text
|
# This causes wasted space at the edge of the table in Qt's rich text
|
||||||
# engine, see https://bugs.launchpad.net/calibre/+bug/1881488
|
# engine, see https://bugs.launchpad.net/calibre/+bug/1881488
|
||||||
|
@ -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),
|
field_list = get_field_list(getattr(mi, 'field_metadata', field_metadata),
|
||||||
pref_name=pref_name, mi=mi)
|
pref_name=pref_name, mi=mi)
|
||||||
field_list = [(x, all_fields or display) for x, display in field_list]
|
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(
|
return mi_to_html(
|
||||||
mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(),
|
mi, field_list=field_list, use_roman_numbers=use_roman_numbers, rtl=is_rtl(),
|
||||||
rating_font=rating_font(), default_author_link=default_author_link(),
|
rating_font=rating_font(), default_author_link=default_author_link(),
|
||||||
comments_heading_pos=gprefs['book_details_comments_heading_pos'], for_qt=True,
|
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())
|
html = render_html(mi, self.vertical, self.parent())
|
||||||
set_html(mi, html, self)
|
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):
|
def mouseDoubleClickEvent(self, ev):
|
||||||
v = self.viewport()
|
v = self.viewport()
|
||||||
if v.rect().contains(self.mapFromGlobal(ev.globalPos())):
|
if v.rect().contains(self.mapFromGlobal(ev.globalPos())):
|
||||||
|
@ -288,7 +288,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QTextEdit.__init__(self, parent)
|
QTextEdit.__init__(self, parent)
|
||||||
self.setTabChangesFocus(True)
|
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()
|
font = self.font()
|
||||||
f = QFontInfo(font)
|
f = QFontInfo(font)
|
||||||
delta = tweaks['change_book_details_font_size_by'] + 1
|
delta = tweaks['change_book_details_font_size_by'] + 1
|
||||||
|
@ -17,7 +17,7 @@ class Preview(HTMLDisplay):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setDefaultStyleSheet(css())
|
self.setDefaultStyleSheet(css().replace('palette(placeholder-text)', 'gray'))
|
||||||
self.setTabChangesFocus(True)
|
self.setTabChangesFocus(True)
|
||||||
self.base_url = None
|
self.base_url = None
|
||||||
|
|
||||||
|
@ -547,7 +547,7 @@ class HTMLDisplay(QTextBrowser):
|
|||||||
|
|
||||||
def setDefaultStyleSheet(self, css=''):
|
def setDefaultStyleSheet(self, css=''):
|
||||||
self.external_css = 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):
|
def palette_changed(self):
|
||||||
app = QApplication.instance()
|
app = QApplication.instance()
|
||||||
@ -557,9 +557,12 @@ class HTMLDisplay(QTextBrowser):
|
|||||||
self.default_css = 'a { color: %s }\n\n' % col.name(QColor.NameFormat.HexRgb)
|
self.default_css = 'a { color: %s }\n\n' % col.name(QColor.NameFormat.HexRgb)
|
||||||
else:
|
else:
|
||||||
self.default_css = ''
|
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)
|
self.setHtml(self.last_set_html)
|
||||||
|
|
||||||
|
def process_external_css(self, css):
|
||||||
|
return css
|
||||||
|
|
||||||
def on_anchor_clicked(self, qurl):
|
def on_anchor_clicked(self, qurl):
|
||||||
if not qurl.scheme() and qurl.hasFragment() and qurl.toString().startswith('#'):
|
if not qurl.scheme() and qurl.hasFragment() and qurl.toString().startswith('#'):
|
||||||
frag = qurl.fragment(QUrl.ComponentFormattingOption.FullyDecoded)
|
frag = qurl.fragment(QUrl.ComponentFormattingOption.FullyDecoded)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user