From 0bb08fc852f277fa85a0cad5bec0eb58d99c051b Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 29 Jun 2020 17:23:28 +0200 Subject: [PATCH] feat(ProfilePopup): implement copy-to-clipboard button Closes #282 --- src/app/chat/view.nim | 3 + .../Chat/components/ProfilePopup.qml | 56 +++++++++---------- ui/shared/CopyToClipBoardIcon.qml | 34 +++++++++++ ui/shared/img/copy-to-clipboard-icon.svg | 4 ++ ui/shared/qmldir | 1 + 5 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 ui/shared/CopyToClipBoardIcon.qml create mode 100644 ui/shared/img/copy-to-clipboard-icon.svg diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index ce1bccdb53..42ebef3e4c 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -164,6 +164,9 @@ QtObject: proc addRecentStickerToList*(self: ChatsView, sticker: Sticker) = self.stickers[RECENT_STICKERS].addStickerToList(sticker) + proc copyToClipboard*(self: ChatsView, content: string) {.slot.} = + setClipBoardText(content) + proc sendSticker*(self: ChatsView, hash: string, pack: int) {.slot.} = let sticker = Sticker(hash: hash, packId: pack) self.addRecentStickerToList(sticker) diff --git a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml index f7c399e4fd..62045daf9d 100644 --- a/ui/app/AppLayouts/Chat/components/ProfilePopup.qml +++ b/ui/app/AppLayouts/Chat/components/ProfilePopup.qml @@ -143,6 +143,15 @@ ModalPopup { anchors.topMargin: Theme.smallPadding } + CopyToClipBoardIcon { + anchors.top: labelEnsUsername.bottom + anchors.left: valueEnsName.right + anchors.leftMargin: Theme.smallPadding + onClick: function (){ + chatsModel.copyToClipboard(valueEnsName.text) + } + } + StyledText { id: labelChatKey text: qsTr("Chat key") @@ -167,6 +176,15 @@ ModalPopup { anchors.topMargin: Theme.smallPadding } + CopyToClipBoardIcon { + anchors.top: labelChatKey.bottom + anchors.left: valueChatKey.right + anchors.leftMargin: Theme.smallPadding + onClick: function (){ + chatsModel.copyToClipboard(valueChatKey.text) + } + } + Separator { id: separator anchors.top: valueChatKey.bottom @@ -199,37 +217,17 @@ ModalPopup { anchors.top: labelShareURL.bottom anchors.topMargin: Theme.smallPadding } + + CopyToClipBoardIcon { + anchors.top: labelShareURL.bottom + anchors.left: valueShareURL.right + anchors.leftMargin: Theme.smallPadding + onClick: function (){ + chatsModel.copyToClipboard("https://join.status.im/u/" + fromAuthor) + } + } } - // TODO(pascal): implement copy to clipboard component - // Rectangle { - // id: copyToClipboardButton - // height: 32 - // width: 32 - // anchors.top: labelShareURL.bottom - // anchors.topMargin: Theme.padding - // anchors.left: valueShareURL.right - // anchors.leftMargin: Theme.padding - // radius: 8 - - // SVGImage { - // source: "../../../../shared/img/copy-to-clipboard-icon.svg" - // anchors.horizontalCenter: parent.horizontalCenter - // anchors.verticalCenter: parent.verticalCenter - // } - - // MouseArea { - // cursorShape: Qt.PointingHandCursor - // anchors.fill: parent - // hoverEnabled: true - // onExited: { - // copyToClipboardButton.color = Theme.white - // } - // onEntered:{ - // copyToClipboardButton.color = Theme.grey - // } - // } - // } footer: Item { width: parent.width height: children[0].height diff --git a/ui/shared/CopyToClipBoardIcon.qml b/ui/shared/CopyToClipBoardIcon.qml new file mode 100644 index 0000000000..c582764ca1 --- /dev/null +++ b/ui/shared/CopyToClipBoardIcon.qml @@ -0,0 +1,34 @@ +import QtQuick 2.13 +import QtQuick.Controls 2.13 +import "../imports" + +Rectangle { + id: copyToClipboardButton + height: 32 + width: 32 + radius: 8 + property var onClick: function() {} + + SVGImage { + width: 20 + height: 20 + source: "./img/copy-to-clipboard-icon.svg" + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + } + + MouseArea { + cursorShape: Qt.PointingHandCursor + anchors.fill: parent + hoverEnabled: true + onExited: { + parent.color = Theme.white + } + onEntered:{ + parent.color = Theme.grey + } + onClicked: onClick() + } +} + + diff --git a/ui/shared/img/copy-to-clipboard-icon.svg b/ui/shared/img/copy-to-clipboard-icon.svg new file mode 100644 index 0000000000..aae5708761 --- /dev/null +++ b/ui/shared/img/copy-to-clipboard-icon.svg @@ -0,0 +1,4 @@ + + + + diff --git a/ui/shared/qmldir b/ui/shared/qmldir index c2e702db1a..fd1e183601 100644 --- a/ui/shared/qmldir +++ b/ui/shared/qmldir @@ -15,3 +15,4 @@ StyledTextEdit 1.0 StyledTextEdit.qml Identicon 1.0 Identicon.qml RoundedImage 1.0 RoundedImage.qml SplitViewHandle 1.0 SplitViewHandle.qml +CopyToClipBoardIcon 1.0 CopyToClipBoardIcon.qml