From 72b5954ce314a5851a1c7315e68da6c49f6117bc Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 17 Aug 2019 13:35:43 -0400 Subject: [PATCH] Simplify startup and improve its animation - Remove Python.loadingAccounts/willLoadAccounts - Fix HPage SwipeView bug that caused its inner SidePane to steal focus - Use overshoot for animation - Get rid of sidepane flickering - Set default HNumberAnimation easing.type to OutQuad, specify InOutQuad for HCheckBox --- TODO.md | 1 - src/qml/Base/HCheckBox.qml | 7 +++++- src/qml/Base/HNumberAnimation.qml | 6 ++--- src/qml/Base/HPage.qml | 3 ++- src/qml/Python.qml | 15 ++++-------- src/qml/SidePane/SidePane.qml | 5 +++- src/qml/UI.qml | 40 +++++++++++++++---------------- src/qml/Window.qml | 2 +- 8 files changed, 39 insertions(+), 40 deletions(-) diff --git a/TODO.md b/TODO.md index 221bfdbd..5a41f357 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ - `^property type name$` - Use [Animators](https://doc.qt.io/qt-5/qml-qtquick-animator.html) - Choose a better default easing type for animations - - Use overshoot for the scale login thing - Sendbox - HButton - Control: hovered, visualFocus, enaled diff --git a/src/qml/Base/HCheckBox.qml b/src/qml/Base/HCheckBox.qml index 7aac9fe0..00c0ecd8 100644 --- a/src/qml/Base/HCheckBox.qml +++ b/src/qml/Base/HCheckBox.qml @@ -30,7 +30,12 @@ CheckBox { visible: scale > 0 scale: box.checked ? 1 : 0 - Behavior on scale { HNumberAnimation { overshoot: 4 } } + Behavior on scale { + HNumberAnimation { + overshoot: 4 + easing.type: Easing.InOutBack + } + } } } diff --git a/src/qml/Base/HNumberAnimation.qml b/src/qml/Base/HNumberAnimation.qml index 7864f5ff..09b391a8 100644 --- a/src/qml/Base/HNumberAnimation.qml +++ b/src/qml/Base/HNumberAnimation.qml @@ -1,10 +1,10 @@ import QtQuick 2.12 NumberAnimation { - property real factor: Math.max(overshoot / 1.75, 1.0) + property real factor: 1.0 property real overshoot: 1.0 - duration: theme.animationDuration * factor - easing.type: overshoot > 1 ? Easing.InOutBack : Easing.Linear + duration: theme.animationDuration * Math.max(overshoot / 1.7, 1.0) * factor + easing.type: overshoot > 1 ? Easing.OutBack : Easing.Linear easing.overshoot: overshoot } diff --git a/src/qml/Base/HPage.qml b/src/qml/Base/HPage.qml index 019415bf..2fd86c2e 100644 --- a/src/qml/Base/HPage.qml +++ b/src/qml/Base/HPage.qml @@ -18,12 +18,13 @@ SwipeView { Math.min(theme.spacing * width / 400, theme.spacing) id: swipeView - currentIndex: 1 clip: true interactive: sidePane.reduce + currentIndex: 1 SidePane { implicitWidth: swipeView.width + animateWidth: false // Without this, the SidePane gets auto-focused collapse: false reduce: false visible: swipeView.interactive diff --git a/src/qml/Python.qml b/src/qml/Python.qml index 70cf74ac..66f99880 100644 --- a/src/qml/Python.qml +++ b/src/qml/Python.qml @@ -7,11 +7,9 @@ Python { id: py property bool ready: false + property bool startupAnyAccountsSaved: false property var pendingCoroutines: ({}) - signal willLoadAccounts(bool will) - property bool loadingAccounts: false - function callSync(name, args=[]) { return call_sync("APP.backend." + name, args) } @@ -59,15 +57,10 @@ Python { importNames("python", ["APP"], () => { loadSettings(() => { callCoro("saved_accounts.any_saved", [], any => { - py.ready = true - willLoadAccounts(any) + if (any) { py.callCoro("load_saved_accounts", []) } - if (any) { - py.loadingAccounts = true - py.callCoro("load_saved_accounts", [], () => { - py.loadingAccounts = false - }) - } + py.startupAnyAccountsSaved = any + py.ready = true }) }) }) diff --git a/src/qml/SidePane/SidePane.qml b/src/qml/SidePane/SidePane.qml index 23ece37f..dc3ecd7d 100644 --- a/src/qml/SidePane/SidePane.qml +++ b/src/qml/SidePane/SidePane.qml @@ -14,6 +14,7 @@ HRectangle { property bool manuallyResizing: false property bool manuallyResized: false property int manualWidth: 0 + property bool animateWidth: true Component.onCompleted: { if (window.uiState.sidePaneManualWidth) { @@ -61,7 +62,9 @@ HRectangle { 0 : theme.spacing Behavior on currentSpacing { HNumberAnimation {} } - Behavior on implicitWidth { HNumberAnimation {} } + Behavior on implicitWidth { + HNumberAnimation { factor: animateWidth ? 1 : 0 } + } HColumnLayout { diff --git a/src/qml/UI.qml b/src/qml/UI.qml index 00840059..9a6dae5a 100644 --- a/src/qml/UI.qml +++ b/src/qml/UI.qml @@ -22,27 +22,9 @@ HRectangle { } } - Connections { - target: py - onWillLoadAccounts: will => { - if (! will) { - pageStack.showPage("SignIn") - return - } - - let page = window.uiState.page - let props = window.uiState.pageProperties - - if (page == "Chat/Chat.qml") { - pageStack.showRoom(props.userId, props.roomId) - } else { - pageStack.show(page, props) - } - } - } - property bool accountsPresent: - (modelSources["Account"] || []).length > 0 || py.loadingAccounts + (modelSources["Account"] || []).length > 0 || + py.startupAnyAccountsSaved HImage { id: mainUIBackground @@ -74,7 +56,7 @@ HRectangle { width: implicitWidth Layout.minimumWidth: reduce ? 0 : theme.sidePane.collapsedWidth Layout.maximumWidth: - window.width -theme.minimumSupportedWidthPlusSpacing + window.width - theme.minimumSupportedWidthPlusSpacing Behavior on Layout.minimumWidth { HNumberAnimation {} } } @@ -83,6 +65,22 @@ HRectangle { id: pageStack property bool isWide: width > theme.contentIsWideAbove + Component.onCompleted: { + if (! py.startupAnyAccountsSaved) { + pageStack.showPage("SignIn") + return + } + + let page = window.uiState.page + let props = window.uiState.pageProperties + + if (page == "Chat/Chat.qml") { + pageStack.showRoom(props.userId, props.roomId) + } else { + pageStack.show(page, props) + } + } + function show(componentUrl, properties={}) { pageStack.replace(componentUrl, properties) } diff --git a/src/qml/Window.qml b/src/qml/Window.qml index ec20a40b..93936d00 100644 --- a/src/qml/Window.qml +++ b/src/qml/Window.qml @@ -43,6 +43,6 @@ ApplicationWindow { scale: py.ready ? 1 : 0.5 source: py.ready ? "UI.qml" : "" - Behavior on scale { HNumberAnimation {} } + Behavior on scale { HNumberAnimation { overshoot: 5; factor: 1.2 } } } }