mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
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:
parent
a6b078e26b
commit
81c5bc7d79
@ -9,7 +9,7 @@ Browsing book collection by tags.
|
||||
|
||||
from itertools import izip
|
||||
|
||||
from PyQt4.Qt import Qt, QTreeView, \
|
||||
from PyQt4.Qt import Qt, QTreeView, QApplication, \
|
||||
QFont, SIGNAL, QSize, QIcon, QPoint, \
|
||||
QAbstractItemModel, QVariant, QModelIndex
|
||||
from calibre.gui2 import config, NONE
|
||||
@ -36,7 +36,9 @@ class TagsView(QTreeView):
|
||||
self.model().refresh()
|
||||
|
||||
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._model.tokens(), self.match_all.isChecked())
|
||||
|
||||
@ -227,12 +229,14 @@ class TagsModel(QAbstractItemModel):
|
||||
|
||||
return len(parent_item.children)
|
||||
|
||||
def reset_all_states(self):
|
||||
def reset_all_states(self, except_=None):
|
||||
for i in xrange(self.rowCount(QModelIndex())):
|
||||
category_index = self.index(i, 0, QModelIndex())
|
||||
for j in xrange(self.rowCount(category_index)):
|
||||
tag_index = self.index(j, 0, category_index)
|
||||
tag_item = tag_index.internalPointer()
|
||||
if tag_item is except_:
|
||||
continue
|
||||
tag = tag_item.tag
|
||||
if tag.state != 0:
|
||||
tag.state = 0
|
||||
@ -248,10 +252,12 @@ class TagsModel(QAbstractItemModel):
|
||||
else:
|
||||
self.ignore_next_search -= 1
|
||||
|
||||
def toggle(self, index):
|
||||
def toggle(self, index, exclusive):
|
||||
if not index.isValid(): return False
|
||||
item = index.internalPointer()
|
||||
if item.type == TagTreeItem.TAG:
|
||||
if exclusive:
|
||||
self.reset_all_states(except_=item)
|
||||
item.toggle()
|
||||
self.ignore_next_search = 2
|
||||
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'), index, index)
|
||||
|
Loading…
x
Reference in New Issue
Block a user