From cb4fc7905b8215c520039db743375c1cddddc800 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 6 Jan 2024 09:22:34 +0530 Subject: [PATCH] Fix a regression in the previous release that caused comments in the Book details panel to be rendered below rather than at the side of the other information --- src/calibre/gui2/book_details.py | 46 +++++++++++++++++++++------ src/calibre/gui2/central.py | 2 +- src/calibre/gui2/dialogs/book_info.py | 2 +- src/calibre/gui2/init.py | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 56235d57d7..6576744b1d 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -287,6 +287,17 @@ def render_html(mi, vertical, widget, all_fields=False, render_data_func=None, ans = str(col.name()) return ans + comments = '' + if comment_fields: + comments = '\n'.join('
%s
' % x for x in comment_fields) + # Comments cause issues with rendering in QTextBrowser + comments = comments_pat().sub('', comments) + + html = render_parts(table, comments, vertical) + return html, table, comments + + +def render_parts(table, comments, vertical): templ = '''\ @@ -295,11 +306,6 @@ def render_html(mi, vertical, widget, all_fields=False, render_data_func=None, '''%('vertical' if vertical else 'horizontal') - comments = '' - if comment_fields: - comments = '\n'.join('
%s
' % x for x in comment_fields) - # Comments cause issues with rendering in QTextBrowser - comments = comments_pat().sub('', comments) right_pane = comments if vertical: @@ -712,7 +718,7 @@ class CoverView(QWidget): # {{{ def __init__(self, vertical, parent=None): QWidget.__init__(self, parent) self._current_pixmap_size = QSize(120, 120) - self.vertical = vertical + self.change_layout(vertical) self.animation = QPropertyAnimation(self, b'current_pixmap_size', self) self.animation.setEasingCurve(QEasingCurve(QEasingCurve.Type.OutExpo)) @@ -720,9 +726,6 @@ class CoverView(QWidget): # {{{ self.animation.setStartValue(QSize(0, 0)) self.animation.valueChanged.connect(self.value_changed) - self.setSizePolicy( - QSizePolicy.Policy.Expanding if vertical else QSizePolicy.Policy.Minimum, - QSizePolicy.Policy.Expanding) self.default_pixmap = QApplication.instance().cached_qpixmap('default_cover.png', device_pixel_ratio=self.devicePixelRatio()) self.pixmap = self.default_pixmap @@ -732,6 +735,12 @@ class CoverView(QWidget): # {{{ self.do_layout() + def change_layout(self, vertical): + self.vertical = vertical + self.setSizePolicy( + QSizePolicy.Policy.Expanding if vertical else QSizePolicy.Policy.Minimum, + QSizePolicy.Policy.Expanding) + def value_changed(self, val): self.update() @@ -988,6 +997,7 @@ class BookInfo(HTMLDisplay): def __init__(self, vertical, parent=None): HTMLDisplay.__init__(self, parent=parent, save_resources_in_document=False) self.vertical = vertical + self.last_rendered_html = '', '', '' self.anchor_clicked.connect(self.link_activated) for x, icon in [ ('remove_format', 'trash.png'), ('save_format', 'save.png'), @@ -1015,6 +1025,14 @@ class BookInfo(HTMLDisplay): self.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.setDefaultStyleSheet(css()) + def change_layout(self, vertical): + if vertical != self.vertical: + self.vertical = vertical + if self.last_rendered_html[0]: + html = render_parts(self.last_rendered_html[1], self.last_rendered_html[2], self.vertical) + self.last_rendered_html = html, self.last_rendered_html[1], self.last_rendered_html[2] + self.setHtml(html) + def refresh_css(self): self.setDefaultStyleSheet(css(True)) @@ -1069,7 +1087,7 @@ class BookInfo(HTMLDisplay): self.link_clicked.emit(link) def show_data(self, mi): - html = render_html(mi, self.vertical, self.parent()) + html, table, comments = self.last_rendered_html = render_html(mi, self.vertical, self.parent()) set_html(mi, html, self) def process_external_css(self, css): @@ -1319,6 +1337,14 @@ class BookDetails(DetailsLayout): # {{{ self.book_info.edit_identifiers.connect(self.edit_identifiers) self.setCursor(Qt.CursorShape.PointingHandCursor) + def change_layout(self, vertical): + if vertical != self.vertical: + self.vertical = vertical + self.cover_view.change_layout(vertical) + self.book_info.change_layout(vertical) + self.setOrientation(Qt.Orientation.Vertical if self.vertical else Qt.Orientation.Horizontal) + self.do_layout(self.rect()) + def search_internet(self, data): if self.last_data: if data.author is None: diff --git a/src/calibre/gui2/central.py b/src/calibre/gui2/central.py index 7ed6cc7a7d..4e0766cc7e 100644 --- a/src/calibre/gui2/central.py +++ b/src/calibre/gui2/central.py @@ -399,7 +399,7 @@ class CentralContainer(QWidget): ss = self.serialized_settings() before = ss[self.layout.name + '_visibility'] after = ss[layout.name + '_visibility'] - gui.book_details.vertical = is_wide + gui.book_details.change_layout(is_wide) self.layout = layout self.write_settings() # apply visibility changes by clicking buttons to ensure button diff --git a/src/calibre/gui2/dialogs/book_info.py b/src/calibre/gui2/dialogs/book_info.py index 4bd0931111..2af465b97d 100644 --- a/src/calibre/gui2/dialogs/book_info.py +++ b/src/calibre/gui2/dialogs/book_info.py @@ -419,7 +419,7 @@ class BookInfo(QDialog): self.cover_pixmap.setDevicePixelRatio(dpr) self.marked = mi.marked self.resize_cover() - html = render_html(mi, True, self, pref_name='popup_book_display_fields') + html = render_html(mi, True, self, pref_name='popup_book_display_fields')[0] set_html(mi, html, self.details) self.update_cover_tooltip() diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 272ce00971..f9b1e085fb 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -733,7 +733,7 @@ class LayoutMixin: # {{{ def read_layout_settings(self): # View states are restored automatically when set_database is called self.layout_container.read_settings() - self.book_details.vertical = self.layout_container.is_wide + self.book_details.change_layout(self.layout_container.is_wide) self.place_layout_buttons() self.grid_view_button.restore_state() self.search_bar_button.restore_state()