mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Cover grid: Add an option under Preferences->Look & feel->Cover grid->Cover size to round the corners of the displayed covers
This commit is contained in:
parent
265558ee63
commit
2dd1114c5a
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -393,36 +393,27 @@
|
||||
<string>Cover size</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0" colspan="5">
|
||||
<widget class="QLabel" name="cover_size_label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="cover_grid_smaller_cover">
|
||||
<property name="toolTip">
|
||||
<string>Make the covers smaller, maintaining current aspect ratio.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>By default, calibre chooses a cover size based on your computer's screen size. You can change the cover size here:</string>
|
||||
<string>&Smaller covers</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
<normaloff>:/images/minus.png</normaloff>:/images/minus.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="5">
|
||||
<widget class="QLabel" name="cover_grid_aspect_ratio">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Cover &width: </string>
|
||||
<string>Cover &height: </string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_cover_grid_width</cstring>
|
||||
<cstring>opt_cover_grid_height</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -443,30 +434,6 @@ A value of zero means calculate automatically.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="cover_grid_larger_cover">
|
||||
<property name="toolTip">
|
||||
<string>Make the covers larger, maintaining current aspect ratio.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Larger covers</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
<normaloff>:/images/plus.png</normaloff>:/images/plus.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Cover &height: </string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_cover_grid_height</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="opt_cover_grid_height">
|
||||
<property name="toolTip">
|
||||
@ -484,27 +451,50 @@ A value of zero means calculate automatically.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="cover_grid_smaller_cover">
|
||||
<property name="toolTip">
|
||||
<string>Make the covers smaller, maintaining current aspect ratio.</string>
|
||||
<item row="0" column="0" colspan="5">
|
||||
<widget class="QLabel" name="cover_size_label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Smaller covers</string>
|
||||
<string>By default, calibre chooses a cover size based on your computer's screen size. You can change the cover size here:</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
<normaloff>:/images/minus.png</normaloff>:/images/minus.png</iconset>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="2">
|
||||
<widget class="QPushButton" name="cover_grid_reset_size">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>Cover &width: </string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_cover_grid_width</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="5">
|
||||
<widget class="QLabel" name="cover_grid_aspect_ratio">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="cover_grid_larger_cover">
|
||||
<property name="toolTip">
|
||||
<string>Reset size to automatic</string>
|
||||
<string>Make the covers larger, maintaining current aspect ratio.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Reset size</string>
|
||||
<string>&Larger covers</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
<normaloff>:/images/plus.png</normaloff>:/images/plus.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -521,6 +511,39 @@ A value of zero means calculate automatically.</string>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="3" rowspan="2">
|
||||
<widget class="QPushButton" name="cover_grid_reset_size">
|
||||
<property name="toolTip">
|
||||
<string>Reset size to automatic</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Reset size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>&Round the corners:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_cover_grid_corner_radius</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QSpinBox" name="opt_cover_grid_corner_radius">
|
||||
<property name="toolTip">
|
||||
<string>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.</string>
|
||||
</property>
|
||||
<property name="specialValueText">
|
||||
<string>no rounding</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string> px</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user