ui: added context menu option to copy a graph-node's name

This commit is contained in:
malte_langkabel
2017-01-19 12:01:08 +01:00
parent 0cdddb616d
commit 212c0e71fa
3 changed files with 60 additions and 9 deletions
+50 -1
View File
@@ -5,9 +5,14 @@
#include <QScrollBar>
#include <QTimer>
#include <QApplication>
#include <QClipboard>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#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<QtGraphNode*>(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<QAction*>(1, m_exportGraphAction));
m_clipboardNodeName = "";
QtGraphNode* node = getNodeAtCursorPosition();
while (node)
{
if (dynamic_cast<QtGraphNodeData*>(node) || dynamic_cast<QtGraphNodeBundle*>(node))
{
m_clipboardNodeName = node->getName();
break;
}
node = node->getParent();
}
std::vector<QAction*> 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;
+7
View File
@@ -8,6 +8,7 @@
#include <memory>
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<QTimer> m_timer;
std::shared_ptr<QTimer> m_timerStopper;
QAction* m_exportGraphAction;
QAction* m_copyNodeNameAction;
};
#endif // QT_GRAPHICS_VIEW_H
+3 -8
View File
@@ -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<QtGraphNode*>(item->parentItem());
if (node)
{
node->hoverEnter();
}
node->hoverEnter();
}
if (m_activeNode)