00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "node.h"
00023 #include <QGraphicsScene>
00024
00025
00026 Node::Node(QGraphicsItem * parent, QGraphicsScene * scene): QGraphicsItem(parent, scene), name(), type() { }
00027
00028 void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
00029 {
00030
00031 QGraphicsItem *ancestor = parentItem();
00032 while (ancestor) {
00033 ancestor->update();
00034 ancestor = ancestor->parentItem();
00035 }
00036
00037 QGraphicsItem::mouseMoveEvent(event);
00038
00039 }
00040
00041 void Node::addInLink(Link *link)
00042 {
00043 myInLinks.append(link);
00044 }
00045
00046 void Node::addOutLink(Link *link)
00047 {
00048 myOutLinks.append(link);
00049 }
00050
00051 void Node::removeLink(Link *link)
00052 {
00053 myInLinks.removeAll(link);
00054 myOutLinks.removeAll(link);
00055 }
00056
00057 QList<Link *> Node::getLinks() const
00058 {
00059 return (myInLinks + myOutLinks);
00060 }
00061
00062 QList<Link *> Node::getInLinks() const
00063 {
00064 return myInLinks;
00065 }
00066
00067 QList<Link *> Node::getOutLinks() const
00068 {
00069 return myOutLinks;
00070 }
00071
00072 int Node::precursors(QList<Node *> tail)
00073 {
00074 if (myInLinks.isEmpty()) {
00075 return 0;
00076 }
00077 else if (tail.contains(this)) {
00078 return 0;
00079 }
00080 else {
00081 int maxPre = 0;
00082 tail.append(this);
00083 foreach(Link *link, myInLinks) {
00084 if ((link) && (link->fromNode())) {
00085 int pre = link->fromNode()->precursors(tail);
00086 if (maxPre < pre) maxPre = pre;
00087 }
00088 }
00089 return maxPre + 1;
00090 }
00091 }
00092
00093
00094
00095 void Node::setText(const QString &text)
00096 {
00097 prepareGeometryChange();
00098 myText = text;
00099 update();
00100 }
00101
00102 QString Node::text() const
00103 {
00104 return myText;
00105 }
00106
00107 void Node::setTextColor(const QColor &color)
00108 {
00109 myTextColor = color;
00110 update();
00111 }
00112
00113 QColor Node::textColor() const
00114 {
00115 return myTextColor;
00116 }
00117
00118 void Node::setOutlineColor(const QColor &color)
00119 {
00120 myOutlineColor = color;
00121 update();
00122 }
00123
00124 QColor Node::outlineColor() const
00125 {
00126 return myOutlineColor;
00127 }
00128
00129 void Node::setBackgroundColor(const QColor &color)
00130 {
00131 myBackgroundColor = color;
00132 update();
00133 }
00134
00135 QColor Node::backgroundColor() const
00136 {
00137 return myBackgroundColor;
00138 }
00139
00140 QRectF Node::boundingRect() const
00141 {
00142 const int Margin = 1;
00143 return outlineRect().adjusted(-Margin, -Margin, +Margin, +Margin);
00144 }
00145
00146 QPainterPath Node::shape() const
00147 {
00148 QRectF rect = outlineRect();
00149
00150 QPainterPath path;
00151 path.addRoundRect(rect, roundness(rect.width()),
00152 roundness(rect.height()));
00153 return path;
00154 }
00155