FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodeeditor/src/ConnectionPainter.cpp at exmix-master · 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
313 lines (227 loc) · 6.86 KB
Breadcrumbs
nodeeditor
/
src
/
ConnectionPainter.cpp
Copy path
File metadata and controls
313 lines (227 loc) · 6.86 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#
include
"
ConnectionPainter.hpp
"
#
include
<
QtGui/QIcon
>
#
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;
static
QPainterPath
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);
}
#
ifdef
NODE_DEBUG_DRAWING
static
void
debugDrawing
(QPainter * painter,
Connection
const
& connection)
{
Q_UNUSED
(painter);
Q_UNUSED
(connection);
ConnectionGeometry
const
& geom =
connection.
connectionGeometry
();
{
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
static
void
drawSketchLine
(QPainter * painter,
Connection
const
& connection)
{
using
QtNodes::ConnectionState;
ConnectionState
const
& state =
connection.
connectionState
();
if
(state.
requiresPort
())
{
auto
const
& connectionStyle =
QtNodes::StyleCollection::connectionStyle
();
QPen p;
p.
setWidth
(connectionStyle.
constructionLineWidth
());
p.
setColor
(connectionStyle.
constructionColor
());
p.
setStyle
(Qt::DashLine);
painter->
setPen
(p);
painter->
setBrush
(Qt::NoBrush);
using
QtNodes::ConnectionGeometry;
ConnectionGeometry
const
& geom = connection.
connectionGeometry
();
auto
cubic =
cubicPath
(geom);
//
cubic spline
painter->
drawPath
(cubic);
}
}
static
void
drawHoveredOrSelected
(QPainter * painter,
Connection
const
& connection)
{
using
QtNodes::ConnectionGeometry;
ConnectionGeometry
const
& geom = connection.
connectionGeometry
();
bool
const
hovered = geom.
hovered
();
auto
const
& graphicsObject =
connection.
getConnectionGraphicsObject
();
bool
const
selected = graphicsObject.
isSelected
();
//
drawn as a fat background
if
(hovered || selected)
{
QPen p;
auto
const
&connectionStyle =
QtNodes::StyleCollection::connectionStyle
();
double
const
lineWidth = connectionStyle.
lineWidth
();
p.
setWidth
(
2
* lineWidth);
p.
setColor
(selected ?
connectionStyle.
selectedHaloColor
() :
connectionStyle.
hoveredColor
());
painter->
setPen
(p);
painter->
setBrush
(Qt::NoBrush);
//
cubic spline
auto
cubic =
cubicPath
(geom);
painter->
drawPath
(cubic);
}
}
static
void
drawNormalLine
(QPainter * painter,
Connection
const
& connection)
{
using
QtNodes::ConnectionState;
ConnectionState
const
& state =
connection.
connectionState
();
if
(state.
requiresPort
())
return
;
//
colors
auto
const
&connectionStyle =
QtNodes::StyleCollection::connectionStyle
();
QColor normalColorOut = connectionStyle.
normalColor
();
QColor normalColorIn = connectionStyle.
normalColor
();
QColor selectedColor = connectionStyle.
selectedColor
();
bool
gradientColor =
false
;
if
(connectionStyle.
useDataDefinedColors
())
{
using
QtNodes::PortType;
auto
dataTypeOut = connection.
dataType
(PortType::Out);
auto
dataTypeIn = connection.
dataType
(PortType::In);
gradientColor = (dataTypeOut.
id
!= dataTypeIn.
id
);
normalColorOut = connectionStyle.
normalColor
(dataTypeOut.
id
);
normalColorIn = connectionStyle.
normalColor
(dataTypeIn.
id
);
selectedColor = normalColorOut.
darker
(
200
);
}
//
geometry
ConnectionGeometry
const
& geom = connection.
connectionGeometry
();
double
const
lineWidth = connectionStyle.
lineWidth
();
//
draw normal line
QPen p;
p.
setWidth
(lineWidth);
auto
const
& graphicsObject = connection.
getConnectionGraphicsObject
();
bool
const
selected = graphicsObject.
isSelected
();
auto
cubic =
cubicPath
(geom);
if
(gradientColor)
{
painter->
setBrush
(Qt::NoBrush);
QColor c = normalColorOut;
if
(selected)
c = c.
darker
(
200
);
p.
setColor
(c);
painter->
setPen
(p);
unsigned
int
const
segments =
60
;
for
(
unsigned
int
i =
0ul
; i < segments; ++i)
{
double
ratioPrev =
double
(i) / segments;
double
ratio =
double
(i +
1
) / segments;
if
(i == segments /
2
)
{
QColor c = normalColorIn;
if
(selected)
c = c.
darker
(
200
);
p.
setColor
(c);
painter->
setPen
(p);
}
painter->
drawLine
(cubic.
pointAtPercent
(ratioPrev),
cubic.
pointAtPercent
(ratio));
}
{
QIcon
icon
(
"
:convert.png
"
);
QPixmap pixmap = icon.
pixmap
(
QSize
(
22
,
22
));
painter->
drawPixmap
(cubic.
pointAtPercent
(
0.50
) -
QPoint
(pixmap.
width
()/
2
,
pixmap.
height
()/
2
),
pixmap);
}
}
else
{
p.
setColor
(normalColorOut);
if
(selected)
{
p.
setColor
(selectedColor);
}
painter->
setPen
(p);
painter->
setBrush
(Qt::NoBrush);
painter->
drawPath
(cubic);
}
}
void
ConnectionPainter::
paint
(QPainter* painter,
Connection
const
&connection)
{
drawHoveredOrSelected
(painter, connection);
drawSketchLine
(painter, connection);
drawNormalLine
(painter, connection);
#
ifdef
NODE_DEBUG_DRAWING
debugDrawing
(painter, connection);
#
endif
//
draw end points
ConnectionGeometry
const
& geom = connection.
connectionGeometry
();
QPointF
const
& source = geom.
source
();
QPointF
const
& sink = geom.
sink
();
auto
const
& connectionStyle =
QtNodes::StyleCollection::connectionStyle
();
double
const
pointDiameter = connectionStyle.
pointDiameter
();
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