Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions include/QtNodes/internal/NodeDelegateModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace QtNodes {
struct NodeValidationState
{
enum class State : int {
Valid = 0, ///< All required inputs are present and correct.
Warning = 1, ///< Some inputs are missing or questionable, processing may be unreliable.
Error = 2, ///< Inputs or settings are invalid, preventing successful computation.
Valid = 0, ///< All required inputs are present and correct.
Warning = 1, ///< Some inputs are missing or questionable, processing may be unreliable.
Error = 2, ///< Inputs or settings are invalid, preventing successful computation.
};
bool isValid() { return _state == State::Valid; };
QString const message() { return _stateMessage; }
Expand All @@ -39,7 +39,9 @@ class StyleCollection;
* AbstractGraphModel.
* This class is the same what has been called NodeDataModel before v3.
*/
class NODE_EDITOR_PUBLIC NodeDelegateModel : public QObject, public Serializable
class NODE_EDITOR_PUBLIC NodeDelegateModel
: public QObject
, public Serializable
{
Q_OBJECT

Expand Down
47 changes: 41 additions & 6 deletions src/DefaultHorizontalNodeGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ void DefaultHorizontalNodeGeometry::recomputeSize(NodeId const nodeId) const
}

QRectF const capRect = captionRect(nodeId);
QRectF const lblRect = labelRect(nodeId);

height += capRect.height();
if (!lblRect.isNull()) {
height += lblRect.height();
height += _portSpasing / 2;
}

height += _portSpasing; // space above caption
height += _portSpasing; // space below caption
Expand All @@ -64,7 +69,11 @@ void DefaultHorizontalNodeGeometry::recomputeSize(NodeId const nodeId) const
width += w->width();
}

width = std::max(width, static_cast<unsigned int>(capRect.width()) + 2 * _portSpasing);
unsigned int textWidth = static_cast<unsigned int>(capRect.width());
if (!lblRect.isNull())
textWidth = std::max(textWidth, static_cast<unsigned int>(lblRect.width()));

width = std::max(width, textWidth + 2 * _portSpasing);

QSize size(width, height);

Expand All @@ -82,6 +91,12 @@ QPointF DefaultHorizontalNodeGeometry::portPosition(NodeId const nodeId,
double totalHeight = 0.0;

totalHeight += captionRect(nodeId).height();

if (_graphModel.nodeData<bool>(nodeId, NodeRole::LabelVisible)) {
totalHeight += labelRect(nodeId).height();
totalHeight += _portSpasing / 2.0;
}

totalHeight += _portSpasing;

totalHeight += step * portIndex;
Expand Down Expand Up @@ -152,8 +167,14 @@ QRectF DefaultHorizontalNodeGeometry::captionRect(NodeId const nodeId) const
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());

QRectF cap = captionRect(nodeId);
QRectF lbl = labelRect(nodeId);

double y = 0.5 * _portSpasing + cap.height();
y += _portSpasing / 2.0 + lbl.height();

return QPointF(0.5 * (size.width() - captionRect(nodeId).width()), y);
}

QRectF DefaultHorizontalNodeGeometry::labelRect(NodeId const nodeId) const
Expand All @@ -173,16 +194,30 @@ QRectF DefaultHorizontalNodeGeometry::labelRect(NodeId const nodeId) const

