graphicsnode.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 3.1
4  Written in Qt
5 
6  graphicsnode.h - description
7  -------------------
8  copyright : (C) 2005-2023 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 addInEdge( GraphicsEdge *edge ) ;
96  void removeInEdge(GraphicsEdge*);
97  void addOutEdge( GraphicsEdge *edge ) ;
98  void removeOutEdge(GraphicsEdge*);
99 
100  void setSize(const int &);
101  int size() const;
102 
103  void setShape (const QString, const QString &iconPath=QString());
104  QString nodeShape() {return m_shape;}
105 
106  void setColor(const QString &colorName);
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 
143 
144 
145 private:
146 
148  QPainterPath m_path;
149  QPointF newPos;
150  QPolygonF *m_poly_t;
151  int m_num;
152  int m_size, m_size_orig;
153  int m_state;
158  QString m_shape, m_iconPath;
159  QString m_numColor;
160  QColor m_col, m_col_orig;
162  QString m_labelText, m_labelColor;
163  bool m_hasNumber, m_hasLabel, m_hasNumberInside, m_edgeHighLighting;
165  list<GraphicsEdge*> inEdgeList, outEdgeList;
168 };
169 
170 #endif
Definition: graphicsedge.h:60
Definition: graphicsnodelabel.h:37
Definition: graphicsnodenumber.h:38
Definition: graphicsnode.h:58
void nodeClicked(GraphicsNode *)
GraphicsWidget * graphicsWidget
Definition: graphicsnode.h:147
QString nodeShape()
Definition: graphicsnode.h:104
int m_labelSize
Definition: graphicsnode.h:155
QString m_iconPath
Definition: graphicsnode.h:158
int m_labelDistance
Definition: graphicsnode.h:157
bool m_edgeHighLighting
Definition: graphicsnode.h:163
int m_state
Definition: graphicsnode.h:153
QPolygonF * m_poly_t
Definition: graphicsnode.h:150
int m_num
Definition: graphicsnode.h:151
int m_numSize
Definition: graphicsnode.h:154
QColor m_col_outline
Definition: graphicsnode.h:161
QString m_labelColor
Definition: graphicsnode.h:162
GraphicsNodeNumber * m_number
Definition: graphicsnode.h:167
QPointF newPos
Definition: graphicsnode.h:149
int type() const
Definition: graphicsnode.h:87
QPainterPath m_path
Definition: graphicsnode.h:148
QColor m_col
Definition: graphicsnode.h:160
list< GraphicsEdge * > inEdgeList
Definition: graphicsnode.h:165
GraphicsNodeLabel * m_label
Definition: graphicsnode.h:166
QString m_numColor
Definition: graphicsnode.h:159
int nodeNumber()
Definition: graphicsnode.h:93
int m_numberDistance
Definition: graphicsnode.h:156
int m_size
Definition: graphicsnode.h:152
Definition: graphicswidget.h:53
static const int TypeNode
Definition: graphicsnode.h:44
static const int ZValueNodeHighlighted
Definition: graphicsnode.h:46
static const int ZValueNode
Definition: graphicsnode.h:45