add context menu
1 files changed, 20 insertions(+), 1 deletions(-)

M qml/GraphView.qml
M qml/GraphView.qml +20 -1
@@ 1,4 1,5 @@ 
 import QtQuick 2.12
+import QtQuick.Controls 2.12
 import QuickGraphLayout 1.0
 
 Flickable {

          
@@ 136,7 137,7 @@ Flickable {
 
             MouseArea {
                 anchors.fill: parent
-                acceptedButtons: Qt.LeftButton | Qt.MiddleButton
+                acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
                 hoverEnabled: true
 
                 onClicked: {

          
@@ 144,6 145,8 @@ Flickable {
                         node.focus = !node.focus;
                     } else if (mouse.button === Qt.MiddleButton) {
                         layoutModel.removeNode(model.nodeId);
+                    } else if (mouse.button === Qt.RightButton) {
+                        contextMenu.popup();
                     }
                 }
 

          
@@ 162,6 165,22 @@ Flickable {
                 }
             }
 
+            Menu {
+                id: contextMenu
+                Action {
+                    text: "Add node"
+                    onTriggered: {
+                        layoutModel.addNode(model.nodeId, GraphLayoutModel.NodeType.Square);
+                    }
+                }
+                Action {
+                    text: "Remove node"
+                    onTriggered: {
+                        layoutModel.removeNode(model.nodeId);
+                    }
+                }
+            }
+
             Behavior on y {
                 NumberAnimation {
                     duration: 200