From a2b9fc3deec89ec6a6b5248e1615f162b0ddb1fc Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Wed, 15 Feb 2023 08:33:40 +0100 Subject: [PATCH] feat(GODT-2273): menu with "Close window" and "Quit Bridge" button in main window. --- .../bridge-gui/qml/ContentWrapper.qml | 53 ++++++++++++++++++- .../bridge-gui/bridge-gui/qml/MainWindow.qml | 11 ++++ .../bridge-gui/qml/NotificationPopups.qml | 5 ++ .../qml/Notifications/Notifications.qml | 51 +++++++++++++++++- .../bridge-gui/qml/Proton/MenuItem.qml | 5 +- 5 files changed, 119 insertions(+), 6 deletions(-) diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml b/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml index 93b2e8f7..6dc46d79 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml @@ -29,6 +29,8 @@ Item { property var notifications signal showSetupGuide(var user, string address) + signal closeWindow() + signal quitBridge() RowLayout { anchors.fill: parent @@ -107,7 +109,7 @@ Item { Layout.topMargin: 16 Layout.bottomMargin: 9 - Layout.rightMargin: 16 + Layout.rightMargin: 4 horizontalPadding: 0 @@ -115,6 +117,55 @@ Item { onClicked: rightContent.showGeneralSettings() } + + Button { + id: dotMenuButton + Layout.bottomMargin: 9 + Layout.maximumHeight: 36 + Layout.maximumWidth: 36 + Layout.minimumHeight: 36 + Layout.minimumWidth: 36 + Layout.preferredHeight: 36 + Layout.preferredWidth: 36 + Layout.rightMargin: 16 + Layout.topMargin: 16 + colorScheme: leftBar.colorScheme + horizontalPadding: 0 + icon.source: "/qml/icons/ic-three-dots-vertical.svg" + + onClicked: { + dotMenu.open() + } + + Menu { + id: dotMenu + colorScheme: root.colorScheme + modal: true + y: dotMenuButton.Layout.preferredHeight + dotMenuButton.Layout.bottomMargin + + MenuItem { + colorScheme: root.colorScheme + text: qsTr("Close window") + onClicked: { + root.closeWindow() + } + } + MenuItem { + colorScheme: root.colorScheme + text: qsTr("Quit Bridge") + onClicked: { + root.quitBridge() + } + } + + onClosed: { + parent.checked = false + } + onOpened: { + parent.checked = true + } + } + } } Item {implicitHeight:10} diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml b/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml index 2abb52b4..491206ad 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml @@ -142,6 +142,17 @@ ApplicationWindow { onShowSetupGuide: function(user, address) { root.showSetup(user,address) } + + onCloseWindow: { + root.close() + } + + onQuitBridge: { + // If we ever want to add a confirmation dialog before quitting: + //root.notifications.askQuestion("Quit Bridge", "Insert warning message here.", "Quit", "Cancel", Backend.quit, null) + root.close() + Backend.quit() + } } WelcomeGuide { // 1 diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml b/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml index 5c65ddad..bf6d45bb 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/NotificationPopups.qml @@ -138,4 +138,9 @@ Item { colorScheme: root.colorScheme notification: root.notifications.genericError } + + NotificationDialog { + colorScheme: root.colorScheme + notification: root.notifications.genericQuestion + } } diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml b/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml index c4d250cc..2564f336 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/Notifications/Notifications.qml @@ -32,7 +32,7 @@ QtObject { signal askResetBridge() signal askChangeAllMailVisibility(var isVisibleNow) signal askDeleteAccount(var user) - + signal askQuestion(var title, var description, var option1, var option2, var action1, var action2) enum Group { Connection = 1, Update = 2, @@ -82,7 +82,8 @@ QtObject { root.noActiveKeyForRecipient, root.userBadEvent, root.imapLoginWhileSignedOut, - root.genericError + root.genericError, + root.genericQuestion, ] // Connection @@ -1201,4 +1202,50 @@ QtObject { } ] } + + property Notification genericQuestion: Notification { + title: "" + brief: "" + description: "" + type: Notification.NotificationType.Warning + group: Notifications.Group.Dialogs + property var option1: "" + property var option2: "" + property variant action1: null + property variant action2: null + + Connections { + target: root + function onAskQuestion(title, description, option1, option2, action1, action2) { + root.genericQuestion.title = title + root.genericQuestion.description = description + root.genericQuestion.option1 = option1 + root.genericQuestion.option2 = option2 + root.genericQuestion.action1 = action1 + root.genericQuestion.action2 = action2 + root.genericQuestion.active = true + } + } + + action: [ + Action { + text: root.genericQuestion.option1 + + onTriggered: { + root.genericQuestion.active = false + if (root.genericQuestion.action1) + root.genericQuestion.action1() + } + }, + Action { + text: root.genericQuestion.option2 + + onTriggered: { + root.genericQuestion.active = false + if (root.genericQuestion.action2) + root.genericQuestion.action2() + } + } + ] + } } diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/Proton/MenuItem.qml b/internal/frontend/bridge-gui/bridge-gui/qml/Proton/MenuItem.qml index 7a6c6c1a..7c30d353 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/Proton/MenuItem.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/Proton/MenuItem.qml @@ -26,13 +26,12 @@ T.MenuItem { property ColorScheme colorScheme - implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) + width: parent.width // required. Other item overflows to the right of the menu and get clipped. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding, implicitIndicatorHeight + topPadding + bottomPadding) - padding: 6 + padding: 12 spacing: 6 icon.width: 24