node.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.2
4  Written in Qt
5 
6  node.h - description
7  -------------------
8  copyright : (C) 2005-2017 by Dimitris B. Kalamaras
9  project site : http://socnetv.org
10 
11  ***************************************************************************/
12 
13 /*******************************************************************************
14 * This program is free software: you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation, either version 3 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
26 ********************************************************************************/
27 
28 #ifndef NODE_H
29 #define NODE_H
30 
31 
32 #include <QGraphicsItem>
33 #include <QObject>
34 #include <QPolygon>
35 
36 class GraphicsWidget;
37 class QGraphicsSceneMouseEvent;
38 class Edge;
39 class NodeLabel;
40 class NodeNumber;
41 
42 using namespace std;
43 
44 static const int TypeNode = QGraphicsItem::UserType+1;
45 static const int ZValueNode = 100;
46 static const int ZValueNodeHighlighted = 110;
47 
54 //
55 
56 class Node : public QObject, public QGraphicsItem {
57  Q_OBJECT
58  Q_INTERFACES (QGraphicsItem)
59 
60 public:
61  Node (GraphicsWidget* gw, const int &num, const int &size,
62  const QString &color, const QString &shape,
63  const bool &showNumbers, const bool &numbersInside,
64  const QString &numberColor, const int &numberSize, const int &numDistance,
65  const bool &showLabels, const QString &label, const QString &labelColor,
66  const int &labelSize, const int &labelDistance,
67  QPointF p
68  );
69  ~Node();
70 
71  enum { Type = UserType + 1 };
72  int type() const { return Type; }
73 
74  QRectF boundingRect() const;
75  QPainterPath shape() const;
76  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
77 
78  long int nodeNumber() {return m_num;}
79 
80  void addInLink( Edge *edge ) ;
81  void deleteInLink(Edge*);
82  void addOutLink( Edge *edge ) ;
83  void deleteOutLink(Edge*);
84 
85  void setSize(const int &);
86  int size() const;
87 
88  void setShape (const QString);
89  QString nodeShape() {return m_shape;}
90 
91  void setColor(QString str);
92  void setColor(QColor color);
93  QString color ();
94 
95  void addLabel();
96  NodeLabel* label();
97  void deleteLabel();
98  void setLabelVisibility(const bool &toggle);
99  void setLabelSize(const int &size);
100  void setLabelText ( QString label) ;
101  void setLabelColor (const QString &color) ;
102  QString labelText();
103  void setLabelDistance(const int &distance);
104 
105  void addNumber () ;
106  NodeNumber* number();
107  void deleteNumber();
108  void setNumberVisibility(const bool &toggle);
109  void setNumberInside(const bool &toggle);
110  void setNumberSize(const int &size);
111  void setNumberDistance(const int &distance);
112  void setNumberColor(const QString &color);
113 
114  void toggleAntialiasing(bool);
115 
116 
117 protected:
118  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
119  void mousePressEvent(QGraphicsSceneMouseEvent *event);
120  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
121  void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
122  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
123 signals:
124  void nodeClicked(Node*);
125  void startEdge(Node *);
126  void adjustOutEdge();
127  void adjustInEdge();
128  void removeOutEdge();
129  void removeInEdge();
130 private:
132  QPainterPath *m_path;
133  QPointF newPos;
134  QPolygonF *m_poly_t;
135  int m_size, m_numSize, m_labelSize, m_numberDistance, m_labelDistance;
136  long int m_num;
137  QString m_shape, m_col_str, m_numColor, m_labelText, m_labelColor;
138  QColor m_col;
139  bool m_hasNumber, m_hasLabel, m_hasNumberInside;
141  list<Edge*> inEdgeList, outEdgeList;
144 };
145 
146 #endif
QPointF newPos
Definition: node.h:133
static const int ZValueNode
Definition: node.h:45
long int nodeNumber()
Definition: node.h:78
Definition: node.h:56
Definition: nodenumber.h:39
QColor m_col
Definition: node.h:138
Definition: edge.h:54
int type() const
Definition: node.h:72
static const int TypeNode
Definition: node.h:44
Definition: nodelabel.h:37
QString nodeShape()
Definition: node.h:89
NodeNumber * m_number
Definition: node.h:143
NodeLabel * m_label
Definition: node.h:142
bool m_hasNumberInside
Definition: node.h:139
int m_size
Definition: node.h:135
list< Edge * > outEdgeList
Definition: node.h:141
QPolygonF * m_poly_t
Definition: node.h:134
QString m_shape
Definition: node.h:137
long int m_num
Definition: node.h:136
Definition: graphicswidget.h:53
QPainterPath * m_path
Definition: node.h:132
GraphicsWidget * graphicsWidget
Definition: node.h:131
static const int ZValueNodeHighlighted
Definition: node.h:46