QPointF DefaultHorizontalNodeGeometry::labelPosition(NodeId const nodeId) const
{
QSize size = _graphModel.nodeData<QSize>(nodeId, NodeRole::Size);
return QPointF(0.4 * (size.width() - labelRect(nodeId).width()),
0.5 * _portSpasing + labelRect(nodeId).height());
QRectF cap = captionRect(nodeId);
QRectF lbl = labelRect(nodeId);

double y = 0.5 * _portSpasing + cap.height();
y += _portSpasing / 2.0 + lbl.height();

if (!_graphModel.nodeData<bool>(nodeId, NodeRole::CaptionVisible)) {
return QPointF(captionPosition(nodeId).x()
+ 0.5 * (captionRect(nodeId).width() - 2 * labelRect(nodeId).width()),
y);
}

return QPointF(captionPosition(nodeId).x()
+ 0.5 * (captionRect(nodeId).width() - 2 * labelRect(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 (_graphModel.nodeData<bool>(nodeId, NodeRole::LabelVisible))
captionHeight += labelRect(nodeId).height() + _portSpasing / 2;

if (auto w = _graphModel.nodeData<QWidget *>(nodeId, NodeRole::Widget)) {
// If the widget wants to use as much vertical space as possible,
Expand Down
4 changes: 3 additions & 1 deletion src/DefaultNodePainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ void DefaultNodePainter::drawNodeCaption(QPainter *painter, NodeGraphicsObject &
QString const name = model.nodeData(nodeId, NodeRole::Caption).toString();

QFont f = painter->font();
f.setBold(true);
f.setBold(!model.nodeData(nodeId, NodeRole::LabelVisible).toBool());
f.setItalic(model.nodeData(nodeId, NodeRole::LabelVisible).toBool());

QPointF position = geometry.captionPosition(nodeId);

Expand All @@ -242,6 +243,7 @@ void DefaultNodePainter::drawNodeCaption(QPainter *painter, NodeGraphicsObject &
painter->drawText(position, name);

f.setBold(false);
f.setItalic(false);
painter->setFont(f);
}

Expand Down
35 changes: 32 additions & 3 deletions src/DefaultVerticalNodeGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
}

QRectF const capRect = captionRect(nodeId);
QRectF const lblRect = labelRect(nodeId);

height += capRect.height();
if (!lblRect.isNull()) {
height += lblRect.height();
height += _portSpasing / 2;
}

height += _portSpasing;
height += _portSpasing;
Expand Down Expand Up @@ -80,7 +85,11 @@ void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
width = std::max(width, static_cast<unsigned int>(w->width()));
}

width = std::max(width, static_cast<unsigned int>(capRect.width()));
unsigned int textWidth = static_cast<unsigned int>(capRect.width());
if (!lblRect.isNull())
textWidth = std::max(textWidth, static_cast<unsigned int>(lblRect.width()));

width = std::max(width, textWidth);

width += _portSpasing;
width += _portSpasing;
Expand Down Expand Up @@ -185,19 +194,39 @@ QPointF DefaultVerticalNodeGeometry::captionPosition(NodeId const nodeId) const

QPointF DefaultVerticalNodeGeometry::labelPosition(const NodeId nodeId) const
{
return QPointF();
QSize size = _graphModel.nodeData<QSize>(nodeId, NodeRole::Size);

QRectF rect = labelRect(nodeId);

unsigned int step = portCaptionsHeight(nodeId, PortType::In);
step += _portSpasing;
step += captionRect(nodeId).height();
step += _portSpasing / 2;

return QPointF(0.5 * (size.width() - rect.width()), step + rect.height());
}

QRectF DefaultVerticalNodeGeometry::labelRect(NodeId const nodeId) const
{
return QRectF();
if (!_graphModel.nodeData<bool>(nodeId, NodeRole::LabelVisible))
return QRectF();

QString nickname = _graphModel.nodeData<QString>(nodeId, NodeRole::Label);

QRectF rect = _boldFontMetrics.boundingRect(nickname);
rect.setWidth(rect.width() * 0.5);
rect.setHeight(rect.height() * 0.5);

return rect;
}

QPointF DefaultVerticalNodeGeometry::widgetPosition(NodeId const nodeId) const
{
QSize size = _graphModel.nodeData<QSize>(nodeId, NodeRole::Size);

unsigned int captionHeight = captionRect(nodeId).height();
if (_graphModel.nodeData<bool>(nodeId, NodeRole::LabelVisible))
captionHeight += labelRect(nodeId).height() + _portSpasing / 2;

if (auto w = _graphModel.nodeData<QWidget *>(nodeId, NodeRole::Widget)) {
// If the widget wants to use as much vertical space as possible,
Expand Down
Loading