Browse by tags: Make clicking on a tag cause all other tags to be un selected, unless CTRL or SHIFT is pressed.

This commit is contained in:
Kovid Goyal 2009-12-30 20:14:33 -07:00
parent a6b078e26b
commit 81c5bc7d79

View File

@ -9,7 +9,7 @@ Browsing book collection by tags.
from itertools import izip from itertools import izip
from PyQt4.Qt import Qt, QTreeView, \ from PyQt4.Qt import Qt, QTreeView, QApplication, \
QFont, SIGNAL, QSize, QIcon, QPoint, \ QFont, SIGNAL, QSize, QIcon, QPoint, \
QAbstractItemModel, QVariant, QModelIndex QAbstractItemModel, QVariant, QModelIndex
from calibre.gui2 import config, NONE from calibre.gui2 import config, NONE
@ -36,7 +36,9 @@ class TagsView(QTreeView):
self.model().refresh() self.model().refresh()
def toggle(self, index): def toggle(self, index):
if self._model.toggle(index): modifiers = int(QApplication.keyboardModifiers())
exclusive = modifiers not in (Qt.CTRL, Qt.SHIFT)
if self._model.toggle(index, exclusive):
self.emit(SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'), self.emit(SIGNAL('tags_marked(PyQt_PyObject, PyQt_PyObject)'),
self._model.tokens(), self.match_all.isChecked()) self._model.tokens(), self.match_all.isChecked())
@ -227,12 +229,14 @@ class TagsModel(QAbstractItemModel):
return len(parent_item.children) return len(parent_item.children)
def reset_all_states(self): def reset_all_states(self, except_=None):
for i in xrange(self.rowCount(QModelIndex())): for i in xrange(self.rowCount(QModelIndex())):
category_index = self.index(i, 0, QModelIndex()) category_index = self.index(i, 0, QModelIndex())
for j in xrange(self.rowCount(category_index)): for j in xrange(self.rowCount(category_index)):
tag_index = self.index(j, 0, category_index) tag_index = self.index(j, 0, category_index)
tag_item = tag_index.internalPointer() tag_item = tag_index.internalPointer()
if tag_item is except_:
continue
tag = tag_item.tag tag = tag_item.tag
if tag.state != 0: if tag.state != 0:
tag.state = 0 tag.state = 0
@ -248,10 +252,12 @@ class TagsModel(QAbstractItemModel):
else: else:
self.ignore_next_search -= 1 self.ignore_next_search -= 1
def toggle(self, index): def toggle(self, index, exclusive):
if not index.isValid(): return False if not index.isValid(): return False
item = index.internalPointer() item = index.internalPointer()
if item.type == TagTreeItem.TAG: if item.type == TagTreeItem.TAG:
if exclusive:
self.reset_all_states(except_=item)
item.toggle() item.toggle()
self.ignore_next_search = 2 self.ignore_next_search = 2
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), index, index) self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), index, index)