diff --git a/src/calibre/gui2/viewer/search.py b/src/calibre/gui2/viewer/search.py index 30002aaeada2..16cd6b59f53d 100644 --- a/src/calibre/gui2/viewer/search.py +++ b/src/calibre/gui2/viewer/search.py @@ -6,8 +6,8 @@ from collections import Counter, OrderedDict from html import escape from qt.core import ( - QAbstractItemView, QCheckBox, QComboBox, QFont, QHBoxLayout, QIcon, QLabel, Qt, - QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal, + QAbstractItemView, QCheckBox, QComboBox, QFont, QHBoxLayout, QIcon, QLabel, QMenu, + Qt, QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal, ) from threading import Thread @@ -542,6 +542,8 @@ class Results(QTreeWidget): # {{{ def __init__(self, parent=None): QTreeWidget.__init__(self, parent) + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) + self.customContextMenuRequested.connect(self.show_context_menu) self.setHeaderHidden(True) self.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.delegate = ResultsDelegate(self) @@ -558,6 +560,14 @@ def __init__(self, parent=None): self.gesture_manager = GestureManager(self) self.setVerticalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel) + def show_context_menu(self, point): + self.context_menu = m = QMenu(self) + m.addAction(QIcon.ic('plus.png'), _('Expand all'), self.expandAll) + m.addAction(QIcon.ic('minus.png'), _('Collapse all'), self.collapseAll) + self.context_menu.popup(self.mapToGlobal(point)) + return True + + def viewportEvent(self, ev): if hasattr(self, 'gesture_manager'): ret = self.gesture_manager.handle_event(ev)