From 2cc6b87ff3a7323e35cce7ce3b1c8bd9a9b058d4 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 31 Mar 2013 12:06:27 +0200 Subject: [PATCH] When an image is used for a column icon, display that image full-width if the image's width is more than 50% larger than the image's height, otherwise display it in an icon bounding box. --- resources/default_tweaks.py | 15 --------------- src/calibre/gui2/library/models.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 5011227a73..ff1a53de96 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -531,18 +531,3 @@ numeric_collation = False # number here. The default is ten libraries. many_libraries = 10 -#: Use rectangular (non-square) images for icons for columns -# When using column icons, the images are normally displayed as square icons in -# a small box. If necessary, the images are scaled to fit into that box to -# ensure that all the images are the same size. In some cases you might not want -# this behavior, instead wanting the image to be shown as rectangles with their -# orignal aspect ratio. Enter the lookup names of columns where you want this -# behavior. Note that calibre will scale the image so that it is maximum 128 -# pixels wide and that it fits within the height of the displaying row. For this -# reason you should be sure that the images are oriented in landscape, not -# portrait. -# Examples: -# use_rectangular_images_for_icons_for_columns = ['#enum2', '#myrating'] -# use_rectangular_images_for_icons_for_columns = [] -use_rectangular_images_for_icons_for_columns = [''] - diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index b348b724b9..a08c13c79b 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -94,10 +94,14 @@ class ColumnIcon(object): return icon_bitmap d = os.path.join(config_dir, 'cc_icons', icon) if (os.path.exists(d)): - if key in tweaks['use_rectangular_images_for_icons_for_columns']: - icon_bitmap = QPixmap(d) - else: - 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