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

View File

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

View File

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

View File

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

View File

@ -240,7 +240,11 @@ class Background(QWidget): # {{{
path = texture_path(self.btex) path = texture_path(self.btex)
if path: if path:
p = QPixmap(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.brush.setTexture(p)
self.update() self.update()

View File

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