PARP Research Group University of Murcia, Spain


src/qvgui/qvdesigner/slate/grouplink.cpp

00001 /*
00002  *      Copyright (C) 2008, 2009. 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 <QtGui>
00023 
00024 #include "grouplink.h"
00025 #include "node.h"
00026 
00027 GroupLink::GroupLink(Node *fromNode, QString fromProp, Node *toNode, QString toProp, bool _input, QGraphicsItem * parent, QGraphicsScene * scene): Link(fromNode, fromProp, toNode, toProp, parent, scene), input(_input)
00028 {
00029         setColor(QColor(255, 127, 0));
00030         QPen dotPen = pen();
00031         dotPen.setStyle(Qt::DashDotLine);
00032         setPen(dotPen);
00033 }
00034 
00035 void GroupLink::trackNodes()
00036 {
00037         // actualiza el zValue al máximo de los dos, o al del mayor grupo al que pertenecen
00038         // reducimos el tamaño del Pen del link en función del número de antecesores (*0.5 por cada uno)
00039         //(solo se mira para uno pq no se permiten enlaces entre grupos)
00040         double zvalue = (myFromNode->zValue() > myToNode->zValue()) ? myFromNode->zValue() + 1 : myToNode->zValue() + 1;
00041 
00042         // obtenemos el pen
00043         QGraphicsItem *ancestor = myFromNode->parentItem();
00044         QPen myPen = pen();
00045     while (ancestor) {
00046                 setZValue(ancestor->zValue() + 1);
00047                 myPen.setWidthF(myPen.width() * 0.4);
00048                 ancestor = ancestor->parentItem();
00049         }
00050 
00051         // obtenemos las posiciones origen y destino
00052         QPointF orig = myFromNode->scenePointPos(myFromProp, input); // dependiend de si es input o no tiene que tomar los puntos de origen o de destino
00053         QPointF dest = myToNode->scenePointPos(myToProp, input); // dependiend de si es input o no tiene que tomar los puntos de origen o de destino
00054 
00055         if (orig.x() <= dest.x()) {
00056                 setZValue(zvalue);
00057                 setPen(myPen);
00058                 setLine(QLineF(orig, dest));
00059                 line2.hide();
00060                 line3.hide();
00061                 line4.hide();
00062                 line5.hide();
00063         }
00064         else {
00065                 // obtenemos el desplazamiento lateral para esta propiedad dentro de sus nodos (para que no se solapen verticalmente)
00066                 double origDesp = 10.0 * (fromNode()->numProps() - fromNode()->propPoint(fromProp(), true) + 1);
00067                 double destDesp = 10.0 * (toNode()->numProps() - toNode()->propPoint(toProp(), true) + 1);
00068 
00069                 // obtenemos la coordenada Y de las partes inferior
00070                 double origBottom = /*fromNode()->scenePos().y() +*/ fromNode()->sceneBoundingRect().bottom() + origDesp;
00071                 double destBottom = /*toNode()->scenePos().y() +*/ toNode()->sceneBoundingRect().bottom() + destDesp;
00072                 double bottom = origBottom > destBottom ? origBottom : destBottom;
00073 
00074                 setZValue(zvalue);
00075                 line2.setZValue(zvalue);
00076                 line3.setZValue(zvalue);
00077                 line4.setZValue(zvalue);
00078                 line5.setZValue(zvalue);
00079                 setPen(myPen);
00080                 line2.setPen(myPen);
00081                 line3.setPen(myPen);
00082                 line4.setPen(myPen);
00083                 line5.setPen(myPen);
00084                 setLine(QLineF(orig, orig + QPointF(origDesp, 0.0)));
00085                 line2.setLine(QLineF(orig + QPointF(origDesp, 0.0), QPointF(orig.x() + origDesp, bottom)));
00086                 line3.setLine(QLineF(QPointF(orig.x() + origDesp, bottom), QPointF(dest.x() - destDesp, bottom)));
00087                 line4.setLine(QLineF(QPointF(dest.x() - destDesp, bottom), dest + QPointF(0.0 - destDesp, 0.0)));
00088                 line5.setLine(QLineF(dest + QPointF(0.0 - destDesp, 0.0), dest));
00089                 line2.show();
00090                 line3.show();
00091                 line4.show();
00092                 line5.show();
00093         }
00094 }
00095 
00096 



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