fix: menu dropdowns not closing on button click and position

This commit is contained in:
Jonathan Rainville 2021-04-01 14:22:08 -04:00 committed by Iuri Matias
parent 62b0c63965
commit 6c0fce5b0c
4 changed files with 32 additions and 10 deletions

View File

@ -95,6 +95,7 @@ Rectangle {
ChannelContextMenu { ChannelContextMenu {
id: chatContextMenu id: chatContextMenu
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
} }
PopupMenu { PopupMenu {

View File

@ -1,6 +1,7 @@
import QtQuick 2.13 import QtQuick 2.13
import QtQuick.Controls 2.13 import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
import "../../../../imports"
import "../../../../shared" import "../../../../shared"
import "../../../../shared/status" import "../../../../shared/status"
import "../components" import "../components"
@ -13,15 +14,19 @@ StatusRoundButton {
width: 36 width: 36
height: 36 height: 36
onClicked: { onClicked: {
btnAdd.state = "pressed" if (newChatMenu.opened) {
let x = btnAdd.iconX + btnAdd.icon.width / 2 - newChatMenu.width / 2 newChatMenu.close()
newChatMenu.popup(x, btnAdd.icon.height + 14) } else {
let x = btnAdd.iconX + btnAdd.icon.width / 2 - newChatMenu.width / 2
newChatMenu.popup(x, btnAdd.height + 4)
}
} }
PopupMenu { PopupMenu {
id: newChatMenu id: newChatMenu
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Action { Action {
//% "Start new chat" //% "Start new chat"
text: qsTrId("start-new-chat") text: qsTrId("start-new-chat")
@ -57,6 +62,10 @@ StatusRoundButton {
openPopup(communitiesPopupComponent) openPopup(communitiesPopupComponent)
} }
} }
onAboutToShow: {
btnAdd.state = "pressed"
}
onAboutToHide: { onAboutToHide: {
btnAdd.state = "default" btnAdd.state = "default"
} }

View File

@ -145,15 +145,19 @@ Item {
flipImage: true flipImage: true
text: "" text: ""
onClicked: function () { onClicked: function () {
// FIXME the button is too much on the right, so the arrow can never align if (newSettingsMenu.opened) {
let x = settingsBtn.x + settingsBtn.width / 2 - newSettingsMenu.width / 2 newSettingsMenu.close()
newSettingsMenu.popup(x, settingsBtn.height) } else {
let x = settingsBtn.x + settingsBtn.width / 2 - newSettingsMenu.width / 2
newSettingsMenu.popup(x, settingsBtn.height)
}
} }
anchors.left: receiveBtn.right anchors.left: receiveBtn.right
anchors.leftMargin: walletMenu.btnOuterMargin anchors.leftMargin: walletMenu.btnOuterMargin
PopupMenu { PopupMenu {
id: newSettingsMenu id: newSettingsMenu
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
width: 176 width: 176
Action { Action {
//% "Account Settings" //% "Account Settings"

View File

@ -14,9 +14,12 @@ StatusRoundButton {
height: 36 height: 36
onClicked: { onClicked: {
btnAdd.state = "pressed" if (newAccountMenu.opened) {
let x = btnAdd.iconX + btnAdd.icon.width / 2 - newAccountMenu.width / 2 newAccountMenu.close()
newAccountMenu.popup(x, btnAdd.icon.height + 10) } else {
let x = btnAdd.iconX + btnAdd.icon.width / 2 - newAccountMenu.width / 2
newAccountMenu.popup(x, btnAdd.height + 4)
}
} }
GenerateAccountModal { GenerateAccountModal {
@ -35,6 +38,7 @@ StatusRoundButton {
PopupMenu { PopupMenu {
id: newAccountMenu id: newAccountMenu
width: 260 width: 260
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
Action { Action {
//% "Generate an account" //% "Generate an account"
text: qsTrId("generate-a-new-account") text: qsTrId("generate-a-new-account")
@ -75,6 +79,10 @@ StatusRoundButton {
addAccountWithPrivateKeydModal.open() addAccountWithPrivateKeydModal.open()
} }
} }
onAboutToShow: {
btnAdd.state = "pressed"
}
onAboutToHide: { onAboutToHide: {
btnAdd.state = "default" btnAdd.state = "default"
} }