build: trial version target

builds now app and trail target, lib_gui added, istrail function
This commit is contained in:
Andreas Stallinger
2015-12-08 17:55:12 +01:00
parent ed4b6546f0
commit 43409cd6b7
154 changed files with 444 additions and 213 deletions
@@ -0,0 +1,230 @@
#include "qt/view/graphElements/QtGraphEdge.h"
#include <QGraphicsSceneEvent>
#include "utility/messaging/type/MessageActivateEdge.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeBundleSplit.h"
#include "component/view/GraphViewStyle.h"
#include "data/graph/Edge.h"
#include "data/graph/token_component/TokenComponentAggregation.h"
#include "qt/graphics/QtAngledLineItem.h"
#include "qt/graphics/QtStraightLineItem.h"
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphEdge::QtGraphEdge(
const std::weak_ptr<QtGraphNode>& owner, const std::weak_ptr<QtGraphNode>& target, const Edge* data, size_t weight
)
: m_data(data)
, m_owner(owner)
, m_target(target)
, m_child(nullptr)
, m_isActive(false)
, m_fromActive(false)
, m_toActive(false)
, m_weight(weight)
, m_direction(TokenComponentAggregation::DIRECTION_NONE)
, m_mousePos(0.0f, 0.0f)
, m_mouseMoved(false)
{
m_fromActive = m_owner.lock()->getIsActive();
m_toActive = m_target.lock()->getIsActive();
this->updateLine();
}
QtGraphEdge::~QtGraphEdge()
{
}
const Edge* QtGraphEdge::getData() const
{
return m_data;
}
std::weak_ptr<QtGraphNode> QtGraphEdge::getOwner()
{
return m_owner;
}
std::weak_ptr<QtGraphNode> QtGraphEdge::getTarget()
{
return m_target;
}
void QtGraphEdge::updateLine()
{
std::shared_ptr<QtGraphNode> owner = m_owner.lock();
std::shared_ptr<QtGraphNode> target = m_target.lock();
if (owner == NULL || target == NULL)
{
LOG_WARNING("Either the owner or the target node is null.");
return;
}
Edge::EdgeType type;
if (getData())
{
type = getData()->getType();
}
else
{
type = Edge::EDGE_AGGREGATION;
}
GraphViewStyle::EdgeStyle style = GraphViewStyle::getStyleForEdgeType(type, m_isActive, false);
if (style.isStraight)
{
if (!m_child)
{
m_child = new QtStraightLineItem(this);
}
bool showArrow = m_direction != TokenComponentAggregation::DIRECTION_NONE;
if (m_direction == TokenComponentAggregation::DIRECTION_BACKWARD)
{
owner.swap(target);
}
GraphViewStyle::NodeStyle countStyle = GraphViewStyle::getStyleOfCountCircle();
dynamic_cast<QtStraightLineItem*>(m_child)->updateLine(
owner->getBoundingRect(), target->getBoundingRect(), m_weight, style, countStyle, showArrow);
}
else
{
if (!m_child)
{
m_child = new QtAngledLineItem(this);
}
dynamic_cast<QtAngledLineItem*>(m_child)->updateLine(
owner->getBoundingRect(), target->getBoundingRect(),
owner->getParentBoundingRect(), target->getParentBoundingRect(),
style);
if (m_fromActive && owner->getLastParent() == target->getLastParent())
{
dynamic_cast<QtAngledLineItem*>(m_child)->setOnBack(true);
}
if (m_toActive)
{
dynamic_cast<QtAngledLineItem*>(m_child)->setHorizontalIn(true);
}
}
if (m_data)
{
m_child->setToolTip(QString::fromStdString(m_data->getTypeString()));
}
else
{
m_child->setToolTip(QString::fromStdString(Edge::getTypeString(Edge::EDGE_AGGREGATION)));
}
this->setZValue(style.zValue); // Used to draw edges always on top of nodes.
}
bool QtGraphEdge::getIsActive() const
{
return m_isActive;
}
void QtGraphEdge::setIsActive(bool isActive)
{
if (m_isActive != isActive)
{
m_isActive = isActive;
updateLine();
}
}
void QtGraphEdge::onClick()
{
if (!getData())
{
MessageGraphNodeBundleSplit(m_target.lock()->getTokenId()).dispatch();
}
else
{
MessageActivateEdge(
getData()->getId(),
getData()->getType(),
getData()->getFrom()->getNameHierarchy(),
getData()->getTo()->getNameHierarchy()
).dispatch();
}
}
void QtGraphEdge::focusIn()
{
bool isActive = m_isActive;
this->setIsActive(true);
m_isActive = isActive;
}
void QtGraphEdge::focusOut()
{
updateLine();
}
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)
{
if (!getData())
{
focusIn();
return;
}
MessageFocusIn(std::vector<Id>(1, getData()->getId())).dispatch();
}
void QtGraphEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
if (!getData())
{
focusOut();
return;
}
MessageFocusOut(std::vector<Id>(1, getData()->getId())).dispatch();
}
void QtGraphEdge::setDirection(TokenComponentAggregation::Direction direction)
{
if (m_direction != direction)
{
m_direction = direction;
updateLine();
}
}
@@ -0,0 +1,71 @@
#ifndef QT_GRAPH_EDGE_H
#define QT_GRAPH_EDGE_H
#include <memory>
#include <QGraphicsItem>
#include "utility/math/Vector2.h"
#include "data/graph/token_component/TokenComponentAggregation.h"
class Edge;
class QtGraphNode;
class QtGraphEdge
: public QObject
, public QGraphicsItemGroup
{
Q_OBJECT
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
public:
QtGraphEdge(const std::weak_ptr<QtGraphNode>& owner, const std::weak_ptr<QtGraphNode>& target, const Edge* data, size_t weight);
virtual ~QtGraphEdge();
const Edge* getData() const;
std::weak_ptr<QtGraphNode> getOwner();
std::weak_ptr<QtGraphNode> getTarget();
void updateLine();
bool getIsActive() const;
void setIsActive(bool isActive);
void setFromAndToActive(bool fromActive, bool toActive);
void onClick();
void focusIn();
void focusOut();
void setDirection(TokenComponentAggregation::Direction direction);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
private:
const Edge* m_data;
std::weak_ptr<QtGraphNode> m_owner;
std::weak_ptr<QtGraphNode> m_target;
QGraphicsLineItem* m_child;
bool m_isActive;
bool m_fromActive;
bool m_toActive;
size_t m_weight;
TokenComponentAggregation::Direction m_direction;
Vec2i m_mousePos;
bool m_mouseMoved;
};
#endif // QT_GRAPH_EDGE_H
@@ -0,0 +1,401 @@
#include "qt/view/graphElements/QtGraphNode.h"
#include <QBrush>
#include <QFont>
#include <QGraphicsSceneEvent>
#include <QPen>
#include "component/controller/helper/GraphPostprocessor.h"
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/utilityQt.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(GraphViewStyle::getFontNameForNodeType(type).c_str());
font.setPixelSize(GraphViewStyle::getFontSizeForNodeType(type));
return font;
}
QtGraphNode::QtGraphNode()
: m_undefinedRect(nullptr)
, m_icon(nullptr)
, m_isActive(false)
, m_isHovering(false)
{
this->setPen(QPen(Qt::transparent));
m_rect = new QtRoundedRectItem(this);
m_text = new QGraphicsSimpleTextItem(this);
}
QtGraphNode::~QtGraphNode()
{
}
QtGraphNode* QtGraphNode::getParent() const
{
return m_parentNode.lock().get();
}
QtGraphNode* QtGraphNode::getLastParent() const
{
QtGraphNode* node = const_cast<QtGraphNode*>(this);
while (true)
{
QtGraphNode* parent = dynamic_cast<QtGraphNode*>(node->parentItem());
if (!parent)
{
break;
}
node = parent;
}
return node;
}
void QtGraphNode::setParent(std::weak_ptr<QtGraphNode> parentNode)
{
m_parentNode = parentNode;
std::shared_ptr<QtGraphNode> parent = parentNode.lock();
if (parent != NULL)
{
QGraphicsRectItem::setParentItem(parent.get());
}
}
std::list<std::shared_ptr<QtGraphNode>> QtGraphNode::getSubNodes() const
{
return m_subNodes;
}
Vec2i QtGraphNode::getPosition() const
{
return Vec2i(this->scenePos().x(), this->scenePos().y());
}
bool QtGraphNode::setPosition(const Vec2i& position)
{
Vec2i currentPosition = getPosition();
Vec2i offset = position - currentPosition;
if (offset.getLength() > 0.0f)
{
this->moveBy(offset.x, offset.y);
notifyEdgesAfterMove();
return true;
}
return false;
}
Vec2i QtGraphNode::getSize() const
{
return m_size;
}
void QtGraphNode::setSize(const Vec2i& size)
{
m_size = size;
this->setRect(0, 0, size.x, size.y);
m_rect->setRect(0, 0, size.x, size.y);
if (m_undefinedRect)
{
m_undefinedRect->setRect(1, 1, size.x - 2, size.y - 2);
}
}
QSize QtGraphNode::size() const
{
return QSize(m_size.x, m_size.y);
}
void QtGraphNode::setSize(const QSize& size)
{
setSize(Vec2i(size.width(), size.height()));
}
Vec4i QtGraphNode::getBoundingRect() const
{
Vec2i pos = getPosition();
Vec2i size = getSize();
return Vec4i(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
}
Vec4i QtGraphNode::getParentBoundingRect() const
{
return getLastParent()->getBoundingRect();
}
void QtGraphNode::addOutEdge(const std::shared_ptr<QtGraphEdge>& edge)
{
m_outEdges.push_back(edge);
}
void QtGraphNode::addInEdge(const std::weak_ptr<QtGraphEdge>& edge)
{
m_inEdges.push_back(edge);
}
size_t QtGraphNode::getOutEdgeCount() const
{
return m_outEdges.size();
}
size_t QtGraphNode::getInEdgeCount() const
{
return m_inEdges.size();
}
bool QtGraphNode::getIsActive() const
{
return m_isActive;
}
void QtGraphNode::setIsActive(bool isActive)
{
m_isActive = isActive;
updateStyle();
}
std::string QtGraphNode::getName() const
{
return m_text->text().toStdString();
}
void QtGraphNode::setName(const std::string& name)
{
m_text->setText(QString::fromStdString(name));
}
void QtGraphNode::addComponent(const std::shared_ptr<QtGraphNodeComponent>& component)
{
m_components.push_back(component);
}
void QtGraphNode::hoverEnter()
{
hoverEnterEvent(nullptr);
QtGraphNode* parent = getParent();
if (parent)
{
parent->hoverEnter();
}
}
void QtGraphNode::focusIn()
{
m_isHovering = true;
updateStyle();
}
void QtGraphNode::focusOut()
{
m_isHovering = false;
updateStyle();
}
bool QtGraphNode::isDataNode() const
{
return false;
}
bool QtGraphNode::isAccessNode() const
{
return false;
}
bool QtGraphNode::isExpandToggleNode() const
{
return false;
}
bool QtGraphNode::isBundleNode() const
{
return false;
}
Id QtGraphNode::getTokenId() const
{
return 0;
}
void QtGraphNode::addSubNode(const std::shared_ptr<QtGraphNode>& node)
{
m_subNodes.push_back(node);
}
void QtGraphNode::moved(const Vec2i& oldPosition)
{
setPosition(GraphPostprocessor::alignOnRaster(getPosition()));
}
void QtGraphNode::onClick()
{
}
void QtGraphNode::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
event->ignore();
for (std::shared_ptr<QtGraphNodeComponent> component : m_components)
{
component->nodeMousePressEvent(event);
}
if (!event->isAccepted())
{
QtGraphNode* parent = getParent();
if (parent)
{
parent->mousePressEvent(event);
}
}
}
void QtGraphNode::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
event->ignore();
for (std::shared_ptr<QtGraphNodeComponent> component : m_components)
{
component->nodeMouseMoveEvent(event);
}
if (!event->isAccepted())
{
QtGraphNode* parent = getParent();
if (parent)
{
parent->mouseMoveEvent(event);
}
}
}
void QtGraphNode::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
event->ignore();
for (std::shared_ptr<QtGraphNodeComponent> component : m_components)
{
component->nodeMouseReleaseEvent(event);
}
if (!event->isAccepted())
{
QtGraphNode* parent = getParent();
if (parent)
{
parent->mouseReleaseEvent(event);
}
}
}
void QtGraphNode::notifyEdgesAfterMove()
{
for (const std::shared_ptr<QtGraphEdge>& edge : m_outEdges)
{
edge->updateLine();
}
for (const std::weak_ptr<QtGraphEdge>& e : m_inEdges)
{
std::shared_ptr<QtGraphEdge> edge = e.lock();
if (edge)
{
edge->updateLine();
}
}
for (const std::shared_ptr<QtGraphNode>& node : m_subNodes)
{
node->notifyEdgesAfterMove();
}
}
void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style)
{
QPen pen(Qt::transparent);
if (style.borderWidth > 0)
{
pen.setColor(style.color.border.c_str());
pen.setWidthF(style.borderWidth);
if (style.borderDashed)
{
pen.setStyle(Qt::DashLine);
}
}
m_rect->setPen(pen);
m_rect->setBrush(QBrush(style.color.fill.c_str()));
qreal radius = style.cornerRadius;
m_rect->setRadius(radius);
if (style.hasHatching)
{
QtDeviceScaledPixmap pattern("data/gui/graph_view/images/pattern.png");
pattern.scaleToHeight(10);
QPixmap pixmap = utility::colorizePixmap(pattern.pixmap(), style.color.hatching.c_str());
if (!m_undefinedRect)
{
m_undefinedRect = new QtRoundedRectItem(this);
setSize(getSize());
}
pen.setWidth(0);
pen.setColor(Qt::transparent);
m_undefinedRect->setPen(pen);
m_undefinedRect->setBrush(pixmap);
m_undefinedRect->setRadius(radius);
}
if (style.iconPath.size())
{
QtDeviceScaledPixmap pixmap(QString::fromStdString(style.iconPath));
pixmap.scaleToHeight(style.iconSize);
m_icon = new QGraphicsPixmapItem(utility::colorizePixmap(pixmap.pixmap(), style.color.icon.c_str()), this);
m_icon->setPos(style.iconOffset.x, style.iconOffset.y);
}
QFont font(style.fontName.c_str());
font.setPixelSize(style.fontSize);
if (style.fontBold)
{
font.setWeight(QFont::Bold);
}
m_text->setFont(font);
m_text->setBrush(QBrush(style.color.text.c_str()));
m_text->setPos(style.iconOffset.x + style.iconSize + style.textOffset.x, style.textOffset.y);
}
@@ -0,0 +1,117 @@
#ifndef QT_GRAPH_NODE_H
#define QT_GRAPH_NODE_H
#include <QGraphicsItem>
#include "utility/math/Vector4.h"
#include "component/view/GraphViewStyle.h"
class QFont;
class QtGraphEdge;
class QtRoundedRectItem;
class QtGraphNodeComponent;
class QtGraphNode
: public QObject
, 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);
QtGraphNode();
virtual ~QtGraphNode();
QtGraphNode* getParent() const;
QtGraphNode* getLastParent() const;
void setParent(std::weak_ptr<QtGraphNode> parentNode);
std::list<std::shared_ptr<QtGraphNode>> getSubNodes() const;
Vec2i getPosition() const;
bool setPosition(const Vec2i& position);
Vec2i getSize() const;
void setSize(const Vec2i& size);
QSize size() const;
void setSize(const QSize& size);
Vec4i getBoundingRect() const;
Vec4i getParentBoundingRect() const;
void addOutEdge(const std::shared_ptr<QtGraphEdge>& edge);
void addInEdge(const std::weak_ptr<QtGraphEdge>& edge);
size_t getOutEdgeCount() const;
size_t getInEdgeCount() const;
bool getIsActive() const;
void setIsActive(bool isActive);
std::string getName() const;
void setName(const std::string& name);
void addComponent(const std::shared_ptr<QtGraphNodeComponent>& component);
void hoverEnter();
void focusIn();
void focusOut();
virtual bool isDataNode() const;
virtual bool isAccessNode() const;
virtual bool isExpandToggleNode() const;
virtual bool isBundleNode() const;
virtual Id getTokenId() const;
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
virtual void onClick();
virtual void moved(const Vec2i& oldPosition);
virtual void updateStyle() = 0;
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
void notifyEdgesAfterMove();
void setStyle(const GraphViewStyle::NodeStyle& style);
std::list<std::shared_ptr<QtGraphEdge>> m_outEdges;
std::list<std::weak_ptr<QtGraphEdge>> m_inEdges;
std::weak_ptr<QtGraphNode> m_parentNode;
std::list<std::shared_ptr<QtGraphNode>> m_subNodes;
QGraphicsSimpleTextItem* m_text;
QtRoundedRectItem* m_rect;
QtRoundedRectItem* m_undefinedRect;
QGraphicsPixmapItem* m_icon;
Vec2i m_size;
bool m_isActive;
bool m_isHovering;
private:
std::list<std::shared_ptr<QtGraphNodeComponent>> m_components;
};
#endif // QT_GRAPH_NODE_H
@@ -0,0 +1,65 @@
#include "qt/view/graphElements/QtGraphNodeAccess.h"
#include <QBrush>
#include <QFontMetrics>
#include <QPen>
#include "component/view/GraphViewStyle.h"
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/utilityQt.h"
QtGraphNodeAccess::QtGraphNodeAccess(TokenComponentAccess::AccessType accessType)
: QtGraphNode()
, m_access(accessType)
, m_accessIconSize(20)
{
std::string accessString = TokenComponentAccess::getAccessString(accessType);
this->setName(accessString);
m_text->hide();
QtDeviceScaledPixmap pixmap(QString::fromStdString("data/gui/graph_view/images/" + accessString + ".png"));
pixmap.scaleToHeight(m_accessIconSize);
m_accessIcon = new QGraphicsPixmapItem(pixmap.pixmap(), this);
}
QtGraphNodeAccess::~QtGraphNodeAccess()
{
}
TokenComponentAccess::AccessType QtGraphNodeAccess::getAccessType() const
{
return m_access;
}
bool QtGraphNodeAccess::isAccessNode() const
{
return true;
}
void QtGraphNodeAccess::addSubNode(const std::shared_ptr<QtGraphNode>& node)
{
QtGraphNode::addSubNode(node);
m_text->show();
}
void QtGraphNodeAccess::updateStyle()
{
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfAccessNode();
setStyle(style);
QFont font = m_text->font();
font.setCapitalization(QFont::AllUppercase);
m_text->setFont(font);
m_text->setPos(style.textOffset.x + m_accessIconSize + 3, style.textOffset.x + m_accessIconSize + 2 - style.fontSize);
m_accessIcon->setPos(style.textOffset.x, style.textOffset.y);
m_accessIcon->setPixmap(utility::colorizePixmap(m_accessIcon->pixmap(), style.color.icon.c_str()));
}
void QtGraphNodeAccess::hideLabel()
{
m_text->hide();
}
@@ -0,0 +1,31 @@
#ifndef QT_GRAPH_NODE_ACCESS_H
#define QT_GRAPH_NODE_ACCESS_H
#include "data/graph/token_component/TokenComponentAccess.h"
#include "qt/view/graphElements/QtGraphNode.h"
class QtGraphNodeAccess
: public QtGraphNode
{
public:
QtGraphNodeAccess(TokenComponentAccess::AccessType accessType);
virtual ~QtGraphNodeAccess();
TokenComponentAccess::AccessType getAccessType() const;
// QtGraphNode implementation
virtual bool isAccessNode() const;
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
virtual void updateStyle();
void hideLabel();
private:
TokenComponentAccess::AccessType m_access;
QGraphicsPixmapItem* m_accessIcon;
int m_accessIconSize;
};
#endif // QT_GRAPH_NODE_ACCESS_H
@@ -0,0 +1,69 @@
#include "qt/view/graphElements/QtGraphNodeBundle.h"
#include <QBrush>
#include <QPen>
#include "utility/messaging/type/MessageGraphNodeBundleSplit.h"
#include "component/view/GraphViewStyle.h"
#include "qt/graphics/QtCountCircleItem.h"
QtGraphNodeBundle::QtGraphNodeBundle(Id tokenId, size_t nodeCount, std::string name)
: QtGraphNode()
, m_tokenId(tokenId)
{
this->setName(name);
m_circle = new QtCountCircleItem(this);
m_circle->setNumber(nodeCount);
this->setAcceptHoverEvents(true);
this->setToolTip("bundle");
}
QtGraphNodeBundle::~QtGraphNodeBundle()
{
}
bool QtGraphNodeBundle::isBundleNode() const
{
return true;
}
Id QtGraphNodeBundle::getTokenId() const
{
return m_tokenId;
}
void QtGraphNodeBundle::onClick()
{
MessageGraphNodeBundleSplit(m_tokenId).dispatch();
}
void QtGraphNodeBundle::updateStyle()
{
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfBundleNode(m_isHovering);
setStyle(style);
m_circle->setPosition(Vec2f(m_rect->rect().right() - 3, m_rect->rect().top() + 3));
GraphViewStyle::NodeStyle accessStyle = GraphViewStyle::getStyleOfCountCircle();
m_circle->setStyle(
accessStyle.color.fill.c_str(),
accessStyle.color.text.c_str(),
accessStyle.color.border.c_str(),
style.borderWidth
);
}
void QtGraphNodeBundle::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
focusIn();
}
void QtGraphNodeBundle::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
focusOut();
}
@@ -0,0 +1,32 @@
#ifndef QT_GRAPH_NODE_BUNDLE_H
#define QT_GRAPH_NODE_BUNDLE_H
#include "qt/view/graphElements/QtGraphNode.h"
class QtCountCircleItem;
class QtGraphNodeBundle
: public QtGraphNode
{
public:
QtGraphNodeBundle(Id tokenId, size_t nodeCount, std::string name);
virtual ~QtGraphNodeBundle();
// QtGraphNode implementation
virtual bool isBundleNode() const;
virtual Id getTokenId() const;
virtual void onClick();
virtual void updateStyle();
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
private:
QtCountCircleItem* m_circle;
Id m_tokenId;
};
#endif // QT_GRAPH_NODE_BUNDLE_H
@@ -0,0 +1,91 @@
#include "qt/view/graphElements/QtGraphNodeData.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
#include "data/graph/token_component/TokenComponentSignature.h"
QtGraphNodeData::QtGraphNodeData(const Node* data, bool hasParent, bool childVisible)
: m_data(data)
, m_childVisible(childVisible)
{
this->setAcceptHoverEvents(true);
if (!hasParent)
{
this->setName(data->getFullName());
}
else
{
this->setName(data->getName());
}
std::string toolTip = data->getTypeString();
if (!data->isDefined() && !data->isType(Node::NODE_UNDEFINED))
{
toolTip = "undefined " + toolTip;
}
if (data->isType(Node::NODE_FUNCTION | Node::NODE_METHOD))
{
TokenComponentSignature* sig = data->getComponent<TokenComponentSignature>();
if (sig)
{
toolTip += ": " + sig->getSignature();
}
}
this->setToolTip(QString::fromStdString(toolTip));
}
QtGraphNodeData::~QtGraphNodeData()
{
}
const Node* QtGraphNodeData::getData() const
{
return m_data;
}
bool QtGraphNodeData::isDataNode() const
{
return true;
}
Id QtGraphNodeData::getTokenId() const
{
return m_data->getId();
}
void QtGraphNodeData::onClick()
{
MessageActivateNodes message;
message.addNode(m_data->getId(), m_data->getType(), m_data->getNameHierarchy());
message.dispatch();
}
void QtGraphNodeData::moved(const Vec2i& oldPosition)
{
QtGraphNode::moved(oldPosition);
MessageGraphNodeMove(m_data->getId(), getPosition() - oldPosition).dispatch();
}
void QtGraphNodeData::updateStyle()
{
GraphViewStyle::NodeStyle style =
GraphViewStyle::getStyleForNodeType(m_data->getType(), m_data->isDefined(), m_isActive, m_isHovering, m_childVisible);
setStyle(style);
}
void QtGraphNodeData::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
MessageFocusIn(std::vector<Id>(1, m_data->getId())).dispatch();
}
void QtGraphNodeData::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
MessageFocusOut(std::vector<Id>(1, m_data->getId())).dispatch();
}
@@ -0,0 +1,33 @@
#ifndef QT_GRAPH_NODE_DATA_H
#define QT_GRAPH_NODE_DATA_H
#include "qt/view/graphElements/QtGraphNode.h"
class QtGraphNodeData
: public QtGraphNode
{
public:
QtGraphNodeData(const Node* data, bool hasParent, bool childVisible);
virtual ~QtGraphNodeData();
const Node* getData() const;
// QtGraphNode implementation
virtual bool isDataNode() const;
virtual Id getTokenId() const;
virtual void onClick();
virtual void moved(const Vec2i& oldPosition);
virtual void updateStyle();
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
private:
const Node* m_data;
bool m_childVisible;
};
#endif // QT_GRAPH_NODE_DATA_H
@@ -0,0 +1,77 @@
#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
#include <QFontMetrics>
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageGraphNodeExpand.h"
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/utilityQt.h"
#include "qt/view/graphElements/QtGraphNodeData.h"
QtGraphNodeExpandToggle::QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount)
: m_invisibleSubNodeCount(invisibleSubNodeCount)
, m_expanded(expanded)
{
if (!expanded && !invisibleSubNodeCount)
{
LOG_ERROR("ExpandToggle shouldn't be visible");
return;
}
const int iconHeight = 4;
m_icon = new QGraphicsPixmapItem(this);
QtDeviceScaledPixmap pixmap("data/gui/graph_view/images/arrow.png");
pixmap.scaleToHeight(iconHeight);
if (invisibleSubNodeCount)
{
QString numberStr = QString::number(invisibleSubNodeCount);
m_text->setText(numberStr);
}
else
{
pixmap.mirror();
}
m_icon->setPixmap(pixmap.pixmap());
}
QtGraphNodeExpandToggle::~QtGraphNodeExpandToggle()
{
}
bool QtGraphNodeExpandToggle::isExpandToggleNode() const
{
return true;
}
void QtGraphNodeExpandToggle::onClick()
{
QtGraphNode* parent = getParent();
if (parent && parent->getTokenId())
{
MessageGraphNodeExpand(parent->getTokenId(), !m_expanded).dispatch();
}
}
void QtGraphNodeExpandToggle::updateStyle()
{
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleOfExpandToggleNode();
setStyle(style);
m_text->setPos(
(m_rect->rect().width() - QFontMetrics(m_text->font()).width(m_text->text())) / 2,
6
);
m_icon->setPos(
(m_rect->rect().width() - m_icon->pixmap().width() / QtDeviceScaledPixmap::devicePixelRatio()) / 2,
(m_invisibleSubNodeCount == 0 ? m_rect->rect().height() / 2 - 2 : m_rect->rect().height() - 7)
);
m_icon->setPixmap(utility::colorizePixmap(m_icon->pixmap(), style.color.icon.c_str()));
}
@@ -0,0 +1,27 @@
#ifndef QT_EXPAND_TOGGLE_H
#define QT_EXPAND_TOGGLE_H
#include <QGraphicsItem>
#include "qt/view/graphElements/QtGraphNode.h"
class QtGraphNodeExpandToggle
: public QtGraphNode
{
public:
QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount);
virtual ~QtGraphNodeExpandToggle();
// QtGraphNode implementation
virtual bool isExpandToggleNode() const;
virtual void onClick();
virtual void updateStyle();
private:
QGraphicsPixmapItem* m_icon;
bool m_invisibleSubNodeCount;
bool m_expanded;
};
#endif // QT_EXPAND_TOGGLE_H
@@ -0,0 +1,22 @@
#include "QtGraphNodeComponent.h"
QtGraphNodeComponent::QtGraphNodeComponent(const std::weak_ptr<QtGraphNode>& graphNode)
: m_graphNode(graphNode)
{
}
QtGraphNodeComponent::~QtGraphNodeComponent()
{
}
void QtGraphNodeComponent::nodeMousePressEvent(QGraphicsSceneMouseEvent* event)
{
}
void QtGraphNodeComponent::nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
}
void QtGraphNodeComponent::nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
}
@@ -0,0 +1,24 @@
#ifndef QT_GRAPH_NODE_COMPONENT_H
#define QT_GRAPH_NODE_COMPONENT_H
#include <memory>
#include <QGraphicsItem>
class QtGraphNode;
class QtGraphNodeComponent
{
public:
QtGraphNodeComponent(const std::weak_ptr<QtGraphNode>& graphNode);
virtual ~QtGraphNodeComponent();
virtual void nodeMousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
protected:
std::weak_ptr<QtGraphNode> m_graphNode;
};
#endif // QT_GRAPH_NODE_COMPONENT_H
@@ -0,0 +1,45 @@
#include "QtGraphNodeComponentClickable.h"
#include <QGraphicsSceneEvent>
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphNodeComponentClickable::QtGraphNodeComponentClickable(const std::weak_ptr<QtGraphNode>& graphNode)
: QtGraphNodeComponent(graphNode)
, m_mousePos(0.0f, 0.0f)
, m_mouseMoved(false)
{
}
QtGraphNodeComponentClickable::~QtGraphNodeComponentClickable()
{
}
void QtGraphNodeComponentClickable::nodeMousePressEvent(QGraphicsSceneMouseEvent* event)
{
m_mousePos = Vec2i(event->scenePos().x(), event->scenePos().y());
m_mouseMoved = false;
}
void QtGraphNodeComponentClickable::nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
Vec2i mousePos = Vec2i(event->scenePos().x(), event->scenePos().y());
if ((mousePos - m_mousePos).getLength() > 1.0f)
{
m_mouseMoved = true;
}
}
void QtGraphNodeComponentClickable::nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
if (!m_mouseMoved)
{
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
node->onClick();
event->accept();
}
}
}
@@ -0,0 +1,24 @@
#ifndef QT_GRAPH_NODE_COMPONENT_CLICKABLE
#define QT_GRAPH_NODE_COMPONENT_CLICKABLE
#include "QtGraphNodeComponent.h"
#include "utility/math/Vector2.h"
class QtGraphNodeComponentClickable
: public QtGraphNodeComponent
{
public:
QtGraphNodeComponentClickable(const std::weak_ptr<QtGraphNode>& graphNode);
virtual ~QtGraphNodeComponentClickable();
virtual void nodeMousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
private:
Vec2i m_mousePos;
bool m_mouseMoved;
};
#endif // QT_GRAPH_NODE_COMPONENT_CLICKABLE
@@ -0,0 +1,52 @@
#include "QtGraphNodeComponentMoveable.h"
#include <QGraphicsSceneEvent>
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphNodeComponentMoveable::QtGraphNodeComponentMoveable(const std::weak_ptr<QtGraphNode>& graphNode)
: QtGraphNodeComponent(graphNode)
, m_mouseOffset(0.0f, 0.0f)
{
}
QtGraphNodeComponentMoveable::~QtGraphNodeComponentMoveable()
{
}
void QtGraphNodeComponentMoveable::nodeMousePressEvent(QGraphicsSceneMouseEvent* event)
{
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
m_oldPos = node->getPosition();
m_mouseOffset.x = event->scenePos().x() - m_oldPos.x;
m_mouseOffset.y = event->scenePos().y() - m_oldPos.y;
event->accept();
}
}
void QtGraphNodeComponentMoveable::nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
node->setPosition(Vec2i(event->scenePos().x() - m_mouseOffset.x, event->scenePos().y() - m_mouseOffset.y));
event->accept();
}
}
void QtGraphNodeComponentMoveable::nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event)
{
if (event->isAccepted())
{
return;
}
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
node->moved(m_oldPos);
}
}
@@ -0,0 +1,24 @@
#ifndef QT_GRAPH_NODE_COMPONENT_MOVEABLE
#define QT_GRAPH_NODE_COMPONENT_MOVEABLE
#include "QtGraphNodeComponent.h"
#include "utility/math/Vector2.h"
class QtGraphNodeComponentMoveable
: public QtGraphNodeComponent
{
public:
QtGraphNodeComponentMoveable(const std::weak_ptr<QtGraphNode>& graphNode);
virtual ~QtGraphNodeComponentMoveable();
virtual void nodeMousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void nodeMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
private:
Vec2i m_mouseOffset;
Vec2i m_oldPos;
};
#endif // QT_GRAPH_NODE_COMPONENT_MOVEABLE