diff --git a/src/calibre/gui2/tweak_book/editor/insert_resource.py b/src/calibre/gui2/tweak_book/editor/insert_resource.py index f6905685ba..50e67eeee2 100644 --- a/src/calibre/gui2/tweak_book/editor/insert_resource.py +++ b/src/calibre/gui2/tweak_book/editor/insert_resource.py @@ -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_() diff --git a/src/calibre/gui2/tweak_book/reports.py b/src/calibre/gui2/tweak_book/reports.py index eb2ee41eb7..5f54928ea0 100644 --- a/src/calibre/gui2/tweak_book/reports.py +++ b/src/calibre/gui2/tweak_book/reports.py @@ -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