Fix Copilot's mistakes

This commit is contained in:
Kovid Goyal 2026-02-23 06:46:03 +05:30
parent acc180b4af
commit a16e8e8ee1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 312 additions and 312 deletions

View File

@ -763,7 +763,7 @@ class CoverDelegate(QStyledItemDelegate):
if self.title_height != 0:
if self.flush_bottom:
trect.setTop(rect.bottom() + 5)
self.paint_title(painter, trect, db, book_id)
self.paint_title(painter, trect, db, book_id, align_top=self.flush_bottom)
if self.emblem_size > 0:
# We don't draw embossed emblems as the ondevice/marked emblems are drawn in the gutter
return
@ -787,15 +787,20 @@ class CoverDelegate(QStyledItemDelegate):
with clip_border_radius(painter, rect):
painter.drawPixmap(rect, pixmap)
def paint_title(self, painter, rect, db, book_id):
def paint_title(self, painter, rect, db, book_id, align_top: bool = False):
painter.setRenderHint(QPainter.RenderHint.TextAntialiasing, True)
title, is_stars = self.render_field(db, book_id)
if is_stars:
painter.setFont(self.rating_font)
metrics = painter.fontMetrics()
painter.setPen(self.highlight_color)
painter.drawText(rect, Qt.AlignmentFlag.AlignCenter|Qt.TextFlag.TextSingleLine,
metrics.elidedText(title, Qt.TextElideMode.ElideRight, rect.width()))
text = metrics.elidedText(title, Qt.TextElideMode.ElideRight, rect.width())
align = Qt.TextFlag.TextSingleLine
if align_top:
align |= Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignHCenter
else:
align |= Qt.AlignmentFlag.AlignCenter
painter.drawText(rect, align, text)
def paint_emblems(self, painter, rect, emblems):
gutter = self.emblem_size + self.MARGIN

View File

@ -11,12 +11,12 @@ from calibre.gui2 import gprefs
from calibre.gui2.library.alternate_views import CM_TO_INCH, auto_height
from calibre.gui2.preferences import LazyConfigWidgetBase
from calibre.gui2.preferences.look_feel_tabs import RulesSetting
from calibre.gui2.preferences.look_feel_tabs.cover_grid_ui import Ui_Form
from calibre.gui2.preferences.look_feel_tabs.cover_grid_ui import Ui_cover_grid_tab
from calibre.startup import connect_lambda
from calibre.utils.icu import sort_key
class CoverGridTab(QTabWidget, LazyConfigWidgetBase, Ui_Form):
class CoverGridTab(QTabWidget, LazyConfigWidgetBase, Ui_cover_grid_tab):
changed_signal = pyqtSignal()
restart_now = pyqtSignal()

View File

