ui: extented graph view ui features
* fitting boxes to name length * highlighting active edges and nodes * hover for edges and nodes * single click selection for edges and nodes * edges have transparent second line for easier clicking * sub structure class members by public/protected/private
This commit is contained in:
@@ -1,34 +1,75 @@
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneEvent>
|
||||
#include <QPen>
|
||||
|
||||
#include "component/view/graphElements/GraphNode.h"
|
||||
|
||||
QtGraphEdge::QtGraphEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target, const Id id)
|
||||
: GraphEdge(id)
|
||||
QtGraphEdge::QtGraphEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target, const Edge* data)
|
||||
: GraphEdge(data)
|
||||
, m_owner(owner)
|
||||
, m_target(target)
|
||||
, m_color(0, 0, 0, 0)
|
||||
, m_isActive(false)
|
||||
, m_mousePos(0.0f, 0.0f)
|
||||
, m_mouseMoved(false)
|
||||
{
|
||||
std::shared_ptr<GraphNode> o = owner.lock();
|
||||
std::shared_ptr<GraphNode> t = target.lock();
|
||||
|
||||
Vec2i ownerPos;
|
||||
Vec2i targetPos;
|
||||
|
||||
if (o != NULL && t != NULL)
|
||||
{
|
||||
Vec2i ownerPos = o->getPosition();
|
||||
this->setLine(ownerPos.x, ownerPos.y,t->getPosition().x, t->getPosition().y);
|
||||
ownerPos = o->getPosition();
|
||||
targetPos = t->getPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARNING("Either the owner or the target node is null.");
|
||||
}
|
||||
|
||||
QPen blackPen(Qt::black);
|
||||
blackPen.setWidth(2);
|
||||
this->setLine(ownerPos.x, ownerPos.y, targetPos.x, targetPos.y);
|
||||
|
||||
this->setPen(blackPen);
|
||||
this->setAcceptHoverEvents(true);
|
||||
this->setZValue(1); // Used to draw edges always on top of nodes.
|
||||
|
||||
QPen pen(Qt::transparent);
|
||||
pen.setWidth(10);
|
||||
this->setPen(pen);
|
||||
|
||||
m_child = new QGraphicsLineItem(this);
|
||||
m_child->setLine(ownerPos.x, ownerPos.y, targetPos.x, targetPos.y);
|
||||
|
||||
pen.setColor(Qt::black);
|
||||
pen.setWidth(2);
|
||||
|
||||
switch (data->getType())
|
||||
{
|
||||
case Edge::EDGE_CALL:
|
||||
pen.setColor(QColor(100, 100, 100));
|
||||
break;
|
||||
case Edge::EDGE_USAGE:
|
||||
pen.setColor(QColor(66, 230, 103));
|
||||
break;
|
||||
case Edge::EDGE_TYPE_OF:
|
||||
pen.setColor(QColor(73, 155, 222));
|
||||
break;
|
||||
case Edge::EDGE_RETURN_TYPE_OF:
|
||||
pen.setColor(QColor(231, 65, 65));
|
||||
break;
|
||||
case Edge::EDGE_PARAMETER_TYPE_OF:
|
||||
pen.setColor(QColor(227, 180, 68));
|
||||
break;
|
||||
case Edge::EDGE_INHERITANCE:
|
||||
pen.setColor(QColor(113, 96, 191));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_child->setPen(pen);
|
||||
}
|
||||
|
||||
QtGraphEdge::~QtGraphEdge()
|
||||
@@ -41,8 +82,11 @@ void QtGraphEdge::ownerMoved()
|
||||
|
||||
if (node != NULL)
|
||||
{
|
||||
Vec2i pos = node->getPosition();
|
||||
this->setLine(pos.x, pos.y, this->line().x2(), this->line().y2());
|
||||
Vec2i posA = node->getPosition();
|
||||
Vec2i posB(this->line().x2(), this->line().y2());
|
||||
|
||||
this->setLine(posA.x, posA.y, posB.x, posB.y);
|
||||
m_child->setLine(posA.x, posA.y, posB.x, posB.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -56,7 +100,11 @@ void QtGraphEdge::targetMoved()
|
||||
|
||||
if (node != NULL)
|
||||
{
|
||||
this->setLine(this->line().x1(), this->line().y1(), node->getPosition().x, node->getPosition().y);
|
||||
Vec2i posA(this->line().x1(), this->line().y1());
|
||||
Vec2i posB = node->getPosition();
|
||||
|
||||
this->setLine(posA.x, posA.y, posB.x, posB.y);
|
||||
m_child->setLine(posA.x, posA.y, posB.x, posB.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,22 +136,64 @@ std::weak_ptr<GraphNode> QtGraphEdge::getTarget()
|
||||
return m_target;
|
||||
}
|
||||
|
||||
void QtGraphEdge::setColor(const Vec4i& color)
|
||||
bool QtGraphEdge::getIsActive() const
|
||||
{
|
||||
m_color = color;
|
||||
|
||||
QPen pen(QColor(color.x, color.y, color.z, color.w));
|
||||
pen.setWidth(2);
|
||||
this->setPen(pen);
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
Vec4i QtGraphEdge::getColor() const
|
||||
void QtGraphEdge::setIsActive(bool isActive)
|
||||
{
|
||||
return m_color;
|
||||
m_isActive = isActive;
|
||||
|
||||
QPen p = m_child->pen();
|
||||
if (isActive)
|
||||
{
|
||||
p.setWidth(4);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.setWidth(2);
|
||||
}
|
||||
m_child->setPen(p);
|
||||
}
|
||||
|
||||
void QtGraphEdge::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
|
||||
void QtGraphEdge::onClick()
|
||||
{
|
||||
MessageActivateToken message(m_tokenId);
|
||||
message.dispatch();
|
||||
MessageActivateToken(getTokenId()).dispatch();
|
||||
}
|
||||
|
||||
void QtGraphEdge::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
m_mousePos = Vec2i(event->scenePos().x(), event->scenePos().y());
|
||||
m_mouseMoved = false;
|
||||
}
|
||||
|
||||
void QtGraphEdge::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
Vec2i mousePos = Vec2i(event->scenePos().x(), event->scenePos().y());
|
||||
|
||||
if ((mousePos - m_mousePos).getLength() > 1.0f)
|
||||
{
|
||||
m_mouseMoved = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphEdge::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
if (!m_mouseMoved)
|
||||
{
|
||||
this->onClick();
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphEdge::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
bool isActive = m_isActive;
|
||||
this->setIsActive(true);
|
||||
m_isActive = isActive;
|
||||
}
|
||||
|
||||
void QtGraphEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
this->setIsActive(m_isActive);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user