From a66c5bb4d5a697964eba46fc246a9cdbb8593691 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Aug 2013 23:57:43 +0530 Subject: [PATCH] Grid View: Replace broken Qt shift-click implementation --- src/calibre/gui2/library/alternate_views.py | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 72f79b6b92..119725a751 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -61,6 +61,8 @@ def mousePressEvent(base_class, self, event): if self.indexAt(ep) in self.selectionModel().selectedIndexes() and \ event.button() == Qt.LeftButton and not self.event_has_mods(): self.drag_start_pos = ep + if hasattr(self, 'handle_mouse_press_event'): + return self.handle_mouse_press_event(event) return base_class.mousePressEvent(self, event) def drag_icon(self, cover, multiple): @@ -733,4 +735,30 @@ class GridView(QListView): def restore_hpos(self, hpos): pass + + def handle_mouse_press_event(self, ev): + if QApplication.keyboardModifiers() & Qt.ShiftModifier: + # Shift-Click in QLitView is broken. It selects extra items in + # various circumstances, for example, click on some item in the + # middle of a row then click on an item in the next row, all items + # in the first row will be selected instead of only items after the + # middle item. + index = self.indexAt(ev.pos()) + if not index.isValid(): + return + ci = self.currentIndex() + sm = self.selectionModel() + sm.setCurrentIndex(index, sm.NoUpdate) + if not ci.isValid(): + return + if not sm.hasSelection(): + sm.select(index, sm.ClearAndSelect) + return + cr = ci.row() + tgt = index.row() + top = self.model().index(min(cr, tgt), 0) + bottom = self.model().index(max(cr, tgt), 0) + sm.select(QItemSelection(top, bottom), sm.Select) + else: + return QListView.mousePressEvent(self, ev) # }}}