mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Couple more high DPI fixes for the editor
This commit is contained in:
parent
6be52464ae
commit
04d8f2cda5
@ -108,11 +108,13 @@ class ImageDelegate(QStyledItemDelegate):
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
dpr = painter.device().devicePixelRatio()
|
||||
cover.loadFromData(raw)
|
||||
cover.setDevicePixelRatio(dpr)
|
||||
if not cover.isNull():
|
||||
scaled, width, height = fit_image(cover.width(), cover.height(), self.cover_size.width(), self.cover_size.height())
|
||||
if scaled:
|
||||
cover = self.cover_cache[name] = cover.scaled(width, height, transformMode=Qt.SmoothTransformation)
|
||||
cover = self.cover_cache[name] = cover.scaled(int(dpr*width), int(dpr*height), transformMode=Qt.SmoothTransformation)
|
||||
|
||||
painter.save()
|
||||
try:
|
||||
@ -121,8 +123,8 @@ class ImageDelegate(QStyledItemDelegate):
|
||||
trect = QRect(rect)
|
||||
rect.setBottom(rect.bottom() - self.title_height)
|
||||
if not cover.isNull():
|
||||
dx = max(0, int((rect.width() - cover.width())/2.0))
|
||||
dy = max(0, rect.height() - cover.height())
|
||||
dx = max(0, int((rect.width() - int(cover.width()/cover.devicePixelRatio()))/2.0))
|
||||
dy = max(0, rect.height() - int(cover.height()/cover.devicePixelRatio()))
|
||||
rect.adjust(dx, dy, -dx, 0)
|
||||
painter.drawPixmap(rect, cover)
|
||||
rect = trect
|
||||
@ -455,7 +457,5 @@ if __name__ == '__main__':
|
||||
from calibre.gui2.tweak_book.boss import get_container
|
||||
set_current_container(get_container(sys.argv[-1]))
|
||||
|
||||
d = ChooseFolder()
|
||||
if d.exec_() == d.Accepted:
|
||||
print (repr(d.chosen_folder))
|
||||
|
||||
d = InsertImage(for_browsing=True)
|
||||
d.exec_()
|
||||
|
@ -373,25 +373,28 @@ class ImagesDelegate(QStyledItemDelegate):
|
||||
k = (th, entry.name)
|
||||
pmap = self.cache.get(k)
|
||||
if pmap is None:
|
||||
pmap = self.cache[k] = self.pixmap(th, entry)
|
||||
pmap = self.cache[k] = self.pixmap(th, entry, painter.device().devicePixelRatio())
|
||||
if pmap.isNull():
|
||||
bottom = option.rect.top()
|
||||
else:
|
||||
m = 2 * self.MARGIN
|
||||
x = option.rect.left() + (option.rect.width() - m - pmap.width()) // 2
|
||||
x = option.rect.left() + (option.rect.width() - m - int(pmap.width()/pmap.devicePixelRatio())) // 2
|
||||
painter.drawPixmap(x, option.rect.top() + self.MARGIN, pmap)
|
||||
bottom = m + pmap.height() + option.rect.top()
|
||||
bottom = m + int(pmap.height() / pmap.devicePixelRatio()) + option.rect.top()
|
||||
rect = QRect(option.rect.left(), bottom, option.rect.width(), option.rect.bottom() - bottom)
|
||||
if option.state & QStyle.State_Selected:
|
||||
painter.setPen(self.parent().palette().color(QPalette.HighlightedText))
|
||||
painter.drawText(rect, Qt.AlignHCenter | Qt.AlignVCenter, entry.basename)
|
||||
painter.restore()
|
||||
|
||||
def pixmap(self, thumbnail_height, entry):
|
||||
def pixmap(self, thumbnail_height, entry, dpr):
|
||||
pmap = QPixmap(current_container().name_to_abspath(entry.name)) if entry.width > 0 and entry.height > 0 else QPixmap()
|
||||
scaled, width, height = fit_image(entry.width, entry.height, thumbnail_height, thumbnail_height)
|
||||
if scaled and not pmap.isNull():
|
||||
pmap = pmap.scaled(width, height, transformMode=Qt.SmoothTransformation)
|
||||
if not pmap.isNull():
|
||||
pmap.setDevicePixelRatio(dpr)
|
||||
scaled, width, height = fit_image(entry.width, entry.height, thumbnail_height, thumbnail_height)
|
||||
if scaled:
|
||||
pmap = pmap.scaled(int(dpr * width), int(dpr * height), transformMode=Qt.SmoothTransformation)
|
||||
pmap.setDevicePixelRatio(dpr)
|
||||
return pmap
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user