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-2019 by Dimitris B. Kalamaras
9  project site : https://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 
65  const int &num,
66  const int &size,
67  const QString &color,
68  const QString &shape,
69  const QString &iconPath,
70  const bool &showNumbers,
71  const bool &numbersInside,
72  const QString &numberColor,
73  const int &numberSize,
74  const int &numDistance,
75  const bool &showLabels,
76  const QString &label,
77  const QString &labelColor,
78  const int &labelSize,
79  const int &labelDistance,
80  const bool &edgeHighlighting,
81  QPointF p
82  );
83 
84  ~GraphicsNode();
85 
86  enum { Type = UserType + 1 };
87  int type() const { return Type; }
88 
89  QRectF boundingRect() const;
90  QPainterPath shape() const;
91  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
92 
93  int nodeNumber() {return m_num;}
94 
95  void addInLink( GraphicsEdge *edge ) ;
96  void deleteInLink(GraphicsEdge*);
97  void addOutLink( GraphicsEdge *edge ) ;
98  void deleteOutLink(GraphicsEdge*);
99 
100  void setSize(const int &);
101  int size() const;
102 
103  void setShape (const QString, const QString &iconPath=QString::null);
104  QString nodeShape() {return m_shape;}
105 
106  void setColor(const QString &colorStr);
107  void setColor(QColor color);
108  QString color ();
109 
110  void addLabel();
111  GraphicsNodeLabel* label();
112  void deleteLabel();
113  void setLabelVisibility(const bool &toggle);
114  void setLabelSize(const int &size);
115  void setLabelText ( const QString &label) ;
116  void setLabelColor (const QString &color) ;
117  QString labelText();
118  void setLabelDistance(const int &distance);
119 
120  void addNumber () ;
121  GraphicsNodeNumber* number();
122  void deleteNumber();
123  void setNumberVisibility(const bool &toggle);
124  void setNumberInside(const bool &toggle);
125  void setNumberSize(const int &size);
126  void setNumberDistance(const int &distance);
127  void setNumberColor(const QString &color);
128 
129  void setEdgeHighLighting(const bool &toggle) ;
130 
131 
132 protected:
133 
134  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
135  void mousePressEvent(QGraphicsSceneMouseEvent *event);
136  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
137  void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
138  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
139 
140 signals:
141 
142  void nodeClicked(GraphicsNode*);
143  void startEdge(GraphicsNode *);
144  void adjustOutEdge();
145  void adjustInEdge();
146  void removeOutEdge();
147  void removeInEdge();
148 
149 
150 private:
151 
153  QPainterPath m_path;
154  QPointF newPos;
155  QPolygonF *m_poly_t;
156  int m_size, m_size_orig;
157  int m_state;
162  int m_num;
163  QString m_shape, m_iconPath;
164  QString m_col_str, m_numColor, m_labelText, m_labelColor;
165  QColor m_col, m_col_orig;
166  bool m_hasNumber, m_hasLabel, m_hasNumberInside, m_edgeHighLighting;
168  list<GraphicsEdge*> inEdgeList, outEdgeList;
171 };
172 
173 #endif
int m_state
Definition: graphicsnode.h:157
static const int TypeNode
Definition: graphicsnode.h:44
GraphicsNodeLabel * m_label
Definition: graphicsnode.h:169
int m_size_orig
Definition: graphicsnode.h:156
static const int ZValueNodeHighlighted
Definition: graphicsnode.h:46
QString m_numColor
Definition: graphicsnode.h:164
int m_numSize
Definition: graphicsnode.h:158
static const int ZValueNode
Definition: graphicsnode.h:45
QColor m_col_orig
Definition: graphicsnode.h:165
Definition: graphicsnodelabel.h:37
QPolygonF * m_poly_t
Definition: graphicsnode.h:155
list< GraphicsEdge * > outEdgeList
Definition: graphicsnode.h:168
int m_numberDistance
Definition: graphicsnode.h:160
Definition: graphicsnodenumber.h:39
int nodeNumber()
Definition: graphicsnode.h:93
QString nodeShape()
Definition: graphicsnode.h:104
Definition: graphicsedge.h:60
GraphicsNodeNumber * m_number
Definition: graphicsnode.h:170
Definition: graphicsnode.h:58
GraphicsWidget * graphicsWidget
Definition: graphicsnode.h:152
QPainterPath m_path
Definition: graphicsnode.h:153
Definition: graphicswidget.h:55
int m_labelSize
Definition: graphicsnode.h:159
int m_labelDistance
Definition: graphicsnode.h:161
int type() const
Definition: graphicsnode.h:87
QString m_shape
Definition: graphicsnode.h:163
QPointF newPos
Definition: graphicsnode.h:154
bool m_hasNumberInside
Definition: graphicsnode.h:166
int m_num
Definition: graphicsnode.h:162