PARP Research Group University of Murcia, Spain


src/qvgui/qvdesigner/slate/node.h

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 #ifndef NODE_H
00023 #define NODE_H
00024 
00025 #include <QApplication>
00026 #include <QColor>
00027 #include <QGraphicsItem>
00028 #include <QSet>
00029 
00030 #include "link.h"
00031 #include "slatewindow.h"
00032 #include "../facade/itemproperties.h"
00033 
00034 class ItemProperties;
00035 
00036 #ifndef DOXYGEN_IGNORE_THIS
00037 
00038 class Node : public QGraphicsItem
00039 {
00040         friend class GroupNode;
00041     Q_DECLARE_TR_FUNCTIONS(Node)
00042 
00043 public:
00044     Node(QString _name, SlateWindow *wind, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0);
00045     Node(ItemProperties item, QString _name, uint _id, SlateWindow *wind, QGraphicsItem * parent = 0, QGraphicsScene * scene = 0);
00046     ~Node();
00047 
00048     void setText(const QString &text);
00049     QString text() const;
00050     void setTextColor(const QColor &color);
00051     QColor textColor() const;
00052     void setOutlineColor(const QColor &color);
00053     QColor outlineColor() const;
00054     void setBackgroundColor(const QColor &color);
00055     QColor backgroundColor() const;
00056 
00057     void addInLink(Link *link);
00058     void addOutLink(Link *link);
00059     virtual void removeLink(Link *link);
00060         QList<Link *> getLinks() const;
00061         QList<Link *> getInLinks() const;
00062         QList<Link *> getOutLinks() const;
00063         int precursors(QList<Node *> tail = QList<Node *>());
00064 
00065         QString getName() const { return name; }
00066         QString getType() const { return type; }
00067         void setType(QString _type) { type = _type; }
00068     QRectF boundingRect() const;
00069     QPainterPath shape() const;
00070 
00071         virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00072         virtual QPointF scenePointPos(int point) const;
00073         virtual QPointF scenePointPos(QString name, bool in) const;
00074         virtual void updateLinksPos();
00075         virtual void setHide(bool hide);
00076         int numProps() const;
00077         QString propName(int point) const; // devuelve el nombre de la propiedad señalada por point
00078         int propPoint(QString name, bool in) const; // devuelve el punto (de entrada o salida) de una propiedad.
00079         int propType(int point) const; // devuelve el tipo de la propiedad señalada por point
00080         void insertProperty(int pos, QString name, int type, bool input, bool output);
00081         int insertProperty(QString name, int type, bool input, bool output);
00082         void removeProperty(QString name);
00083         uint getId();
00084         void setName(QString _name);
00085         void prepareHierarchy(); // actualiza a toda la gerarquía de grupos que tiene por encima
00086         void updateHierarchy(); // actualiza a toda la gerarquía de grupos que tiene por encima
00087         void publicPrepareGeometryChange();
00088 
00089 
00090 protected:
00091         virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event);
00092         void mousePressEvent(QGraphicsSceneMouseEvent * event);
00093         void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
00094         void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
00095     QVariant itemChange(GraphicsItemChange change, const QVariant &value);
00096         void CorrectTextChange();
00097 
00098         void markPoint(int point, bool validity);
00099         void unmarkPoint();
00100         bool isValidLink(Node *fromNode, int fromPoint, Node *toNode, int toPoint) const;
00101         void deleteProperty(int pos);
00102         void delLastProp();
00103 
00104         virtual QRectF outlineRect() const;
00105         virtual int roundness(double size) const;
00106         virtual int pointAt(QPointF pos) const;
00107         virtual int insertPos() const; // posición en que se quieren insertar las nuevas propiedades, para que sea la última menos el los de los "..."
00108         virtual void validLinkRelease(Node *fromNode, int fromPoint, Node *toNode, int toPoint); // función que trata un nuevo enlace y llama a la slate para crearlo
00109         ItemProperties getItemProp() { return itemProp; }
00110 
00111     QList<Link *> myInLinks;
00112         QList<Link *> myOutLinks;
00113 
00114     QString myText;
00115     QColor myTextColor;
00116     QColor myBackgroundColor;
00117     QColor myOutlineColor;
00118 
00119         QString name;
00120         QString type;
00121 
00122         ItemProperties itemProp; // propiedades del worker asociado
00123         int numProp; // número de propiedades del worker asociado
00124         SlateWindow *window; // ventana con que se ha creado, para lanzarle las peticiones de creación de links
00125         QRectF outlinerect;
00126 
00127         int clickedPoint; // indica si el último click se ha hecho sobre una de los puntos, y sobre cual
00128         QGraphicsLineItem *line; // linea indicadora del proceso de enlace
00129         int externalMarkedPoint; // punto de otro item sobre el que se está intentando realizar un enlace
00130         Node *externalMarkedItem; // item sobre el que se esa intentando realizar el enlace
00131         int markedPoint; // punto local que se ha seleccionado para colorear por que se está intentando hacer un link sobre el
00132         bool markedValidity; // indica si el markedPoint es un objetivo correcto, lo que determinará el color usado
00133 
00134         uint id;
00135 
00136         double lineSpacing;
00137 };
00138 
00139 #endif
00140 #endif



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