examples/qvdesigner0.2/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 
00073 
00074 void Node::setText(const QString &text)
00075 {
00076     prepareGeometryChange();
00077     myText = text;
00078     update();
00079 }
00080 
00081 QString Node::text() const
00082 {
00083     return myText;
00084 }
00085 
00086 void Node::setTextColor(const QColor &color)
00087 {
00088     myTextColor = color;
00089     update();
00090 }
00091 
00092 QColor Node::textColor() const
00093 {
00094     return myTextColor;
00095 }
00096 
00097 void Node::setOutlineColor(const QColor &color)
00098 {
00099     myOutlineColor = color;
00100     update();
00101 }
00102 
00103 QColor Node::outlineColor() const
00104 {
00105     return myOutlineColor;
00106 }
00107 
00108 void Node::setBackgroundColor(const QColor &color)
00109 {
00110     myBackgroundColor = color;
00111     update();
00112 }
00113 
00114 QColor Node::backgroundColor() const
00115 {
00116     return myBackgroundColor;
00117 }
00118 
00119 QRectF Node::boundingRect() const
00120 {
00121     const int Margin = 1;
00122     return outlineRect().adjusted(-Margin, -Margin, +Margin, +Margin);
00123 }
00124 
00125 QPainterPath Node::shape() const
00126 {
00127     QRectF rect = outlineRect();
00128 
00129     QPainterPath path;
00130     path.addRoundRect(rect, roundness(rect.width()),
00131                       roundness(rect.height()));
00132     return path;
00133 }
00134