From 74e12ce71d00e7e9aea43a985e8a9dbfc4ad0844 Mon Sep 17 00:00:00 2001 From: xiphon Date: Fri, 8 Nov 2019 00:56:10 +0000 Subject: [PATCH] ContextMenu: implement 'paste' context menu for all text fields --- components/ContextMenu.qml | 43 +++++++++++++++++++++++++++++++++ components/Input.qml | 8 ++++++ components/InputDialog.qml | 2 +- components/InputMulti.qml | 11 +++++++++ components/LineEditMulti.qml | 8 +++--- components/PasswordDialog.qml | 4 +-- pages/AddressBook.qml | 4 +-- pages/Transfer.qml | 8 ++---- pages/merchant/Merchant.qml | 2 +- qml.qrc | 1 + wizard/WizardAskPassword.qml | 4 +-- wizard/WizardRestoreWallet1.qml | 2 +- 12 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 components/ContextMenu.qml diff --git a/components/ContextMenu.qml b/components/ContextMenu.qml new file mode 100644 index 00000000..58442e8d --- /dev/null +++ b/components/ContextMenu.qml @@ -0,0 +1,43 @@ +import QtQuick.Controls 2.2 +import QtQuick 2.9 + +import "../components" as MoneroComponents + +MouseArea { + signal paste() + + id: root + acceptedButtons: Qt.RightButton + anchors.fill: parent + onClicked: { + if (mouse.button === Qt.RightButton) + contextMenu.open() + } + + Menu { + id: contextMenu + + background: Rectangle { + radius: 2 + color: MoneroComponents.Style.buttonInlineBackgroundColor + } + + font.family: MoneroComponents.Style.fontRegular.name + font.pixelSize: 14 + width: 50 + x: root.mouseX + y: root.mouseY + + MenuItem { + id: pasteItem + background: Rectangle { + radius: 2 + color: MoneroComponents.Style.buttonBackgroundColorDisabledHover + opacity: pasteItem.down ? 1 : 0 + } + enabled: root.parent.canPaste + onTriggered: root.paste() + text: qsTr("Paste") + translationManager.emptyString + } + } +} diff --git a/components/Input.qml b/components/Input.qml index 752b461d..3ac9a532 100644 --- a/components/Input.qml +++ b/components/Input.qml @@ -32,6 +32,7 @@ import QtQuick 2.9 import "../components" as MoneroComponents TextField { + id: textField font.family: MoneroComponents.Style.fontRegular.name font.pixelSize: 18 font.bold: true @@ -44,4 +45,11 @@ TextField { background: Rectangle { color: "transparent" } + + MoneroComponents.ContextMenu { + onPaste: { + textField.clear(); + textField.paste(); + } + } } diff --git a/components/InputDialog.qml b/components/InputDialog.qml index 01d1e2c5..c5963f04 100644 --- a/components/InputDialog.qml +++ b/components/InputDialog.qml @@ -86,7 +86,7 @@ Item { color: MoneroComponents.Style.defaultFontColor } - TextField { + MoneroComponents.Input { id : input focus: true Layout.topMargin: 6 diff --git a/components/InputMulti.qml b/components/InputMulti.qml index 891bdc4f..8fccb6a6 100644 --- a/components/InputMulti.qml +++ b/components/InputMulti.qml @@ -57,6 +57,10 @@ TextArea { onTextChanged: { if(addressValidation){ // js replacement for `RegExpValidator { regExp: /[0-9A-Fa-f]{95}/g }` + if (textArea.text.startsWith("monero:")) { + error = false; + return; + } textArea.text = textArea.text.replace(/[^a-z0-9.@\-]/gi,''); var address_ok = TxUtils.checkAddress(textArea.text, appWindow.persistentSettings.nettype) || TxUtils.isValidOpenAliasAddress(textArea.text); if(!address_ok) error = true; @@ -64,4 +68,11 @@ TextArea { TextArea.cursorPosition = textArea.text.length; } } + + MoneroComponents.ContextMenu { + onPaste: { + textArea.clear(); + textArea.paste(); + } + } } diff --git a/components/LineEditMulti.qml b/components/LineEditMulti.qml index 266c6a30..46052495 100644 --- a/components/LineEditMulti.qml +++ b/components/LineEditMulti.qml @@ -80,9 +80,6 @@ ColumnLayout { property alias readOnly: input.readOnly property bool copyButton: false property bool pasteButton: false - property var onPaste: function(clipboardText) { - item.text = clipboardText; - } property bool showingHeader: labelText != "" || copyButton || pasteButton property var wrapMode: Text.NoWrap property alias addressValidation: input.addressValidation @@ -146,7 +143,10 @@ ColumnLayout { MoneroComponents.LabelButton { id: pasteButtonId - onClicked: item.onPaste(clipboard.text()) + onClicked: { + input.clear(); + input.paste(); + } text: qsTr("Paste") + translationManager.emptyString visible: pasteButton } diff --git a/components/PasswordDialog.qml b/components/PasswordDialog.qml index 81e74ef3..bfea8948 100644 --- a/components/PasswordDialog.qml +++ b/components/PasswordDialog.qml @@ -187,7 +187,7 @@ Item { text: qsTr("CAPSLOCKS IS ON.") + translationManager.emptyString; } - TextField { + MoneroComponents.Input { id: passwordInput1 Layout.topMargin: 6 Layout.fillWidth: true @@ -296,7 +296,7 @@ Item { color: MoneroComponents.Style.defaultFontColor } - TextField { + MoneroComponents.Input { id: passwordInput2 visible: !passwordDialogMode Layout.topMargin: 6 diff --git a/pages/AddressBook.qml b/pages/AddressBook.qml index ce8acfe5..5812dac5 100644 --- a/pages/AddressBook.qml +++ b/pages/AddressBook.qml @@ -325,8 +325,8 @@ Rectangle { wrapMode: Text.WrapAnywhere addressValidation: true pasteButton: true - onPaste: function(clipboardText) { - const parsed = walletManager.parse_uri_to_object(clipboardText); + onTextChanged: { + const parsed = walletManager.parse_uri_to_object(addressLine.text); if (!parsed.error) { addressLine.text = parsed.address; descriptionLine.text = parsed.tx_description; diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 3e93339c..dd36f1c0 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -257,18 +257,14 @@ Rectangle { appWindow.showPageRequest("AddressBook"); } pasteButton: true - onPaste: function(clipboardText) { - const parsed = walletManager.parse_uri_to_object(clipboardText); + onTextChanged: { + const parsed = walletManager.parse_uri_to_object(text); if (!parsed.error) { addressLine.text = parsed.address; setPaymentId(parsed.payment_id); amountLine.text = parsed.amount; setDescription(parsed.tx_description); - } else { - addressLine.text = clipboardText; } - } - onTextChanged: { warningLongPidTransfer = isLongPidService(text); } inlineButton.text: FontAwesome.qrcode diff --git a/pages/merchant/Merchant.qml b/pages/merchant/Merchant.qml index 93b78148..8096001e 100644 --- a/pages/merchant/Merchant.qml +++ b/pages/merchant/Merchant.qml @@ -455,7 +455,7 @@ Item { width: 220 source: "qrc:///images/merchant/input_box.png" - TextField { + MoneroComponents.Input { id: amountToReceive topPadding: 0 leftPadding: 10 diff --git a/qml.qrc b/qml.qrc index c70999e5..d5605b83 100644 --- a/qml.qrc +++ b/qml.qrc @@ -21,6 +21,7 @@ pages/History.qml pages/AddressBook.qml pages/Mining.qml + components/ContextMenu.qml components/NetworkStatusItem.qml components/Input.qml components/StandardButton.qml diff --git a/wizard/WizardAskPassword.qml b/wizard/WizardAskPassword.qml index fcb5ccb1..ed2a0ecb 100644 --- a/wizard/WizardAskPassword.qml +++ b/wizard/WizardAskPassword.qml @@ -150,7 +150,7 @@ ColumnLayout { color: MoneroComponents.Style.defaultFontColor } - TextField { + MoneroComponents.Input { id: passwordInput Layout.topMargin: 6 @@ -207,7 +207,7 @@ ColumnLayout { color: MoneroComponents.Style.defaultFontColor } - TextField { + MoneroComponents.Input { id : passwordInputConfirm Layout.topMargin: 6 diff --git a/wizard/WizardRestoreWallet1.qml b/wizard/WizardRestoreWallet1.qml index 1a0dd201..7e8457aa 100644 --- a/wizard/WizardRestoreWallet1.qml +++ b/wizard/WizardRestoreWallet1.qml @@ -185,7 +185,7 @@ Rectangle { } } - TextArea { + MoneroComponents.InputMulti { id: seedInput property bool error: false width: parent.width