Book list: Fix Ctrl+Home/End not selecting the first/last book

This commit is contained in:
Kovid Goyal 2014-08-27 18:29:05 +05:30
parent e8d2a6a02f
commit 5ace899bfb
2 changed files with 13 additions and 2 deletions

View File

@ -18,7 +18,8 @@ from PyQt5.Qt import (
QTimer, QPalette, QColor, QItemSelection, QPixmap, QMenu, QApplication, QTimer, QPalette, QColor, QItemSelection, QPixmap, QMenu, QApplication,
QMimeData, QUrl, QDrag, QPoint, QPainter, QRect, pyqtProperty, QEvent, QMimeData, QUrl, QDrag, QPoint, QPainter, QRect, pyqtProperty, QEvent,
QPropertyAnimation, QEasingCurve, pyqtSlot, QHelpEvent, QAbstractItemView, QPropertyAnimation, QEasingCurve, pyqtSlot, QHelpEvent, QAbstractItemView,
QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush, qRed, qGreen, qBlue) QStyleOptionViewItem, QToolTip, QByteArray, QBuffer, QBrush, qRed, qGreen,
qBlue, QItemSelectionModel)
from calibre import fit_image, prints, prepare_string_for_xml, human_readable from calibre import fit_image, prints, prepare_string_for_xml, human_readable
from calibre.constants import DEBUG, config_dir from calibre.constants import DEBUG, config_dir
@ -955,4 +956,9 @@ class GridView(QListView):
index = self.model().index(nr, 0) index = self.model().index(nr, 0)
return index return index
def selectionCommand(self, index, event):
if event and event.type() == event.KeyPress and event.key() in (Qt.Key_Home, Qt.Key_End) and event.modifiers() & Qt.CTRL:
return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows
return super(GridView, self).selectionCommand(index, event)
# }}} # }}}

View File

@ -13,7 +13,7 @@ from collections import OrderedDict
from PyQt5.Qt import ( from PyQt5.Qt import (
QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, QFont, QModelIndex, QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, QFont, QModelIndex,
QIcon, QItemSelection, QMimeData, QDrag, QStyle, QPoint, QUrl, QHeaderView, QIcon, QItemSelection, QMimeData, QDrag, QStyle, QPoint, QUrl, QHeaderView,
QStyleOptionHeader) QStyleOptionHeader, QItemSelectionModel)
from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate, from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate,
TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate, TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate,
@ -904,6 +904,11 @@ class BooksView(QTableView): # {{{
return self.model().index(self.model().rowCount(QModelIndex()) - 1, orig.column()) return self.model().index(self.model().rowCount(QModelIndex()) - 1, orig.column())
return index return index
def selectionCommand(self, index, event):
if event and event.type() == event.KeyPress and event.key() in (Qt.Key_Home, Qt.Key_End) and event.modifiers() & Qt.CTRL:
return QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows
return super(BooksView, self).selectionCommand(index, event)
def ids_to_rows(self, ids): def ids_to_rows(self, ids):
row_map = OrderedDict() row_map = OrderedDict()
ids = frozenset(ids) ids = frozenset(ids)