ui: panning GraphView and resizing after node was moved

This commit is contained in:
Eberhard Graether
2015-03-23 16:16:26 +01:00
parent 5fc7182dc0
commit 7790241926
9 changed files with 37 additions and 14 deletions
+3
View File
@@ -26,6 +26,9 @@ QtMainWindow::QtMainWindow()
setCentralWidget(nullptr);
setDockNestingEnabled(true);
setWindowIcon(QIcon("./data/gui/icon/logo_1024_1024.png"));
QApplication::setOverrideCursor(Qt::ArrowCursor);
setupProjectMenu();
setupEditMenu();
setupViewMenu();
+18 -6
View File
@@ -12,17 +12,18 @@
#include "qt/utility/utilityQt.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponentMoveable.h"
#include "qt/view/graphElements/QtGraphEdge.h"
#include "qt/view/graphElements/QtGraphNode.h"
#include "qt/view/graphElements/QtGraphNodeAccess.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponentMoveable.h"
QtGraphView::QtGraphView(ViewLayout* viewLayout)
: GraphView(viewLayout)
, m_rebuildGraphFunctor(
std::bind(&QtGraphView::doRebuildGraph, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))
, m_clearFunctor(std::bind(&QtGraphView::doClear, this))
, m_resizeFunctor(std::bind(&QtGraphView::doResize, this))
{
}
@@ -48,6 +49,7 @@ void QtGraphView::initView()
QGraphicsScene* scene = new QGraphicsScene(widget);
QGraphicsView* view = new QGraphicsView(widget);
view->setScene(scene);
view->setDragMode(QGraphicsView::ScrollHandDrag);
widget->layout()->addWidget(view);
}
@@ -69,6 +71,11 @@ void QtGraphView::clear()
m_clearFunctor();
}
void QtGraphView::resizeView()
{
m_resizeFunctor();
}
Vec2i QtGraphView::getViewSize() const
{
QGraphicsView* view = getView();
@@ -98,12 +105,10 @@ void QtGraphView::switchToNewGraphData()
m_nodes.clear();
m_edges.clear();
QGraphicsView* view = getView();
int margin = 25;
view->setSceneRect(itemsBoundingRect(m_oldNodes).adjusted(-margin, -margin, margin, margin).translated(m_sceneRectOffset));
doResize();
// Manually hover the item below the mouse cursor.
QGraphicsView* view = getView();
QPointF point = view->mapToScene(view->mapFromGlobal(QCursor::pos()));
QGraphicsItem* item = view->scene()->itemAt(point, QTransform());
if (item)
@@ -189,6 +194,13 @@ void QtGraphView::doClear()
m_oldGraph.reset();
}
void QtGraphView::doResize()
{
int margin = 25;
QGraphicsView* view = getView();
view->setSceneRect(itemsBoundingRect(m_oldNodes).adjusted(-margin, -margin, margin, margin).translated(m_sceneRectOffset));
}
std::shared_ptr<QtGraphNode> QtGraphView::findNodeRecursive(const std::list<std::shared_ptr<QtGraphNode>>& nodes, Id tokenId)
{
for (const std::shared_ptr<QtGraphNode>& node : nodes)
+4
View File
@@ -35,6 +35,8 @@ public:
virtual void rebuildGraph(std::shared_ptr<Graph> graph, const std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
virtual void clear();
virtual void resizeView();
virtual Vec2i getViewSize() const;
private slots:
@@ -47,6 +49,7 @@ private:
void doRebuildGraph(std::shared_ptr<Graph> graph, const std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
void doClear();
void doResize();
std::shared_ptr<QtGraphNode> findNodeRecursive(const std::list<std::shared_ptr<QtGraphNode>>& nodes, Id tokenId);
@@ -68,6 +71,7 @@ private:
QtThreadedFunctor<std::shared_ptr<Graph>, const std::vector<DummyNode>&, const std::vector<DummyEdge>&> m_rebuildGraphFunctor;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_resizeFunctor;
std::shared_ptr<Graph> m_graph;
std::shared_ptr<Graph> m_oldGraph;
@@ -9,6 +9,7 @@
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/QtGraphPostprocessor.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h"
#include "qt/view/graphElements/QtGraphEdge.h"
@@ -106,11 +107,13 @@ bool QtGraphNode::setPosition(const Vec2i& position)
return false;
}
void QtGraphNode::moveTo(const Vec2i& position)
void QtGraphNode::moved()
{
if (setPosition(position) && m_data)
QtGraphPostprocessor::alignNodeOnRaster(this);
if (m_data)
{
MessageGraphNodeMove(m_data->getId(), position).dispatch();
MessageGraphNodeMove(m_data->getId(), getPosition()).dispatch();
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ public:
virtual Vec2i getPosition() const;
virtual bool setPosition(const Vec2i& position);
virtual void moveTo(const Vec2i& position);
virtual void moved();
virtual Vec2i getSize() const;
virtual void setSize(const Vec2i& size);
@@ -2,7 +2,6 @@
#include <QGraphicsSceneEvent>
#include "qt/utility/QtGraphPostprocessor.h"
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphNodeComponentMoveable::QtGraphNodeComponentMoveable(const std::weak_ptr<QtGraphNode>& graphNode)
@@ -32,7 +31,7 @@ void QtGraphNodeComponentMoveable::nodeMouseMoveEvent(QGraphicsSceneMouseEvent*
std::shared_ptr<GraphNode> node = m_graphNode.lock();
if (node != NULL)
{
node->moveTo(Vec2i(event->scenePos().x() - m_mouseOffset.x, event->scenePos().y() - m_mouseOffset.y));
node->setPosition(Vec2i(event->scenePos().x() - m_mouseOffset.x, event->scenePos().y() - m_mouseOffset.y));
event->accept();
}
}
@@ -47,6 +46,6 @@ void QtGraphNodeComponentMoveable::nodeMouseReleaseEvent(QGraphicsSceneMouseEven
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
QtGraphPostprocessor::alignNodeOnRaster(node.get());
node->moved();
}
}
@@ -78,6 +78,7 @@ void GraphController::handleMessage(MessageGraphNodeMove* message)
if (node)
{
node->position = message->position;
getView()->resizeView();
}
}
+2
View File
@@ -25,6 +25,8 @@ public:
std::shared_ptr<Graph> graph, const std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges) = 0;
virtual void clear() = 0;
virtual void resizeView() = 0;
virtual Vec2i getViewSize() const = 0;
};
@@ -29,7 +29,6 @@ public:
virtual Vec2i getPosition() const = 0;
virtual bool setPosition(const Vec2i& position) = 0;
virtual void moveTo(const Vec2i& position) = 0;
virtual Vec2i getSize() const = 0;
virtual void setSize(const Vec2i& size) = 0;