FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodeeditor/src/ConnectionPainter.cpp at hahaton · DigitalPulseSoftware/nodeeditor · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
DigitalPulseSoftware
/
nodeeditor
Public
forked from
paceholder/nodeeditor
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodeeditor
/
src
/
ConnectionPainter.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
186 lines (131 loc) · 3.93 KB
Breadcrumbs
nodeeditor
/
src
/
ConnectionPainter.cpp
Copy path
File metadata and controls
186 lines (131 loc) · 3.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#
include
"
ConnectionPainter.hpp
"
//
#define DEBUG_DRAWING 1
#
include
"
ConnectionGeometry.hpp
"
#
include
"
ConnectionState.hpp
"
#
include
"
ConnectionGraphicsObject.hpp
"
#
include
"
Connection.hpp
"
#
include
"
NodeData.hpp
"
#
include
"
StyleCollection.hpp
"
using
QtNodes::ConnectionPainter;
using
QtNodes::ConnectionGeometry;
using
QtNodes::Connection;
ConnectionPainter::
ConnectionPainter
()
{}
QPainterPath
ConnectionPainter::
cubicPath
(ConnectionGeometry
const
& geom)
{
QPointF
const
& source = geom.
source
();
QPointF
const
& sink = geom.
sink
();
auto
c1c2 = geom.
pointsC1C2
();
//
cubic spline
QPainterPath
cubic
(source);
cubic.
cubicTo
(c1c2.
first
, c1c2.
second
, sink);
return
cubic;
}
QPainterPath
ConnectionPainter::
getPainterStroke
(ConnectionGeometry
const
& geom)
{
auto
cubic =
cubicPath
(geom);
QPointF
const
& source = geom.
source
();
QPainterPath
result
(source);
unsigned
segments =
20
;
for
(
auto
i =
0ul
; i < segments; ++i)
{
double
ratio =
double
(i +
1
) / segments;
result.
lineTo
(cubic.
pointAtPercent
(ratio));
}
QPainterPathStroker stroker; stroker.
setWidth
(
10.0
);
return
stroker.
createStroke
(result);
}
#
include
<
limits
>
#
include
<
QDebug
>
void
ConnectionPainter::
paint
(QPainter* painter,
Connection
const
&connection)
{
auto
const
&connectionStyle =
StyleCollection::connectionStyle
();
QColor normalColor = connectionStyle.
normalColor
();
QColor hoverColor = connectionStyle.
hoveredColor
();
QColor selectedColor = connectionStyle.
selectedColor
();
auto
dataType = connection.
dataType
();
if
(connectionStyle.
useDataDefinedColors
())
{
normalColor = connectionStyle.
normalColor
(dataType.
id
);
hoverColor = normalColor.
lighter
(
200
);
selectedColor = normalColor.
darker
(
200
);
}
ConnectionGeometry
const
& geom =
connection.
connectionGeometry
();
ConnectionState
const
& state =
connection.
connectionState
();
double
const
lineWidth = connectionStyle.
lineWidth
();
double
const
pointDiameter = connectionStyle.
pointDiameter
();
#
ifdef
DEBUG_DRAWING
{
QPointF
const
& source = geom.
source
();
QPointF
const
& sink = geom.
sink
();
auto
points = geom.
pointsC1C2
();
painter->
setPen
(Qt::red);
painter->
setBrush
(Qt::red);
painter->
drawLine
(
QLineF
(source, points.
first
));
painter->
drawLine
(
QLineF
(points.
first
, points.
second
));
painter->
drawLine
(
QLineF
(points.
second
, sink));
painter->
drawEllipse
(points.
first
,
3
,
3
);
painter->
drawEllipse
(points.
second
,
3
,
3
);
painter->
setBrush
(Qt::NoBrush);
painter->
drawPath
(
cubicPath
(geom));
}
{
painter->
setPen
(Qt::yellow);
painter->
drawRect
(geom.
boundingRect
());
}
#
endif
auto
cubic =
cubicPath
(geom);
bool
const
hovered = geom.
hovered
();
auto
const
& graphicsObject =
connection.
getConnectionGraphicsObject
();
bool
const
selected = graphicsObject.
isSelected
();
if
(hovered || selected)
{
QPen p;
p.
setWidth
(
2
* lineWidth);
p.
setColor
(selected ?
connectionStyle.
selectedHaloColor
() :
hoverColor);
painter->
setPen
(p);
painter->
setBrush
(Qt::NoBrush);
//
cubic spline
painter->
drawPath
(cubic);
}
//
draw normal line
{
QPen p;
p.
setWidth
(lineWidth);
if
(selected)
p.
setColor
(selectedColor);
else
p.
setColor
(normalColor);
if
(state.
requiresPort
())
{
p.
setWidth
(connectionStyle.
constructionLineWidth
());
p.
setColor
(connectionStyle.
constructionColor
());
p.
setStyle
(Qt::DashLine);
}
painter->
setPen
(p);
painter->
setBrush
(Qt::NoBrush);
//
cubic spline
painter->
drawPath
(cubic);
}
QPointF
const
& source = geom.
source
();
QPointF
const
& sink = geom.
sink
();
painter->
setPen
(connectionStyle.
constructionColor
());
painter->
setBrush
(connectionStyle.
constructionColor
());
double
const
pointRadius = pointDiameter /
2.0
;
painter->
drawEllipse
(source, pointRadius, pointRadius);
painter->
drawEllipse
(sink, pointRadius, pointRadius);
}
Back
|
FazBrowse Home
|
New Git URL