mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
A few more places where we need to handle non-integer device pixel ratios
This commit is contained in:
parent
2948a6210d
commit
d55ec4e00b
@ -289,7 +289,10 @@ class CoverView(QWidget): # {{{
|
||||
target = QRect(x, y, width, height)
|
||||
p = QPainter(self)
|
||||
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.setDevicePixelRatio(dpr)
|
||||
p.drawPixmap(target, spmap)
|
||||
|
@ -166,7 +166,10 @@ class BookInfo(QDialog):
|
||||
pixmap.height(), self.cover.size().width()-10,
|
||||
self.cover.size().height()-10)
|
||||
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),
|
||||
Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
||||
pixmap.setDevicePixelRatio(dpr)
|
||||
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
||||
|
@ -595,7 +595,10 @@ class Canvas(QWidget):
|
||||
i = self.current_image
|
||||
width, height = i.width(), i.height()
|
||||
scaled, width, height = fit_image(width, height, pwidth, pheight)
|
||||
dpr = self.devicePixelRatio()
|
||||
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)
|
||||
self.current_scaled_pixmap = QPixmap.fromImage(i)
|
||||
@ -604,7 +607,10 @@ class Canvas(QWidget):
|
||||
@painter
|
||||
def draw_pixmap(self, painter):
|
||||
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)
|
||||
pwidth, pheight = self.last_canvas_size
|
||||
x = int(abs(pwidth - width)/2.)
|
||||
|
Loading…
x
Reference in New Issue
Block a user