More custom comments as html work

This commit is contained in:
Charles Haley 2010-12-25 12:40:55 +00:00
parent c0c4df77ca
commit 092982e057
3 changed files with 15 additions and 10 deletions

View File

@ -12,6 +12,7 @@ from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo
from calibre.gui2 import dynamic, open_local_file
from calibre import fit_image
from calibre.library.comments import comments_to_html
from calibre.utils.icu import sort_key
class BookInfo(QDialog, Ui_BookInfo):
@ -130,9 +131,11 @@ class BookInfo(QDialog, Ui_BookInfo):
for f in formats:
f = f.strip()
info[_('Formats')] += '<a href="%s">%s</a>, '%(f,f)
for key in info.keys():
for key in sorted(info.keys(), key=sort_key):
if key == 'id': continue
txt = info[key]
if key.endswith(':html'):
key = key[:-5]
if key != _('Path'):
txt = u'<br />\n'.join(textwrap.wrap(txt, 120))
rows += u'<tr><td><b>%s:</b></td><td>%s</td></tr>'%(key, txt)

View File

@ -296,19 +296,19 @@ class CcCommentsDelegate(QStyledItemDelegate): # {{{
Delegate for comments data.
'''
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent)
self.document = QTextDocument()
def paint(self, painter, option, index):
document = QTextDocument()
value = index.data(Qt.DisplayRole)
# if value.isValid() and not value.isNull():
# QString text("<span style='background-color: lightgreen'>This</span> is highlighted.");
text = value.toString()
document.setHtml(text);
self.document.setHtml(index.data(Qt.DisplayRole).toString())
painter.save()
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
painter.setClipRect(option.rect)
painter.translate(option.rect.topLeft());
document.drawContents(painter);
painter.translate(option.rect.topLeft())
self.document.drawContents(painter)
painter.restore()
# painter.translate(-option.rect.topLeft());
def createEditor(self, parent, option, index):
m = index.model()

View File

@ -173,6 +173,8 @@ def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS, prefix):
extra.append('%s: %s<br />'%(xml(name), xml(format_tag_string(val, ',',
ignore_max=True,
no_tag_count=True))))
elif datatype == 'comments':
extra.append('%s: %s<br />'%(xml(name), comments_to_html(unicode(val))))
else:
extra.append('%s: %s<br />'%(xml(name), xml(unicode(val))))
comments = item[FM['comments']]