Implement proper full-screen mode

This commit is contained in:
Matthias Metelka 2023-01-14 03:05:49 +01:00
parent 08f02e441d
commit e3d11e278e
2 changed files with 37 additions and 13 deletions

View file

@ -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="{}" {}>{}</button>""".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
##########################################################################

View file

@ -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:
def reset_timer(self) -> None:
self.hide_timer.stop()
self.hide_timer.setInterval(1000)
return True
return False
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()