From 9460911d90ae480336b50301344d31291e48d883 Mon Sep 17 00:00:00 2001 From: Yuki <65764619+YukiNagat0@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:18:32 +0300 Subject: [PATCH] Fix menubar in fullscreen (#3710) * Fix/menubar in fullscreen * CONTRIBUTORS file * Fix/menubar in fullscreen * CONTRIBUTORS file * Fix and add Type hints --- CONTRIBUTORS | 2 ++ qt/aqt/main.py | 17 +++++++++++++++-- qt/aqt/toolbar.py | 6 +++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 107f7419a..002db5545 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -206,6 +206,8 @@ Lukas Sommer Niclas Heinz Omar Kohl David Elizalde +Yuki + ******************** The text of the 3 clause BSD license follows: diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 9482a27e7..37876c2f7 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -147,17 +147,27 @@ class MainWebView(AnkiWebView): return # Main webview specific event handling - def eventFilter(self, obj, evt): + def eventFilter(self, obj: QObject | None, evt: QEvent | None) -> bool: if handled := super().eventFilter(obj, evt): return handled if evt.type() == QEvent.Type.Leave: + handled_leave = False + + # Show menubar when mouse moves outside main webview in fullscreen + if self.mw.fullscreen: + self.mw.show_menubar() + handled_leave = True + # Show toolbar when mouse moves outside main webview # and automatically hide it with delay after mouse has entered again + # The toolbar's hide timer will also trigger menubar hiding when in fullscreen mode if self.mw.pm.hide_top_bar() or self.mw.pm.hide_bottom_bar(): self.mw.toolbarWeb.show() self.mw.bottomWeb.show() - return True + handled_leave = True + + return handled_leave if evt.type() == QEvent.Type.Enter: self.mw.toolbarWeb.hide_timer.start() @@ -790,6 +800,9 @@ class AnkiQt(QMainWindow): def _reviewState(self, oldState: MainWindowState) -> None: self.reviewer.show() + if self.fullscreen: + self.hide_menubar() + if self.pm.hide_top_bar(): self.toolbarWeb.hide_timer.setInterval(500) self.toolbarWeb.hide_timer.start() diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index 56fcb206e..ab40c510c 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -98,6 +98,9 @@ class TopWebView(ToolbarWebView): if self.mw.state != "review": return + if self.mw.fullscreen: + self.mw.hide_menubar() + if self.mw.pm.hide_top_bar(): if ( self.mw.pm.top_bar_hide_mode() == HideMode.FULLSCREEN @@ -115,14 +118,11 @@ class TopWebView(ToolbarWebView): self.eval( """document.body.classList.add("hidden"); """, ) - if self.mw.fullscreen: - self.mw.hide_menubar() def show(self) -> None: super().show() self.eval("""document.body.classList.remove("hidden"); """) - self.mw.show_menubar() def flatten(self) -> None: self.eval("""document.body.classList.add("flat"); """)