Skip to content

Commit

Permalink
Fix #2034757 [[Enhancement] E-book viewer: search pane should have a …
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Sep 14, 2023
1 parent ad2f746 commit 3b6e829
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/calibre/gui2/viewer/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 3b6e829

Please sign in to comment.