# HG changeset patch # User Yuya Nishihara # Date 1585323729 -32400 # Sat Mar 28 00:42:09 2020 +0900 # Node ID 5f50806fb9c6147f02183e84fd596c5a35087ad4 # Parent 4b0a89e876ed9ee81b159b3743593288461538bf add context menu diff --git a/qml/GraphView.qml b/qml/GraphView.qml --- a/qml/GraphView.qml +++ b/qml/GraphView.qml @@ -1,4 +1,5 @@ import QtQuick 2.12 +import QtQuick.Controls 2.12 import QuickGraphLayout 1.0 Flickable { @@ -136,7 +137,7 @@ MouseArea { anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.MiddleButton + acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton hoverEnabled: true onClicked: { @@ -144,6 +145,8 @@ 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 @@ } } + 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