Skip to content
Open
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
4 changes: 4 additions & 0 deletions include/QtNodes/internal/BasicGraphicsScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class NODE_EDITOR_PUBLIC BasicGraphicsScene : public QGraphicsScene

void nodeHoverLeft(NodeId const nodeId);

void connectionSelected(ConnectionId const connectionId);

void connectionDoubleClicked(ConnectionId const connectionId);

void connectionHovered(ConnectionId const connectionId, QPoint const screenPos);

void connectionHoverLeft(ConnectionId const connectionId);
Expand Down
10 changes: 9 additions & 1 deletion include/QtNodes/internal/ConnectionGraphicsObject.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#pragma once

#include <utility>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

#include <utility>
#include <QPainterPath>
#include <QPolygonF>
#include <QtCore/QUuid>
#include <QtWidgets/QGraphicsObject>

Expand Down Expand Up @@ -48,6 +53,7 @@ class ConnectionGraphicsObject : public QGraphicsObject
QPointF in() const { return _in; }

std::pair<QPointF, QPointF> pointsC1C2() const;
QPolygonF arrow(QPainterPath target, qreal delta = M_PI / 8) const;

void setEndPoint(PortType portType, QPointF const &point);

Expand All @@ -69,6 +75,8 @@ class ConnectionGraphicsObject : public QGraphicsObject

void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;

void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;

void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;

void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
Expand Down
4 changes: 2 additions & 2 deletions include/QtNodes/internal/ConnectionIdUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ inline QJsonObject toJson(ConnectionId const &connId)

connJson["outNodeId"] = static_cast<qint64>(connId.outNodeId);
connJson["outPortIndex"] = static_cast<qint64>(connId.outPortIndex);
connJson["intNodeId"] = static_cast<qint64>(connId.inNodeId);
connJson["inNodeId"] = static_cast<qint64>(connId.inNodeId);
connJson["inPortIndex"] = static_cast<qint64>(connId.inPortIndex);

return connJson;
Expand All @@ -142,7 +142,7 @@ inline ConnectionId fromJson(QJsonObject const &connJson)
{
ConnectionId connId{static_cast<NodeId>(connJson["outNodeId"].toInt(InvalidNodeId)),
static_cast<PortIndex>(connJson["outPortIndex"].toInt(InvalidPortIndex)),
static_cast<NodeId>(connJson["intNodeId"].toInt(InvalidNodeId)),
static_cast<NodeId>((connJson.contains("inNodeId") ? connJson["inNodeId"] : connJson["intNodeId"]).toInt(InvalidNodeId)),
static_cast<PortIndex>(connJson["inPortIndex"].toInt(InvalidPortIndex))};

return connId;
Expand Down
2 changes: 2 additions & 0 deletions include/QtNodes/internal/ConnectionStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NODE_EDITOR_PUBLIC ConnectionStyle : public Style
float pointDiameter() const;

bool useDataDefinedColors() const;
bool withArrow() const;

private:
QColor ConstructionColor;
Expand All @@ -50,5 +51,6 @@ class NODE_EDITOR_PUBLIC ConnectionStyle : public Style
float PointDiameter;

bool UseDataDefinedColors;
bool WithArrow;
};
} // namespace QtNodes
9 changes: 9 additions & 0 deletions include/QtNodes/internal/DataFlowGraphModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ class NODE_EDITOR_PUBLIC DataFlowGraphModel : public AbstractGraphModel, public
QPointF pos;
};

enum CtlOption {
None,
NoSceneMenu,
};

public:
DataFlowGraphModel(std::shared_ptr<NodeDelegateModelRegistry> registry);

std::shared_ptr<NodeDelegateModelRegistry> dataModelRegistry() { return _registry; }

virtual bool is(CtlOption ctl);

public:
std::unordered_set<NodeId> allNodeIds() const override;

Expand Down Expand Up @@ -130,6 +137,8 @@ private Q_SLOTS:
std::unordered_set<ConnectionId> _connectivity;

mutable std::unordered_map<NodeId, NodeGeometryData> _nodeGeometryData;

mutable std::unordered_map<NodeId, std::shared_ptr<QJsonObject>> _styles;
};

} // namespace QtNodes
5 changes: 4 additions & 1 deletion include/QtNodes/internal/NodeGraphicsObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class NodeGraphicsObject : public QGraphicsObject
/// Repaints the node once with reacting ports.
void reactToConnection(ConnectionGraphicsObject const *cgo);

void nodeFlagsUpdated(NodeId const nodeId);

protected:
void paint(QPainter *painter,
QStyleOptionGraphicsItem const *option,
Expand All @@ -73,10 +75,11 @@ class NodeGraphicsObject : public QGraphicsObject

void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;


private:
void embedQWidget();

void setLockedState();
void setLockedState(NodeFlags flags);

private:
NodeId _nodeId;
Expand Down
2 changes: 2 additions & 0 deletions include/QtNodes/internal/NodeStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ class NODE_EDITOR_PUBLIC NodeStyle : public Style

QColor WarningColor;
QColor ErrorColor;
QColor FillColor;

float PenWidth;
float HoveredPenWidth;

float ConnectionPointDiameter;

float Opacity;
float CornerRadius;
};
} // namespace QtNodes
54 changes: 54 additions & 0 deletions include/QtNodes/internal/Style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,60 @@
#include <QtCore/QObject>
#include <QtCore/QString>

