@@ -23,7 +23,11 @@ NodeGeometry(std::unique_ptr<NodeDataModel> const &dataModel)
2323 , _draggingPos(-1000 , -1000 )
2424 , _dataModel(dataModel)
2525 , _fontMetrics(QFont())
26- {}
26+ , _boldFontMetrics(QFont())
27+ {
28+ QFont f; f.setBold (true );
29+ _boldFontMetrics = QFontMetrics (f);
30+ }
2731
2832QRectF
2933NodeGeometry::
@@ -70,7 +74,7 @@ recalculateSize() const
7074 _height = std::max (_height, static_cast <unsigned >(w->height ()));
7175 }
7276
73- _height += nameHeight ();
77+ _height += captionHeight ();
7478
7579 _inputPortWidth = portWidth (PortType::In);
7680 _outputPortWidth = portWidth (PortType::Out);
@@ -83,16 +87,25 @@ recalculateSize() const
8387 {
8488 _width += w->width ();
8589 }
90+
91+ _width = std::max (_width, captionWidth ());
8692}
8793
8894
8995void
9096NodeGeometry::
91- recalculateSize (QFontMetrics const & fontMetrics ) const
97+ recalculateSize (QFont const & font ) const
9298{
93- if (_fontMetrics != fontMetrics)
99+ QFontMetrics fontMetrics (font);
100+ QFont boldFont = font;
101+ boldFont.setBold (true );
102+
103+ QFontMetrics boldFontMetrics (boldFont);
104+
105+ if (_boldFontMetrics != boldFontMetrics)
94106 {
95107 _fontMetrics = fontMetrics;
108+ _boldFontMetrics = boldFontMetrics;
96109
97110 recalculateSize ();
98111 }
@@ -113,7 +126,7 @@ portScenePosition(int index,
113126
114127 double totalHeight = 0.0 ;
115128
116- totalHeight += nameHeight ();
129+ totalHeight += captionHeight ();
117130
118131 totalHeight += step * index;
119132
@@ -202,7 +215,7 @@ widgetPosition() const
202215 {
203216
204217 return QPointF (_spacing + portWidth (PortType::In),
205- (nameHeight () + _height - w->height ()) / 2.0 );
218+ (captionHeight () + _height - w->height ()) / 2.0 );
206219 }
207220
208221 return QPointF ();
@@ -211,14 +224,27 @@ widgetPosition() const
211224
212225unsigned int
213226NodeGeometry::
214- nameHeight () const
227+ captionHeight () const
228+ {
229+ if (!_dataModel->captionVisible ())
230+ return 0 ;
231+
232+ QString name = _dataModel->caption ();
233+
234+ return _boldFontMetrics.boundingRect (name).height ();
235+ }
236+
237+
238+ unsigned int
239+ NodeGeometry::
240+ captionWidth () const
215241{
216242 if (!_dataModel->captionVisible ())
217243 return 0 ;
218244
219245 QString name = _dataModel->caption ();
220246
221- return _fontMetrics .boundingRect (name).height ();
247+ return _boldFontMetrics .boundingRect (name).width ();
222248}
223249
224250
0 commit comments