Nicer mouse cursor handling for the Tag Browser

This commit is contained in:
Kovid Goyal 2014-10-04 10:57:33 +05:30
parent bb1a9b70f1
commit 258954e17b

View File

@ -65,7 +65,6 @@ class TagDelegate(QStyledItemDelegate): # {{{
icon.On) icon.On)
painter.restore() painter.restore()
# }}} # }}}
class TagsView(QTreeView): # {{{ class TagsView(QTreeView): # {{{
@ -89,10 +88,10 @@ class TagsView(QTreeView): # {{{
def __init__(self, parent=None): def __init__(self, parent=None):
QTreeView.__init__(self, parent=None) QTreeView.__init__(self, parent=None)
self.setMouseTracking(True)
self.alter_tb = None self.alter_tb = None
self.disable_recounting = False self.disable_recounting = False
self.setUniformRowHeights(True) self.setUniformRowHeights(True)
self.setCursor(Qt.PointingHandCursor)
self.setIconSize(QSize(20, 20)) self.setIconSize(QSize(20, 20))
self.setTabKeyNavigation(True) self.setTabKeyNavigation(True)
self.setAnimated(True) self.setAnimated(True)
@ -236,6 +235,10 @@ class TagsView(QTreeView): # {{{
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
dex = self.indexAt(event.pos()) dex = self.indexAt(event.pos())
if dex.isValid():
self.setCursor(Qt.PointingHandCursor)
else:
self.unsetCursor()
if self.in_drag_drop or not dex.isValid(): if self.in_drag_drop or not dex.isValid():
QTreeView.mouseMoveEvent(self, event) QTreeView.mouseMoveEvent(self, event)
return return
@ -485,11 +488,11 @@ class TagsView(QTreeView): # {{{
action='delete_search', key=tag.original_name)) action='delete_search', key=tag.original_name))
if key.startswith('@') and not item.is_gst: if key.startswith('@') and not item.is_gst:
self.context_menu.addAction(self.user_category_icon, self.context_menu.addAction(self.user_category_icon,
_('Remove %(item)s from category %(cat)s')% _('Remove %(item)s from category %(cat)s')%
dict(item=display_name(tag), cat=item.py_name), dict(item=display_name(tag), cat=item.py_name),
partial(self.context_menu_handler, partial(self.context_menu_handler,
action='delete_item_from_user_category', action='delete_item_from_user_category',
key=key, index=tag_item)) key=key, index=tag_item))
if tag.is_searchable: if tag.is_searchable:
# Add the search for value items. All leaf nodes are searchable # Add the search for value items. All leaf nodes are searchable
self.context_menu.addAction(self.search_icon, self.context_menu.addAction(self.search_icon,
@ -727,5 +730,3 @@ class TagsView(QTreeView): # {{{
self.setCurrentIndex(idx) self.setCurrentIndex(idx)
# }}} # }}}