From 5d0289606d8d2fbc154aaefcb118f85e06057d9c Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 4 Apr 2021 10:34:03 +0100 Subject: [PATCH 1/2] Allow advanced emblem rules to return multiple icon names using the same syntax as icon rules. --- src/calibre/gui2/library/alternate_views.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index dc94eb7623..37734eb956 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -533,9 +533,10 @@ class CoverDelegate(QStyledItemDelegate): for i, (kind, column, rule) in enumerate(emblem_rules): icon_name, mi = self.render_emblem(book_id, rule, i, m.cover_grid_emblem_cache, mi, db, m.formatter, m.cover_grid_template_cache) if icon_name is not None: - pixmap = self.cached_emblem(m.cover_grid_bitmap_cache, icon_name) - if pixmap is not None: - emblems.append(pixmap) + for one_icon in [i.strip() for i in icon_name.split(':') if i.strip()]: + pixmap = self.cached_emblem(m.cover_grid_bitmap_cache, one_icon) + if pixmap is not None: + emblems.append(pixmap) if marked: emblems.insert(0, self.cached_emblem(m.cover_grid_bitmap_cache, ':marked', m.marked_icon)) if on_device: From 85db0feaf1afa5525e498cc0e574601d293ec911 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sun, 4 Apr 2021 10:39:10 +0100 Subject: [PATCH 2/2] 1) Make the 'Separator' class more general by moving it to widgets2 and making it usable in .ui files. 2) Change the template tester to use FlowLayout. --- src/calibre/gui2/dialogs/template_dialog.ui | 67 +++++++-------------- src/calibre/gui2/preferences/coloring.py | 29 +-------- src/calibre/gui2/widgets2.py | 38 +++++++++++- 3 files changed, 61 insertions(+), 73 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui index cb98554c12..6ad74354f2 100644 --- a/src/calibre/gui2/dialogs/template_dialog.ui +++ b/src/calibre/gui2/dialogs/template_dialog.ui @@ -170,9 +170,7 @@ - - - + T&emplate: @@ -184,20 +182,9 @@ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - Qt::Horizontal - - - - 1 - 0 - - - - + + + @@ -211,15 +198,9 @@ you the value as well as all the local variables</p> - - - QFrame::VLine - - - QFrame::Raised - - - 3 + + + go_button @@ -241,15 +222,9 @@ you the value as well as all the local variables</p> - - - QFrame::VLine - - - QFrame::Raised - - - 3 + + + go_button @@ -303,15 +278,9 @@ you the value as well as all the local variables</p> - - - QFrame::VLine - - - QFrame::Raised - - - 3 + + + go_button @@ -773,11 +742,21 @@ you the value as well as all the local variables</p> QPushButton
calibre/gui2/widgets2.h
+ + FlowLayout + QLayout +
calibre/gui2/widgets2.h
+
BoxLayout QBoxLayout
calibre/gui2/dialogs/template_dialog_box_layout.h
+ + Separator + QWidget +
calibre/gui2/widgets2.h
+
CodeEditor QPlainTextEdit diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index f78274d69d..ddf900e1c4 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -22,7 +22,7 @@ from calibre.gui2 import (error_dialog, choose_files, pixmap_to_data, gprefs, choose_save_file, open_local_file) from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.metadata.single_download import RichTextDelegate -from calibre.gui2.widgets2 import ColorButton, FlowLayout +from calibre.gui2.widgets2 import ColorButton, FlowLayout, Separator from calibre.library.coloring import (Rule, conditionable_columns, displayable_columns, rule_from_template, color_row_key) from calibre.utils.localization import lang_map @@ -896,33 +896,6 @@ class RulesView(QListView): # {{{ # }}} -class Separator(QWidget): # {{{ - - def __init__(self, parent, widget_for_height): - QWidget.__init__(self, parent) - self.bcol = QColor(QPalette.ColorRole.Text) - self.update_brush() - self.widget_for_height = widget_for_height - self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.MinimumExpanding) - - def update_brush(self): - self.brush = QBrush(self.bcol) - self.update() - - def sizeHint(self): - return QSize(1, self.widget_for_height.height()) - - def paintEvent(self, ev): - painter = QPainter(self) - # Purely subjective: shorten the line a bit to look 'better' - r = ev.rect() - r.setTop(r.top() + 3) - r.setBottom(r.bottom() - 3) - painter.fillRect(r, self.brush) - painter.end() -# }}} - - class EditRules(QWidget): # {{{ changed = pyqtSignal() diff --git a/src/calibre/gui2/widgets2.py b/src/calibre/gui2/widgets2.py index cc6143e0c3..8920eaf778 100644 --- a/src/calibre/gui2/widgets2.py +++ b/src/calibre/gui2/widgets2.py @@ -10,7 +10,7 @@ from qt.core import ( QFontInfo, QFontMetrics, QIcon, QKeySequence, QLabel, QLayout, QMenu, QMimeData, QPalette, QPixmap, QPoint, QPushButton, QRect, QScrollArea, QSize, QSizePolicy, QStyle, QStyledItemDelegate, Qt, QTabWidget, QTextBrowser, QToolButton, QTextCursor, - QUndoCommand, QUndoStack, QUrl, QWidget, pyqtSignal + QUndoCommand, QUndoStack, QUrl, QWidget, pyqtSignal, QBrush, QPainter ) from calibre.ebooks.metadata import rating_to_stars @@ -439,6 +439,42 @@ class FlowLayout(QLayout): # {{{ return w # }}} +class Separator(QWidget): # {{{ + + ''' Vertical separator lines usable in FlowLayout ''' + + def __init__(self, parent, widget_for_height=None): + ''' + You must provide a widget in the layout either here or with setBuddy. + The height of the separator is computed using this widget, + ''' + QWidget.__init__(self, parent) + self.bcol = QColor(QPalette.ColorRole.Text) + self.update_brush() + self.widget_for_height = widget_for_height + self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.MinimumExpanding) + + def update_brush(self): + self.brush = QBrush(self.bcol) + self.update() + + def setBuddy(self, widget_for_height): + ''' See __init__. This is repurposed to support Qt Designer .ui files. ''' + self.widget_for_height = widget_for_height + + def sizeHint(self): + return QSize(1, 1 if self.widget_for_height is None else self.widget_for_height.height()) + + def paintEvent(self, ev): + painter = QPainter(self) + # Purely subjective: shorten the line a bit to look 'better' + r = ev.rect() + r.setTop(r.top() + 3) + r.setBottom(r.bottom() - 3) + painter.fillRect(r, self.brush) + painter.end() +# }}} + class HTMLDisplay(QTextBrowser):