Skip to content

Commit 0d808ac

Browse files
tuvokpaceholder
authored andcommitted
Modifications to allow custom context menus on node objects (paceholder#112)
* Modifications to allow custom context menus on node objects * Added position of ContextMenuEvent in signal
1 parent 167a349 commit 0d808ac

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

src/FlowScene.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class NODE_EDITOR_PUBLIC FlowScene
112112

113113
void nodeHoverLeft(Node& n);
114114

115+
void nodeContextMenu(Node& n, const QPointF& pos);
116+
115117
private:
116118

117119
using SharedConnection = std::shared_ptr<Connection>;

src/FlowView.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ void
8383
FlowView::
8484
contextMenuEvent(QContextMenuEvent *event)
8585
{
86+
if (itemAt(event->pos()))
87+
{
88+
QGraphicsView::contextMenuEvent(event);
89+
return;
90+
}
91+
8692
QMenu modelMenu;
8793

8894
auto skipText = QStringLiteral("skip me");

src/NodeGraphicsObject.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ NodeGraphicsObject(FlowScene &scene,
6565
};
6666
connect(this, &QGraphicsObject::xChanged, this, onMoveSlot);
6767
connect(this, &QGraphicsObject::yChanged, this, onMoveSlot);
68+
6869
}
6970

7071

@@ -401,3 +402,10 @@ mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
401402

402403
_scene.nodeDoubleClicked(node());
403404
}
405+
406+
void
407+
NodeGraphicsObject::
408+
contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
409+
{
410+
_scene.nodeContextMenu(node(), mapToScene(event->pos()));
411+
}

src/NodeGraphicsObject.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class NodeGraphicsObject : public QGraphicsObject
8484
void
8585
mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
8686

87+
void
88+
contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
89+
8790
private:
8891
void
8992
embedQWidget();

0 commit comments

Comments
 (0)