Change icon stuff to use the context menu

This commit is contained in:
Charles Haley 2012-12-20 17:26:58 +01:00
parent 7dd6fbd80e
commit a3e9634e38
3 changed files with 42 additions and 10 deletions

View File

@ -106,6 +106,7 @@ gprefs.defaults['tag_browser_old_look'] = False
gprefs.defaults['book_list_tooltips'] = True
gprefs.defaults['bd_show_cover'] = True
gprefs.defaults['bd_overlay_cover_size'] = False
gprefs.defaults['tags_browser_category_icons'] = {}
# }}}
NONE = QVariant() #: Null value to return from the data function of item models

View File

@ -214,6 +214,10 @@ class TagsModel(QAbstractItemModel): # {{{
iconmap[key] = QIcon(I(category_icon_map[key]))
self.category_icon_map = TagsIcons(iconmap)
self.category_custom_icons = dict()
for k,v in gprefs['tags_browser_category_icons'].items():
icon = QIcon(v)
if len(icon.availableSizes()) > 0:
self.category_custom_icons[k] = icon
self.categories_with_ratings = ['authors', 'series', 'publisher', 'tags']
self.icon_state_map = [None, QIcon(I('plus.png')), QIcon(I('plusplus.png')),
QIcon(I('minus.png')), QIcon(I('minusminus.png'))]
@ -232,6 +236,16 @@ class TagsModel(QAbstractItemModel): # {{{
def gui_parent(self):
return QObject.parent(self)
def set_custom_category_icon(self, key, path):
d = gprefs['tags_browser_category_icons']
if path:
d[key] = path
self.category_custom_icons[key] = QIcon(path)
else:
del d[key]
del self.category_custom_icons[key]
gprefs['tags_browser_category_icons'] = d
def reread_collapse_model(self, state_map, rebuild=True):
if gprefs['tags_browser_collapse_at'] == 0:
self.collapse_model = 'disable'
@ -312,16 +326,9 @@ class TagsModel(QAbstractItemModel): # {{{
else:
tt = _(u'The lookup/search name is "{0}"').format(key)
# Get any customized icons. Done here to account for columns
# coming and going. Should be done only once per model instantiation
if self.category_custom_icons.get(key, None) is None:
icon = QIcon(I('tbci_' + key))
if len(icon.availableSizes()) > 0:
self.category_custom_icons[key] = icon
else:
self.category_custom_icons[key] = \
self.category_icon_map['gst'] if is_gst else \
self.category_icon_map[key]
self.category_custom_icons[key] = \
self.category_icon_map['gst'] if is_gst else self.category_icon_map[key]
if key.startswith('@'):
path_parts = [p for p in key.split('.')]

View File

@ -13,11 +13,12 @@ from itertools import izip
from PyQt4.Qt import (QStyledItemDelegate, Qt, QTreeView, pyqtSignal, QSize,
QIcon, QApplication, QMenu, QPoint, QModelIndex, QToolTip, QCursor,
QDrag)
QDrag, QFileDialog)
from calibre.gui2.tag_browser.model import (TagTreeItem, TAG_SEARCH_STATES,
TagsModel)
from calibre.gui2 import config, gprefs
from calibre.utils.resources import get_image_path
from calibre.utils.search_query_parser import saved_searches
from calibre.utils.icu import sort_key
@ -296,6 +297,22 @@ class TagsView(QTreeView): # {{{
if not action:
return
try:
if action == 'set_icon':
try:
path = QFileDialog.getOpenFileName(self, 'New Icon', get_image_path(None),
filter='*.png *.jpg')
if path:
self._model.set_custom_category_icon(key, unicode(path))
self.recount()
except:
import traceback
traceback.print_exc()
return
if action == 'clear_icon':
self._model.set_custom_category_icon(key, None)
self.recount()
return
if action == 'edit_item':
self.edit(index)
return
@ -533,6 +550,12 @@ class TagsView(QTreeView): # {{{
partial(self.context_menu_handler, action='manage_searches',
category=tag.name if tag else None))
self.context_menu.addSeparator()
self.context_menu.addAction(_('Change category icon'),
partial(self.context_menu_handler, action='set_icon', key=key))
self.context_menu.addAction(_('Restore default icon'),
partial(self.context_menu_handler, action='clear_icon', key=key))
# Always show the user categories editor
self.context_menu.addSeparator()
if key.startswith('@') and \
@ -551,6 +574,7 @@ class TagsView(QTreeView): # {{{
self.context_menu.addAction(_('Show all categories'),
partial(self.context_menu_handler, action='defaults'))
m = self.context_menu.addMenu(_('Change sub-categorization scheme'))
da = m.addAction(_('Disable'),
partial(self.context_menu_handler, action='categorization', category='disable'))