refactor: make use of StatusContextMenuButton

This commit is contained in:
Pascal Precht 2021-03-17 10:22:35 +01:00
parent f497091c3e
commit b4389402e9
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 58 additions and 102 deletions

View File

@ -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()
}
}
}

View File

@ -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()