#define X_VALUE_EXISTS(v) \
(v.type() != QJsonValue::Undefined && v.type() != QJsonValue::Null)

#define X_STYLE_READ_COLOR(values, variable) \
{ \
auto valueRef = values[#variable]; \
if (X_VALUE_EXISTS(valueRef)) { \
if (valueRef.isArray()) { \
auto colorArray = valueRef.toArray(); \
std::vector<int> rgb; \
rgb.reserve(3); \
int alpha = 255; \
for (auto it = colorArray.begin(); it != colorArray.end(); ++it) { \
rgb.push_back((*it).toInt()); \
} \
if (colorArray.size() > 3) \
alpha = colorArray[3].toInt(); \
variable = QColor(rgb[0], rgb[1], rgb[2], alpha); \
} else { \
variable = QColor(valueRef.toString()); \
} \
} \
}

#define X_STYLE_WRITE_COLOR(values, variable) \
{ \
values[#variable] = variable.name(QColor::HexArgb); \
}

#define X_STYLE_READ_FLOAT(values, variable) \
{ \
auto valueRef = values[#variable]; \
if (X_VALUE_EXISTS(valueRef)) \
variable = valueRef.toDouble(); \
}

#define X_STYLE_WRITE_FLOAT(values, variable) \
{ \
values[#variable] = variable; \
}

#define X_STYLE_READ_BOOL(values, variable) \
{ \
auto valueRef = values[#variable]; \
if (X_VALUE_EXISTS(valueRef)) \
variable = valueRef.toBool(); \
}

#define X_STYLE_WRITE_BOOL(values, variable) \
{ \
values[#variable] = variable; \
}


namespace QtNodes {

class Style // : public QObject
Expand Down
7 changes: 5 additions & 2 deletions resources/DefaultStyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
"FilledConnectionPointColor": "cyan",
"ErrorColor": "red",
"WarningColor": [128, 128, 0],
"FillColor": "none",

"PenWidth": 1.0,
"HoveredPenWidth": 1.5,

"ConnectionPointDiameter": 8.0,

"Opacity": 0.8
"Opacity": 0.8,
"CornerRadius": 3.0
},
"ConnectionStyle": {
"ConstructionColor": "gray",
Expand All @@ -37,6 +39,7 @@
"ConstructionLineWidth": 2.0,
"PointDiameter": 10.0,

"UseDataDefinedColors": false
"UseDataDefinedColors": false,
"WithArrow": false
}
}
29 changes: 29 additions & 0 deletions src/ConnectionGraphicsObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ void ConnectionGraphicsObject::paint(QPainter *painter,

void ConnectionGraphicsObject::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!isSelected()) {
Q_EMIT nodeScene()->connectionSelected(connectionId());
}
QGraphicsItem::mousePressEvent(event);
}

Expand Down Expand Up @@ -263,6 +266,13 @@ void ConnectionGraphicsObject::mouseReleaseEvent(QGraphicsSceneMouseEvent *event
}
}

void ConnectionGraphicsObject::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseDoubleClickEvent(event);
Q_EMIT nodeScene()->connectionDoubleClicked(connectionId());
}


void ConnectionGraphicsObject::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
_connectionState.setHovered(true);
Expand Down Expand Up @@ -377,4 +387,23 @@ std::pair<QPointF, QPointF> ConnectionGraphicsObject::pointsC1C2Vertical() const
return std::make_pair(c1, c2);
}

QPolygonF ConnectionGraphicsObject::arrow(QPainterPath target, qreal delta) const
{
QPointF const &in = endPoint(PortType::In);
QPointF const &out = endPoint(PortType::In);

QPointF first = in, second, third;
int z = 16;
qreal angle = target.angleAtPercent((z*2.0/3)*cos(delta) / target.length()) * M_PI / 180.0;
if ((nodeScene()->orientation() == Qt::Horizontal && in.x() < out.x())
|| (nodeScene()->orientation() == Qt::Vertical && in.y() < out.y()) ) {
z = -16;
}
second = QPointF(in.x() - z * cos(angle - delta), in.y() + z * sin(angle - delta));
third = QPointF(in.x() - z * cos(angle + delta), in.y() + z * sin(angle + delta));
QPolygonF poly;
poly << first << second << third << first;
return poly;
}

} // namespace QtNodes
15 changes: 14 additions & 1 deletion src/ConnectionPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ static void drawNormalLine(QPainter *painter, ConnectionGraphicsObject const &cg
p.setWidth(lineWidth);

bool const selected = cgo.isSelected();

auto cubic = cubicPath(cgo);

if (useGradientColor) {
painter->setBrush(Qt::NoBrush);

Expand Down Expand Up @@ -225,6 +225,19 @@ static void drawNormalLine(QPainter *painter, ConnectionGraphicsObject const &cg

painter->drawPath(cubic);
}

if (connectionStyle.withArrow()) {
bool hovered = cgo.connectionState().hovered();
painter->setBrush(selected
? connectionStyle.selectedHaloColor()
: (hovered
? connectionStyle.hoveredColor()
: normalColorIn));
painter->setPen(Qt::NoPen);

QPolygonF poly = cgo.arrow(cubic);
painter->drawPolygon(poly);
}
}

void ConnectionPainter::paint(QPainter *painter, ConnectionGraphicsObject const &cgo)
Expand Down
Loading