From 2195c67f58b242d5c6be8df66b73d9731cad7a4c Mon Sep 17 00:00:00 2001 From: xiphon Date: Tue, 28 Apr 2020 12:15:18 +0000 Subject: [PATCH] LineEdit: password mode, linking. PasswordDialog: use LineEdit --- components/LineEdit.qml | 52 +++++++- components/PasswordDialog.qml | 212 ++++++-------------------------- pages/settings/SettingsNode.qml | 2 +- wizard/WizardRestoreWallet1.qml | 2 +- 4 files changed, 90 insertions(+), 178 deletions(-) diff --git a/components/LineEdit.qml b/components/LineEdit.qml index 554140d9..8c6346d5 100644 --- a/components/LineEdit.qml +++ b/components/LineEdit.qml @@ -26,6 +26,7 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import FontAwesome 1.0 import QtQuick 2.9 import QtGraphicalEffects 1.0 @@ -36,6 +37,10 @@ Item { property alias input: input property alias text: input.text + property bool password: false + property bool passwordHidden: true + property var passwordLinked: null + property alias placeholderText: placeholderLabel.text property bool placeholderCenter: false property string placeholderFontFamily: MoneroComponents.Style.fontRegular.name @@ -48,7 +53,6 @@ Item { property alias validator: input.validator property alias readOnly : input.readOnly property alias cursorPosition: input.cursorPosition - property alias echoMode: input.echoMode property alias inlineButton: inlineButtonId property alias inlineButtonText: inlineButtonId.text property alias inlineIcon: inlineIcon.visible @@ -109,6 +113,31 @@ Item { } } + function isPasswordHidden() { + if (password) { + return passwordHidden; + } + if (passwordLinked) { + return passwordLinked.passwordHidden; + } + return false; + } + + function reset() { + text = ""; + if (!passwordLinked) { + passwordHidden = true; + } + } + + function passwordToggle() { + if (passwordLinked) { + passwordLinked.passwordHidden = !passwordLinked.passwordHidden; + } else { + passwordHidden = !passwordHidden; + } + } + MoneroComponents.TextPlain { id: inputLabel anchors.top: parent.top @@ -210,6 +239,27 @@ Item { onTextChanged: item.textUpdated() topPadding: 10 bottomPadding: 10 + echoMode: isPasswordHidden() ? TextInput.Password : TextInput.Normal + + MoneroComponents.Label { + visible: password || passwordLinked + fontSize: 20 + text: isPasswordHidden() ? FontAwesome.eye : FontAwesome.eyeSlash + opacity: eyeMouseArea.containsMouse ? 0.9 : 0.7 + fontFamily: FontAwesome.fontFamily + anchors.right: parent.right + anchors.rightMargin: 15 + anchors.verticalCenter: parent.verticalCenter + anchors.verticalCenterOffset: 1 + + MouseArea { + id: eyeMouseArea + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + hoverEnabled: true + onClicked: passwordToggle() + } + } } MoneroComponents.InlineButton { diff --git a/components/PasswordDialog.qml b/components/PasswordDialog.qml index 43d2a2e6..f9ea5569 100644 --- a/components/PasswordDialog.qml +++ b/components/PasswordDialog.qml @@ -43,7 +43,6 @@ Item { visible: false z: parent.z + 2 - property bool isHidden: true property alias password: passwordInput1.text property string walletName property string errorText @@ -61,12 +60,9 @@ Item { signal closeCallback() function _openInit(walletName, errorText) { - isHidden = true capsLockTextLabel.visible = oshelper.isCapsLock(); - passwordInput1.echoMode = TextInput.Password - passwordInput2.echoMode = TextInput.Password - passwordInput1.text = "" - passwordInput2.text = "" + passwordInput1.reset(); + passwordInput2.reset(); passwordInput1.forceActiveFocus(); root.walletName = walletName ? walletName : "" errorTextLabel.text = errorText ? errorText : ""; @@ -116,10 +112,29 @@ Item { closeCallback(); } - function toggleIsHidden() { - passwordInput1.echoMode = isHidden ? TextInput.Normal : TextInput.Password; - passwordInput2.echoMode = isHidden ? TextInput.Normal : TextInput.Password; - isHidden = !isHidden; + function onOk() { + if (!passwordDialogMode && passwordInput1.text !== passwordInput2.text) { + return; + } + root.close() + if (passwordDialogMode) { + root.accepted() + } else if (newPasswordDialogMode) { + root.acceptedNewPassword() + } else if (passphraseDialogMode) { + root.acceptedPassphrase() + } + } + + function onCancel() { + root.close() + if (passwordDialogMode) { + root.rejected() + } else if (newPasswordDialogMode) { + root.rejectedNewPassword() + } else if (passphraseDialogMode) { + root.rejectedPassphrase() + } } ColumnLayout { @@ -184,15 +199,11 @@ Item { text: qsTr("CAPSLOCKS IS ON.") + translationManager.emptyString; } - MoneroComponents.Input { + MoneroComponents.LineEdit { id: passwordInput1 + password: true Layout.topMargin: 6 Layout.fillWidth: true - horizontalAlignment: TextInput.AlignLeft - verticalAlignment: TextInput.AlignVCenter - font.family: MoneroComponents.Style.fontLight.name - font.pixelSize: 24 - echoMode: TextInput.Password KeyNavigation.tab: { if (passwordDialogMode) { return okButton @@ -200,81 +211,12 @@ Item { return passwordInput2 } } - implicitHeight: 50 - bottomPadding: 10 - leftPadding: 10 - topPadding: 10 - color: MoneroComponents.Style.defaultFontColor - selectionColor: MoneroComponents.Style.textSelectionColor - selectedTextColor: MoneroComponents.Style.textSelectedColor onTextChanged: capsLockTextLabel.visible = oshelper.isCapsLock(); - background: Rectangle { - radius: 2 - color: MoneroComponents.Style.blackTheme ? "black" : "#A9FFFFFF" - border.color: MoneroComponents.Style.inputBorderColorInActive - border.width: 1 - - MoneroEffects.ColorTransition { - targetObj: parent - blackColor: "black" - whiteColor: "#A9FFFFFF" - } - - MoneroComponents.Label { - fontSize: 20 - text: isHidden ? FontAwesome.eye : FontAwesome.eyeSlash - opacity: 0.7 - fontFamily: FontAwesome.fontFamily - anchors.right: parent.right - anchors.rightMargin: 15 - anchors.verticalCenter: parent.verticalCenter - anchors.verticalCenterOffset: 1 - - MouseArea { - anchors.fill: parent - cursorShape: Qt.PointingHandCursor - hoverEnabled: true - onClicked: { - toggleIsHidden(); - } - onEntered: { - parent.opacity = 0.9 - parent.fontSize = 24 - } - onExited: { - parent.opacity = 0.7 - parent.fontSize = 20 - } - } - } - } - Keys.enabled: root.visible - Keys.onEnterPressed: Keys.onReturnPressed(event) - Keys.onReturnPressed: { - if (!passwordDialogMode && passwordInput1.text !== passwordInput2.text) { - return; - } - root.close() - if (passwordDialogMode) { - root.accepted() - } else if (newPasswordDialogMode) { - root.acceptedNewPassword() - } else if (passphraseDialogMode) { - root.acceptedPassphrase() - } - } - Keys.onEscapePressed: { - root.close() - if (passwordDialogMode) { - root.rejected() - } else if (newPasswordDialogMode) { - root.rejectedNewPassword() - } else if (passphraseDialogMode) { - root.rejectedPassphrase() - } - } + Keys.onEnterPressed: root.onOk() + Keys.onReturnPressed: root.onOk() + Keys.onEscapePressed: root.onCancel() } // padding @@ -298,81 +240,19 @@ Item { color: MoneroComponents.Style.defaultFontColor } - MoneroComponents.Input { + MoneroComponents.LineEdit { id: passwordInput2 + passwordLinked: passwordInput1 visible: !passwordDialogMode Layout.topMargin: 6 Layout.fillWidth: true - horizontalAlignment: TextInput.AlignLeft - verticalAlignment: TextInput.AlignVCenter - font.family: MoneroComponents.Style.fontLight.name - font.pixelSize: 24 - echoMode: TextInput.Password KeyNavigation.tab: okButton - implicitHeight: 50 - bottomPadding: 10 - leftPadding: 10 - topPadding: 10 - color: MoneroComponents.Style.defaultFontColor - selectionColor: MoneroComponents.Style.textSelectionColor - selectedTextColor: MoneroComponents.Style.textSelectedColor onTextChanged: capsLockTextLabel.visible = oshelper.isCapsLock(); - background: Rectangle { - radius: 2 - border.color: MoneroComponents.Style.inputBorderColorInActive - border.width: 1 - color: MoneroComponents.Style.blackTheme ? "black" : "#A9FFFFFF" - - MoneroComponents.Label { - fontSize: 20 - text: isHidden ? FontAwesome.eye : FontAwesome.eyeSlash - opacity: 0.7 - fontFamily: FontAwesome.fontFamily - anchors.right: parent.right - anchors.rightMargin: 15 - anchors.verticalCenter: parent.verticalCenter - anchors.verticalCenterOffset: 1 - - MouseArea { - anchors.fill: parent - cursorShape: Qt.PointingHandCursor - hoverEnabled: true - onClicked: { - toggleIsHidden() - } - onEntered: { - parent.opacity = 0.9 - parent.fontSize = 24 - } - onExited: { - parent.opacity = 0.7 - parent.fontSize = 20 - } - } - } - } - Keys.enabled: root.visible - Keys.onEnterPressed: Keys.onReturnPressed(event) - Keys.onReturnPressed: { - if (passwordInput1.text === passwordInput2.text) { - root.close() - if (newPasswordDialogMode) { - root.acceptedNewPassword() - } else if (passphraseDialogMode) { - root.acceptedPassphrase() - } - } - } - Keys.onEscapePressed: { - root.close() - if (newPasswordDialogMode) { - root.rejectedNewPassword() - } else if (passphraseDialogMode) { - root.rejectedPassphrase() - } - } + Keys.onEnterPressed: root.onOk() + Keys.onReturnPressed: root.onOk() + Keys.onEscapePressed: root.onCancel() } // padding @@ -397,16 +277,7 @@ Item { small: true text: qsTr("Cancel") + translationManager.emptyString KeyNavigation.tab: passwordInput1 - onClicked: { - root.close() - if (passwordDialogMode) { - root.rejected() - } else if (newPasswordDialogMode) { - root.rejectedNewPassword() - } else if (passphraseDialogMode) { - root.rejectedPassphrase() - } - } + onClicked: onCancel() } MoneroComponents.StandardButton { @@ -415,16 +286,7 @@ Item { text: qsTr("Ok") + translationManager.emptyString KeyNavigation.tab: cancelButton enabled: (passwordDialogMode == true) ? true : passwordInput1.text === passwordInput2.text - onClicked: { - root.close() - if (passwordDialogMode) { - root.accepted() - } else if (newPasswordDialogMode) { - root.acceptedNewPassword() - } else if (passphraseDialogMode) { - root.acceptedPassphrase() - } - } + onClicked: onOk() } } } diff --git a/pages/settings/SettingsNode.qml b/pages/settings/SettingsNode.qml index 9c6714f6..047b435c 100644 --- a/pages/settings/SettingsNode.qml +++ b/pages/settings/SettingsNode.qml @@ -318,7 +318,7 @@ Rectangle{ labelText: qsTr("Daemon password") + translationManager.emptyString text: persistentSettings.daemonPassword placeholderText: qsTr("Password") + translationManager.emptyString - echoMode: TextInput.Password + password: true placeholderFontSize: 15 labelFontSize: 14 fontSize: 15 diff --git a/wizard/WizardRestoreWallet1.qml b/wizard/WizardRestoreWallet1.qml index cc903bb8..b698aa5d 100644 --- a/wizard/WizardRestoreWallet1.qml +++ b/wizard/WizardRestoreWallet1.qml @@ -225,7 +225,7 @@ Rectangle { MoneroComponents.LineEdit { id: seedOffset - echoMode: TextInput.Password + password: true Layout.fillWidth: true placeholderFontSize: 16 placeholderText: qsTr("Passphrase") + translationManager.emptyString