FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodeeditor/src/DefaultHorizontalNodeGeometry.cpp at bt · BehaviorTree/nodeeditor · GitHub
BehaviorTree
/
nodeeditor
Public
forked from
l3enQ/nodeeditor
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Pull requests
1
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
/
DefaultHorizontalNodeGeometry.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
265 lines (197 loc) · 8.38 KB
Breadcrumbs
nodeeditor
/
src
/
DefaultHorizontalNodeGeometry.cpp
Copy path
File metadata and controls
265 lines (197 loc) · 8.38 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
#
include
"
DefaultHorizontalNodeGeometry.hpp
"
#
include
"
AbstractGraphModel.hpp
"
#
include
"
NodeData.hpp
"
#
include
"
StyleCollection.hpp
"
#
include
<
QPoint
>
#
include
<
QRect
>
#
include
<
QWidget
>
namespace
QtNodes
{
DefaultHorizontalNodeGeometry::DefaultHorizontalNodeGeometry
(AbstractGraphModel &graphModel)
: AbstractNodeGeometry(graphModel)
, _portSize(
20
)
, _portSpasing(
4
)
, _fontMetrics(QFont())
, _boldFontMetrics(QFont())
{
QFont f;
f.
setBold
(
true
);
_boldFontMetrics =
QFontMetrics
(f);
_portSize = _fontMetrics.
height
();
}
QRectF
DefaultHorizontalNodeGeometry::boundingRect
(
const
NodeId nodeId)
const
{
auto
r =
AbstractNodeGeometry::boundingRect
(nodeId);
auto
const
&nodeStyle =
StyleCollection::nodeStyle
();
int
addon = nodeStyle.
ConnectionPointDiameter
*
1.2
+ nodeStyle.
HoveredPenWidth
;
QMargins
margins
(addon,
0
, addon,
0
);
return
r.
marginsAdded
(margins);
}
QSize
DefaultHorizontalNodeGeometry::size
(NodeId
const
nodeId)
const
{
return
_graphModel.
nodeData
<QSize>(nodeId, NodeRole::Size);
}
void
DefaultHorizontalNodeGeometry::recomputeSize
(NodeId
const
nodeId)
const
{
unsigned
int
height =
maxVerticalPortsExtent
(nodeId);
if
(
auto
w = _graphModel.
nodeData
<QWidget *>(nodeId, NodeRole::Widget)) {
height =
std::max
(height,
static_cast
<
unsigned
int
>(w->
height
()));
}
QRectF
const
capRect =
captionRect
(nodeId);
height += capRect.
height
();
height += _portSpasing;
//
space above caption
height += _portSpasing;
//
space below caption
unsigned
int
inPortWidth =
maxPortsTextAdvance
(nodeId, PortType::In);
unsigned
int
outPortWidth =
maxPortsTextAdvance
(nodeId, PortType::Out);
unsigned
int
width = inPortWidth + outPortWidth +
4
* _portSpasing;
if
(
auto
w = _graphModel.
nodeData
<QWidget *>(nodeId, NodeRole::Widget)) {
width += w->
width
();
}
width =
std::max
(width,
static_cast
<
unsigned
int
>(capRect.
width
()) +
2
* _portSpasing);
QSize
size
(width, height);
_graphModel.
setNodeData
(nodeId, NodeRole::Size, size);
}
QPointF
DefaultHorizontalNodeGeometry::portPosition
(NodeId
const
nodeId,
PortType
const
portType,
PortIndex
const
portIndex)
const
{
unsigned
int
const
step = _portSize + _portSpasing;
QPointF result;
double
totalHeight =
0.0
;
totalHeight +=
captionRect
(nodeId).
height
();
totalHeight += _portSpasing;
totalHeight += step * portIndex;
totalHeight += step /
2.0
;
QSize size = _graphModel.
nodeData
<QSize>(nodeId, NodeRole::Size);
switch
(portType) {
case
PortType::In: {
double
x =
0.0
;
//
overrides the default one by groot!
PortCount nInPorts = _graphModel.
nodeData
<PortCount>(nodeId, NodeRole::InPortCount);
int
step = size.
height
() / (
1
+ nInPorts);
double
posY = (
1
+ portIndex) * step;
totalHeight = posY;
result =
QPointF
(x, totalHeight);
break
;
}
case
PortType::Out: {
double
x = size.
width
();
//
overrides the default one by groot!
PortCount nOutPorts = _graphModel.
nodeData
<PortCount>(nodeId, NodeRole::OutPortCount);
int
step = size.
height
() / (
1
+ nOutPorts);
double
posY = (
1
+ portIndex) * step;
totalHeight = posY;
result =
QPointF
(x, totalHeight);
break
;
}
default
:
break
;
}
return
result;
}
QPointF
DefaultHorizontalNodeGeometry::portTextPosition
(NodeId
const
nodeId,
PortType
const
portType,
PortIndex
const
portIndex)
const
{
QPointF p =
portPosition
(nodeId, portType, portIndex);
QRectF rect =
portTextRect
(nodeId, portType, portIndex);
p.
setY
(p.
y
() + rect.
height
() /
4.0
);
QSize size = _graphModel.
nodeData
<QSize>(nodeId, NodeRole::Size);
switch
(portType) {
case
PortType::In:
p.
setX
(_portSpasing);
break
;
case
PortType::Out:
p.
setX
(size.
width
() - _portSpasing - rect.
width
());
break
;
default
:
break
;
}
return
p;
}
QRectF
DefaultHorizontalNodeGeometry::captionRect
(NodeId
const
nodeId)
const
{
if
(!_graphModel.
nodeData
<
bool
>(nodeId, NodeRole::CaptionVisible))
return
QRect
();
QString name = _graphModel.
nodeData
<QString>(nodeId, NodeRole::Caption);
return
_boldFontMetrics.
boundingRect
(name);
}
QPointF
DefaultHorizontalNodeGeometry::captionPosition
(NodeId
const
nodeId)
const
{
QSize size = _graphModel.
nodeData
<QSize>(nodeId, NodeRole::Size);
return
QPointF
(
0.5
* (size.
width
() -
captionRect
(nodeId).
width
()),
0.5
* _portSpasing +
captionRect
(nodeId).
height
());
}
QPointF
DefaultHorizontalNodeGeometry::widgetPosition
(NodeId
const
nodeId)
const
{
QSize size = _graphModel.
nodeData
<QSize>(nodeId, NodeRole::Size);
unsigned
int
captionHeight =
captionRect
(nodeId).
height
();
if
(
auto
w = _graphModel.
nodeData
<QWidget *>(nodeId, NodeRole::Widget)) {
//
If the widget wants to use as much vertical space as possible,
//
place it immediately after the caption.
if
(w->
sizePolicy
().
verticalPolicy
() & QSizePolicy::ExpandFlag) {
return
QPointF
(
2.0
* _portSpasing +
maxPortsTextAdvance
(nodeId, PortType::In),
captionHeight);
}
else
{
//
size should have more height than w unless there will be an unexpected behaviour
return
QPointF
(
2.0
* _portSpasing +
maxPortsTextAdvance
(nodeId, PortType::In),
(captionHeight + size.
height
() - w->
height
()) /
2.0
);
}
}
return
QPointF
();
}
QRect
DefaultHorizontalNodeGeometry::resizeHandleRect
(NodeId
const
nodeId)
const
{
QSize size = _graphModel.
nodeData
<QSize>(nodeId, NodeRole::Size);
unsigned
int
rectSize =
7
;
return
QRect
(size.
width
() - _portSpasing, size.
height
() - _portSpasing, rectSize, rectSize);
}
QRectF
DefaultHorizontalNodeGeometry::portTextRect
(NodeId
const
nodeId,
PortType
const
portType,
PortIndex
const
portIndex)
const
{
QString s;
if
(_graphModel.
portData
<
bool
>(nodeId, portType, portIndex, PortRole::CaptionVisible)) {
s = _graphModel.
portData
<QString>(nodeId, portType, portIndex, PortRole::Caption);
}
else
{
auto
portData = _graphModel.
portData
(nodeId, portType, portIndex, PortRole::DataType);
s = portData.
value
<NodeDataType>().
name
;
}
return
_fontMetrics.
boundingRect
(s);
}
unsigned
int
DefaultHorizontalNodeGeometry::maxVerticalPortsExtent
(NodeId
const
nodeId)
const
{
PortCount nInPorts = _graphModel.
nodeData
<PortCount>(nodeId, NodeRole::InPortCount);
PortCount nOutPorts = _graphModel.
nodeData
<PortCount>(nodeId, NodeRole::OutPortCount);
unsigned
int
maxNumOfEntries =
std::max
(nInPorts, nOutPorts);
unsigned
int
step = _portSize + _portSpasing;
return
step * maxNumOfEntries;
}
unsigned
int
DefaultHorizontalNodeGeometry::maxPortsTextAdvance
(NodeId
const
nodeId,
PortType
const
portType)
const
{
unsigned
int
width =
0
;
size_t
const
n = _graphModel
.
nodeData
(nodeId,
(portType == PortType::Out) ? NodeRole::OutPortCount
: NodeRole::InPortCount)
.
toUInt
();
for
(PortIndex portIndex =
0ul
; portIndex < n; ++portIndex) {
QString name;
if
(_graphModel.
portData
<
bool
>(nodeId, portType, portIndex, PortRole::CaptionVisible)) {
name = _graphModel.
portData
<QString>(nodeId, portType, portIndex, PortRole::Caption);
}
else
{
NodeDataType portData = _graphModel.
portData
<NodeDataType>(nodeId,
portType,
portIndex,
PortRole::DataType);
name = portData.
name
;
}
#
if
QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
width =
std::max
(
unsigned
(_fontMetrics.
horizontalAdvance
(name)), width);
#
else
width =
std::max
(
unsigned
(_fontMetrics.
width
(name)), width);
#
endif
}
return
width;
}
}
//
namespace QtNodes
Back
|
FazBrowse Home
|
New Git URL