From 0db5a3233d536faaf60c7dfab59e2a47eaf8c493 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 27 Apr 2019 18:54:33 -0400 Subject: [PATCH] Change pages organization - UI (previously MainUI) is back to being the only component loaded as Window's child - UI has the background image previously only for the SignInPage - If there are no accounts, the UI Loader's initialItem is the SignInPage - The SidePane becomes visible when there's >=1 account connected --- harmonyqml/components/UI.qml | 51 ++++++++++++ harmonyqml/components/Window.qml | 3 +- .../components/pages/LoginPage/LoginPage.qml | 17 ---- .../components/pages/LoginPage/SignInBox.qml | 75 ------------------ harmonyqml/components/pages/MainUI.qml | 42 ---------- harmonyqml/components/pages/SignIn.qml | 79 +++++++++++++++++++ 6 files changed, 131 insertions(+), 136 deletions(-) create mode 100644 harmonyqml/components/UI.qml delete mode 100644 harmonyqml/components/pages/LoginPage/LoginPage.qml delete mode 100644 harmonyqml/components/pages/LoginPage/SignInBox.qml delete mode 100644 harmonyqml/components/pages/MainUI.qml create mode 100644 harmonyqml/components/pages/SignIn.qml diff --git a/harmonyqml/components/UI.qml b/harmonyqml/components/UI.qml new file mode 100644 index 00000000..e66035e2 --- /dev/null +++ b/harmonyqml/components/UI.qml @@ -0,0 +1,51 @@ +import QtQuick 2.7 +import QtQuick.Controls 1.4 as Controls1 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 +import "base" as Base +import "sidePane" as SidePane +import "chat" as Chat + +Base.HImage { + id: loginPage + fillMode: Image.PreserveAspectCrop + source: "../images/login_background.jpg" + anchors.fill: parent + + property bool accountsLoggedIn: Backend.clientManager.clientCount > 0 + + //https://doc.qt.io/qt-5/qml-qtquick-controls-splitview.html + Controls1.SplitView { + anchors.fill: parent + + SidePane.Root { + Layout.minimumWidth: 36 + width: 200 + visible: accountsLoggedIn + } + + StackView { + function showPage(path, properties) { + pageStack.replace(path, properties || {}) + } + + function showRoom(userId, roomId) { + pageStack.replace( + "chat/Root.qml", { userId: userId, roomId: roomId } + ) + } + + id: pageStack + initialItem: accountsLoggedIn ? undefined : "pages/SignIn.qml" + + onCurrentItemChanged: if (currentItem) { + currentItem.forceActiveFocus() + } + + // Buggy + replaceExit: null + popExit: null + pushExit: null + } + } +} diff --git a/harmonyqml/components/Window.qml b/harmonyqml/components/Window.qml index f0f3207a..f8f80c9b 100644 --- a/harmonyqml/components/Window.qml +++ b/harmonyqml/components/Window.qml @@ -9,8 +9,7 @@ ApplicationWindow { Loader { anchors.fill: parent - source: Backend.clientManager.clientCount < 1 ? - "pages/LoginPage/LoginPage.qml" : "pages/MainUI.qml" + source: "UI.qml" objectName: "UILoader" } } diff --git a/harmonyqml/components/pages/LoginPage/LoginPage.qml b/harmonyqml/components/pages/LoginPage/LoginPage.qml deleted file mode 100644 index fd6eef3c..00000000 --- a/harmonyqml/components/pages/LoginPage/LoginPage.qml +++ /dev/null @@ -1,17 +0,0 @@ -import QtQuick 2.7 -import QtQuick.Controls 2.2 -import QtQuick.Layouts 1.4 -import "../../base" as Base - -Base.HImage { - id: loginPage - fillMode: Image.PreserveAspectCrop - source: "../../../images/login_background.jpg" - - Loader { - anchors.centerIn: parent - Component.onCompleted: setSource( - "SignInBox.qml", { "container": loginPage } - ) - } -} diff --git a/harmonyqml/components/pages/LoginPage/SignInBox.qml b/harmonyqml/components/pages/LoginPage/SignInBox.qml deleted file mode 100644 index 878fd40a..00000000 --- a/harmonyqml/components/pages/LoginPage/SignInBox.qml +++ /dev/null @@ -1,75 +0,0 @@ -import QtQuick 2.7 -import QtQuick.Controls 2.2 -import QtQuick.Layouts 1.4 -import "../../base" as Base - -Base.HInterfaceBox { - id: signInBox - title: "Sign in" - - property string loginWith: "username" - - enterButtonTarget: "login" - - buttonModel: [ - { name: "register", text: qsTr("Register") }, - { name: "login", text: qsTr("Login") }, - { name: "forgot", text: qsTr("Forgot?") } - ] - - buttonCallbacks: { - "register": function(button) {}, - - "login": function(button) { - button.loadingUntilFutureDone( - Backend.clientManager.new( - "matrix.org", identifierField.text, passwordField.text - ) - ) - }, - - "forgot": function(button) {} - } - - Base.HRowLayout { - spacing: signInBox.margins * 1.25 - Layout.margins: signInBox.margins - Layout.alignment: Qt.AlignHCenter - - Repeater { - model: ["username", "email", "phone"] - - Base.HButton { - iconName: modelData - circle: true - checked: loginWith == modelData - autoExclusive: true - onClicked: loginWith = modelData - } - } - } - - Base.HTextField { - id: identifierField - placeholderText: qsTr( - loginWith === "email" ? "Email" : - loginWith === "phone" ? "Phone" : - "Username" - ) - onAccepted: signInBox.clickEnterButtonTarget() - Component.onCompleted: forceActiveFocus() - - Layout.fillWidth: true - Layout.margins: signInBox.margins - } - - Base.HTextField { - id: passwordField - placeholderText: qsTr("Password") - echoMode: TextField.Password - onAccepted: signInBox.clickEnterButtonTarget() - - Layout.fillWidth: true - Layout.margins: signInBox.margins - } -} diff --git a/harmonyqml/components/pages/MainUI.qml b/harmonyqml/components/pages/MainUI.qml deleted file mode 100644 index d42e3abe..00000000 --- a/harmonyqml/components/pages/MainUI.qml +++ /dev/null @@ -1,42 +0,0 @@ -import QtQuick 2.7 -import QtQuick.Controls 1.4 as Controls1 -import QtQuick.Controls 2.2 -import QtQuick.Layouts 1.4 -import "../sidePane" as SidePane -import "../chat" as Chat - -//https://doc.qt.io/qt-5/qml-qtquick-controls-splitview.html -Controls1.SplitView { - anchors.fill: parent - - SidePane.Root { - Layout.minimumWidth: 36 - width: 200 - } - - StackView { - function showRoom(userId, roomId) { - pageStack.replace( - "../chat/Root.qml", { userId: userId, roomId: roomId } - ) - } - - id: pageStack - - onCurrentItemChanged: if (currentItem) { - currentItem.forceActiveFocus() - } - - initialItem: Item { // TODO: (test, remove) - Keys.onEnterPressed: pageStack.showRoom( - "@test_mary:matrix.org", "!TSXGsbBbdwsdylIOJZ:matrix.org" - //"@test_mary:matrix.org", "!TEXkdeErtVCMqClNfb:matrix.org" - ) - } - - // Buggy - replaceExit: null - popExit: null - pushExit: null - } -} diff --git a/harmonyqml/components/pages/SignIn.qml b/harmonyqml/components/pages/SignIn.qml new file mode 100644 index 00000000..631157e0 --- /dev/null +++ b/harmonyqml/components/pages/SignIn.qml @@ -0,0 +1,79 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 +import "../base" as Base + +Item { + property string loginWith: "username" + + onFocusChanged: identifierField.forceActiveFocus() + + Base.HInterfaceBox { + id: signInBox + title: "Sign in" + anchors.centerIn: parent + + enterButtonTarget: "login" + + buttonModel: [ + { name: "register", text: qsTr("Register") }, + { name: "login", text: qsTr("Login") }, + { name: "forgot", text: qsTr("Forgot?") } + ] + + buttonCallbacks: { + "register": function(button) {}, + + "login": function(button) { + button.loadingUntilFutureDone( + Backend.clientManager.new( + "matrix.org", identifierField.text, passwordField.text + ) + ) + }, + + "forgot": function(button) {} + } + + Base.HRowLayout { + spacing: signInBox.margins * 1.25 + Layout.margins: signInBox.margins + Layout.alignment: Qt.AlignHCenter + + Repeater { + model: ["username", "email", "phone"] + + Base.HButton { + iconName: modelData + circle: true + checked: loginWith == modelData + autoExclusive: true + onClicked: loginWith = modelData + } + } + } + + Base.HTextField { + id: identifierField + placeholderText: qsTr( + loginWith === "email" ? "Email" : + loginWith === "phone" ? "Phone" : + "Username" + ) + onAccepted: signInBox.clickEnterButtonTarget() + + Layout.fillWidth: true + Layout.margins: signInBox.margins + } + + Base.HTextField { + id: passwordField + placeholderText: qsTr("Password") + echoMode: TextField.Password + onAccepted: signInBox.clickEnterButtonTarget() + + Layout.fillWidth: true + Layout.margins: signInBox.margins + } + } +}