Viewer: Fix keyboard shortcut to toggle highlights panel not working when the highlights panel is itself focused. Fixes #1900938 [E-book reader: Ctrl+h doesn't hide the Highlights panel](https://bugs.launchpad.net/calibre/+bug/1900938)

This commit is contained in:
Kovid Goyal 2020-10-23 11:50:38 +05:30
parent 654097bdc6
commit 3482bbe852
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 1 deletions

View File

@ -24,7 +24,7 @@ from calibre.gui2.library.annotations import (
) )
from calibre.gui2.viewer.config import vprefs from calibre.gui2.viewer.config import vprefs
from calibre.gui2.viewer.search import SearchInput from calibre.gui2.viewer.search import SearchInput
from calibre.gui2.viewer.shortcuts import index_to_key_sequence from calibre.gui2.viewer.shortcuts import get_shortcut_for, index_to_key_sequence
from calibre.gui2.widgets2 import Dialog from calibre.gui2.widgets2 import Dialog
from calibre_extensions.progress_indicator import set_no_activate_on_click from calibre_extensions.progress_indicator import set_no_activate_on_click
from polyglot.builtins import range from polyglot.builtins import range
@ -398,6 +398,7 @@ class HighlightsPanel(QWidget):
jump_to_cfi = pyqtSignal(object) jump_to_cfi = pyqtSignal(object)
request_highlight_action = pyqtSignal(object, object) request_highlight_action = pyqtSignal(object, object)
web_action = pyqtSignal(object, object) web_action = pyqtSignal(object, object)
toggle_requested = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
@ -514,3 +515,9 @@ class HighlightsPanel(QWidget):
def selected_text_changed(self, text, annot_id): def selected_text_changed(self, text, annot_id):
if annot_id: if annot_id:
self.highlights.find_annot_id(annot_id) self.highlights.find_annot_id(annot_id)
def keyPressEvent(self, ev):
sc = get_shortcut_for(self, ev)
if sc == 'toggle_highlights' or ev.key() == Qt.Key_Escape:
self.toggle_requested.emit()
return super().keyPressEvent(ev)

View File

@ -156,6 +156,7 @@ class EbookViewer(MainWindow):
self.highlights_widget = w = HighlightsPanel(self) self.highlights_widget = w = HighlightsPanel(self)
self.highlights_dock.setWidget(w) self.highlights_dock.setWidget(w)
w.toggle_requested.connect(self.toggle_highlights)
self.web_view = WebView(self) self.web_view = WebView(self)
self.web_view.cfi_changed.connect(self.cfi_changed) self.web_view.cfi_changed.connect(self.cfi_changed)