From bcb3f1c5552901d54f6936fb5b2796efd6731f2e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 19 Jun 2017 21:30:35 +0530 Subject: [PATCH] Tag browser: Add an option to control the spacing between items Also tighten the default spacing a little bit --- src/calibre/gui2/__init__.py | 1 + src/calibre/gui2/preferences/look_feel.py | 4 +- src/calibre/gui2/preferences/look_feel.ui | 52 ++++++++++++++++++----- src/calibre/gui2/tag_browser/view.py | 22 ++++++---- 4 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index e0ca699e9b..51941369fa 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -150,6 +150,7 @@ def create_defs(): defs['tag_browser_show_counts'] = True defs['row_numbers_in_book_list'] = True defs['hidpi'] = 'auto' + defs['tag_browser_item_padding'] = 0.5 create_defs() diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 8e9e54c926..fafbb771c8 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -350,7 +350,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('book_list_tooltips', gprefs) r('show_layout_buttons', gprefs, restart_required=True) r('row_numbers_in_book_list', gprefs) - r('tag_browser_old_look', gprefs, restart_required=True) + r('tag_browser_old_look', gprefs) r('tag_browser_hide_empty_categories', gprefs) r('bd_show_cover', gprefs) r('bd_overlay_cover_size', gprefs) @@ -361,6 +361,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('cover_grid_spacing', gprefs) r('cover_grid_show_title', gprefs) r('tag_browser_show_counts', gprefs) + r('tag_browser_item_padding', gprefs) r('cover_flow_queue_length', config, restart_required=True) r('cover_browser_reflections', gprefs) @@ -707,6 +708,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): m = gui.library_view.model() m.beginResetModel(), m.endResetModel() self.update_font_display() + gui.tags_view.set_look_and_feel() gui.tags_view.reread_collapse_parameters() gui.library_view.refresh_book_details() gui.library_view.set_row_header_visibility() diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 0a1f849848..30b693b814 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -839,7 +839,7 @@ A value of zero means calculate automatically. QFormLayout::ExpandingFieldsGrow - + Co&llapse when more items than: @@ -849,7 +849,7 @@ A value of zero means calculate automatically. - + If a Tag browser category has more than this number of items, it is divided @@ -860,7 +860,7 @@ up into subcategories. If the partition method is set to disable, this value is - + Categories &not to partition: @@ -870,7 +870,7 @@ up into subcategories. If the partition method is set to disable, this value is - + @@ -887,7 +887,7 @@ a few top-level elements. - + Categories with &hierarchical items: @@ -897,7 +897,7 @@ a few top-level elements. - + @@ -915,14 +915,14 @@ then the tags will be displayed each on their own line. - + Use &alternating row colors in the Tag browser - + When checked, calibre will automatically hide any category @@ -956,7 +956,7 @@ if you never want subcategories - + Show &average ratings in the Tag browser @@ -966,7 +966,7 @@ if you never want subcategories - + Show counts for items in the Tag browser. Such as the number of books @@ -978,6 +978,38 @@ see the counts by hovering your mouse over any item. + + + + &Padding between items: + + + opt_tag_browser_item_padding + + + + + + + The spacing between consecutive items in the Tag browser. In units of (ex) which is the approximate height of the letter 'x' in the currently used font. + + + ex + + + 1 + + + -1.000000000000000 + + + 2.000000000000000 + + + 0.100000000000000 + + + diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index a9e5cd8e57..d1daac1aa8 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -30,7 +30,7 @@ class TagDelegate(QStyledItemDelegate): # {{{ def __init__(self, *args, **kwargs): QStyledItemDelegate.__init__(self, *args, **kwargs) - self.old_look = gprefs['tag_browser_old_look'] + self.old_look = False self.rating_pat = re.compile(r'[%s]' % rating_to_stars(3, True)) self.rating_font = QFont(rating_font()) @@ -162,6 +162,12 @@ class TagsView(QTreeView): # {{{ self._model.user_categories_edited.connect(self.user_categories_edited, type=Qt.QueuedConnection) self._model.drag_drop_finished.connect(self.drag_drop_finished) + self.set_look_and_feel() + # Allowing keyboard focus looks bad in the Qt Fusion style and is useless + # anyway since the enter/spacebar keys do nothing + self.setFocusPolicy(Qt.NoFocus) + + def set_look_and_feel(self): stylish_tb = ''' QTreeView { background-color: palette(window); @@ -172,8 +178,8 @@ class TagsView(QTreeView): # {{{ self.setStyleSheet(''' QTreeView::item { border: 1px solid transparent; - padding-top:0.8ex; - padding-bottom:0.8ex; + padding-top:PADex; + padding-bottom:PADex; } QTreeView::item:hover { @@ -181,12 +187,10 @@ class TagsView(QTreeView): # {{{ border: 1px solid #bfcde4; border-radius: 6px; } - ''' + ('' if gprefs['tag_browser_old_look'] else stylish_tb)) - if gprefs['tag_browser_old_look']: - self.setAlternatingRowColors(True) - # Allowing keyboard focus looks bad in the Qt Fusion style and is useless - # anyway since the enter/spacebar keys do nothing - self.setFocusPolicy(Qt.NoFocus) + '''.replace('PAD', str(gprefs['tag_browser_item_padding'])) + ( + '' if gprefs['tag_browser_old_look'] else stylish_tb)) + self.setAlternatingRowColors(gprefs['tag_browser_old_look']) + self.itemDelegate().old_look = gprefs['tag_browser_old_look'] @property def hidden_categories(self):