Column icons: Allow use of wide images as column icons

This commit is contained in:
Kovid Goyal 2013-03-31 16:14:40 +05:30
commit 434e159e2b

View file

@ -9,7 +9,7 @@
from collections import defaultdict
from PyQt4.Qt import (QAbstractTableModel, Qt, pyqtSignal, QIcon, QImage,
QModelIndex, QVariant, QDateTime, QColor)
QModelIndex, QVariant, QDateTime, QColor, QPixmap)
from calibre.gui2 import NONE, UNDEFINED_QDATETIME, error_dialog
from calibre.utils.pyparsing import ParseException
@ -94,7 +94,14 @@ def __call__(self, id_, key, fmt, kind, db, icon_cache, icon_bitmap_cache):
return icon_bitmap
d = os.path.join(config_dir, 'cc_icons', icon)
if (os.path.exists(d)):
icon_bitmap = QIcon(d)
icon_bitmap = QPixmap(d)
h = icon_bitmap.height()
w = icon_bitmap.width()
# If the image is landscape and width is more than 50%
# large than height, use the pixmap. This tells Qt to display
# the image full width. It might be clipped to row height.
if w < (3 * h)/2:
icon_bitmap = QIcon(icon_bitmap)
icon_cache[id_][dex] = icon_bitmap
icon_bitmap_cache[icon] = icon_bitmap
self.mi = None