edge.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.2
4  Written in Qt
5 
6  edge.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 EDGE_H
29 #define EDGE_H
30 
31 
32 #include <QGraphicsItem>
33 #include <QObject>
34 #include <utility> //declares pair construct
35 
36 
37 class GraphicsWidget;
38 class QGraphicsSceneMouseEvent;
39 class Node;
40 class EdgeWeight;
41 class EdgeLabel;
42 
43 using namespace std;
44 
45 
46 static const int TypeEdge= QGraphicsItem::UserType+2;
47 static const int ZValueEdge = 50;
48 static const int ZValueEdgeHighlighted = 99;
49 
50 static const int EDGE_STATE_REGULAR = 0;
51 static const int EDGE_STATE_HIGHLIGHT = 1;
52 static const int EDGE_STATE_HOVER = 2;
53 
54 class Edge : public QObject, public QGraphicsItem {
55  Q_OBJECT
56  Q_INTERFACES (QGraphicsItem)
57 
58 public:
59  Edge(GraphicsWidget *, Node*, Node*, const float &weight,
60  const QString &label, const QString &color,
61  const Qt::PenStyle &style,
62  const int&type, const bool & drawArrows, const bool &bezier,
63  const bool &weightNumbers=false);
64  ~Edge();
65  enum { Type = UserType + 2 };
66  int type() const { return Type; }
67  Node *sourceNode() const;
68  void setSourceNode(Node *node);
69 
70  Node *targetNode() const;
71  void setTargetNode(Node *node);
72 
73  void setStartOffset(const int & );
74  void setEndOffset(int );
75  void removeRefs();
76 
77  int sourceNodeNumber();
78  int targetNodeNumber();
79 
80  void setWeight( const float &w) ;
81  float weight() const;
82  void addWeightNumber ();
83  //void deleteWeightNumber();
84  void setWeightNumberVisibility (const bool &toggle);
85 
86  void setLabel( const QString &label) ;
87  QString label() const;
88  void addLabel();
89  //void deleteLabel();
90  void setLabelVisibility (const bool &toggle);
91 
92  void showArrows(const bool &);
93  void toggleAntialiasing(bool);
94 
95  void setUndirected();
96  bool isUndirected();
97  void setDirectedWithOpposite();
98 
99  float width() const;
100 
101  QPen pen() const;
102  void setState(const int &state);
103 
104  void setStyle( const Qt::PenStyle &style);
105  Qt::PenStyle style() const;
106 
107  void setColor( const QString &str) ;
108  QString color() const ;
109  QString colorToPajek();
110 
111  void highlight (const bool &flag);
112 
113  QPainterPath shape() const;
114 
115 public slots:
116  void adjust ();
117 
118 protected:
119  QRectF boundingRect() const;
120  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
121  void mousePressEvent(QGraphicsSceneMouseEvent *event);
122 
123 
124 private:
126  Node *source, *target;
127  QPainterPath *m_path, *m_path_up, *m_path_down, *m_path_shape;
128  QPointF sourcePoint, targetPoint;
129  qreal m_arrowSize, m_startOffset, m_endOffset;
130  Qt::PenStyle m_style;
131  int m_state;
134 
135  QString m_color, m_colorNegative, m_label;
136  int eFrom, eTo;
137  float m_weight;
138  int tox1, tox2, toy1, toy2, size;
140  double rad, theta, theta1, theta2;
141  qreal angle, line_length, line_dx, line_dy;
142  bool m_Bezier, m_drawArrows, m_directed_first, m_drawWeightNumber;
144 };
145 
146 #endif
int m_edgeType
Definition: edge.h:139
static const int EDGE_STATE_HOVER
Definition: edge.h:52
Definition: node.h:56
static const int EDGE_STATE_HIGHLIGHT
Definition: edge.h:51
static const int TypeEdge
Definition: edge.h:46
float m_weight
Definition: edge.h:137
qreal line_length
Definition: edge.h:141
Definition: edge.h:54
Qt::PenStyle m_style
Definition: edge.h:130
Definition: edgelabel.h:39
GraphicsWidget * graphicsWidget
Definition: edge.h:125
QString m_label
Definition: edge.h:135
static const int ZValueEdgeHighlighted
Definition: edge.h:48
QPointF targetPoint
Definition: edge.h:128
static const int ZValueEdge
Definition: edge.h:47
double theta2
Definition: edge.h:140
int eTo
Definition: edge.h:136
qreal m_startOffset
Definition: edge.h:129
QPainterPath * m_path_up
Definition: edge.h:127
static const int EDGE_STATE_REGULAR
Definition: edge.h:50
bool m_drawWeightNumber
Definition: edge.h:142
Node * target
Definition: edge.h:126
Definition: graphicswidget.h:53
EdgeWeight * weightNumber
Definition: edge.h:132
bool m_drawLabel
Definition: edge.h:143
int toy2
Definition: edge.h:138
int m_state
Definition: edge.h:131
int type() const
Definition: edge.h:66
EdgeLabel * edgeLabel
Definition: edge.h:133
Definition: edgeweight.h:39