From 102baccbe54546b9461847c78840678698600049 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 26 Apr 2019 21:16:45 -0400 Subject: [PATCH] Login loading icon Add standard mechanism in HButton for loading icon display; have HImage and HIcon base components. --- harmonyqml/backend/client_manager.py | 9 +-- harmonyqml/backend/signal_manager.py | 2 - harmonyqml/components/base/HButton.qml | 69 ++++++++++++++--------- harmonyqml/components/base/HIcon.qml | 10 ++++ harmonyqml/components/base/HImage.qml | 8 +++ harmonyqml/components/pages/LoginPage.qml | 8 ++- harmonyqml/icons/none.svg | 1 + 7 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 harmonyqml/components/base/HIcon.qml create mode 100644 harmonyqml/components/base/HImage.qml create mode 100644 harmonyqml/icons/none.svg diff --git a/harmonyqml/backend/client_manager.py b/harmonyqml/backend/client_manager.py index 46e96fe8..9975e8c9 100644 --- a/harmonyqml/backend/client_manager.py +++ b/harmonyqml/backend/client_manager.py @@ -60,14 +60,15 @@ class ClientManager(QObject): .add_done_callback(lambda _, c=client: self._on_connected(c)) - @pyqtSlot(str, str, str) - @pyqtSlot(str, str, str, str) + @pyqtSlot(str, str, str, result="QVariant") + @pyqtSlot(str, str, str, str, result="QVariant") def new(self, hostname: str, username: str, password: str, device_id: str = "") -> None: client = Client(self, hostname, username, device_id) - client.login(password, self.defaultDeviceName)\ - .add_done_callback(lambda _: self._on_connected(client)) + future = client.login(password, self.defaultDeviceName) + future.add_done_callback(lambda _: self._on_connected(client)) + return future def _on_connected(self, client: Client) -> None: diff --git a/harmonyqml/backend/signal_manager.py b/harmonyqml/backend/signal_manager.py index e1e7e088..a98f7eb5 100644 --- a/harmonyqml/backend/signal_manager.py +++ b/harmonyqml/backend/signal_manager.py @@ -33,7 +33,6 @@ class SignalManager(QObject): def onClientAdded(self, client: Client) -> None: - print(client) self.connectClient(client) self.backend.models.accounts.append(User( userId = client.userId, @@ -196,7 +195,6 @@ class SignalManager(QObject): new_event = RoomEvent(type=etype, dateTime=date_time, dict=edict) if etype == "RoomCreateEvent": - print(room_id, "ff") self.backend.fully_loaded_rooms.add(room_id) if self._events_in_transfer: diff --git a/harmonyqml/components/base/HButton.qml b/harmonyqml/components/base/HButton.qml index 8191deeb..870f4d51 100644 --- a/harmonyqml/components/base/HButton.qml +++ b/harmonyqml/components/base/HButton.qml @@ -3,11 +3,19 @@ import QtQuick.Controls 2.2 import QtQuick.Layouts 1.4 Button { - property alias fontSize: buttonLabel.font.pixelSize + property int fontSize: HStyle.fontSize.normal property color backgroundColor: "lightgray" property alias overlayOpacity: buttonBackgroundOverlay.opacity property string iconName: "" property bool circle: false + property bool loading: false + + property int contentWidth: 0 + + function loadingUntilFutureDone(future) { + loading = true + future.onGotResult.connect(function() { loading = false }) + } id: button display: Button.TextBesideIcon @@ -26,37 +34,44 @@ Button { } } - contentItem: HRowLayout { - spacing: button.text && iconName ? 5 : 0 + Component { + id: buttonContent - Component { - id: buttonIcon - Image { - cache: true - mipmap: true - source: "../../icons/" + iconName + ".svg" - fillMode: Image.PreserveAspectFit - width: button.text ? 20 : 24 - height: width + HRowLayout { + id: contentLayout + spacing: button.text && iconName ? 5 : 0 + Component.onCompleted: contentWidth = implicitWidth + + HIcon { + svgName: loading ? "hourglass" : iconName + dimension: contentLayout.height + } + + HLabel { + text: button.text + font.pixelSize: fontSize + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter } } - Loader { - sourceComponent: iconName ? buttonIcon : undefined - Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + } + + Component { + id: loadingOverlay + HRowLayout { + HIcon { + svgName: "hourglass" + Layout.preferredWidth: contentWidth || -1 + Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + } } + } - HLabel { - id: buttonLabel - - text: button.text - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - - elide: Text.ElideRight - maximumLineCount: 1 - Layout.maximumWidth: button.width - buttonIcon.width - Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter - } + contentItem: Loader { + sourceComponent: + loading && ! iconName ? loadingOverlay : buttonContent } MouseArea { diff --git a/harmonyqml/components/base/HIcon.qml b/harmonyqml/components/base/HIcon.qml new file mode 100644 index 00000000..e33a012e --- /dev/null +++ b/harmonyqml/components/base/HIcon.qml @@ -0,0 +1,10 @@ +import QtQuick 2.7 + +HImage { + property var svgName: null + property int dimension: 20 + + source: "../../icons/" + (svgName || "none") + ".svg" + sourceSize.width: svgName ? dimension : 0 + sourceSize.height: svgName ? dimension : 0 +} diff --git a/harmonyqml/components/base/HImage.qml b/harmonyqml/components/base/HImage.qml new file mode 100644 index 00000000..e66c7a87 --- /dev/null +++ b/harmonyqml/components/base/HImage.qml @@ -0,0 +1,8 @@ +import QtQuick 2.7 + +Image { + asynchronous: true + cache: true + mipmap: true + fillMode: Image.PreserveAspectFit +} diff --git a/harmonyqml/components/pages/LoginPage.qml b/harmonyqml/components/pages/LoginPage.qml index 935bc5ce..3b78befd 100644 --- a/harmonyqml/components/pages/LoginPage.qml +++ b/harmonyqml/components/pages/LoginPage.qml @@ -11,9 +11,9 @@ Image { source: "../../images/login_background.jpg" function login() { - Backend.clientManager.new( + loginButton.loadingUntilFutureDone(Backend.clientManager.new( "matrix.org", identifierField.text, passwordField.text - ) + )) } Rectangle { @@ -119,10 +119,13 @@ Image { Base.HButton { text: qsTr("Register") Layout.fillWidth: true + Layout.preferredHeight: 32 } Base.HButton { + id: loginButton text: qsTr("Login") Layout.fillWidth: true + Layout.preferredHeight: 32 MouseArea { anchors.fill: parent @@ -132,6 +135,7 @@ Image { Base.HButton { text: qsTr("Forgot?") Layout.fillWidth: true + Layout.preferredHeight: 32 } } } diff --git a/harmonyqml/icons/none.svg b/harmonyqml/icons/none.svg new file mode 100644 index 00000000..2d320c47 --- /dev/null +++ b/harmonyqml/icons/none.svg @@ -0,0 +1 @@ +