From 274914f2e184fac7d20a86d249da28e17bafdf2d Mon Sep 17 00:00:00 2001 From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com> Date: Mon, 16 Jan 2023 09:16:17 +0100 Subject: [PATCH] Fix bottom toolbar animating on startup Also fix bottom toolbar not appearing when unchecking hide mode in reviewer. --- qt/aqt/main.py | 2 +- qt/aqt/profiles.py | 1 + qt/aqt/toolbar.py | 30 +++++++++++++++--------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 2f54a69f7..066e6f2ee 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -708,7 +708,7 @@ class AnkiQt(QMainWindow): gui_hooks.state_will_change(state, oldState) getattr(self, f"_{state}State", lambda *_: None)(oldState, *args) if state != "resetRequired": - self.bottomWeb.show() + self.bottomWeb.adjustHeightToFit() gui_hooks.state_did_change(state, oldState) def _deckBrowserState(self, oldState: MainWindowState) -> None: diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 5adbee797..9c67baa56 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -552,6 +552,7 @@ create table if not exists profiles def set_hide_bottom_bar(self, on: bool) -> None: self.meta["hide_bottom_bar"] = on + gui_hooks.body_classes_need_update() def bottom_bar_hide_mode(self) -> HideMode: return self.meta.get("bottom_bar_hide_mode", HideMode.FULLSCREEN) diff --git a/qt/aqt/toolbar.py b/qt/aqt/toolbar.py index 9364701ba..0843cc5c6 100644 --- a/qt/aqt/toolbar.py +++ b/qt/aqt/toolbar.py @@ -77,7 +77,6 @@ class TopWebView(ToolbarWebView): def on_body_classes_need_update(self) -> None: super().on_body_classes_need_update() - self.adjustHeightToFit() if self.mw.state == "review": if self.mw.pm.hide_top_bar(): @@ -194,19 +193,14 @@ class BottomWebView(ToolbarWebView): def on_body_classes_need_update(self) -> None: super().on_body_classes_need_update() + if self.mw.state == "review": + self.show() - self.adjustHeightToFit() - self.show() - - def _onHeight(self, qvar: Optional[int]) -> None: - self.web_height = int(qvar) - - if qvar is None: - self.mw.progress.single_shot(1000, self.mw.reset) - return + def animate_height(self, height: int) -> None: + self.web_height = height if self.mw.pm.reduce_motion(): - self.setFixedHeight(int(qvar)) + self.setFixedHeight(height) else: # Collapse/Expand animation self.setMinimumHeight(0) @@ -215,8 +209,8 @@ class BottomWebView(ToolbarWebView): ) self.animation.setDuration(int(theme_manager.var(props.TRANSITION))) self.animation.setStartValue(self.height()) - self.animation.setEndValue(int(qvar)) - qconnect(self.animation.finished, lambda: self.setFixedHeight(int(qvar))) + self.animation.setEndValue(height) + qconnect(self.animation.finished, lambda: self.setFixedHeight(height)) self.animation.start() def hide_if_allowed(self) -> None: @@ -236,13 +230,19 @@ class BottomWebView(ToolbarWebView): def hide(self) -> None: super().hide() - self._onHeight(1) + self.hidden = True + self.animate_height(1) def show(self) -> None: super().show() self.hidden = False - self.adjustHeightToFit() + if self.mw.state == "review": + self.evalWithCallback( + "document.documentElement.offsetHeight", self.animate_height + ) + else: + self.adjustHeightToFit() class Toolbar: