-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.h
More file actions
157 lines (118 loc) · 3.64 KB
/
node.h
File metadata and controls
157 lines (118 loc) · 3.64 KB
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
153
154
155
156
157
#ifndef NODE_H
#define NODE_H
#include <QGraphicsObject>
#include <QRadialGradient>
#include <QGraphicsDropShadowEffect>
class Canvas;
enum NodeType
{
Root,
Cut,
Statement,
Placeholder
};
class Node : public QGraphicsObject
{
public:
static Node* makeRoot(Canvas* can);
~Node();
// Add
Node* addChildCut(QPointF pt, bool usePrediction = true);
Node* addChildStatement(QPointF pt, QString t, bool usePrediction = true);
Node* addChildPlaceholder(QPointF pt);
// Highlight
void setAsHighlight();
void removeHighlight();
// Identifiers
bool isRoot() const { return type == Root; }
bool isCut() const { return type == Cut; }
bool isStatement() const { return type == Statement; }
bool isPlaceholder() const { return type == Placeholder; }
// Getters
Node* getParent() const { return parent; }
QList<Node*> getChildren() const { return children; }
Node* getRightSibling();
Node* getLeftSibling();
Node* getChild();
// Selection
void toggleSelection();
void selectThis();
void deselectThis();
void selectAllKids();
void colorDueToSelectedParent();
void removeColorDueToUnselectedParent();
static void setSelectionFromBox(Node* root, QRectF selBox);
void adoptChild(Node* n);
void updateAncestors();
int getID() { return myID; }
QRectF getSceneDraw(qreal deltaX = 0, qreal deltaY = 0) const;
private:
//////////////
/// Fields ///
//////////////
static int globalID;
int myID;
Canvas* canvas;
Node* parent;
// Visual details
NodeType type;
QString text;
QRectF drawBox;
bool highlighted;
bool mouseDown;
// Copy
bool locked; // can accept copy events
bool copying;
Node* copyMeToParent();
//QRadialGradient gradDefault;
//QRadialGradient gradHighlighted;
//QRadialGradient gradClicked;
//QRadialGradient gradSelected;
QGraphicsDropShadowEffect* shadow;
// Important points
QPointF mouseOffset;
// Children
QList<Node*> children;
// Statement specific details
QString letter;
QFont font;
// Selection
bool selected, parentSelected;
// Change parent
bool ghost;
Node* determineNewParent(QPointF pt);
void raiseAllAncestors();
void lowerAllAncestors();
Node* newParent;
Node* newCopy;
bool target;
// Add
QPointF findPoint(const QList<QPointF> &bloom, qreal w, qreal h, bool isStatement = false);
///////////////
/// Methods ///
///////////////
// Private constructor
Node(Canvas* can, Node* par, NodeType t, QPointF pt);
Node(Canvas* can, Node* par, QString s, QPointF pt);
// Graphics
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget) override;
// Sizing
QRectF toCollision(QRectF draw) const;
QRectF toDraw(QRectF collision) const;
QRectF getSceneCollisionBox(qreal deltaX = 0, qreal deltaY = 0) const;
// Collision Checking
static bool checkPotential(QList<Node*> sel, QPointF pt);
QRectF predictMySceneDraw(QList<Node*> altNodes, QList<QRectF> altDraws);
void setDrawBoxFromPotential(QRectF potDraw);
// Mouse
void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
};
#endif // NODE_H