From 518721ff40a1af0d8414ac3b2696166a8246acd2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Aug 2013 16:01:12 +0530 Subject: [PATCH] Nicer controls for changing grid cover size --- src/calibre/gui2/library/alternate_views.py | 5 +- src/calibre/gui2/preferences/look_feel.py | 19 + src/calibre/gui2/preferences/look_feel.ui | 377 ++++++++++++-------- 3 files changed, 260 insertions(+), 141 deletions(-) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index ea4ecc03e4..d6b05c33ac 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -29,6 +29,9 @@ from calibre.utils.config import prefs CM_TO_INCH = 0.393701 CACHE_FORMAT = 'PPM' +def auto_height(widget): + return max(185, QApplication.instance().desktop().availableGeometry(widget).height() / 5.0) + class EncodeError(ValueError): pass @@ -317,7 +320,7 @@ class CoverDelegate(QStyledItemDelegate): self.original_show_title = show_title = gprefs['cover_grid_show_title'] if height < 0.1: - height = max(185, QApplication.instance().desktop().availableGeometry(self.parent()).height() / 5.0) + height = auto_height(self.parent()) else: height *= self.parent().logicalDpiY() * CM_TO_INCH diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 31f3807ced..27ca36d0a1 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' from threading import Thread +from functools import partial from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, QAbstractListModel, Qt, QIcon, QKeySequence, QPalette, QColor, pyqtSignal) @@ -20,6 +21,7 @@ from calibre.utils.config import prefs, tweaks from calibre.utils.icu import sort_key from calibre.gui2.book_details import get_field_list from calibre.gui2.preferences.coloring import EditRules +from calibre.gui2.library.alternate_views import auto_height, CM_TO_INCH class DisplayedFields(QAbstractListModel): # {{{ @@ -216,9 +218,26 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.tabWidget.currentChanged.connect(self.tab_changed) self.cover_grid_empty_cache.clicked.connect(self.empty_cache) self.cover_grid_open_cache.clicked.connect(self.open_cg_cache) + self.cover_grid_smaller_cover.clicked.connect(partial(self.resize_cover, True)) + self.cover_grid_larger_cover.clicked.connect(partial(self.resize_cover, False)) self.opt_cover_grid_disk_cache_size.setMinimum(self.gui.grid_view.thumbnail_cache.min_disk_cache) self.opt_cover_grid_disk_cache_size.setMaximum(self.gui.grid_view.thumbnail_cache.min_disk_cache * 100) + def resize_cover(self, smaller): + cval = self.opt_cover_grid_height.value() + wval = self.opt_cover_grid_width.value() + if cval < 0.1: + dpi = self.opt_cover_grid_height.logicalDpiY() + cval = auto_height(self.opt_cover_grid_height) / dpi / CM_TO_INCH + if wval < 0.1: + wval = 0.75 * cval + ar = wval / cval + delta = 0.2 * (-1 if smaller else 1) + cval += delta + cval = max(0, cval) + self.opt_cover_grid_height.setValue(cval) + self.opt_cover_grid_width.setValue(cval * ar) + def initialize(self): ConfigWidgetBase.initialize(self) font = gprefs['font'] diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 3669c2efea..71bb3c82db 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -231,47 +231,246 @@ Cover Grid - - - + + + - &Spacing between covers: + Control the cover grid view. You can enble this view by clicking the grid button in the bottom right corner of the main calibre window. - - opt_cover_grid_spacing + + true - - + + - Qt::Horizontal + Qt::Vertical + + + QSizePolicy::Fixed - 417 - 20 + 20 + 10 - - - - - 50 - 50 - - - - true - + + - + Show the book &title below the cover - + + + + + + &Spacing between covers: + + + opt_cover_grid_spacing + + + + + + + The spacing between covers. A value of zero means calculate automatically based on cover size. + + + Automatic + + + cm + + + 1 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Background color for the cover grid: + + + cover_grid_color_button + + + + + + + + 50 + 50 + + + + true + + + + + + + + + + Change &color + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Cover size + + + + + + Cover &Width: + + + opt_cover_grid_width + + + + + + + The width of displayed covers + + + Automatic + + + cm + + + 1 + + + + + + + Make the covers larger, maintaining current aspect ratio. + + + &Larger covers + + + + :/images/plus.png:/images/plus.png + + + + + + + Cover &Height: + + + opt_cover_grid_height + + + + + + + The height of displayed covers + + + Automatic + + + cm + + + 1 + + + + + + + Make the covers smaller, maintaining current aspect ratio. + + + &Smaller covers + + + + :/images/minus.png:/images/minus.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + By default, calibre chooses a cover size based on your computer's screen size. You can change the cover size here: + + + true + + + + + + + Caching of covers for improved performance @@ -364,92 +563,23 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + - - - - Cover &Height: - - - opt_cover_grid_height - - - - - - - Qt::Horizontal - - - - 365 - 20 - - - - - - - - Change &color - - - - - - - Cover &Width: - - - opt_cover_grid_width - - - - - - - The spacing between covers. A value of zero means calculate automatically based on cover size. - - - Automatic - - - cm - - - 1 - - - - - - - Background color for the cover grid: - - - cover_grid_color_button - - - - - - - The width of displayed covers - - - Automatic - - - cm - - - 1 - - - - + Qt::Vertical @@ -462,39 +592,6 @@ - - - - The height of displayed covers - - - Automatic - - - cm - - - 1 - - - - - - - Show the book &title below the cover - - - - - - - Control the cover grid view. You can enble this view by clicking the grid button in the bottom right corner of the main calibre window. - - - true - - -