Fix cover display on high dpi screens in the edit metadata and convert dialog

This commit is contained in:
Kovid Goyal 2016-08-30 09:38:37 +05:30
parent 2035356c53
commit 68c1303c21
3 changed files with 8 additions and 3 deletions

View File

@ -97,11 +97,14 @@ class MetadataWidget(Widget, Ui_Form):
pm = QPixmap() pm = QPixmap()
pm.loadFromData(cover) pm.loadFromData(cover)
if not pm.isNull(): if not pm.isNull():
pm.setDevicePixelRatio(getattr(self, 'devicePixelRatioF', self.devicePixelRatio)())
self.cover.setPixmap(pm) self.cover.setPixmap(pm)
self.cover_data = cover self.cover_data = cover
self.set_cover_tooltip(pm) self.set_cover_tooltip(pm)
else: else:
self.cover.setPixmap(QPixmap(I('default_cover.png'))) pm = QPixmap(I('default_cover.png'))
pm.setDevicePixelRatio(getattr(self, 'devicePixelRatioF', self.devicePixelRatio)())
self.cover.setPixmap(pm)
self.cover.setToolTip(_('This book has no cover')) self.cover.setToolTip(_('This book has no cover'))
for x in ('author', 'series', 'publisher'): for x in ('author', 'series', 'publisher'):
x = getattr(self, x) x = getattr(self, x)
@ -201,6 +204,7 @@ class MetadataWidget(Widget, Ui_Form):
if cover: if cover:
pix = QPixmap() pix = QPixmap()
pix.loadFromData(cover) pix.loadFromData(cover)
pix.setDevicePixelRatio(getattr(self, 'devicePixelRatioF', self.devicePixelRatio)())
if pix.isNull(): if pix.isNull():
d = error_dialog(self.parent(), _('Error reading file'), d = error_dialog(self.parent(), _('Error reading file'),
_file + _(" is not a valid picture")) _file + _(" is not a valid picture"))

View File

@ -1172,6 +1172,7 @@ class Cover(ImageView): # {{{
pm = QPixmap(I('default_cover.png')) pm = QPixmap(I('default_cover.png'))
else: else:
self._cdata = cdata self._cdata = cdata
pm.setDevicePixelRatio(getattr(self, 'devicePixelRatioF', self.devicePixelRatio)())
self.setPixmap(pm) self.setPixmap(pm)
tt = _('This book has no cover') tt = _('This book has no cover')
if self._cdata: if self._cdata:

View File

@ -343,9 +343,9 @@ class ImageView(QWidget, ImageDropMixin): # {{{
cw, ch = self.rect().width(), self.rect().height() cw, ch = self.rect().width(), self.rect().height()
scaled, nw, nh = fit_image(w, h, cw, ch) scaled, nw, nh = fit_image(w, h, cw, ch)
if scaled: if scaled:
pmap = pmap.scaled(nw, nh, Qt.IgnoreAspectRatio, pmap = pmap.scaled(nw*pmap.devicePixelRatio(), nh*pmap.devicePixelRatio(), Qt.IgnoreAspectRatio,
Qt.SmoothTransformation) Qt.SmoothTransformation)
w, h = pmap.width(), pmap.height() w, h = pmap.width()/pmap.devicePixelRatio(), pmap.height()/pmap.devicePixelRatio()
x = int(abs(cw - w)/2.) x = int(abs(cw - w)/2.)
y = int(abs(ch - h)/2.) y = int(abs(ch - h)/2.)
target = QRect(x, y, w, h) target = QRect(x, y, w, h)