From 5fe8bafbf388b29a2eed28ed81d7950645102d87 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Tue, 30 Apr 2019 11:05:35 +0800 Subject: [PATCH] Move most context menu into dir. --- .../Component/Timeline/FileDelegate.qml | 57 +++++------- .../Component/Timeline/ImageDelegate.qml | 66 +++++--------- .../Component/Timeline/MessageDelegate.qml | 54 ++++++------ .../Dialog/AcceptInvitationDialog.qml | 50 +++++++++++ imports/Spectral/Dialog/LoginDialog.qml | 4 +- .../Spectral/Dialog/MessageSourceDialog.qml | 2 +- imports/Spectral/Dialog/qmldir | 1 + imports/Spectral/Menu/RoomListContextMenu.qml | 42 +++++++++ .../Menu/Timeline/FileDelegateContextMenu.qml | 46 ++++++++++ .../Timeline/MessageDelegateContextMenu.qml | 34 ++++++++ imports/Spectral/Menu/Timeline/qmldir | 3 + imports/Spectral/Menu/qmldir | 2 + imports/Spectral/Panel/RoomListPanel.qml | 87 +++---------------- res.qrc | 6 ++ 14 files changed, 269 insertions(+), 185 deletions(-) create mode 100644 imports/Spectral/Dialog/AcceptInvitationDialog.qml create mode 100644 imports/Spectral/Menu/RoomListContextMenu.qml create mode 100644 imports/Spectral/Menu/Timeline/FileDelegateContextMenu.qml create mode 100644 imports/Spectral/Menu/Timeline/MessageDelegateContextMenu.qml create mode 100644 imports/Spectral/Menu/Timeline/qmldir create mode 100644 imports/Spectral/Menu/qmldir diff --git a/imports/Spectral/Component/Timeline/FileDelegate.qml b/imports/Spectral/Component/Timeline/FileDelegate.qml index 92ab4c6..4078c58 100644 --- a/imports/Spectral/Component/Timeline/FileDelegate.qml +++ b/imports/Spectral/Component/Timeline/FileDelegate.qml @@ -10,6 +10,7 @@ import Spectral.Setting 0.1 import Spectral.Component 2.0 import Spectral.Dialog 2.0 +import Spectral.Menu.Timeline 2.0 import Spectral.Font 0.1 import Spectral.Effect 2.0 @@ -125,7 +126,25 @@ ColumnLayout { id: messageMouseArea - onSecondaryClicked: messageContextMenu.popup() + onSecondaryClicked: { + var contextMenu = fileDelegateContextMenu.createObject(ApplicationWindow.overlay) + contextMenu.viewSource.connect(function() { + messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() + }) + contextMenu.downloadAndOpen.connect(downloadAndOpen) + contextMenu.saveFileAs.connect(saveFileAs) + contextMenu.reply.connect(function() { + roomPanelInput.replyUser = author + roomPanelInput.replyEventID = eventId + roomPanelInput.replyContent = message + roomPanelInput.isReply = true + roomPanelInput.focus() + }) + contextMenu.redact.connect(function() { + currentRoom.redactEvent(eventId) + }) + contextMenu.popup() + } Component { id: messageSourceDialog @@ -133,40 +152,10 @@ ColumnLayout { MessageSourceDialog {} } - Menu { - id: messageContextMenu + Component { + id: fileDelegateContextMenu - MenuItem { - text: "View Source" - - onTriggered: messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() - } - MenuItem { - text: "Open Externally" - - onTriggered: downloadAndOpen() - } - MenuItem { - text: "Save As" - - onTriggered: saveFileAs() - } - MenuItem { - text: "Reply" - - onTriggered: { - roomPanelInput.replyUser = author - roomPanelInput.replyEventID = eventId - roomPanelInput.replyContent = message - roomPanelInput.isReply = true - roomPanelInput.focus() - } - } - MenuItem { - text: "Redact" - - onTriggered: currentRoom.redactEvent(eventId) - } + FileDelegateContextMenu {} } } } diff --git a/imports/Spectral/Component/Timeline/ImageDelegate.qml b/imports/Spectral/Component/Timeline/ImageDelegate.qml index 7e9b470..d10150a 100644 --- a/imports/Spectral/Component/Timeline/ImageDelegate.qml +++ b/imports/Spectral/Component/Timeline/ImageDelegate.qml @@ -10,6 +10,7 @@ import Spectral.Setting 0.1 import Spectral.Component 2.0 import Spectral.Dialog 2.0 +import Spectral.Menu.Timeline 2.0 import Spectral.Effect 2.0 import Spectral.Font 0.1 @@ -141,12 +142,27 @@ ColumnLayout { id: messageMouseArea - onPrimaryClicked: { - var window = fullScreenImage.createObject() - window.show() - } + onPrimaryClicked: fullScreenImage.createObject().show() - onSecondaryClicked: messageContextMenu.popup() + onSecondaryClicked: { + var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay) + contextMenu.viewSource.connect(function() { + messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() + }) + contextMenu.downloadAndOpen.connect(downloadAndOpen) + contextMenu.saveFileAs.connect(saveFileAs) + contextMenu.reply.connect(function() { + roomPanelInput.replyUser = author + roomPanelInput.replyEventID = eventId + roomPanelInput.replyContent = message + roomPanelInput.isReply = true + roomPanelInput.focus() + }) + contextMenu.redact.connect(function() { + currentRoom.redactEvent(eventId) + }) + contextMenu.popup() + } Component { id: messageSourceDialog @@ -154,44 +170,10 @@ ColumnLayout { MessageSourceDialog {} } - Menu { - id: messageContextMenu + Component { + id: imageDelegateContextMenu - MenuItem { - text: "View Source" - - onTriggered: messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() - } - - MenuItem { - text: "Open Externally" - - onTriggered: downloadAndOpen() - } - - MenuItem { - text: "Save As" - - onTriggered: saveFileAs() - } - - MenuItem { - text: "Reply" - - onTriggered: { - roomPanelInput.replyUser = author - roomPanelInput.replyEventID = eventId - roomPanelInput.replyContent = message - roomPanelInput.isReply = true - roomPanelInput.focus() - } - } - - MenuItem { - text: "Redact" - - onTriggered: currentRoom.redactEvent(eventId) - } + FileDelegateContextMenu {} } } } diff --git a/imports/Spectral/Component/Timeline/MessageDelegate.qml b/imports/Spectral/Component/Timeline/MessageDelegate.qml index 2248740..2565fb9 100644 --- a/imports/Spectral/Component/Timeline/MessageDelegate.qml +++ b/imports/Spectral/Component/Timeline/MessageDelegate.qml @@ -8,6 +8,7 @@ import Spectral.Setting 0.1 import Spectral.Component 2.0 import Spectral.Dialog 2.0 +import Spectral.Menu.Timeline 2.0 import Spectral.Effect 2.0 import Spectral.Font 0.1 @@ -97,41 +98,36 @@ ColumnLayout { id: messageMouseArea - onSecondaryClicked: messageContextMenu.popup() + onSecondaryClicked: { + var contextMenu = messageDelegateContextMenu.createObject(ApplicationWindow.overlay) + contextMenu.viewSource.connect(function() { + messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() + }) + contextMenu.reply.connect(function() { + roomPanelInput.replyUser = author + roomPanelInput.replyEventID = eventId + roomPanelInput.replyContent = contentLabel.selectedText || message + roomPanelInput.isReply = true + roomPanelInput.focus() + }) + contextMenu.redact.connect(function() { + currentRoom.redactEvent(eventId) + }) + contextMenu.popup() + } + + + Component { + id: messageDelegateContextMenu + + MessageDelegateContextMenu {} + } Component { id: messageSourceDialog MessageSourceDialog {} } - - Menu { - readonly property string selectedText: contentLabel.selectedText - - id: messageContextMenu - - MenuItem { - text: "View Source" - - onTriggered: messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open() - } - MenuItem { - text: "Reply" - - onTriggered: { - roomPanelInput.replyUser = author - roomPanelInput.replyEventID = eventId - roomPanelInput.replyContent = messageContextMenu.selectedText || message - roomPanelInput.isReply = true - roomPanelInput.focus() - } - } - MenuItem { - text: "Redact" - - onTriggered: currentRoom.redactEvent(eventId) - } - } } } diff --git a/imports/Spectral/Dialog/AcceptInvitationDialog.qml b/imports/Spectral/Dialog/AcceptInvitationDialog.qml new file mode 100644 index 0000000..b57c99b --- /dev/null +++ b/imports/Spectral/Dialog/AcceptInvitationDialog.qml @@ -0,0 +1,50 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +Dialog { + property var room + + anchors.centerIn: parent + width: 360 + + id: root + + title: "Invitation Received" + modal: true + + contentItem: Label { + text: "Accept this invitation?" + } + + footer: DialogButtonBox { + Button { + text: "Accept" + flat: true + + onClicked: { + room.acceptInvitation() + close() + } + } + + Button { + text: "Reject" + flat: true + + onClicked: { + room.forget() + close() + } + } + + Button { + text: "Cancel" + flat: true + + onClicked: close() + } + } + + onClosed: destroy() +} + diff --git a/imports/Spectral/Dialog/LoginDialog.qml b/imports/Spectral/Dialog/LoginDialog.qml index 3148300..199cbf5 100644 --- a/imports/Spectral/Dialog/LoginDialog.qml +++ b/imports/Spectral/Dialog/LoginDialog.qml @@ -44,7 +44,7 @@ Dialog { placeholderText: "Password" echoMode: TextInput.Password - onAccepted: root.doLogin() + onAccepted: root.accept() } } @@ -52,5 +52,5 @@ Dialog { spectralController.loginWithCredentials(serverField.text, usernameField.text, passwordField.text) } - onClosed: root.destroy() + onClosed: destroy() } diff --git a/imports/Spectral/Dialog/MessageSourceDialog.qml b/imports/Spectral/Dialog/MessageSourceDialog.qml index 41ab04c..e9cea1c 100644 --- a/imports/Spectral/Dialog/MessageSourceDialog.qml +++ b/imports/Spectral/Dialog/MessageSourceDialog.qml @@ -22,6 +22,6 @@ Popup { } } - onClosed: root.destroy() + onClosed: destroy() } diff --git a/imports/Spectral/Dialog/qmldir b/imports/Spectral/Dialog/qmldir index 0649630..bca9e5f 100644 --- a/imports/Spectral/Dialog/qmldir +++ b/imports/Spectral/Dialog/qmldir @@ -6,3 +6,4 @@ LoginDialog 2.0 LoginDialog.qml CreateRoomDialog 2.0 CreateRoomDialog.qml JoinRoomDialog 2.0 JoinRoomDialog.qml InviteUserDialog 2.0 InviteUserDialog.qml +AcceptInvitationDialog 2.0 AcceptInvitationDialog.qml diff --git a/imports/Spectral/Menu/RoomListContextMenu.qml b/imports/Spectral/Menu/RoomListContextMenu.qml new file mode 100644 index 0000000..b44903e --- /dev/null +++ b/imports/Spectral/Menu/RoomListContextMenu.qml @@ -0,0 +1,42 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 +import QtQuick.Controls.Material 2.12 + +Menu { + property var room + + id: root + + MenuItem { + text: "Favourite" + checkable: true + checked: room.isFavourite + + onTriggered: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0) + } + + MenuItem { + text: "Deprioritize" + checkable: true + checked: room.isLowPriority + + onTriggered: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0) + } + + MenuSeparator {} + + MenuItem { + text: "Mark as Read" + + onTriggered: room.markAllMessagesAsRead() + } + + MenuItem { + text: "Leave Room" + Material.foreground: Material.Red + + onTriggered: room.forget() + } + + onClosed: destroy() +} diff --git a/imports/Spectral/Menu/Timeline/FileDelegateContextMenu.qml b/imports/Spectral/Menu/Timeline/FileDelegateContextMenu.qml new file mode 100644 index 0000000..650e573 --- /dev/null +++ b/imports/Spectral/Menu/Timeline/FileDelegateContextMenu.qml @@ -0,0 +1,46 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Spectral.Dialog 2.0 + +Menu { + signal viewSource() + signal downloadAndOpen() + signal saveFileAs() + signal reply() + signal redact() + + id: root + + MenuItem { + text: "View Source" + + onTriggered: viewSource() + } + + MenuItem { + text: "Open Externally" + + onTriggered: downloadAndOpen() + } + + MenuItem { + text: "Save As" + + onTriggered: saveFileAs() + } + + MenuItem { + text: "Reply" + + onTriggered: reply() + } + + MenuItem { + text: "Redact" + + onTriggered: redact() + } + + onClosed: destroy() +} diff --git a/imports/Spectral/Menu/Timeline/MessageDelegateContextMenu.qml b/imports/Spectral/Menu/Timeline/MessageDelegateContextMenu.qml new file mode 100644 index 0000000..62ca02a --- /dev/null +++ b/imports/Spectral/Menu/Timeline/MessageDelegateContextMenu.qml @@ -0,0 +1,34 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.12 + +import Spectral.Dialog 2.0 + +Menu { + readonly property string selectedText: contentLabel.selectedText + + signal viewSource() + signal reply() + signal redact() + + id: root + + MenuItem { + text: "View Source" + + onTriggered: viewSource() + } + + MenuItem { + text: "Reply" + + onTriggered: reply() + } + + MenuItem { + text: "Redact" + + onTriggered: redact() + } + + onClosed: destroy() +} diff --git a/imports/Spectral/Menu/Timeline/qmldir b/imports/Spectral/Menu/Timeline/qmldir new file mode 100644 index 0000000..20b869c --- /dev/null +++ b/imports/Spectral/Menu/Timeline/qmldir @@ -0,0 +1,3 @@ +module Spectral.Menu.Timeline +MessageDelegateContextMenu 2.0 MessageDelegateContextMenu.qml +FileDelegateContextMenu 2.0 FileDelegateContextMenu.qml diff --git a/imports/Spectral/Menu/qmldir b/imports/Spectral/Menu/qmldir new file mode 100644 index 0000000..c52d0fd --- /dev/null +++ b/imports/Spectral/Menu/qmldir @@ -0,0 +1,2 @@ +module Spectral.Menu +RoomListContextMenu 2.0 RoomListContextMenu.qml diff --git a/imports/Spectral/Panel/RoomListPanel.qml b/imports/Spectral/Panel/RoomListPanel.qml index 5505d9a..30b94cb 100644 --- a/imports/Spectral/Panel/RoomListPanel.qml +++ b/imports/Spectral/Panel/RoomListPanel.qml @@ -5,6 +5,8 @@ import QtQuick.Layouts 1.12 import QtQuick.Controls.Material 2.12 import Spectral.Component 2.0 +import Spectral.Dialog 2.0 +import Spectral.Menu 2.0 import Spectral.Effect 2.0 import Spectral 0.1 @@ -363,11 +365,9 @@ Item { RippleEffect { anchors.fill: parent - onSecondaryClicked: roomContextMenu.popup() onPrimaryClicked: { if (category === RoomType.Invited) { - inviteDialog.currentRoom = currentRoom - inviteDialog.open() + acceptInvitationDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom}).open() } else { if (enteredRoom) { enteredRoom.displayed = false @@ -378,41 +378,13 @@ Item { enteredRoom = currentRoom } } + onSecondaryClicked: roomListContextMenu.createObject(ApplicationWindow.overlay, {"room": currentRoom}).popup() } - Menu { - id: roomContextMenu + Component { + id: roomListContextMenu - MenuItem { - text: "Favourite" - checkable: true - checked: category === RoomType.Favorite - - onTriggered: category === RoomType.Favorite ? currentRoom.removeTag("m.favourite") : currentRoom.addTag("m.favourite", 1.0) - } - - MenuItem { - text: "Deprioritize" - checkable: true - checked: category === RoomType.Deprioritized - - onTriggered: category === RoomType.Deprioritized ? currentRoom.removeTag("m.lowpriority") : currentRoom.addTag("m.lowpriority", 1.0) - } - - MenuSeparator {} - - MenuItem { - text: "Mark as Read" - - onTriggered: currentRoom.markAllMessagesAsRead() - } - - MenuItem { - text: "Leave Room" - Material.foreground: Material.Red - - onTriggered: currentRoom.forget() - } + RoomListContextMenu {} } } @@ -431,48 +403,9 @@ Item { } } - Dialog { - property var currentRoom + Component { + id: acceptInvitationDialog - id: inviteDialog - parent: ApplicationWindow.overlay - - x: (window.width - width) / 2 - y: (window.height - height) / 2 - width: 360 - - title: "Action Required" - modal: true - - contentItem: Label { text: "Accept this invitation?" } - - footer: DialogButtonBox { - Button { - text: "Accept" - flat: true - - onClicked: { - inviteDialog.currentRoom.acceptInvitation() - inviteDialog.close() - } - } - - Button { - text: "Reject" - flat: true - - onClicked: { - inviteDialog.currentRoom.forget() - inviteDialog.close() - } - } - - Button { - text: "Cancel" - flat: true - - onClicked: inviteDialog.close() - } - } + AcceptInvitationDialog {} } } diff --git a/res.qrc b/res.qrc index bdc2d16..b1edf53 100644 --- a/res.qrc +++ b/res.qrc @@ -52,5 +52,11 @@ imports/Spectral/Dialog/CreateRoomDialog.qml imports/Spectral/Dialog/JoinRoomDialog.qml imports/Spectral/Dialog/InviteUserDialog.qml + imports/Spectral/Dialog/AcceptInvitationDialog.qml + imports/Spectral/Menu/qmldir + imports/Spectral/Menu/RoomListContextMenu.qml + imports/Spectral/Menu/Timeline/qmldir + imports/Spectral/Menu/Timeline/MessageDelegateContextMenu.qml + imports/Spectral/Menu/Timeline/FileDelegateContextMenu.qml