A few more places where we need to handle non-integer device pixel ratios

This commit is contained in:
Kovid Goyal 2016-08-26 12:46:02 +05:30
parent 2948a6210d
commit d55ec4e00b
6 changed files with 38 additions and 9 deletions

View File

@ -289,6 +289,9 @@ class CoverView(QWidget): # {{{
target = QRect(x, y, width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
spmap = self.pixmap.scaled(target.size() * dpr, Qt.KeepAspectRatio, Qt.SmoothTransformation)
spmap.setDevicePixelRatio(dpr)

View File

@ -166,6 +166,9 @@ class BookInfo(QDialog):
pixmap.height(), self.cover.size().width()-10,
self.cover.size().height()-10)
if scaled:
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
pixmap = pixmap.scaled(int(dpr * new_width), int(dpr * new_height),
Qt.KeepAspectRatio, Qt.SmoothTransformation)
@ -200,7 +203,11 @@ class BookInfo(QDialog):
self.current_row = row
self.setWindowTitle(mi.title)
self.cover_pixmap = QPixmap.fromImage(mi.cover_data[1])
self.cover_pixmap.setDevicePixelRatio(self.devicePixelRatio())
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
self.cover_pixmap.setDevicePixelRatio(dpr)
self.resize_cover()
html = render_html(mi, self.css, True, self, all_fields=True)
self.details.setHtml(html)

View File

@ -688,9 +688,13 @@ class ChooseTheme(Dialog):
def set_cover(self, theme, cdata):
theme['cover-pixmap'] = p = QPixmap()
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
if isinstance(cdata, bytes):
p.loadFromData(cdata)
p.setDevicePixelRatio(self.devicePixelRatio())
p.setDevicePixelRatio(dpr)
item = self.item_from_name(theme['name'])
if item is not None:
item.setData(Qt.DecorationRole, p)

View File

@ -110,9 +110,14 @@ class PDFCovers(QDialog):
self.reject()
return
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
for i, f in enumerate(sorted(files)):
p = QPixmap(f).scaled(self.covers.iconSize()*self.devicePixelRatio(), aspectRatioMode=Qt.IgnoreAspectRatio, transformMode=Qt.SmoothTransformation)
p.setDevicePixelRatio(self.devicePixelRatio())
p = QPixmap(f).scaled(self.covers.iconSize()*dpr, aspectRatioMode=Qt.IgnoreAspectRatio, transformMode=Qt.SmoothTransformation)
p.setDevicePixelRatio(dpr)
i = QListWidgetItem(_('page %d') % (i + 1))
i.setData(Qt.DecorationRole, p)
i.setData(Qt.UserRole, f)

View File

@ -240,7 +240,11 @@ class Background(QWidget): # {{{
path = texture_path(self.btex)
if path:
p = QPixmap(path)
p.setDevicePixelRatio(self.devicePixelRatio())
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
p.setDevicePixelRatio(dpr)
self.brush.setTexture(p)
self.update()

View File

@ -595,6 +595,9 @@ class Canvas(QWidget):
i = self.current_image
width, height = i.width(), i.height()
scaled, width, height = fit_image(width, height, pwidth, pheight)
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
if scaled:
i = self.current_image.scaled(int(dpr * width), int(dpr * height), transformMode=Qt.SmoothTransformation)
@ -604,6 +607,9 @@ class Canvas(QWidget):
@painter
def draw_pixmap(self, painter):
p = self.current_scaled_pixmap
try:
dpr = self.devicePixelRatioF()
except AttributeError:
dpr = self.devicePixelRatio()
width, height = int(p.width()/dpr), int(p.height()/dpr)
pwidth, pheight = self.last_canvas_size