Use correct 3:4 aspect ratio for default cover image

This commit is contained in:
Kovid Goyal 2010-06-25 22:51:41 -06:00
parent 8207ff2f61
commit ae1446a91d
5 changed files with 3210 additions and 8 deletions

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 105 KiB

View File

@ -248,7 +248,7 @@ def info_dialog(parent, title, msg, det_msg='', show=False):
class Dispatcher(QObject): class Dispatcher(QObject):
'''Convenience class to ensure that a function call always happens in the '''Convenience class to ensure that a function call always happens in the
thread the reciver was created in.''' thread the receiver was created in.'''
dispatch_signal = pyqtSignal(object, object) dispatch_signal = pyqtSignal(object, object)
def __init__(self, func): def __init__(self, func):
@ -507,7 +507,7 @@ def pixmap_to_data(pixmap, format='JPEG'):
buf = QBuffer(ba) buf = QBuffer(ba)
buf.open(QBuffer.WriteOnly) buf.open(QBuffer.WriteOnly)
pixmap.save(buf, format) pixmap.save(buf, format)
return str(ba.data()) return bytes(ba.data())
class ResizableDialog(QDialog): class ResizableDialog(QDialog):

View File

@ -90,7 +90,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
COVER_FETCH_TIMEOUT = 240 # seconds COVER_FETCH_TIMEOUT = 240 # seconds
def do_reset_cover(self, *args): def do_reset_cover(self, *args):
pix = QPixmap(I('book.svg')) pix = QPixmap(I('default_cover.svg'))
self.cover.setPixmap(pix) self.cover.setPixmap(pix)
self.cover_changed = True self.cover_changed = True
self.cover_data = None self.cover_data = None
@ -408,7 +408,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
if cover: if cover:
pm.loadFromData(cover) pm.loadFromData(cover)
if pm.isNull(): if pm.isNull():
pm = QPixmap(I('book.svg')) pm = QPixmap(I('default_cover.svg'))
else: else:
self.cover_data = cover self.cover_data = cover
self.cover.setPixmap(pm) self.cover.setPixmap(pm)

View File

@ -43,6 +43,14 @@ class FormatPath(unicode):
ans.deleted_after_upload = False ans.deleted_after_upload = False
return ans return ans
_default_image = None
def default_image():
global _default_image
if _default_image is None:
_default_image = QImage(I('default_cover.svg'))
return _default_image
class BooksModel(QAbstractTableModel): # {{{ class BooksModel(QAbstractTableModel): # {{{
about_to_be_sorted = pyqtSignal(object, name='aboutToBeSorted') about_to_be_sorted = pyqtSignal(object, name='aboutToBeSorted')
@ -71,7 +79,7 @@ class BooksModel(QAbstractTableModel): # {{{
self.book_on_device = None self.book_on_device = None
self.editable_cols = ['title', 'authors', 'rating', 'publisher', self.editable_cols = ['title', 'authors', 'rating', 'publisher',
'tags', 'series', 'timestamp', 'pubdate'] 'tags', 'series', 'timestamp', 'pubdate']
self.default_image = QImage(I('book.svg')) self.default_image = default_image()
self.sorted_on = DEFAULT_SORT self.sorted_on = DEFAULT_SORT
self.sort_history = [self.sorted_on] self.sort_history = [self.sorted_on]
self.last_search = '' # The last search performed on this model self.last_search = '' # The last search performed on this model

View File

@ -539,17 +539,20 @@ MIME = '''\
</mime-info> </mime-info>
''' '''
def render_svg(image, dest): def render_svg(image, dest, width=128, height=128):
from PyQt4.QtGui import QPainter, QImage from PyQt4.QtGui import QPainter, QImage
from PyQt4.QtSvg import QSvgRenderer from PyQt4.QtSvg import QSvgRenderer
svg = QSvgRenderer(image.readAll()) image = image.readAll() if hasattr(image, 'readAll') else image
svg = QSvgRenderer(image)
painter = QPainter() painter = QPainter()
image = QImage(128,128,QImage.Format_ARGB32_Premultiplied) image = QImage(width, height, QImage.Format_ARGB32)
painter.begin(image) painter.begin(image)
painter.setRenderHints(QPainter.Antialiasing|QPainter.TextAntialiasing|QPainter.SmoothPixmapTransform|QPainter.HighQualityAntialiasing) painter.setRenderHints(QPainter.Antialiasing|QPainter.TextAntialiasing|QPainter.SmoothPixmapTransform|QPainter.HighQualityAntialiasing)
painter.setCompositionMode(QPainter.CompositionMode_SourceOver) painter.setCompositionMode(QPainter.CompositionMode_SourceOver)
svg.render(painter) svg.render(painter)
painter.end() painter.end()
if dest is None:
return image
image.save(dest) image.save(dest)
def main(): def main():