From e3a77bf17fdd78d27bfe3844b793fb4a8a05a95d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Sep 2016 17:46:12 +0530 Subject: [PATCH] Tag Browser: Add an option in Preferences->Look & Feel->Tag Browser to turn off the display of counts in the Tag Browser --- src/calibre/gui2/__init__.py | 1 + src/calibre/gui2/preferences/look_feel.py | 1 + src/calibre/gui2/preferences/look_feel.ui | 18 +++++++++++++++--- src/calibre/gui2/tag_browser/view.py | 16 ++++++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 39cf115a2a..4f9360936c 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -145,6 +145,7 @@ defs['show_emblems'] = False defs['emblem_size'] = 32 defs['emblem_position'] = 'left' defs['metadata_diff_mark_rejected'] = False +defs['tag_browser_show_counts'] = True del defs # }}} diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 8759998bf7..cf0d93b93f 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -288,6 +288,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('cover_grid_disk_cache_size', gprefs) r('cover_grid_spacing', gprefs) r('cover_grid_show_title', gprefs) + r('tag_browser_show_counts', gprefs) r('cover_flow_queue_length', config, restart_required=True) r('cover_browser_reflections', gprefs) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 25aedfd637..fc4a261ffc 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -898,14 +898,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 @@ -932,7 +932,7 @@ if you never want subcategories - Tags browser category &partitioning method: + &Tags browser category partitioning method: opt_tags_browser_partition_method @@ -949,6 +949,18 @@ if you never want subcategories + + + + Show counts for items in the Tag Browser. Such as the number of books +by each author, the number of authors, etc. If you turn it off, you can still +see the counts by hovering your mouse over any item. + + + Show &counts in the Tag Browser + + + diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index 724f9f38a3..67fbccad70 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -59,13 +59,17 @@ class TagDelegate(QStyledItemDelegate): # {{{ def draw_text(self, style, painter, option, widget, index, item): tr = style.subElementRect(style.SE_ItemViewItemText, option, widget) - count = unicode(index.data(COUNT_ROLE)) - width = painter.fontMetrics().boundingRect(count).width() text = index.data(Qt.DisplayRole) - r = QRect(tr) - r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4) - painter.drawText(r, Qt.AlignCenter | Qt.TextSingleLine, count) - tr.setRight(r.left() - 1) + hover = option.state & style.State_MouseOver + if hover or gprefs['tag_browser_show_counts']: + count = unicode(index.data(COUNT_ROLE)) + width = painter.fontMetrics().boundingRect(count).width() + r = QRect(tr) + r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4) + painter.drawText(r, Qt.AlignCenter | Qt.TextSingleLine, count) + tr.setRight(r.left() - 1) + else: + tr.setRight(tr.right() - 1) is_rating = item.type == TagTreeItem.TAG and not self.rating_pat.sub('', text) if is_rating: painter.setFont(self.rating_font)