FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodeeditor/src/NodePainter.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
/
NodePainter.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
414 lines (318 loc) · 9.95 KB
Breadcrumbs
nodeeditor
/
src
/
NodePainter.cpp
Copy path
File metadata and controls
414 lines (318 loc) · 9.95 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#
include
"
NodePainter.hpp
"
#
include
<
cmath
>
#
include
<
QtCore/QMargins
>
#
include
"
StyleCollection.hpp
"
#
include
"
PortType.hpp
"
#
include
"
NodeGraphicsObject.hpp
"
#
include
"
NodeGeometry.hpp
"
#
include
"
NodeState.hpp
"
#
include
"
NodeDataModel.hpp
"
#
include
"
Node.hpp
"
#
include
"
FlowScene.hpp
"
using
QtNodes::NodePainter;
using
QtNodes::NodeGeometry;
using
QtNodes::NodeGraphicsObject;
using
QtNodes::Node;
using
QtNodes::NodeState;
using
QtNodes::NodeDataModel;
using
QtNodes::FlowScene;
void
NodePainter::
paint
(QPainter* painter,
Node & node,
FlowScene
const
& scene)
{
NodeGeometry
const
& geom = node.
nodeGeometry
();
NodeState
const
& state = node.
nodeState
();
NodeGraphicsObject
const
& graphicsObject = node.
nodeGraphicsObject
();
geom.
recalculateSize
(painter->
font
());
//
--------------------------------------------
NodeDataModel
const
* model = node.
nodeDataModel
();
drawNodeRect
(painter, geom, model, graphicsObject);
drawConnectionPoints
(painter, geom, state, model, scene);
drawFilledConnectionPoints
(painter, geom, state, model);
drawModelName
(painter, geom, state, model);
drawEntryLabels
(painter, geom, state, model);
drawResizeRect
(painter, geom, model);
drawValidationRect
(painter, geom, model, graphicsObject);
//
/ call custom painter
if
(
auto
painterDelegate = model->
painterDelegate
())
{
painterDelegate->
paint
(painter, geom, model);
}
}
void
NodePainter::
drawNodeRect
(QPainter* painter,
NodeGeometry
const
& geom,
NodeDataModel
const
* model,
NodeGraphicsObject
const
& graphicsObject)
{
NodeStyle
const
& nodeStyle = model->
nodeStyle
();
auto
color = graphicsObject.
isSelected
()
? nodeStyle.
SelectedBoundaryColor
: nodeStyle.
NormalBoundaryColor
;
if
(geom.
hovered
())
{
QPen
p
(color, nodeStyle.
HoveredPenWidth
);
painter->
setPen
(p);
}
else
{
QPen
p
(color, nodeStyle.
PenWidth
);
painter->
setPen
(p);
}
QLinearGradient
gradient
(
QPointF
(
0.0
,
0.0
),
QPointF
(
2.0
, geom.
height
()));
gradient.
setColorAt
(
0.0
, nodeStyle.
GradientColor0
);
gradient.
setColorAt
(
0.03
, nodeStyle.
GradientColor1
);
gradient.
setColorAt
(
0.97
, nodeStyle.
GradientColor2
);
gradient.
setColorAt
(
1.0
, nodeStyle.
GradientColor3
);
painter->
setBrush
(gradient);
float
diam = nodeStyle.
ConnectionPointDiameter
;
QRectF
boundary
( -diam, -diam,
2.0
* diam + geom.
width
(),
2.0
* diam + geom.
height
());
double
const
radius =
3.0
;
painter->
drawRoundedRect
(boundary, radius, radius);
}
void
NodePainter::
drawConnectionPoints
(QPainter* painter,
NodeGeometry
const
& geom,
NodeState
const
& state,
NodeDataModel
const
* model,
FlowScene
const
& scene)
{
NodeStyle
const
& nodeStyle = model->
nodeStyle
();
auto
const
&connectionStyle =
StyleCollection::connectionStyle
();
float
diameter = nodeStyle.
ConnectionPointDiameter
;
auto
reducedDiameter = diameter *
0.6
;
for
(PortType portType: {PortType::Out, PortType::In})
{
size_t
n = state.
getEntries
(portType).
size
();
for
(
unsigned
int
i =
0
; i < n; ++i)
{
QPointF p = geom.
portScenePosition
(i, portType);
auto
const
& dataType = model->
dataType
(portType, i);
bool
canConnect = (state.
getEntries
(portType)[i].
empty
() ||
model->
portConnectionPolicy
(portType, i) == NodeDataModel::ConnectionPolicy::Many);
double
r =
1.0
;
if
(state.
isReacting
() &&
canConnect &&
portType == state.
reactingPortType
())
{
auto
diff = geom.
draggingPos
() - p;
double
dist =
std::sqrt
(
QPointF::dotProduct
(diff, diff));
bool
typeConvertable =
false
;
{
if
(portType == PortType::In)
{
typeConvertable = scene.
registry
().
getTypeConverter
(state.
reactingDataType
(), dataType) !=
nullptr
;
}
else
{
typeConvertable = scene.
registry
().
getTypeConverter
(dataType, state.
reactingDataType
()) !=
nullptr
;
}
}
if
(state.
reactingDataType
().
id
== dataType.
id
|| typeConvertable)
{
double
const
thres =
40.0
;
r = (dist < thres) ?
(
2.0
- dist / thres ) :
1.0
;
}
else
{
double
const
thres =
80.0
;
r = (dist < thres) ?
(dist / thres) :
1.0
;
}
}
if
(connectionStyle.
useDataDefinedColors
())
{
painter->
setBrush
(connectionStyle.
normalColor
(dataType.
id
));
}
else
{
painter->
setBrush
(nodeStyle.
ConnectionPointColor
);
}
painter->
drawEllipse
(p,
reducedDiameter * r,
reducedDiameter * r);
}
}
;
}
void
NodePainter::
drawFilledConnectionPoints
(QPainter * painter,
NodeGeometry
const
& geom,
NodeState
const
& state,
NodeDataModel
const
* model)
{
NodeStyle
const
& nodeStyle = model->
nodeStyle
();
auto
const
& connectionStyle =
StyleCollection::connectionStyle
();
auto
diameter = nodeStyle.
ConnectionPointDiameter
;
for
(PortType portType: {PortType::Out, PortType::In})
{
size_t
n = state.
getEntries
(portType).
size
();
for
(
size_t
i =
0
; i < n; ++i)
{
QPointF p = geom.
portScenePosition
(i, portType);
if
(!state.
getEntries
(portType)[i].
empty
())
{
auto
const
& dataType = model->
dataType
(portType, i);
if
(connectionStyle.
useDataDefinedColors
())
{
QColor
const
c = connectionStyle.
normalColor
(dataType.
id
);
painter->
setPen
(c);
painter->
setBrush
(c);
}
else
{
painter->
setPen
(nodeStyle.
FilledConnectionPointColor
);
painter->
setBrush
(nodeStyle.
FilledConnectionPointColor
);
}
painter->
drawEllipse
(p,
diameter *
0.4
,
diameter *
0.4
);
}
}
}
}
void
NodePainter::
drawModelName
(QPainter * painter,
NodeGeometry
const
& geom,
NodeState
const
& state,
NodeDataModel
const
* model)
{
NodeStyle
const
& nodeStyle = model->
nodeStyle
();
Q_UNUSED
(state);
if
(!model->
captionVisible
())
return
;
QString
const
&name = model->
caption
();
QFont f = painter->
font
();
f.
setBold
(
true
);
QFontMetrics
metrics
(f);
auto
rect = metrics.
boundingRect
(name);
QPointF
position
((geom.
width
() - rect.
width
()) /
2.0
,
(geom.
spacing
() + geom.
entryHeight
()) /
3.0
);
painter->
setFont
(f);
painter->
setPen
(nodeStyle.
FontColor
);
painter->
drawText
(position, name);
f.
setBold
(
false
);
painter->
setFont
(f);
}
void
NodePainter::
drawEntryLabels
(QPainter * painter,
NodeGeometry
const
& geom,
NodeState
const
& state,
NodeDataModel
const
* model)
{
QFontMetrics
const
& metrics =
painter->
fontMetrics
();
for
(PortType portType: {PortType::Out, PortType::In})
{
auto
const
&nodeStyle = model->
nodeStyle
();
auto
& entries = state.
getEntries
(portType);
size_t
n = entries.
size
();
for
(
size_t
i =
0
; i < n; ++i)
{
QPointF p = geom.
portScenePosition
(i, portType);
if
(entries[i].
empty
())
painter->
setPen
(nodeStyle.
FontColorFaded
);
else
painter->
setPen
(nodeStyle.
FontColor
);
QString s;
if
(model->
portCaptionVisible
(portType, i))
{
s = model->
portCaption
(portType, i);
}
else
{
s = model->
dataType
(portType, i).
name
;
}
auto
rect = metrics.
boundingRect
(s);
p.
setY
(p.
y
() + rect.
height
() /
4.0
);
switch
(portType)
{
case
PortType::In:
p.
setX
(
5.0
);
break
;
case
PortType::Out:
p.
setX
(geom.
width
() -
5.0
- rect.
width
());
break
;
default
:
break
;
}
painter->
drawText
(p, s);
}
}
}
void
NodePainter::
drawResizeRect
(QPainter * painter,
NodeGeometry
const
& geom,
NodeDataModel
const
* model)
{
if
(model->
resizable
())
{
painter->
setBrush
(Qt::gray);
painter->
drawEllipse
(geom.
resizeRect
());
}
}
void
NodePainter::
drawValidationRect
(QPainter * painter,
NodeGeometry
const
& geom,
NodeDataModel
const
* model,
NodeGraphicsObject
const
& graphicsObject)
{
auto
modelValidationState = model->
validationState
();
if
(modelValidationState != NodeValidationState::Valid)
{
NodeStyle
const
& nodeStyle = model->
nodeStyle
();
auto
color = graphicsObject.
isSelected
()
? nodeStyle.
SelectedBoundaryColor
: nodeStyle.
NormalBoundaryColor
;
if
(geom.
hovered
())
{
QPen
p
(color, nodeStyle.
HoveredPenWidth
);
painter->
setPen
(p);
}
else
{
QPen
p
(color, nodeStyle.
PenWidth
);
painter->
setPen
(p);
}
//
Drawing the validation message background
if
(modelValidationState == NodeValidationState::Error)
{
painter->
setBrush
(nodeStyle.
ErrorColor
);
}
else
{
painter->
setBrush
(nodeStyle.
WarningColor
);
}
double
const
radius =
3.0
;
float
diam = nodeStyle.
ConnectionPointDiameter
;
QRectF
boundary
(-diam,
-diam + geom.
height
() - geom.
validationHeight
(),
2.0
* diam + geom.
width
(),
2.0
* diam + geom.
validationHeight
());
painter->
drawRoundedRect
(boundary, radius, radius);
painter->
setBrush
(Qt::gray);
//
Drawing the validation message itself
QString
const
&errorMsg = model->
validationMessage
();
QFont f = painter->
font
();
QFontMetrics
metrics
(f);
auto
rect = metrics.
boundingRect
(errorMsg);
QPointF
position
((geom.
width
() - rect.
width
()) /
2.0
,
geom.
height
() - (geom.
validationHeight
() - diam) /
2.0
);
painter->
setFont
(f);
painter->
setPen
(nodeStyle.
FontColor
);
painter->
drawText
(position, errorMsg);
}
}
Back
|
FazBrowse Home
|
New Git URL