Commit 688989c2 authored by Oliver Bock's avatar Oliver Bock
Browse files

Improved component item node linking

* Items are now in defined z-order: link (-1) -> component (0) -> node (1)
* Ensures that nodes are on top of things
* Makes sure itemAt() works properly on mouse release
* Code cleanup: removed superfluous events and redundant code


git-svn-id: https://svn.origo.ethz.ch/fidelity@27 53d1999f-d1a8-4366-aa61-588fded17473
parent 7e8db7de
......@@ -25,77 +25,56 @@ const int Fidelity::GUI::ANodeItem::NodeSize = 8;
Fidelity::GUI::ANodeItem::ANodeItem(ANode* node, QGraphicsItem* parent) : QGraphicsEllipseItem(parent)
{
m_Node = node;
// Prepare node properties
setAcceptsHoverEvents(true);
setCursor(Qt::CrossCursor);
setRect(0, 0, NodeSize, NodeSize);
// Make sure node is on top of things
setZValue(1);
// Move the node to it's predefined position and resize it to NodeSize
switch(m_Node->Position()) {
case Left:
setPos(-NodeSize, (parent->boundingRect().height() - NodeSize) / 2);
setRect(0, 0, NodeSize, NodeSize);
break;
case UpperLeft:
setPos(-NodeSize, 0);
setRect(0, 0, NodeSize, NodeSize);
break;
case LowerLeft:
setPos(-NodeSize, parent->boundingRect().height() - NodeSize);
setRect(0, 0, NodeSize, NodeSize);
break;
case Right:
setPos(parent->boundingRect().width(), (parent->boundingRect().height() - NodeSize) / 2);
setRect(0, 0, NodeSize, NodeSize);
break;
case UpperRight:
setPos(parent->boundingRect().width(), 0);
setRect(0, 0, NodeSize, NodeSize);
break;
case LowerRight:
setPos(parent->boundingRect().width(), parent->boundingRect().height() - NodeSize);
setRect(0, 0, NodeSize, NodeSize);
break;
case Top:
setPos((parent->boundingRect().width() - NodeSize) / 2, -NodeSize);
setRect(0, 0, NodeSize, NodeSize);
break;
case TopLeft:
setPos(0, -NodeSize);
setRect(0, 0, NodeSize, NodeSize);
break;
case TopRight:
setPos(parent->boundingRect().width() - NodeSize, -NodeSize);
setRect(0, 0, NodeSize, NodeSize);
break;
case Bottom:
setPos((parent->boundingRect().width() - NodeSize) / 2, parent->boundingRect().height());
setRect(0, 0, NodeSize, NodeSize);
break;
case BottomLeft:
setPos(0, parent->boundingRect().height());
setRect(0, 0, NodeSize, NodeSize);
break;
case BottomRight:
setPos(parent->boundingRect().width() - NodeSize, parent->boundingRect().height());
setRect(0, 0, NodeSize, NodeSize);
break;
}
}
// Event handlers
void Fidelity::GUI::ANodeItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
QGraphicsEllipseItem::hoverEnterEvent(event);
setCursor(Qt::CrossCursor);
}
void Fidelity::GUI::ANodeItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
QGraphicsEllipseItem::hoverLeaveEvent(event);
unsetCursor();
}
// Reimplementations
void Fidelity::GUI::ANodeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
......
......@@ -80,20 +80,6 @@ public:
static const int NodeSize;
protected:
/**
* Reimplementation of QGraphicsEllipseItem::hoverEnterEvent().<br>
* We override this method because we want to change the mouse cursor.
* @param event Please see QGraphicsEllipseItem::hoverEnterEvent() for further details.
*/
void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
/**
* Reimplementation of QGraphicsEllipseItem::hoverLeaveEvent().<br>
* We override this method because we want to change the mouse cursor.
* @param event Please see QGraphicsEllipseItem::hoverLeaveEvent() for further details.
*/
void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
/**
* Reimplementation of QGraphicsEllipseItem::paint().<br>
* We override this method because we use antialiased rendering.
......
......@@ -39,6 +39,9 @@ Fidelity::GUI::ComponentItem::ComponentItem(QPointer<IComponent> component)
setFlag(QGraphicsItem::ItemIsSelectable);
setAcceptsHoverEvents(true);
// Components are drawn on the default z-plane
setZValue(0);
if(component!=NULL) {
m_Component = component;
......
......@@ -43,6 +43,10 @@ void Fidelity::GUI::WorkbenchScene::mousePressEvent(QGraphicsSceneMouseEvent* mo
if(beamNode!=NULL || controlNode!=NULL) {
m_NewLink = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(), mouseEvent->scenePos()));
// Line's drawn in the background
m_NewLink->setZValue(-1);
if(beamNode!=NULL) {
m_NewLink->setPen(QPen(Qt::red, 1, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin));
m_NewLinkNode = beamNode;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment