Viewer: Auto-hide the mouse cursor when unused. Can be turned off via a preference in the Miscellaneous section of the viewer preferences

This commit is contained in:
Kovid Goyal 2020-08-08 15:31:27 +05:30
parent 5cfb18055f
commit f1a8dbc2a0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 26 additions and 0 deletions

View File

@ -196,6 +196,7 @@ class EbookViewer(MainWindow):
self.highlights_widget.web_action.connect(self.web_view.generic_action)
if continue_reading:
self.continue_reading()
self.setup_mouse_auto_hide()
def shortcuts_changed(self, smap):
rmap = defaultdict(list)
@ -675,3 +676,26 @@ class EbookViewer(MainWindow):
self.shutdown_done = True
return MainWindow.closeEvent(self, ev)
# }}}
# Auto-hide mouse cursor {{{
def setup_mouse_auto_hide(self):
QApplication.instance().installEventFilter(self)
self.cursor_hidden = False
self.hide_cursor_timer = t = QTimer(self)
t.setSingleShot(True), t.setInterval(3000)
t.timeout.connect(self.hide_cursor)
t.start()
def eventFilter(self, obj, ev):
if ev.type() == ev.MouseMove:
if self.cursor_hidden:
self.cursor_hidden = False
QApplication.instance().restoreOverrideCursor()
self.hide_cursor_timer.start()
return False
def hide_cursor(self):
if get_session_pref('auto_hide_mouse', True):
self.cursor_hidden = True
QApplication.instance().setOverrideCursor(Qt.BlankCursor)
# }}}

View File

@ -21,6 +21,7 @@ DEFAULTS = {
'save_annotations_in_ebook': True,
'sync_annots_user': '',
'singleinstance': False,
'auto_hide_mouse': True,
}
@ -72,6 +73,7 @@ def create_misc_panel(container, apply_func, cancel_func):
container.append(sync_annots)
container.append(cb('singleinstance', _('Allow only a single instance of the viewer (needs restart)')))
container.append(cb('hide_tooltips', _('Hide mouse-over tooltips in the book text')))
container.append(cb('auto_hide_mouse', _('Auto hide the mouse cursor when unused for a few seconds')))
container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func))