diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
index 04716a3cb7..463cdf3316 100644
--- a/src/calibre/gui2/__init__.py
+++ b/src/calibre/gui2/__init__.py
@@ -426,6 +426,7 @@ def create_defs():
defs['cover_grid_disk_cache_size'] = 2500
defs['cover_grid_show_title'] = False
defs['cover_grid_texture'] = None
+ defs['cover_grid_corner_radius'] = 0
defs['show_vl_tabs'] = False
defs['vl_tabs_closable'] = True
defs['show_highlight_toggle_button'] = False
diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py
index 69086f512d..e56b7fe9c0 100644
--- a/src/calibre/gui2/library/alternate_views.py
+++ b/src/calibre/gui2/library/alternate_views.py
@@ -10,6 +10,7 @@ import operator
import os
import weakref
from collections import namedtuple
+from contextlib import contextmanager
from functools import wraps
from io import BytesIO
from textwrap import wrap
@@ -36,11 +37,13 @@ from qt.core import (
QMimeData,
QModelIndex,
QPainter,
+ QPainterPath,
QPalette,
QPixmap,
QPoint,
QPropertyAnimation,
QRect,
+ QRectF,
QSize,
QStyledItemDelegate,
QStyleOptionViewItem,
@@ -562,7 +565,8 @@ class CoverDelegate(QStyledItemDelegate):
return ans
def paint(self, painter, option, index):
- QStyledItemDelegate.paint(self, painter, option, empty_index) # draw the hover and selection highlights
+ with self.clip_border_radius(painter, option.rect):
+ QStyledItemDelegate.paint(self, painter, option, empty_index) # draw the hover and selection highlights
m = index.model()
db = m.db
try:
@@ -636,7 +640,7 @@ class CoverDelegate(QStyledItemDelegate):
dy = max(0, int((rect.height() - ch)/2.0))
right_adjust = dx
rect.adjust(dx, dy, -dx, -dy)
- painter.drawPixmap(rect, cdata)
+ self.paint_cover(painter, rect, cdata)
if self.title_height != 0:
self.paint_title(painter, trect, db, book_id)
if self.emblem_size > 0:
@@ -658,6 +662,23 @@ class CoverDelegate(QStyledItemDelegate):
finally:
painter.restore()
+ @contextmanager
+ def clip_border_radius(self, painter, rect):
+ painter.save()
+ r = gprefs['cover_grid_corner_radius']
+ if r > 0:
+ pp = QPainterPath()
+ pp.addRoundedRect(QRectF(rect), r, r)
+ painter.setClipPath(pp)
+ try:
+ yield
+ finally:
+ painter.restore()
+
+ def paint_cover(self, painter: QPainter, rect: QRect, pixmap: QPixmap):
+ with self.clip_border_radius(painter, rect):
+ painter.drawPixmap(rect, pixmap)
+
def paint_title(self, painter, rect, db, book_id):
painter.setRenderHint(QPainter.RenderHint.TextAntialiasing, True)
title, is_stars = self.render_field(db, book_id)
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index f4779d6125..b9fd91a7da 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -626,6 +626,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('bd_show_cover', gprefs)
r('bd_overlay_cover_size', gprefs)
r('cover_grid_width', gprefs)
+ r('cover_grid_corner_radius', gprefs)
r('cover_grid_height', gprefs)
r('cover_grid_cache_size_multiple', gprefs)
r('cover_grid_disk_cache_size', gprefs)
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index b06af273b3..a2965fe220 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -393,36 +393,27 @@
Cover size
- -
-
-
-
- 0
- 0
-
+
-
+
+
+ Make the covers smaller, maintaining current aspect ratio.
- By default, calibre chooses a cover size based on your computer's screen size. You can change the cover size here:
+ &Smaller covers
-
- true
+
+
+ :/images/minus.png:/images/minus.png
- -
-
+
-
+
-
-
-
-
- -
-
-
- Cover &width:
+ Cover &height:
- opt_cover_grid_width
+ opt_cover_grid_height
@@ -443,30 +434,6 @@ A value of zero means calculate automatically.
- -
-
-
- Make the covers larger, maintaining current aspect ratio.
-
-
- &Larger covers
-
-
-
- :/images/plus.png:/images/plus.png
-
-
-
- -
-
-
- Cover &height:
-
-
- opt_cover_grid_height
-
-
-
-
@@ -484,27 +451,50 @@ A value of zero means calculate automatically.
- -
-
-
- Make the covers smaller, maintaining current aspect ratio.
+
-
+
+
+
+ 0
+ 0
+
- &Smaller covers
+ By default, calibre chooses a cover size based on your computer's screen size. You can change the cover size here:
-
-
- :/images/minus.png:/images/minus.png
+
+ true
- -
-
+
-
+
+
+ Cover &width:
+
+
+ opt_cover_grid_width
+
+
+
+ -
+
+
+
+
+
+
+ -
+
- Reset size to automatic
+ Make the covers larger, maintaining current aspect ratio.
- &Reset size
+ &Larger covers
+
+
+
+ :/images/plus.png:/images/plus.png
@@ -521,6 +511,39 @@ A value of zero means calculate automatically.
+ -
+
+
+ Reset size to automatic
+
+
+ &Reset size
+
+
+
+ -
+
+
+ &Round the corners:
+
+
+ opt_cover_grid_corner_radius
+
+
+
+ -
+
+
+ The amount by which to round the corners of the covers when they are displayed in the Cover grid. A value of 10 looks good with typical cover sizes. Adjust to your preference. A value of zero disables rounding.
+
+
+ no rounding
+
+
+ px
+
+
+