-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedge.h
152 lines (128 loc) · 4.18 KB
/
edge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* File: edge.h
* Author: Rachel Bood
* Date: 2014/11/07 (?)
* Version: 1.14
*
* Purpose: creates an edge for the users graph
* Modification history:
* Nov 13, 2019 (JD V1.1):
* (a) Minor formatting tweaks.
* (b) Apply change of name label.h -> html-label.h
* Nov 13, 2019 (JD V1.2):
* (a) Rename (in this order!)
* label -> htmlLabel,
* setWeightLabelSize() -> setLabelSize(),
* getWeightLabelSize() -> getLabelSize(),
* setWeight() -> setLabel(),
* getWeight() -> getLabel(),
* editWeight() -> editLabel(),
* weight -> label,
* esize -> labelSize,
* in order to rationalize the naming scheme.
* Nov 30, 2019 (JD V1.3):
* (a) Made offset1 and offset2 local variables in
* createSelectionPolygon(), rather than having them as private
* class variables. (Changed edge.cpp accordingly.)
* (b) Removed decl for the unused isDigits() function.
* Dec 12, 2019 (JD V1.4):
* (a) Include defuns.h.
* Dec 15, 2019 (JD V1.5):
* (a) Remove (globally) unused "penWidth" private variable.
* Jun 18, 2020 (IC V1.6)
* (a) Added setEdgeLabel() slot to update label when changes are made on the
* canvas in edit mode.
* (b) Changed htmlLabel to public for use in labelcontroller.cpp
* Jun 25, 2020 (IC V1.7)
* (a) Add causedConnect to edge object.
* (b) #include <QTextDocument>. (TODO: Why??)
* Jul 28, 2020 (IC V1.8)
* (a) Add checked member.
* Jul 29, 2020 (IC V1.9)
* (a) Added eventFilter() to receive edit tab events so we can identify
* the edge being edited/looked at.
* (b) Added penStyle so edges can be drawn solid or dashed.
* Aug 19, 2020 (IC V1.10)
* (a) Remove now-unneeded setEdgeLabel() function.
* (b) Move setLabel() from public to public slots.
* Aug 21, 2020 (IC V1.11)
* (a) Added the ability to number edge labels similar to nodes so setLabel
* has been replaced with copies of the label functions from node.cpp.
* (b) setLabelSize renamed to setEdgeLabelSize for clarity.
* Sep 3, 2020 (IC V1.12)
* (a) Add chosen(), which sets the pen style.
* Oct 18, 2020 (JD V1.13)
* (a) Fix spelling.
* Nov 11, 2020 (JD V1.14)
* (a) Removed rotation attribute.
*/
#ifndef EDGE_H
#define EDGE_H
#include "defuns.h"
#include "html-label.h"
#include <QGraphicsItem>
#include <QGraphicsObject>
#include <QList>
#include <QGraphicsSimpleTextItem>
#include <QGraphicsSceneMouseEvent>
#include <QTextDocument>
class Node;
class CanvasView;
class PreView;
class Edge: public QGraphicsObject
{
Q_OBJECT
public:
Edge(Node * sourceNode, Node * destNode);
void setDestRadius(qreal aRadius);
qreal getDestRadius();
void setSourceRadius(qreal aRadius);
qreal getSourceRadius();
void setPenWidth(qreal aPenWidth);
qreal getPenWidth();
void setRotation(qreal rotationAmount);
qreal getRotation();
void setColour(QColor colour);
QColor getColour();
void setEdgeLabel(int number);
void setEdgeLabel(QString aLabel, int number);
void setEdgeLabel(QString aLabel, QString subscript);
void setEdgeLabelSize(qreal edgeLabelSize);
qreal getLabelSize();
QRectF boundingRect() const;
QPainterPath shape() const;
QString getLabel();
void adjust();
void setDestNode(Node * node);
void setSourceNode(Node * node);
enum { Type = UserType + 2 };
int type() const { return Type; }
Node * sourceNode() const;
Node * destNode() const;
void editLabel(bool edit);
QGraphicsItem * getRootParent();
void chosen(int group1);
//~Edge(); deconstructor a WIP
HTML_Label * htmlLabel;
int causedConnect;
int checked;
public slots:
void setEdgeLabel(QString aLabel);
protected:
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option,
QWidget * widget);
bool eventFilter(QObject * obj, QEvent * event);
private:
void createSelectionPolygon();
Node * source, * dest; // Original names based on directed graphs
QPointF sourcePoint, destPoint;
QPolygonF selectionPolygon;
qreal destRadius, sourceRadius;
QLineF edgeLine;
QString label;
int penStyle;
qreal labelSize, penSize;
QColor edgeColour;
void labelToHtml();
};
#endif // EDGE_H