graphicsnode.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.5
4  Written in Qt
5 
6  graphicsnode.h - description
7  -------------------
8  copyright : (C) 2005-2018 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 GRAPHICSNODE_H
29 #define GRAPHICSNODE_H
30 
31 
32 #include <QGraphicsItem>
33 #include <QObject>
34 #include <QPolygon>
35 
36 class GraphicsWidget;
37 class QGraphicsSceneMouseEvent;
38 class GraphicsEdge;
39 class GraphicsNodeLabel;
40 class GraphicsNodeNumber;
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 
48 
49 
56 //
57 
58 class GraphicsNode : public QObject, public QGraphicsItem {
59  Q_OBJECT
60  Q_INTERFACES (QGraphicsItem)
61 
62 public:
63  GraphicsNode (GraphicsWidget* gw, const int &num, const int &size,
64  const QString &color, const QString &shape,
65  const bool &showNumbers, const bool &numbersInside,
66  const QString &numberColor, const int &numberSize, const int &numDistance,
67  const bool &showLabels, const QString &label, const QString &labelColor,
68  const int &labelSize, const int &labelDistance,
69  const bool &edgeHighlighting,
70  QPointF p
71  );
72  ~GraphicsNode();
73 
74  enum { Type = UserType + 1 };
75  int type() const { return Type; }
76 
77 
78  QRectF boundingRect() const;
79  QPainterPath shape() const;
80  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
81 
82  long int nodeNumber() {return m_num;}
83 
84  void addInLink( GraphicsEdge *edge ) ;
85  void deleteInLink(GraphicsEdge*);
86  void addOutLink( GraphicsEdge *edge ) ;
87  void deleteOutLink(GraphicsEdge*);
88 
89  void setSize(const int &);
90  int size() const;
91 
92 
93  void setShape (const QString);
94  QString nodeShape() {return m_shape;}
95 
96  void setColor(QString str);
97  void setColor(QColor color);
98  QString color ();
99 
100  void addLabel();
101  GraphicsNodeLabel* label();
102  void deleteLabel();
103  void setLabelVisibility(const bool &toggle);
104  void setLabelSize(const int &size);
105  void setLabelText ( QString label) ;
106  void setLabelColor (const QString &color) ;
107  QString labelText();
108  void setLabelDistance(const int &distance);
109 
110  void addNumber () ;
111  GraphicsNodeNumber* number();
112  void deleteNumber();
113  void setNumberVisibility(const bool &toggle);
114  void setNumberInside(const bool &toggle);
115  void setNumberSize(const int &size);
116  void setNumberDistance(const int &distance);
117  void setNumberColor(const QString &color);
118 
119  void setEdgeHighLighting(const bool &toggle) ;
120 
121 protected:
122  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
123  void mousePressEvent(QGraphicsSceneMouseEvent *event);
124  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
125  void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
126  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
127 signals:
128  void nodeClicked(GraphicsNode*);
129  void startEdge(GraphicsNode *);
130  void adjustOutEdge();
131  void adjustInEdge();
132  void removeOutEdge();
133  void removeInEdge();
134 private:
136  QPainterPath m_path;
137  QPointF newPos;
138  QPolygonF *m_poly_t;
139  int m_size, m_size_orig;
140  int m_state;
145  long int m_num;
146  QString m_shape, m_col_str, m_numColor, m_labelText, m_labelColor;
147  QColor m_col, m_col_orig;
148  bool m_hasNumber, m_hasLabel, m_hasNumberInside, m_edgeHighLighting;
150  list<GraphicsEdge*> inEdgeList, outEdgeList;
153 };
154 
155 #endif
int m_state
Definition: graphicsnode.h:140
static const int TypeNode
Definition: graphicsnode.h:44
GraphicsNodeLabel * m_label
Definition: graphicsnode.h:151
int m_size_orig
Definition: graphicsnode.h:139
static const int ZValueNodeHighlighted
Definition: graphicsnode.h:46
int m_numSize
Definition: graphicsnode.h:141
static const int ZValueNode
Definition: graphicsnode.h:45
QColor m_col_orig
Definition: graphicsnode.h:147
Definition: graphicsnodelabel.h:37
QPolygonF * m_poly_t
Definition: graphicsnode.h:138
list< GraphicsEdge * > outEdgeList
Definition: graphicsnode.h:150
int m_numberDistance
Definition: graphicsnode.h:143
Definition: graphicsnodenumber.h:39
QString nodeShape()
Definition: graphicsnode.h:94
Definition: graphicsedge.h:58
GraphicsNodeNumber * m_number
Definition: graphicsnode.h:152
Definition: graphicsnode.h:58
long int nodeNumber()
Definition: graphicsnode.h:82
GraphicsWidget * graphicsWidget
Definition: graphicsnode.h:135
int type() const
Definition: graphicsnode.h:75
QPainterPath m_path
Definition: graphicsnode.h:136
Definition: graphicswidget.h:59
long int m_num
Definition: graphicsnode.h:145
int m_labelSize
Definition: graphicsnode.h:142
int m_labelDistance
Definition: graphicsnode.h:144
QString m_shape
Definition: graphicsnode.h:146
QPointF newPos
Definition: graphicsnode.h:137
bool m_hasNumberInside
Definition: graphicsnode.h:148