mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow customizing the text that appears below covers in the cover grid
You can now show any metadata field below the covers in the cover grid view, not just title. To change the displayed field go to Preferences->Look & Feel->Cover Grid.
This commit is contained in:
parent
eba54de1ce
commit
6e9f48b175
@ -428,6 +428,7 @@ class DB(object):
|
|||||||
defs['virtual_lib_on_startup'] = defs['cs_virtual_lib_on_startup'] = ''
|
defs['virtual_lib_on_startup'] = defs['cs_virtual_lib_on_startup'] = ''
|
||||||
defs['virt_libs_hidden'] = defs['virt_libs_order'] = ()
|
defs['virt_libs_hidden'] = defs['virt_libs_order'] = ()
|
||||||
defs['update_all_last_mod_dates_on_start'] = False
|
defs['update_all_last_mod_dates_on_start'] = False
|
||||||
|
defs['field_under_covers_in_grid'] = 'title'
|
||||||
|
|
||||||
# Migrate the bool tristate tweak
|
# Migrate the bool tristate tweak
|
||||||
defs['bools_are_tristate'] = \
|
defs['bools_are_tristate'] = \
|
||||||
|
@ -20,7 +20,8 @@ from PyQt4.Qt import (
|
|||||||
QPropertyAnimation, QEasingCurve, pyqtSlot, QHelpEvent, QAbstractItemView,
|
QPropertyAnimation, QEasingCurve, pyqtSlot, QHelpEvent, QAbstractItemView,
|
||||||
QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush)
|
QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush)
|
||||||
|
|
||||||
from calibre import fit_image, prints, prepare_string_for_xml
|
from calibre import fit_image, prints, prepare_string_for_xml, human_readable
|
||||||
|
from calibre.constants import DEBUG
|
||||||
from calibre.ebooks.metadata import fmt_sidx
|
from calibre.ebooks.metadata import fmt_sidx
|
||||||
from calibre.utils import join_with_timeout
|
from calibre.utils import join_with_timeout
|
||||||
from calibre.gui2 import gprefs, config
|
from calibre.gui2 import gprefs, config
|
||||||
@ -369,6 +370,23 @@ class CoverDelegate(QStyledItemDelegate):
|
|||||||
def sizeHint(self, option, index):
|
def sizeHint(self, option, index):
|
||||||
return self.item_size
|
return self.item_size
|
||||||
|
|
||||||
|
def render_field(self, db, book_id):
|
||||||
|
try:
|
||||||
|
field = db.pref('field_under_covers_in_grid', 'title')
|
||||||
|
if field == 'size':
|
||||||
|
ans = human_readable(db.field_for(field, book_id, default_value=0))
|
||||||
|
else:
|
||||||
|
mi = db.get_proxy_metadata(book_id)
|
||||||
|
display_name, ans, val, fm = mi.format_field_extended(field)
|
||||||
|
if fm and fm['datatype'] == 'rating':
|
||||||
|
ans = u'\u2605' * int(val/2.0)
|
||||||
|
return unicode(ans)
|
||||||
|
except Exception:
|
||||||
|
if DEBUG:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return ''
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
QStyledItemDelegate.paint(self, painter, option, QModelIndex()) # draw the hover and selection highlights
|
QStyledItemDelegate.paint(self, painter, option, QModelIndex()) # draw the hover and selection highlights
|
||||||
m = index.model()
|
m = index.model()
|
||||||
@ -418,7 +436,7 @@ class CoverDelegate(QStyledItemDelegate):
|
|||||||
rect = trect
|
rect = trect
|
||||||
rect.setTop(rect.bottom() - self.title_height + 5)
|
rect.setTop(rect.bottom() - self.title_height + 5)
|
||||||
painter.setRenderHint(QPainter.TextAntialiasing, True)
|
painter.setRenderHint(QPainter.TextAntialiasing, True)
|
||||||
title = db.field_for('title', book_id, default_value='')
|
title = self.render_field(db, book_id)
|
||||||
metrics = painter.fontMetrics()
|
metrics = painter.fontMetrics()
|
||||||
painter.drawText(rect, Qt.AlignCenter|Qt.TextSingleLine,
|
painter.drawText(rect, Qt.AlignCenter|Qt.TextSingleLine,
|
||||||
metrics.elidedText(title, Qt.ElideRight, rect.width()))
|
metrics.elidedText(title, Qt.ElideRight, rect.width()))
|
||||||
|
@ -212,6 +212,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
r('categories_using_hierarchy', db.prefs, setting=CommaSeparatedList,
|
r('categories_using_hierarchy', db.prefs, setting=CommaSeparatedList,
|
||||||
choices=sorted(list(choices), key=sort_key))
|
choices=sorted(list(choices), key=sort_key))
|
||||||
|
|
||||||
|
fm = db.field_metadata
|
||||||
|
choices = sorted(((fm[k]['name'], k) for k in fm.displayable_field_keys() if fm[k]['name']),
|
||||||
|
key=lambda x:sort_key(x[0]))
|
||||||
|
r('field_under_covers_in_grid', db.prefs, choices=choices)
|
||||||
|
|
||||||
self.current_font = self.initial_font = None
|
self.current_font = self.initial_font = None
|
||||||
self.change_font_button.clicked.connect(self.change_font)
|
self.change_font_button.clicked.connect(self.change_font)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>820</width>
|
<width>820</width>
|
||||||
<height>519</height>
|
<height>546</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -261,10 +261,40 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="opt_cover_grid_show_title">
|
<widget class="QCheckBox" name="opt_cover_grid_show_title">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Show the book &title below the cover</string>
|
<string>Show a field (such as title) &under the covers</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_14">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Field to show under the covers:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy">
|
||||||
|
<cstring>opt_field_under_covers_in_grid</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="opt_field_under_covers_in_grid"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
@ -926,5 +956,22 @@ a few top-level elements.</string>
|
|||||||
<resources>
|
<resources>
|
||||||
<include location="../../../../resources/images.qrc"/>
|
<include location="../../../../resources/images.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>opt_cover_grid_show_title</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>opt_field_under_covers_in_grid</receiver>
|
||||||
|
<slot>setEnabled(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>75</x>
|
||||||
|
<y>102</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>289</x>
|
||||||
|
<y>118</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user