Nicer controls for changing grid cover size

This commit is contained in:
Kovid Goyal 2013-08-12 16:01:12 +05:30
parent b19ee15eca
commit 518721ff40
3 changed files with 260 additions and 141 deletions

View File

@ -29,6 +29,9 @@ from calibre.utils.config import prefs
CM_TO_INCH = 0.393701 CM_TO_INCH = 0.393701
CACHE_FORMAT = 'PPM' CACHE_FORMAT = 'PPM'
def auto_height(widget):
return max(185, QApplication.instance().desktop().availableGeometry(widget).height() / 5.0)
class EncodeError(ValueError): class EncodeError(ValueError):
pass pass
@ -317,7 +320,7 @@ class CoverDelegate(QStyledItemDelegate):
self.original_show_title = show_title = gprefs['cover_grid_show_title'] self.original_show_title = show_title = gprefs['cover_grid_show_title']
if height < 0.1: if height < 0.1:
height = max(185, QApplication.instance().desktop().availableGeometry(self.parent()).height() / 5.0) height = auto_height(self.parent())
else: else:
height *= self.parent().logicalDpiY() * CM_TO_INCH height *= self.parent().logicalDpiY() * CM_TO_INCH

View File

@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from threading import Thread from threading import Thread
from functools import partial
from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog, QColorDialog, from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog, QColorDialog,
QAbstractListModel, Qt, QIcon, QKeySequence, QPalette, QColor, pyqtSignal) 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.utils.icu import sort_key
from calibre.gui2.book_details import get_field_list from calibre.gui2.book_details import get_field_list
from calibre.gui2.preferences.coloring import EditRules from calibre.gui2.preferences.coloring import EditRules
from calibre.gui2.library.alternate_views import auto_height, CM_TO_INCH
class DisplayedFields(QAbstractListModel): # {{{ class DisplayedFields(QAbstractListModel): # {{{
@ -216,9 +218,26 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.tabWidget.currentChanged.connect(self.tab_changed) self.tabWidget.currentChanged.connect(self.tab_changed)
self.cover_grid_empty_cache.clicked.connect(self.empty_cache) self.cover_grid_empty_cache.clicked.connect(self.empty_cache)
self.cover_grid_open_cache.clicked.connect(self.open_cg_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.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) 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): def initialize(self):
ConfigWidgetBase.initialize(self) ConfigWidgetBase.initialize(self)
font = gprefs['font'] font = gprefs['font']

View File

@ -231,8 +231,43 @@
<attribute name="title"> <attribute name="title">
<string>Cover Grid</string> <string>Cover Grid</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QVBoxLayout" name="verticalLayout">
<item row="4" column="1" colspan="3"> <item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>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.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="opt_cover_grid_show_title">
<property name="text">
<string>Show the book &amp;title below the cover</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_16"> <widget class="QLabel" name="label_16">
<property name="text"> <property name="text">
<string>&amp;Spacing between covers:</string> <string>&amp;Spacing between covers:</string>
@ -242,20 +277,50 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="7" colspan="2"> <item>
<widget class="QDoubleSpinBox" name="opt_cover_grid_spacing">
<property name="toolTip">
<string>The spacing between covers. A value of zero means calculate automatically based on cover size.</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>417</width> <width>40</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="3" colspan="3"> </layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Background color for the cover grid:</string>
</property>
<property name="buddy">
<cstring>cover_grid_color_button</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="cover_grid_color_label"> <widget class="QLabel" name="cover_grid_color_label">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -271,7 +336,141 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0" colspan="9"> <item>
<widget class="QPushButton" name="cover_grid_color_button">
<property name="text">
<string>Change &amp;color</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Cover size</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Cover &amp;Width: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_width</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_width">
<property name="toolTip">
<string>The width of displayed covers</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="cover_grid_larger_cover">
<property name="toolTip">
<string>Make the covers larger, maintaining current aspect ratio.</string>
</property>
<property name="text">
<string>&amp;Larger covers</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/plus.png</normaloff>:/images/plus.png</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Cover &amp;Height: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_height</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_height">
<property name="toolTip">
<string>The height of displayed covers</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="cover_grid_smaller_cover">
<property name="toolTip">
<string>Make the covers smaller, maintaining current aspect ratio.</string>
</property>
<property name="text">
<string>&amp;Smaller covers</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/minus.png</normaloff>:/images/minus.png</iconset>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_20">
<property name="text">
<string>By default, calibre chooses a cover size based on your computer's screen size. You can change the cover size here:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3"> <widget class="QGroupBox" name="groupBox_3">
<property name="title"> <property name="title">
<string>Caching of covers for improved performance</string> <string>Caching of covers for improved performance</string>
@ -364,92 +563,23 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="1" column="3">
</widget> <spacer name="horizontalSpacer_5">
</item>
<item row="1" column="2" colspan="3">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Cover &amp;Height: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_height</cstring>
</property>
</widget>
</item>
<item row="2" column="8">
<spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>365</width> <width>40</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="6" colspan="2"> </layout>
<widget class="QPushButton" name="cover_grid_color_button">
<property name="text">
<string>Change &amp;color</string>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Cover &amp;Width: </string>
</property>
<property name="buddy">
<cstring>opt_cover_grid_width</cstring>
</property>
</widget>
</item>
<item row="4" column="4" colspan="3">
<widget class="QDoubleSpinBox" name="opt_cover_grid_spacing">
<property name="toolTip">
<string>The spacing between covers. A value of zero means calculate automatically based on cover size.</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Background color for the cover grid:</string>
</property>
<property name="buddy">
<cstring>cover_grid_color_button</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="opt_cover_grid_width">
<property name="toolTip">
<string>The width of displayed covers</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -462,39 +592,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="5" colspan="2">
<widget class="QDoubleSpinBox" name="opt_cover_grid_height">
<property name="toolTip">
<string>The height of displayed covers</string>
</property>
<property name="specialValueText">
<string>Automatic</string>
</property>
<property name="suffix">
<string> cm</string>
</property>
<property name="decimals">
<number>1</number>
</property>
</widget>
</item>
<item row="3" column="0" colspan="9">
<widget class="QCheckBox" name="opt_cover_grid_show_title">
<property name="text">
<string>Show the book &amp;title below the cover</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="9">
<widget class="QLabel" name="label_19">
<property name="text">
<string>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.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_4"> <widget class="QWidget" name="tab_4">