From e3d11e278eac9b11e56b897eb60faaa47ecd0367 Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Sat, 14 Jan 2023 03:05:49 +0100 Subject: [PATCH] Implement proper full-screen mode --- qt/aqt/main.py | 9 ++++++++- qt/aqt/toolbar.py | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index bc1abcda7..11724da9a 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -170,7 +170,7 @@ class AnkiQt(QMainWindow): col: Collection pm: ProfileManagerType web: MainWebView - bottomWeb: AnkiWebView + bottomWeb: BottomWebView def __init__( self, @@ -1363,6 +1363,13 @@ title="{}" {}>{}""".format( window.windowState() ^ Qt.WindowState.WindowFullScreen ) + # Hide Menubar on Windows and Linux + if Qt.WindowState.WindowFullScreen in window.windowState() and not is_mac: + self.form.menubar.setFixedHeight(0) + else: + self.form.menubar.setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX) + self.form.menubar.setMinimumSize(0, 0) + # Auto update ########################################################################## diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index 850be2a3f..073d1e7db 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -3,7 +3,7 @@ from __future__ import annotations import re -from typing import Any, Optional, cast +from typing import Any, Optional, Callable, cast import aqt from anki.sync import SyncStatus @@ -28,6 +28,8 @@ class BottomToolbar: class ToolbarWebView(AnkiWebView): + hide_condition: Callable[..., bool] + def __init__(self, mw: aqt.AnkiQt, title: str) -> None: AnkiWebView.__init__(self, mw, title=title) self.mw = mw @@ -38,17 +40,9 @@ class ToolbarWebView(AnkiWebView): self.hide_timer.setSingleShot(True) self.hide_timer.setInterval(1000) - def eventFilter(self, obj, evt): - if handled := super().eventFilter(obj, evt): - return handled - - # prevent collapse if pointer inside - if evt.type() == QEvent.Type.Enter: - self.hide_timer.stop() - self.hide_timer.setInterval(1000) - return True - - return False + def reset_timer(self) -> None: + self.hide_timer.stop() + self.hide_timer.setInterval(1000) def hide(self) -> None: self.hidden = True @@ -71,6 +65,18 @@ class TopWebView(ToolbarWebView): self.hide_condition = self.mw.pm.hide_top_bar qconnect(self.hide_timer.timeout, self.hide_if_allowed) + def eventFilter(self, obj, evt): + if handled := super().eventFilter(obj, evt): + return handled + + # prevent collapse of both toolbars if pointer is inside one of them + if evt.type() == QEvent.Type.Enter: + self.reset_timer() + self.mw.bottomWeb.reset_timer() + return True + + return False + def on_body_classes_need_update(self) -> None: super().on_body_classes_need_update() self.adjustHeightToFit() @@ -138,6 +144,17 @@ class BottomWebView(ToolbarWebView): self.hide_condition = self.mw.pm.hide_bottom_bar qconnect(self.hide_timer.timeout, self.hide_if_allowed) + def eventFilter(self, obj, evt): + if handled := super().eventFilter(obj, evt): + return handled + + if evt.type() == QEvent.Type.Enter: + self.reset_timer() + self.mw.toolbarWeb.reset_timer() + return True + + return False + def on_body_classes_need_update(self) -> None: super().on_body_classes_need_update()