ui: graph transitions
This change adds animated transitions to the QtGraphView using sequential and parallel animations. First vanishing nodes and all edges get faded out, then the remaining nodes are moved and resized, lastly new nodes and all edges are faded in. fortune cookie message = Sorge dich nicht! Du wirst bekommen, was du brauchst.
This commit is contained in:
@@ -33,6 +33,14 @@ void QtGraphicsRoundedRectItem::setShadow(QColor color, int blurRadius)
|
||||
this->setGraphicsEffect(effect);
|
||||
}
|
||||
|
||||
void QtGraphicsRoundedRectItem::setShadowEnabled(bool enabled)
|
||||
{
|
||||
if (this->graphicsEffect())
|
||||
{
|
||||
this->graphicsEffect()->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphicsRoundedRectItem::setRadius(qreal radius)
|
||||
{
|
||||
m_radius = radius;
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem* options, QWidget* widget);
|
||||
|
||||
void setShadow(QColor color, int blurRadius);
|
||||
void setShadowEnabled(bool enabled);
|
||||
void setRadius(qreal radius);
|
||||
|
||||
private:
|
||||
|
||||
@@ -66,8 +66,11 @@ void QtGraphPostprocessor::doPostprocessing(std::list<std::shared_ptr<QtGraphNod
|
||||
|
||||
void QtGraphPostprocessor::allignNodeOnRaster(QtGraphNode* node)
|
||||
{
|
||||
Vec2i position = node->getPosition();
|
||||
node->setPosition(alignOnRaster(node->getPosition()));
|
||||
}
|
||||
|
||||
Vec2i QtGraphPostprocessor::alignOnRaster(Vec2i position)
|
||||
{
|
||||
int rasterPosDivisor = s_cellSize + s_cellPadding;
|
||||
|
||||
if(position.x % rasterPosDivisor != 0)
|
||||
@@ -110,7 +113,7 @@ void QtGraphPostprocessor::allignNodeOnRaster(QtGraphNode* node)
|
||||
position.y = t * rasterPosDivisor;
|
||||
}
|
||||
|
||||
node->setPosition(position);
|
||||
return position;
|
||||
}
|
||||
|
||||
void QtGraphPostprocessor::resolveOutliers(std::list<std::shared_ptr<QtGraphNode>>& nodes, const Vec2i& centerPoint)
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
static void doPostprocessing(std::list<std::shared_ptr<QtGraphNode>>& nodes);
|
||||
|
||||
static void allignNodeOnRaster(QtGraphNode* node);
|
||||
static Vec2i alignOnRaster(Vec2i position);
|
||||
|
||||
private:
|
||||
static unsigned int s_cellSize;
|
||||
|
||||
+273
-53
@@ -4,6 +4,9 @@
|
||||
#include <QFrame>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QSequentialAnimationGroup>
|
||||
|
||||
#include "qt/utility/QtGraphPostprocessor.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
@@ -69,12 +72,7 @@ void QtGraphView::clear()
|
||||
GraphView::Metrics QtGraphView::getViewMetrics() const
|
||||
{
|
||||
GraphView::Metrics metrics;
|
||||
|
||||
QGraphicsView* view = getView();
|
||||
if (view == NULL)
|
||||
{
|
||||
return metrics;
|
||||
}
|
||||
|
||||
metrics.width = view->width();
|
||||
metrics.height = view->height();
|
||||
@@ -86,61 +84,35 @@ GraphView::Metrics QtGraphView::getViewMetrics() const
|
||||
return metrics;
|
||||
}
|
||||
|
||||
QGraphicsView* QtGraphView::getView() const
|
||||
void QtGraphView::finishedTransition()
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
|
||||
{
|
||||
node->setShadowEnabledRecursive(true);
|
||||
}
|
||||
|
||||
return widget->findChild<QGraphicsView*>("");
|
||||
QGraphicsView* view = getView();
|
||||
view->setInteractive(true);
|
||||
|
||||
switchToNewGraphData();
|
||||
}
|
||||
|
||||
void QtGraphView::doRebuildGraph(
|
||||
std::shared_ptr<Graph> graph,
|
||||
const std::vector<DummyNode>& nodes,
|
||||
const std::vector<DummyEdge>& edges
|
||||
){
|
||||
void QtGraphView::switchToNewGraphData()
|
||||
{
|
||||
m_oldGraph = m_graph;
|
||||
|
||||
m_oldNodes = m_nodes;
|
||||
m_oldEdges = m_edges;
|
||||
|
||||
m_nodes.clear();
|
||||
m_edges.clear();
|
||||
|
||||
QGraphicsView* view = getView();
|
||||
|
||||
if (view == NULL)
|
||||
{
|
||||
LOG_WARNING("Failed to get QGraphicsView");
|
||||
return;
|
||||
}
|
||||
int margin = 25;
|
||||
view->setSceneRect(itemsBoundingRect(m_oldNodes).adjusted(-margin, -margin, margin, margin).translated(m_sceneRectOffset));
|
||||
|
||||
// Temporary stores all nodes (existing and newly created) needed in the new graph
|
||||
// this is a relatively easy and cheap way to save existing nodes that are still needed
|
||||
std::list<std::shared_ptr<QtGraphNode>> newNodes;
|
||||
|
||||
// create nodes (or find existing nodes for re-use)
|
||||
for (unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
std::shared_ptr<QtGraphNode> node = createNodeRecursive(view, NULL, nodes[i]);
|
||||
if (node)
|
||||
{
|
||||
newNodes.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
doClear();
|
||||
m_nodes = newNodes;
|
||||
|
||||
for (unsigned int i = 0; i < edges.size(); i++)
|
||||
{
|
||||
std::shared_ptr<QtGraphEdge> edge = createEdge(view, edges[i]);
|
||||
if (edge != NULL)
|
||||
{
|
||||
m_edges.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
if (graph)
|
||||
{
|
||||
m_graph = graph;
|
||||
}
|
||||
|
||||
QtGraphPostprocessor::doPostprocessing(m_nodes);
|
||||
|
||||
// Manually hover the items below the mouse cursor.
|
||||
view->scene()->setSceneRect(view->scene()->itemsBoundingRect());
|
||||
// Manually hover the item below the mouse cursor.
|
||||
QPointF point = view->mapToScene(view->mapFromGlobal(QCursor::pos()));
|
||||
QGraphicsItem* item = view->scene()->itemAt(point, QTransform());
|
||||
if (item)
|
||||
@@ -153,10 +125,77 @@ void QtGraphView::doRebuildGraph(
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsView* QtGraphView::getView() const
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
|
||||
|
||||
QGraphicsView* view = widget->findChild<QGraphicsView*>("");
|
||||
|
||||
if (!view)
|
||||
{
|
||||
LOG_ERROR("Failed to get QGraphicsView");
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
void QtGraphView::doRebuildGraph(
|
||||
std::shared_ptr<Graph> graph,
|
||||
const std::vector<DummyNode>& nodes,
|
||||
const std::vector<DummyEdge>& edges
|
||||
){
|
||||
QGraphicsView* view = getView();
|
||||
|
||||
m_nodes.clear();
|
||||
for (unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
std::shared_ptr<QtGraphNode> node = createNodeRecursive(view, NULL, nodes[i]);
|
||||
if (node)
|
||||
{
|
||||
m_nodes.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
QtGraphPostprocessor::doPostprocessing(m_nodes);
|
||||
|
||||
QPointF center = itemsBoundingRect(m_nodes).center();
|
||||
Vec2i o = QtGraphPostprocessor::alignOnRaster(Vec2i(center.x(), center.y()));
|
||||
QPointF offset = QPointF(o.x, o.y);
|
||||
m_sceneRectOffset = offset - center;
|
||||
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
|
||||
{
|
||||
node->setPos(node->pos() - offset);
|
||||
}
|
||||
|
||||
m_edges.clear();
|
||||
for (unsigned int i = 0; i < edges.size(); i++)
|
||||
{
|
||||
std::shared_ptr<QtGraphEdge> edge = createEdge(view, edges[i]);
|
||||
if (edge)
|
||||
{
|
||||
m_edges.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
if (graph)
|
||||
{
|
||||
m_graph = graph;
|
||||
}
|
||||
|
||||
createTransition();
|
||||
}
|
||||
|
||||
void QtGraphView::doClear()
|
||||
{
|
||||
m_nodes.clear();
|
||||
m_edges.clear();
|
||||
|
||||
m_oldNodes.clear();
|
||||
m_oldEdges.clear();
|
||||
|
||||
m_graph.reset();
|
||||
m_oldGraph.reset();
|
||||
}
|
||||
|
||||
std::shared_ptr<QtGraphNode> QtGraphView::findNodeRecursive(const std::list<std::shared_ptr<QtGraphNode>>& nodes, Id tokenId)
|
||||
@@ -258,3 +297,184 @@ std::shared_ptr<QtGraphEdge> QtGraphView::createEdge(QGraphicsView* view, const
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
QRectF QtGraphView::itemsBoundingRect(const std::list<std::shared_ptr<T>>& items) const
|
||||
{
|
||||
QRectF boundingRect;
|
||||
for (const std::shared_ptr<T>& item : items)
|
||||
{
|
||||
boundingRect |= item->sceneBoundingRect();
|
||||
}
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
void QtGraphView::compareNodesRecursive(
|
||||
std::list<std::shared_ptr<QtGraphNode>> newSubNodes,
|
||||
std::list<std::shared_ptr<QtGraphNode>> oldSubNodes,
|
||||
std::list<QtGraphNode*>* appearingNodes,
|
||||
std::list<QtGraphNode*>* vanishingNodes,
|
||||
std::vector<std::pair<QtGraphNode*, QtGraphNode*>>* remainingNodes
|
||||
){
|
||||
for (std::list<std::shared_ptr<QtGraphNode>>::iterator it = newSubNodes.begin(); it != newSubNodes.end(); it++)
|
||||
{
|
||||
bool remains = false;
|
||||
|
||||
for (std::list<std::shared_ptr<QtGraphNode>>::iterator it2 = oldSubNodes.begin(); it2 != oldSubNodes.end(); it2++)
|
||||
{
|
||||
if (((*it)->getTokenId() && (*it)->getTokenId() == (*it2)->getTokenId()) ||
|
||||
((*it)->isAccessNode() && (*it2)->isAccessNode() &&
|
||||
dynamic_cast<QtGraphNodeAccess*>((*it).get())->getAccessType() ==
|
||||
dynamic_cast<QtGraphNodeAccess*>((*it2).get())->getAccessType()))
|
||||
{
|
||||
remainingNodes->push_back(std::pair<QtGraphNode*, QtGraphNode*>((*it).get(), (*it2).get()));
|
||||
compareNodesRecursive((*it)->getSubNodes(), (*it2)->getSubNodes(), appearingNodes, vanishingNodes, remainingNodes);
|
||||
|
||||
oldSubNodes.erase(it2);
|
||||
remains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!remains)
|
||||
{
|
||||
appearingNodes->push_back((*it).get());
|
||||
}
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtGraphNode>& node : oldSubNodes)
|
||||
{
|
||||
vanishingNodes->push_back(node.get());
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphView::createTransition()
|
||||
{
|
||||
std::list<QtGraphNode*> appearingNodes;
|
||||
std::list<QtGraphNode*> vanishingNodes;
|
||||
std::vector<std::pair<QtGraphNode*, QtGraphNode*>> remainingNodes;
|
||||
|
||||
compareNodesRecursive(m_nodes, m_oldNodes, &appearingNodes, &vanishingNodes, &remainingNodes);
|
||||
|
||||
if (!vanishingNodes.size() && !appearingNodes.size())
|
||||
{
|
||||
switchToNewGraphData();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
|
||||
{
|
||||
node->setShadowEnabledRecursive(false);
|
||||
}
|
||||
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_oldNodes)
|
||||
{
|
||||
node->setShadowEnabledRecursive(false);
|
||||
}
|
||||
|
||||
QGraphicsView* view = getView();
|
||||
view->setInteractive(false);
|
||||
|
||||
QSequentialAnimationGroup* group = new QSequentialAnimationGroup();
|
||||
|
||||
// fade out
|
||||
if (vanishingNodes.size() || m_oldEdges.size())
|
||||
{
|
||||
QParallelAnimationGroup* vanish = new QParallelAnimationGroup();
|
||||
|
||||
for (QtGraphNode* node : vanishingNodes)
|
||||
{
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(node, "opacity");
|
||||
anim->setDuration(300);
|
||||
anim->setStartValue(1.0f);
|
||||
anim->setEndValue(0.0f);
|
||||
|
||||
vanish->addAnimation(anim);
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
|
||||
{
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(edge.get(), "opacity");
|
||||
anim->setDuration(150);
|
||||
anim->setStartValue(1.0f);
|
||||
anim->setEndValue(0.0f);
|
||||
|
||||
vanish->addAnimation(anim);
|
||||
}
|
||||
|
||||
group->addAnimation(vanish);
|
||||
}
|
||||
|
||||
// move and scale
|
||||
if (remainingNodes.size())
|
||||
{
|
||||
QParallelAnimationGroup* remain = new QParallelAnimationGroup();
|
||||
|
||||
for (std::pair<QtGraphNode*, QtGraphNode*> p : remainingNodes)
|
||||
{
|
||||
QtGraphNode* newNode = p.first;
|
||||
QtGraphNode* oldNode = p.second;
|
||||
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(oldNode, "pos");
|
||||
anim->setDuration(300);
|
||||
anim->setStartValue(oldNode->pos());
|
||||
anim->setEndValue(newNode->pos());
|
||||
|
||||
remain->addAnimation(anim);
|
||||
|
||||
connect(anim, SIGNAL(finished()), newNode, SLOT(showNode()));
|
||||
connect(anim, SIGNAL(finished()), oldNode, SLOT(hideNode()));
|
||||
newNode->hide();
|
||||
|
||||
anim = new QPropertyAnimation(oldNode, "size");
|
||||
anim->setDuration(300);
|
||||
anim->setStartValue(oldNode->size());
|
||||
anim->setEndValue(newNode->size());
|
||||
|
||||
remain->addAnimation(anim);
|
||||
|
||||
if (newNode->isAccessNode() && newNode->getSubNodes().size() == 0 && oldNode->getSubNodes().size() > 0)
|
||||
{
|
||||
dynamic_cast<QtGraphNodeAccess*>(oldNode)->hideLabel();
|
||||
}
|
||||
}
|
||||
|
||||
group->addAnimation(remain);
|
||||
}
|
||||
|
||||
// fade in
|
||||
if (appearingNodes.size() || m_edges.size())
|
||||
{
|
||||
QParallelAnimationGroup* appear = new QParallelAnimationGroup();
|
||||
|
||||
for (QtGraphNode* node : appearingNodes)
|
||||
{
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(node, "opacity");
|
||||
anim->setDuration(300);
|
||||
anim->setStartValue(0.0f);
|
||||
anim->setEndValue(1.0f);
|
||||
|
||||
appear->addAnimation(anim);
|
||||
|
||||
connect(anim, SIGNAL(finished()), node, SLOT(blendIn()));
|
||||
node->blendOut();
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtGraphEdge> edge : m_edges)
|
||||
{
|
||||
QPropertyAnimation* anim = new QPropertyAnimation(edge.get(), "opacity");
|
||||
anim->setDuration(150);
|
||||
anim->setStartValue(0.0f);
|
||||
anim->setEndValue(1.0f);
|
||||
|
||||
appear->addAnimation(anim);
|
||||
|
||||
edge->setOpacity(0.0f);
|
||||
}
|
||||
|
||||
group->addAnimation(appear);
|
||||
}
|
||||
|
||||
connect(group, SIGNAL(finished()), this, SLOT(finishedTransition()));
|
||||
group->start();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef QT_GRAPH_VIEW_H
|
||||
#define QT_GRAPH_VIEW_H
|
||||
|
||||
#include <QPointF>
|
||||
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
#include "utility/math/MatrixDynamicBase.h"
|
||||
#include "utility/math/Vector4.h"
|
||||
@@ -14,8 +16,12 @@ class QGraphicsView;
|
||||
class QtGraphEdge;
|
||||
class QtGraphNode;
|
||||
|
||||
class QtGraphView: public GraphView
|
||||
class QtGraphView
|
||||
: public QObject
|
||||
, public GraphView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtGraphView(ViewLayout* viewLayout);
|
||||
virtual ~QtGraphView();
|
||||
@@ -30,7 +36,12 @@ public:
|
||||
|
||||
virtual GraphView::Metrics getViewMetrics() const;
|
||||
|
||||
private slots:
|
||||
void finishedTransition();
|
||||
|
||||
private:
|
||||
void switchToNewGraphData();
|
||||
|
||||
QGraphicsView* getView() const;
|
||||
|
||||
void doRebuildGraph(std::shared_ptr<Graph> graph, const std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
|
||||
@@ -42,13 +53,31 @@ private:
|
||||
QGraphicsView* view, std::shared_ptr<QtGraphNode> parentNode, const DummyNode& node);
|
||||
std::shared_ptr<QtGraphEdge> createEdge(QGraphicsView* view, const DummyEdge& edge);
|
||||
|
||||
template <typename T>
|
||||
QRectF itemsBoundingRect(const std::list<std::shared_ptr<T>>& items) const;
|
||||
|
||||
void compareNodesRecursive(
|
||||
std::list<std::shared_ptr<QtGraphNode>> newSubNodes,
|
||||
std::list<std::shared_ptr<QtGraphNode>> oldSubNodes,
|
||||
std::list<QtGraphNode*>* appearingNodes,
|
||||
std::list<QtGraphNode*>* vanishingNodes,
|
||||
std::vector<std::pair<QtGraphNode*, QtGraphNode*>>* remainingNodes);
|
||||
|
||||
void createTransition();
|
||||
|
||||
QtThreadedFunctor<std::shared_ptr<Graph>, const std::vector<DummyNode>&, const std::vector<DummyEdge>&> m_rebuildGraphFunctor;
|
||||
QtThreadedFunctor<void> m_clearFunctor;
|
||||
|
||||
std::shared_ptr<Graph> m_graph;
|
||||
std::shared_ptr<Graph> m_oldGraph;
|
||||
|
||||
std::list<std::shared_ptr<QtGraphEdge>> m_edges;
|
||||
std::list<std::shared_ptr<QtGraphEdge>> m_oldEdges;
|
||||
|
||||
std::list<std::shared_ptr<QtGraphNode>> m_nodes;
|
||||
std::list<std::shared_ptr<QtGraphNode>> m_oldNodes;
|
||||
|
||||
QPointF m_sceneRectOffset;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_VIEW_H
|
||||
|
||||
@@ -55,9 +55,13 @@ private:
|
||||
|
||||
|
||||
class QtGraphEdge
|
||||
: public GraphEdge
|
||||
: public QObject
|
||||
, public GraphEdge
|
||||
, public QGraphicsItemGroup
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
||||
|
||||
public:
|
||||
QtGraphEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target, const Edge* data);
|
||||
virtual ~QtGraphEdge();
|
||||
|
||||
@@ -9,10 +9,29 @@
|
||||
|
||||
#include "qt/graphics/QtGraphicsRoundedRectItem.h"
|
||||
#include "qt/utility/QtDeviceScaledPixmap.h"
|
||||
#include "qt/utility/QtGraphPostprocessor.h"
|
||||
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h"
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
|
||||
void QtGraphNode::blendIn()
|
||||
{
|
||||
setOpacity(1.0f);
|
||||
}
|
||||
|
||||
void QtGraphNode::blendOut()
|
||||
{
|
||||
setOpacity(0.0f);
|
||||
}
|
||||
|
||||
void QtGraphNode::showNode()
|
||||
{
|
||||
this->show();
|
||||
}
|
||||
|
||||
void QtGraphNode::hideNode()
|
||||
{
|
||||
this->hide();
|
||||
}
|
||||
|
||||
QFont QtGraphNode::getFontForNodeType(Node::NodeType type)
|
||||
{
|
||||
QFont font("Source Code Pro");
|
||||
@@ -92,6 +111,11 @@ void QtGraphNode::setName(const std::string& name)
|
||||
m_text->setText(QString::fromStdString(name));
|
||||
}
|
||||
|
||||
bool QtGraphNode::isAccessNode() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec2i QtGraphNode::getPosition() const
|
||||
{
|
||||
return Vec2i(this->scenePos().x(), this->scenePos().y());
|
||||
@@ -205,6 +229,16 @@ unsigned int QtGraphNode::getInEdgeCount() const
|
||||
return m_inEdges.size();
|
||||
}
|
||||
|
||||
QSize QtGraphNode::size() const
|
||||
{
|
||||
return QSize(m_size.x, m_size.y);
|
||||
}
|
||||
|
||||
void QtGraphNode::setSize(const QSize& size)
|
||||
{
|
||||
setSize(Vec2i(size.width(), size.height()));
|
||||
}
|
||||
|
||||
bool QtGraphNode::getIsActive() const
|
||||
{
|
||||
return m_isActive;
|
||||
@@ -394,6 +428,16 @@ void QtGraphNode::setStyle()
|
||||
m_text->setPos(padding.x, padding.y);
|
||||
}
|
||||
|
||||
void QtGraphNode::setShadowEnabledRecursive(bool enabled)
|
||||
{
|
||||
m_rect->setShadowEnabled(enabled);
|
||||
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_subNodes)
|
||||
{
|
||||
node->setShadowEnabledRecursive(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNode::onClick()
|
||||
{
|
||||
if (m_data && !m_data->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE))
|
||||
@@ -468,8 +512,6 @@ void QtGraphNode::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||
parent->mouseReleaseEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
QtGraphPostprocessor::allignNodeOnRaster(this);
|
||||
}
|
||||
|
||||
void QtGraphNode::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
|
||||
|
||||
@@ -11,9 +11,22 @@ class QtGraphicsRoundedRectItem;
|
||||
class QtGraphNodeComponent;
|
||||
|
||||
class QtGraphNode
|
||||
: public GraphNode
|
||||
: public QObject
|
||||
, public GraphNode
|
||||
, public QGraphicsRectItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
||||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
||||
Q_PROPERTY(QSize size READ size WRITE setSize)
|
||||
|
||||
public slots:
|
||||
void blendIn();
|
||||
void blendOut();
|
||||
|
||||
void showNode();
|
||||
void hideNode();
|
||||
|
||||
public:
|
||||
static QFont getFontForNodeType(Node::NodeType type);
|
||||
|
||||
@@ -24,6 +37,8 @@ public:
|
||||
virtual std::string getName() const;
|
||||
void setName(const std::string& name);
|
||||
|
||||
virtual bool isAccessNode() const;
|
||||
|
||||
virtual Vec2i getPosition() const;
|
||||
virtual bool setPosition(const Vec2i& position);
|
||||
virtual void moveTo(const Vec2i& position);
|
||||
@@ -40,6 +55,9 @@ public:
|
||||
virtual unsigned int getOutEdgeCount() const;
|
||||
virtual unsigned int getInEdgeCount() const;
|
||||
|
||||
QSize size() const;
|
||||
void setSize(const QSize& size);
|
||||
|
||||
bool getIsActive() const;
|
||||
void setIsActive(bool isActive);
|
||||
|
||||
@@ -52,6 +70,7 @@ public:
|
||||
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
|
||||
|
||||
void setStyle();
|
||||
void setShadowEnabledRecursive(bool enabled);
|
||||
|
||||
virtual void onClick();
|
||||
void hoverEnter();
|
||||
|
||||
@@ -95,6 +95,16 @@ QtGraphNodeAccess::~QtGraphNodeAccess()
|
||||
{
|
||||
}
|
||||
|
||||
bool QtGraphNodeAccess::isAccessNode() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
TokenComponentAccess::AccessType QtGraphNodeAccess::getAccessType() const
|
||||
{
|
||||
return m_access;
|
||||
}
|
||||
|
||||
void QtGraphNodeAccess::setSize(const Vec2i& size)
|
||||
{
|
||||
QtGraphNode::setSize(size);
|
||||
@@ -105,7 +115,6 @@ void QtGraphNodeAccess::setSize(const Vec2i& size)
|
||||
void QtGraphNodeAccess::addSubNode(const std::shared_ptr<QtGraphNode>& node)
|
||||
{
|
||||
QtGraphNode::addSubNode(node);
|
||||
|
||||
m_text->show();
|
||||
}
|
||||
|
||||
@@ -118,3 +127,8 @@ void QtGraphNodeAccess::onClick()
|
||||
MessageGraphNodeExpand(parent->getData()->getId(), m_access).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNodeAccess::hideLabel()
|
||||
{
|
||||
m_text->hide();
|
||||
}
|
||||
|
||||
@@ -20,16 +20,18 @@ public:
|
||||
QGraphicsSimpleTextItem* m_number;
|
||||
};
|
||||
|
||||
|
||||
QtGraphNodeAccess(TokenComponentAccess::AccessType accessType, bool expanded, int invisibleSubNodeCount);
|
||||
virtual ~QtGraphNodeAccess();
|
||||
|
||||
virtual bool isAccessNode() const;
|
||||
TokenComponentAccess::AccessType getAccessType() const;
|
||||
|
||||
virtual void setSize(const Vec2i& size);
|
||||
|
||||
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
|
||||
|
||||
virtual void onClick();
|
||||
|
||||
void hideLabel();
|
||||
|
||||
private:
|
||||
TokenComponentAccess::AccessType m_access;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QGraphicsSceneEvent>
|
||||
|
||||
#include "qt/utility/QtGraphPostprocessor.h"
|
||||
#include "qt/view/graphElements/QtGraphNode.h"
|
||||
|
||||
QtGraphNodeComponentMoveable::QtGraphNodeComponentMoveable(const std::weak_ptr<QtGraphNode>& graphNode)
|
||||
@@ -35,3 +36,17 @@ void QtGraphNodeComponentMoveable::nodeMouseMoveEvent(QGraphicsSceneMouseEvent*
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphNodeComponentMoveable::nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
if (event->isAccepted())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
|
||||
if (node != NULL)
|
||||
{
|
||||
QtGraphPostprocessor::allignNodeOnRaster(node.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
|
||||
virtual void nodeMousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
virtual void nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event);
|
||||
virtual void nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
||||
|
||||
private:
|
||||
Vec2i m_mouseOffset;
|
||||
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
const Node* getData() const;
|
||||
void setData(const Node* data);
|
||||
|
||||
virtual bool isAccessNode() const = 0;
|
||||
|
||||
virtual Vec2i getPosition() const = 0;
|
||||
virtual bool setPosition(const Vec2i& position) = 0;
|
||||
virtual void moveTo(const Vec2i& position) = 0;
|
||||
|
||||
Reference in New Issue
Block a user