@ -1,293 +1,304 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QTabWidget" name="cover_grid_tab">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>&amp;Layout</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Control the Cover grid view. You can enable this view by clicking the &quot;Layout&quot; button in the bottom right corner of the main calibre window.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Field to show &amp;under the covers:</string>
</property>
<property name="buddy">
<cstring>opt_field_under_covers_in_grid</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="opt_field_under_covers_in_grid"/>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="opt_cover_grid_text_flush_bottom">
<property name="text">
<string>Draw field text flush with the &amp;bottom of the rendered cover</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Spac&amp;ing between covers:</string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_spacing</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_spacing">
<property name="toolTip">
<string>The spacing between covers. A value of zero means calculate automatically based on cover size.</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>2</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="BackgroundConfig" name="cg_background_box">
<property name="title">
<string>Background for the Cover grid</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Cover size</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<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>&amp;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="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>&amp;Smaller covers</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/minus.png</normaloff>:/images/minus.png</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Cover &amp;height: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_height</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Cover &amp;width: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_width</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_height">
<property name="toolTip">
<string>The height of displayed covers.
<class>cover_grid_tab</class>
<widget class="QTabWidget" name="cover_grid_tab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>483</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>&amp;Layout</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Control the Cover grid view. You can enable this view by clicking the &quot;Layout&quot; button in the bottom right corner of the main calibre window.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="opt_cover_grid_show_title">
<property name="text">
<string>Show a &amp;field (such as title) under the covers</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Field to show &amp;under the covers:</string>
</property>
<property name="buddy">
<cstring>opt_field_under_covers_in_grid</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="opt_field_under_covers_in_grid"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Spac&amp;ing between covers:</string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_spacing</cstring>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_spacing">
<property name="toolTip">
<string>The spacing between covers. A value of zero means calculate automatically based on cover size.</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>2</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="BackgroundConfig" name="cg_background_box" native="true">
<property name="title" stdset="0">
<string>Background for the Cover grid</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Cover size</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<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>&amp;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="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>&amp;Smaller covers</string>
</property>
<property name="icon">
<iconset resource="../../../../../resources/images.qrc">
<normaloff>:/images/minus.png</normaloff>:/images/minus.png</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Cover &amp;height: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_height</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Cover &amp;width: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_width</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_height">
<property name="toolTip">
<string>The height of displayed covers.
A value of zero means calculate automatically.</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</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>&amp;Reset size</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="5">
<widget class="QLabel" name="cover_grid_aspect_ratio">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="4">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_width">
<property name="toolTip">
<string>The width of displayed covers.
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</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>&amp;Reset size</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="5">
<widget class="QLabel" name="cover_grid_aspect_ratio">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="4">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_width">
<property name="toolTip">
<string>The width of displayed covers.
A value of zero means calculate automatically.</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<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>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="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="11" column="1">
<widget class="QSpinBox" name="opt_emblem_size">
<property name="suffix">
<string> px</string>
</property>
<property name="minimum">
<number>16</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Size of the emblems (if any) shown &amp;next to the covers: </string>
</property>
<property name="buddy">
<cstring>opt_emblem_size</cstring>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="opt_cover_grid_show_title">
<property name="text">
<string>Show a &amp;field (such as title) under the covers</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="label_22">
<property name="text">
<string>&amp;Location of the emblems shown next to the covers:</string>
</property>
<property name="buddy">
<cstring>opt_emblem_position</cstring>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QComboBox" name="opt_emblem_position"/>
</item>
</layout>
</widget>
<widget class="EditRulesWidget" name="opt_cover_grid_icon_rules">
<attribute name="title">
<string>&amp;Emblems</string>
</attribute>
</widget>
<widget class="CoverCacheConfig" name="config_cache">
<attribute name="title">
<string>&amp;Performance</string>
</attribute>
</widget>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<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>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="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Size of the emblems (if any) shown &amp;next to the covers: </string>
</property>
<property name="buddy">
<cstring>opt_emblem_size</cstring>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QSpinBox" name="opt_emblem_size">
<property name="suffix">
<string> px</string>
</property>
<property name="minimum">
<number>16</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="label_22">
<property name="text">
<string>&amp;Location of the emblems shown next to the covers:</string>
</property>
<property name="buddy">
<cstring>opt_emblem_position</cstring>
</property>
</widget>
</item>
<item row="13" column="1">
<widget class="QComboBox" name="opt_emblem_position"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="opt_cover_grid_text_flush_bottom">
<property name="toolTip">
<string>&lt;p&gt;By default, the text is drawn at the bottom of the cell, leaving a gap between text and cover when the cover is small or has a wide aspect ratio. This option instead causes the text to be drawn flush witht he bottom of the cover.</string>
</property>
<property name="text">
<string>Draw text flush with the &amp;bottom of the rendered cover</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="EditRulesWidget" name="opt_cover_grid_icon_rules">
<attribute name="title">
<string>&amp;Emblems</string>
</attribute>
</widget>
<widget class="CoverCacheConfig" name="config_cache">
<attribute name="title">
<string>&amp;Performance</string>
</attribute>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>ConfigWidgetBase</class>
@ -311,7 +322,7 @@ A value of zero means calculate automatically.</string>
</customwidget>
</customwidgets>
<resources>
<include location="../../../../../resources/images.qrc"/>
<include location="../../../../../resources/images.qrc"/>
</resources>
<connections>
<connection>
@ -321,28 +332,12 @@ A value of zero means calculate automatically.</string>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>86</x>
<y>49</y>
<x>88</x>
<y>128</y>
</hint>
<hint type="destinationlabel">
<x>101</x>
<y>51</y>
</hint>
</hints>
</connection>
<connection>
<sender>opt_cover_grid_show_title</sender>
<signal>toggled(bool)</signal>
<receiver>opt_cover_grid_text_flush_bottom</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>86</x>
<y>49</y>
</hint>
<hint type="destinationlabel">
<x>101</x>
<y>75</y>
<x>376</x>
<y>159</y>
</hint>
</hints>
</connection>