PARP Research Group University of Murcia, Spain


src/qvgui/qvdesigner/slate/node.cpp

00001 /*
00002  *      Copyright (C) 2008. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
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         // actualiza a toda la gerarquía de grupos que tiene por encima, por si han de ensancharse
00031         QGraphicsItem *ancestor = parentItem();
00032     while (ancestor) {
00033                 ancestor->update();
00034                 ancestor = ancestor->parentItem();
00035         }
00036 
00037     QGraphicsItem::mouseMoveEvent(event);
00038     //if ( parentItem() ) parentItem()->update();
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)) { // si se ha producido un ciclo
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; //actualizo maxPre
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 



QVision framework. PARP research group, copyright 2007, 2008.