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-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 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 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 
55 
56 
57 
58 class GraphicsEdge : public QObject, public QGraphicsItem {
59  Q_OBJECT
60  Q_INTERFACES (QGraphicsItem)
61 
62 public:
63  GraphicsEdge(GraphicsWidget *, GraphicsNode*, GraphicsNode*, const float &weight,
64  const QString &label, const QString &color,
65  const Qt::PenStyle &style,
66  const int&type, const bool & drawArrows, const bool &bezier,
67  const bool &weightNumbers=false,
68  const bool &highlighting=true);
69  ~GraphicsEdge();
70 
71  enum { Type = UserType + 2 };
72  int type() const { return Type; }
73 
74  GraphicsNode *sourceNode() const;
75  void setSourceNode(GraphicsNode *node);
76 
77  GraphicsNode *targetNode() const;
78  void setTargetNode(GraphicsNode *node);
79 
80  int sourceNodeNumber();
81  int targetNodeNumber();
82 
83  void setSourceNodeSize(const int & size);
84  void setTargetNodeSize(const int & size);
85 
86  void setMinimumOffsetFromNode(const int & offset);
87 
88  void removeRefs();
89 
90  void setWeight( const float &w) ;
91  float weight() const;
92  void addWeightNumber ();
93  //void deleteWeightNumber();
94  void setWeightNumberVisibility (const bool &toggle);
95 
96  void setLabel( const QString &label) ;
97  QString label() const;
98  void addLabel();
99  //void deleteLabel();
100  void setLabelVisibility (const bool &toggle);
101 
102  void showArrows(const bool &);
103 
104  void setDirectionType(const int &dirType=0);
105  int directionType();
106 
107  float width() const;
108 
109  QPen pen() const;
110  void setState(const int &state);
111 
112  void setStyle( const Qt::PenStyle &style);
113  Qt::PenStyle style() const;
114 
115  void setColor( const QString &str) ;
116  QString color() const ;
117  QString colorToPajek();
118 
119  void setHighlighted (const bool &flag);
120  void setHighlighting (const bool &toggle);
121 
122  QPainterPath shape() const;
123 
124 
125 public slots:
126  void adjust ();
127 
128 protected:
129  QRectF boundingRect() const;
130  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
131  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
132  void mousePressEvent(QGraphicsSceneMouseEvent *event);
133 
134 
135 
136 private:
138  GraphicsNode *source, *target;
139  QPainterPath m_path, *m_path_up, *m_path_down, *m_path_shape;
140  QPointF sourcePoint, targetPoint;
141  qreal m_arrowSize;
142 
144  qreal m_offsetFromTargetNode, m_offsetFromSourceNode;
145 
146  Qt::PenStyle m_style;
147  int m_state;
150 
151  QString m_color, m_colorNegative, m_label;
152 
153  float m_weight;
154  int tox1, tox2, toy1, toy2, size;
158  double rad, theta, theta1, theta2;
159  qreal angle, line_length, line_dx, line_dy;
160  bool m_Bezier, m_drawArrows, m_drawWeightNumber;
161  bool m_drawLabel, m_hoverHighlighting;
163 };
164 
165 #endif
GraphicsEdgeLabel * edgeLabel
Definition: graphicsedge.h:149
int sourceOrigSize
Definition: graphicsedge.h:155
qreal m_arrowSize
Definition: graphicsedge.h:141
int m_edgeDirType
Definition: graphicsedge.h:157
Qt::PenStyle m_style
Definition: graphicsedge.h:146
Definition: graphicsedgelabel.h:39
static const int EDGE_STATE_REGULAR
Definition: graphicsedge.h:50
int targetOrigSize
Definition: graphicsedge.h:156
GraphicsNode * target
Definition: graphicsedge.h:138
static const int TypeEdge
Definition: graphicsedge.h:46
bool m_isClicked
Definition: graphicsedge.h:162
GraphicsWidget * graphicsWidget
Definition: graphicsedge.h:137
Definition: graphicsedge.h:58
GraphicsEdgeWeight * weightNumber
Definition: graphicsedge.h:148
static const int EDGE_STATE_HOVER
Definition: graphicsedge.h:52
QPointF targetPoint
Definition: graphicsedge.h:140
Definition: graphicsnode.h:58
static const int ZValueEdge
Definition: graphicsedge.h:47
bool m_hoverHighlighting
Definition: graphicsedge.h:161
Definition: graphicsedgeweight.h:39
qreal m_minOffsetFromNode
Definition: graphicsedge.h:143
int m_state
Definition: graphicsedge.h:147
Definition: graphicswidget.h:59
int type() const
Definition: graphicsedge.h:72
static const int ZValueEdgeHighlighted
Definition: graphicsedge.h:48
qreal line_length
Definition: graphicsedge.h:159
qreal m_offsetFromTargetNode
Definition: graphicsedge.h:144
float m_weight
Definition: graphicsedge.h:153
QString m_label
Definition: graphicsedge.h:151
double theta2
Definition: graphicsedge.h:158
bool m_drawWeightNumber
Definition: graphicsedge.h:160
int toy2
Definition: graphicsedge.h:154
static const int EDGE_STATE_HIGHLIGHT
Definition: graphicsedge.h:51
QPainterPath * m_path_up
Definition: graphicsedge.h:139