diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.cpp b/src/lib_gui/qt/graphics/QtGraphicsView.cpp index d5edb313..168d8a75 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.cpp +++ b/src/lib_gui/qt/graphics/QtGraphicsView.cpp @@ -5,9 +5,14 @@ #include #include +#include +#include #include #include +#include "qt/view/graphElements/QtGraphNode.h" +#include "qt/view/graphElements/QtGraphNodeData.h" +#include "qt/view/graphElements/QtGraphNodeBundle.h" #include "qt/utility/QtContextMenu.h" #include "settings/ApplicationSettings.h" @@ -34,6 +39,11 @@ QtGraphicsView::QtGraphicsView(QWidget* parent) m_exportGraphAction->setStatusTip(tr("Save this graph as image file")); m_exportGraphAction->setToolTip(tr("Save this graph as image file")); connect(m_exportGraphAction, SIGNAL(triggered()), this, SLOT(exportGraph())); + + m_copyNodeNameAction = new QAction(tr("Copy Name"), this); + m_copyNodeNameAction->setStatusTip(tr("Copies the name of this node to the clipboard")); + m_copyNodeNameAction->setToolTip(tr("Copies the name of this node to the clipboard")); + connect(m_copyNodeNameAction, SIGNAL(triggered()), this, SLOT(copyNodeName())); } float QtGraphicsView::getZoomFactor() const @@ -47,6 +57,20 @@ void QtGraphicsView::setAppZoomFactor(float appZoomFactor) updateTransform(); } +QtGraphNode* QtGraphicsView::getNodeAtCursorPosition() const +{ + QtGraphNode* node = nullptr; + + QPointF point = mapToScene(mapFromGlobal(QCursor::pos())); + QGraphicsItem* item = scene()->itemAt(point, QTransform()); + if (item) + { + node = dynamic_cast(item->parentItem()); + } + + return node; +} + void QtGraphicsView::ensureVisibleAnimated(const QRectF& rect, int xmargin, int ymargin) { int xval = horizontalScrollBar()->value(); @@ -187,7 +211,27 @@ void QtGraphicsView::wheelEvent(QWheelEvent* event) void QtGraphicsView::contextMenuEvent(QContextMenuEvent* event) { - QtContextMenu::getInstance()->showExtended(event, this, std::vector(1, m_exportGraphAction)); + m_clipboardNodeName = ""; + + QtGraphNode* node = getNodeAtCursorPosition(); + while (node) + { + if (dynamic_cast(node) || dynamic_cast(node)) + { + m_clipboardNodeName = node->getName(); + break; + } + node = node->getParent(); + } + + std::vector actions; + actions.push_back(m_exportGraphAction); + if (!m_clipboardNodeName.empty()) + { + actions.push_back(m_copyNodeNameAction); + } + + QtContextMenu::getInstance()->showExtended(event, this, actions); } void QtGraphicsView::updateTimer() @@ -322,6 +366,11 @@ void QtGraphicsView::exportGraph() } } +void QtGraphicsView::copyNodeName() +{ + QApplication::clipboard()->setText(m_clipboardNodeName.c_str()); +} + bool QtGraphicsView::moves() const { return m_up || m_down || m_left || m_right; diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.h b/src/lib_gui/qt/graphics/QtGraphicsView.h index b5e61a14..2c845b0b 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.h +++ b/src/lib_gui/qt/graphics/QtGraphicsView.h @@ -8,6 +8,7 @@ #include class QTimer; +class QtGraphNode; class QtGraphicsView : public QGraphicsView @@ -20,6 +21,8 @@ public: float getZoomFactor() const; void setAppZoomFactor(float appZoomFactor); + QtGraphNode* getNodeAtCursorPosition() const; + void ensureVisibleAnimated(const QRectF& rect, int xmargin = 50, int ymargin = 50); protected: @@ -41,6 +44,7 @@ private slots: void stopTimer(); void exportGraph(); + void copyNodeName(); private: bool moves() const; @@ -59,10 +63,13 @@ private: bool m_right; bool m_shift; + std::string m_clipboardNodeName; + std::shared_ptr m_timer; std::shared_ptr m_timerStopper; QAction* m_exportGraphAction; + QAction* m_copyNodeNameAction; }; #endif // QT_GRAPHICS_VIEW_H diff --git a/src/lib_gui/qt/view/QtGraphView.cpp b/src/lib_gui/qt/view/QtGraphView.cpp index f02c9763..4fdb0dc5 100644 --- a/src/lib_gui/qt/view/QtGraphView.cpp +++ b/src/lib_gui/qt/view/QtGraphView.cpp @@ -171,15 +171,10 @@ void QtGraphView::switchToNewGraphData() // Manually hover the item below the mouse cursor. QtGraphicsView* view = getView(); - QPointF point = view->mapToScene(view->mapFromGlobal(QCursor::pos())); - QGraphicsItem* item = view->scene()->itemAt(point, QTransform()); - if (item) + QtGraphNode* node = view->getNodeAtCursorPosition(); + if (node) { - QtGraphNode* node = dynamic_cast(item->parentItem()); - if (node) - { - node->hoverEnter(); - } + node->hoverEnter(); } if (m_activeNode)