graphicsedge.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.5
4  Written in Qt
5 
6  graphicsedge.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 GRAPHICSEDGE_H
29 #define GRAPHICSEDGE_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 GraphicsNode;
40 class GraphicsEdgeWeight;
41 class GraphicsEdgeLabel;
42 
43 QT_USE_NAMESPACE
44 
45 using namespace std;
46 
47 
48 static const int TypeEdge= QGraphicsItem::UserType+2;
49 static const int ZValueEdge = 50;
50 static const int ZValueEdgeHighlighted = 99;
51 
52 static const int EDGE_STATE_REGULAR = 0;
53 static const int EDGE_STATE_HIGHLIGHT = 1;
54 static const int EDGE_STATE_HOVER = 2;
55 
56 
57 
58 
59 
60 class GraphicsEdge : public QObject, public QGraphicsItem {
61  Q_OBJECT
62  Q_INTERFACES (QGraphicsItem)
63 
64 public:
65  GraphicsEdge(GraphicsWidget *, GraphicsNode*, GraphicsNode*, const qreal &weight,
66  const QString &label, const QString &color,
67  const Qt::PenStyle &style,
68  const int&type, const bool & drawArrows, const bool &bezier,
69  const bool &weightNumbers=false,
70  const bool &highlighting=true);
71  ~GraphicsEdge();
72 
73  enum { Type = UserType + 2 };
74  int type() const { return Type; }
75 
76  GraphicsNode *sourceNode() const;
77  void setSourceNode(GraphicsNode *node);
78 
79  GraphicsNode *targetNode() const;
80  void setTargetNode(GraphicsNode *node);
81 
82  int sourceNodeNumber();
83  int targetNodeNumber();
84 
85  qreal dx() const;
86 
87  qreal dy() const;
88 
89  qreal length() const;
90 
91  void setSourceNodeSize(const int & size);
92  void setTargetNodeSize(const int & size);
93 
94  void setMinimumOffsetFromNode(const int & offset);
95 
96  void removeRefs();
97 
98  void setWeight( const qreal &w) ;
99  qreal weight() const;
100  void addWeightNumber ();
101  //void deleteWeightNumber();
102  void setWeightNumberVisibility (const bool &toggle);
103 
104  void setLabel( const QString &label) ;
105  QString label() const;
106  void addLabel();
107  //void deleteLabel();
108  void setLabelVisibility (const bool &toggle);
109 
110  void showArrows(const bool &);
111 
112  void setDirectionType(const int &dirType=0);
113  int directionType();
114 
115  qreal width() const;
116 
117  QPen pen() const;
118  void setState(const int &state);
119 
120  void setStyle( const Qt::PenStyle &style);
121  Qt::PenStyle style() const;
122 
123  void setColor( const QString &str) ;
124  //QString color() const ;
125  QColor color() const;
126  QString colorToPajek();
127 
128  void setHighlighted (const bool &flag);
129  void setHighlighting (const bool &toggle);
130 
131  QPainterPath shape() const;
132 
133 
134 public slots:
135  void adjust ();
136 
137 protected:
138  QRectF boundingRect() const;
139  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
140  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
141  void mousePressEvent(QGraphicsSceneMouseEvent *event);
142 
143 
144 
145 private:
147 
148  GraphicsNode *source, *target;
149 
151 
153 
154  QPainterPath m_path;
155 
156  QPointF sourcePoint, targetPoint;
157 
158  QPointF edgeOffset;
159 
160  qreal m_arrowSize;
161 
163  qreal m_offsetFromTargetNode, m_offsetFromSourceNode;
164 
165  Qt::PenStyle m_style;
166  int m_state;
167 
168  QString m_colorNegative, m_label;
169  QColor m_color;
170 
171  qreal m_weight, m_width;
172 
174 
175  qreal angle, line_length, line_dx, line_dy;
176 
177  bool m_Bezier, m_drawArrows, m_drawWeightNumber;
178  bool m_drawLabel, m_hoverHighlighting;
180 };
181 
182 #endif
QPainterPath m_path
Definition: graphicsedge.h:154
GraphicsEdgeLabel * edgeLabel
Definition: graphicsedge.h:152
qreal m_arrowSize
Definition: graphicsedge.h:160
int m_edgeDirType
Definition: graphicsedge.h:173
Qt::PenStyle m_style
Definition: graphicsedge.h:165
Definition: graphicsedgelabel.h:39
static const int EDGE_STATE_REGULAR
Definition: graphicsedge.h:52
GraphicsNode * target
Definition: graphicsedge.h:148
static const int TypeEdge
Definition: graphicsedge.h:48
bool m_isClicked
Definition: graphicsedge.h:179
qreal m_width
Definition: graphicsedge.h:171
GraphicsWidget * graphicsWidget
Definition: graphicsedge.h:146
Definition: graphicsedge.h:60
GraphicsEdgeWeight * weightNumber
Definition: graphicsedge.h:150
static const int EDGE_STATE_HOVER
Definition: graphicsedge.h:54
QColor m_color
Definition: graphicsedge.h:169
QPointF targetPoint
Definition: graphicsedge.h:156
int type() const
Definition: graphicsedge.h:74
Definition: graphicsnode.h:58
static const int ZValueEdge
Definition: graphicsedge.h:49
bool m_hoverHighlighting
Definition: graphicsedge.h:178
Definition: graphicsedgeweight.h:39
qreal m_minOffsetFromNode
Definition: graphicsedge.h:162
int m_state
Definition: graphicsedge.h:166
Definition: graphicswidget.h:55
static const int ZValueEdgeHighlighted
Definition: graphicsedge.h:50
qreal line_length
Definition: graphicsedge.h:175
qreal m_offsetFromTargetNode
Definition: graphicsedge.h:163
QString m_label
Definition: graphicsedge.h:168
bool m_drawWeightNumber
Definition: graphicsedge.h:177
static const int EDGE_STATE_HIGHLIGHT
Definition: graphicsedge.h:53
QPointF edgeOffset
Definition: graphicsedge.h:158