From b4389402e9ab1ccab4f117532db087fd42ae9d34 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Wed, 17 Mar 2021 10:22:35 +0100 Subject: [PATCH] refactor: make use of StatusContextMenuButton --- ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml | 140 +++++++----------- .../Profile/Sections/Contacts/Contact.qml | 20 +-- 2 files changed, 58 insertions(+), 102 deletions(-) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml index 3bc82aaae0..a525bb6036 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml @@ -69,99 +69,69 @@ Rectangle { } - Rectangle { - id: moreActionsBtnContainer - width: 40 - height: 40 - radius: Style.current.radius - color: Style.current.transparent + StatusContextMenuButton { + id: moreActionsBtn anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right anchors.rightMargin: Style.current.smallPadding - StyledText { - id: moreActionsBtn - text: "..." - font.letterSpacing: 0.5 - font.bold: true - lineHeight: 1.4 - anchors.verticalCenter: parent.verticalCenter - anchors.horizontalCenter: parent.horizontalCenter - font.pixelSize: 25 + onClicked: { + var menu = chatContextMenu; + var isPrivateGroupChat = chatsModel.activeChannel.chatType === Constants.chatTypePrivateGroupChat + if(isPrivateGroupChat){ + menu = groupContextMenu + } + + if (menu.opened) { + return menu.close() + } + + if (isPrivateGroupChat) { + menu.popup(moreActionsBtn.x, moreActionsBtn.height) + } else { + menu.openMenu(chatsModel.activeChannel, chatsModel.getActiveChannelIdx(), + moreActionsBtn.x - chatContextMenu.width + moreActionsBtn.width + 4, + moreActionsBtn.height - 4) + } } - MouseArea { - id: mouseArea - anchors.fill: parent - hoverEnabled: true - onEntered: { - parent.color = Style.current.border + ChannelContextMenu { + id: chatContextMenu + } + + PopupMenu { + id: groupContextMenu + closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent + Action { + icon.source: "../../../img/group_chat.svg" + icon.width: chatTopBarContent.iconSize + icon.height: chatTopBarContent.iconSize + //% "Group Information" + text: qsTrId("group-information") + onTriggered: openPopup(groupInfoPopupComponent, {channel: chatsModel.activeChannel}) } - onExited: { - parent.color = Style.current.transparent + Action { + icon.source: "../../../img/close.svg" + icon.width: chatTopBarContent.iconSize + icon.height: chatTopBarContent.iconSize + //% "Clear History" + text: qsTrId("clear-history") + onTriggered: chatsModel.clearChatHistory(chatsModel.activeChannel.id) } - - onClicked: { - var menu = chatContextMenu; - var isPrivateGroupChat = chatsModel.activeChannel.chatType === Constants.chatTypePrivateGroupChat - if(isPrivateGroupChat){ - menu = groupContextMenu - } - - if (menu.opened) { - return menu.close() - } - - if (isPrivateGroupChat) { - menu.popup(moreActionsBtn.x, moreActionsBtn.height) - } else { - menu.openMenu(chatsModel.activeChannel, chatsModel.getActiveChannelIdx(), - moreActionsBtn.x - chatContextMenu.width + moreActionsBtn.width + 4, - moreActionsBtn.height - 4) - } - } - cursorShape: Qt.PointingHandCursor - acceptedButtons: Qt.LeftButton | Qt.RightButton - - - ChannelContextMenu { - id: chatContextMenu - } - - PopupMenu { - id: groupContextMenu - closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent - Action { - icon.source: "../../../img/group_chat.svg" - icon.width: chatTopBarContent.iconSize - icon.height: chatTopBarContent.iconSize - //% "Group Information" - text: qsTrId("group-information") - onTriggered: openPopup(groupInfoPopupComponent, {channel: chatsModel.activeChannel}) - } - Action { - icon.source: "../../../img/close.svg" - icon.width: chatTopBarContent.iconSize - icon.height: chatTopBarContent.iconSize - //% "Clear History" - text: qsTrId("clear-history") - onTriggered: chatsModel.clearChatHistory(chatsModel.activeChannel.id) - } - Action { - icon.source: "../../../img/leave_chat.svg" - icon.width: chatTopBarContent.iconSize - icon.height: chatTopBarContent.iconSize - //% "Leave group" - text: qsTrId("leave-group") - onTriggered: { - //% "Leave group" - deleteChatConfirmationDialog.title = qsTrId("leave-group") - //% "Leave group" - deleteChatConfirmationDialog.confirmButtonLabel = qsTrId("leave-group") - //% "Are you sure you want to leave this chat?" - deleteChatConfirmationDialog.confirmationText = qsTrId("are-you-sure-you-want-to-leave-this-chat-") - deleteChatConfirmationDialog.open() - } + Action { + icon.source: "../../../img/leave_chat.svg" + icon.width: chatTopBarContent.iconSize + icon.height: chatTopBarContent.iconSize + //% "Leave group" + text: qsTrId("leave-group") + onTriggered: { + //% "Leave group" + deleteChatConfirmationDialog.title = qsTrId("leave-group") + //% "Leave group" + deleteChatConfirmationDialog.confirmButtonLabel = qsTrId("leave-group") + //% "Are you sure you want to leave this chat?" + deleteChatConfirmationDialog.confirmationText = qsTrId("are-you-sure-you-want-to-leave-this-chat-") + deleteChatConfirmationDialog.open() } } } diff --git a/ui/app/AppLayouts/Profile/Sections/Contacts/Contact.qml b/ui/app/AppLayouts/Profile/Sections/Contacts/Contact.qml index 3d89cb50d5..0513ef07b5 100644 --- a/ui/app/AppLayouts/Profile/Sections/Contacts/Contact.qml +++ b/ui/app/AppLayouts/Profile/Sections/Contacts/Contact.qml @@ -67,26 +67,12 @@ Rectangle { } } - Rectangle { + StatusContextMenuButton { property int iconSize: 14 - property bool isHovered: false - readonly property color hoveredBg: Utils.setColorAlpha(Style.current.black, 0.1) id: menuButton - height: 32 - width: 32 anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right anchors.rightMargin: Style.current.padding - radius: 8 - color: isHovered ? hoveredBg : Style.current.transparent - - SVGImage { - source: "../../../../img/dots-icon.svg" - width: 18 - height: 4 - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - } MouseArea { id: mouseArea @@ -95,11 +81,11 @@ Rectangle { hoverEnabled: true onExited: { container.isHovered = false - menuButton.isHovered = false + menuButton.highlighted = false } onEntered: { container.isHovered = true - menuButton.isHovered = true + menuButton.highlighted = true } onClicked: { contactContextMenu.popup()