Ebook viewer: Respond to key presses even when the book display area does not have keyboard focus

This commit is contained in:
Kovid Goyal 2011-08-10 14:14:26 -06:00
parent 9b19e1638e
commit f6ac950be2
2 changed files with 13 additions and 1 deletions

View File

@ -979,6 +979,11 @@ class DocumentView(QWebView): # {{{
return ret
def keyPressEvent(self, event):
if not self.handle_key_press(event):
return QWebView.keyPressEvent(self, event)
def handle_key_press(self, event):
handled = True
key = self.shortcuts.get_match(event)
func = self.goto_location_actions.get(key, None)
if func is not None:
@ -996,7 +1001,8 @@ class DocumentView(QWebView): # {{{
elif key == 'Right':
self.scroll_by(x=15)
else:
return QWebView.keyPressEvent(self, event)
handled = False
return handled
def resizeEvent(self, event):
ret = QWebView.resizeEvent(self, event)

View File

@ -755,6 +755,12 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
if self.current_index > 0:
self.load_path(self.iterator.spine[self.current_index-1], pos=1.0)
def keyPressEvent(self, event):
MainWindow.keyPressEvent(self, event)
if not event.isAccepted():
if not self.view.handle_key_press(event):
event.ignore()
def __enter__(self):
return self