|
@@ -1,4 +1,4 @@
|
|
|
-#include "DefaultNodePainter.hpp"
|
|
|
+#include "DefaultNodePainter.hpp"
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
@@ -18,14 +18,14 @@ namespace QtNodes {
|
|
|
void DefaultNodePainter::paint(QPainter *painter, NodeGraphicsObject &ngo) const
|
|
|
{
|
|
|
// TODO?
|
|
|
- //AbstractNodeGeometry & geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
- //geometry.recomputeSizeIfFontChanged(painter->font());
|
|
|
+ // AbstractNodeGeometry & geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
+ // geometry.recomputeSizeIfFontChanged(painter->font());
|
|
|
|
|
|
drawNodeRect(painter, ngo);
|
|
|
|
|
|
- drawConnectionPoints(painter, ngo);
|
|
|
+ // drawConnectionPoints(painter, ngo);
|
|
|
|
|
|
- drawFilledConnectionPoints(painter, ngo);
|
|
|
+ // drawFilledConnectionPoints(painter, ngo);
|
|
|
|
|
|
drawNodeCaption(painter, ngo);
|
|
|
|
|
@@ -76,8 +76,8 @@ void DefaultNodePainter::drawNodeRect(QPainter *painter, NodeGraphicsObject &ngo
|
|
|
|
|
|
void DefaultNodePainter::drawConnectionPoints(QPainter *painter, NodeGraphicsObject &ngo) const
|
|
|
{
|
|
|
- AbstractGraphModel &model = ngo.graphModel();
|
|
|
- NodeId const nodeId = ngo.nodeId();
|
|
|
+ AbstractGraphModel &model = ngo.graphModel();
|
|
|
+ NodeId const nodeId = ngo.nodeId();
|
|
|
AbstractNodeGeometry &geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
|
|
|
QJsonDocument json = QJsonDocument::fromVariant(model.nodeData(nodeId, NodeRole::Style));
|
|
@@ -85,21 +85,19 @@ void DefaultNodePainter::drawConnectionPoints(QPainter *painter, NodeGraphicsObj
|
|
|
|
|
|
auto const &connectionStyle = StyleCollection::connectionStyle();
|
|
|
|
|
|
- float diameter = nodeStyle.ConnectionPointDiameter;
|
|
|
+ float diameter = nodeStyle.ConnectionPointDiameter;
|
|
|
auto reducedDiameter = diameter * 0.6;
|
|
|
|
|
|
- for (PortType portType : {PortType::Out, PortType::In}) {
|
|
|
- size_t const n = model
|
|
|
- .nodeData(nodeId,
|
|
|
- (portType == PortType::Out) ? NodeRole::OutPortCount
|
|
|
- : NodeRole::InPortCount)
|
|
|
- .toUInt();
|
|
|
+ for (PortType portType : { PortType::Out, PortType::In }) {
|
|
|
+ size_t const n =
|
|
|
+ model.nodeData(nodeId, (portType == PortType::Out) ? NodeRole::OutPortCount : NodeRole::InPortCount)
|
|
|
+ .toUInt();
|
|
|
|
|
|
for (PortIndex portIndex = 0; portIndex < n; ++portIndex) {
|
|
|
QPointF p = geometry.portPosition(nodeId, portType, portIndex);
|
|
|
|
|
|
- auto const &dataType = model.portData(nodeId, portType, portIndex, PortRole::DataType)
|
|
|
- .value<NodeDataType>();
|
|
|
+ auto const &dataType =
|
|
|
+ model.portData(nodeId, portType, portIndex, PortRole::DataType).value<NodeDataType>();
|
|
|
|
|
|
double r = 1.0;
|
|
|
|
|
@@ -109,24 +107,23 @@ void DefaultNodePainter::drawConnectionPoints(QPainter *painter, NodeGraphicsObj
|
|
|
PortType requiredPort = cgo->connectionState().requiredPort();
|
|
|
|
|
|
if (requiredPort == portType) {
|
|
|
- ConnectionId possibleConnectionId = makeCompleteConnectionId(cgo->connectionId(),
|
|
|
- nodeId,
|
|
|
- portIndex);
|
|
|
+ ConnectionId possibleConnectionId =
|
|
|
+ makeCompleteConnectionId(cgo->connectionId(), nodeId, portIndex);
|
|
|
|
|
|
bool const possible = model.connectionPossible(possibleConnectionId);
|
|
|
|
|
|
auto cp = cgo->sceneTransform().map(cgo->endPoint(requiredPort));
|
|
|
- cp = ngo.sceneTransform().inverted().map(cp);
|
|
|
+ cp = ngo.sceneTransform().inverted().map(cp);
|
|
|
|
|
|
- auto diff = cp - p;
|
|
|
+ auto diff = cp - p;
|
|
|
double dist = std::sqrt(QPointF::dotProduct(diff, diff));
|
|
|
|
|
|
if (possible) {
|
|
|
double const thres = 40.0;
|
|
|
- r = (dist < thres) ? (2.0 - dist / thres) : 1.0;
|
|
|
+ r = (dist < thres) ? (2.0 - dist / thres) : 1.0;
|
|
|
} else {
|
|
|
double const thres = 80.0;
|
|
|
- r = (dist < thres) ? (dist / thres) : 1.0;
|
|
|
+ r = (dist < thres) ? (dist / thres) : 1.0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -148,8 +145,8 @@ void DefaultNodePainter::drawConnectionPoints(QPainter *painter, NodeGraphicsObj
|
|
|
|
|
|
void DefaultNodePainter::drawFilledConnectionPoints(QPainter *painter, NodeGraphicsObject &ngo) const
|
|
|
{
|
|
|
- AbstractGraphModel &model = ngo.graphModel();
|
|
|
- NodeId const nodeId = ngo.nodeId();
|
|
|
+ AbstractGraphModel &model = ngo.graphModel();
|
|
|
+ NodeId const nodeId = ngo.nodeId();
|
|
|
AbstractNodeGeometry &geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
|
|
|
QJsonDocument json = QJsonDocument::fromVariant(model.nodeData(nodeId, NodeRole::Style));
|
|
@@ -157,12 +154,10 @@ void DefaultNodePainter::drawFilledConnectionPoints(QPainter *painter, NodeGraph
|
|
|
|
|
|
auto diameter = nodeStyle.ConnectionPointDiameter;
|
|
|
|
|
|
- for (PortType portType : {PortType::Out, PortType::In}) {
|
|
|
- size_t const n = model
|
|
|
- .nodeData(nodeId,
|
|
|
- (portType == PortType::Out) ? NodeRole::OutPortCount
|
|
|
- : NodeRole::InPortCount)
|
|
|
- .toUInt();
|
|
|
+ for (PortType portType : { PortType::Out, PortType::In }) {
|
|
|
+ size_t const n =
|
|
|
+ model.nodeData(nodeId, (portType == PortType::Out) ? NodeRole::OutPortCount : NodeRole::InPortCount)
|
|
|
+ .toUInt();
|
|
|
|
|
|
for (PortIndex portIndex = 0; portIndex < n; ++portIndex) {
|
|
|
QPointF p = geometry.portPosition(nodeId, portType, portIndex);
|
|
@@ -170,9 +165,8 @@ void DefaultNodePainter::drawFilledConnectionPoints(QPainter *painter, NodeGraph
|
|
|
auto const &connected = model.connections(nodeId, portType, portIndex);
|
|
|
|
|
|
if (!connected.empty()) {
|
|
|
- auto const &dataType = model
|
|
|
- .portData(nodeId, portType, portIndex, PortRole::DataType)
|
|
|
- .value<NodeDataType>();
|
|
|
+ auto const &dataType =
|
|
|
+ model.portData(nodeId, portType, portIndex, PortRole::DataType).value<NodeDataType>();
|
|
|
|
|
|
auto const &connectionStyle = StyleCollection::connectionStyle();
|
|
|
if (connectionStyle.useDataDefinedColors()) {
|
|
@@ -192,8 +186,8 @@ void DefaultNodePainter::drawFilledConnectionPoints(QPainter *painter, NodeGraph
|
|
|
|
|
|
void DefaultNodePainter::drawNodeCaption(QPainter *painter, NodeGraphicsObject &ngo) const
|
|
|
{
|
|
|
- AbstractGraphModel &model = ngo.graphModel();
|
|
|
- NodeId const nodeId = ngo.nodeId();
|
|
|
+ AbstractGraphModel &model = ngo.graphModel();
|
|
|
+ NodeId const nodeId = ngo.nodeId();
|
|
|
AbstractNodeGeometry &geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
|
|
|
if (!model.nodeData(nodeId, NodeRole::CaptionVisible).toBool())
|
|
@@ -219,18 +213,16 @@ void DefaultNodePainter::drawNodeCaption(QPainter *painter, NodeGraphicsObject &
|
|
|
|
|
|
void DefaultNodePainter::drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const
|
|
|
{
|
|
|
- AbstractGraphModel &model = ngo.graphModel();
|
|
|
- NodeId const nodeId = ngo.nodeId();
|
|
|
+ AbstractGraphModel &model = ngo.graphModel();
|
|
|
+ NodeId const nodeId = ngo.nodeId();
|
|
|
AbstractNodeGeometry &geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
|
|
|
QJsonDocument json = QJsonDocument::fromVariant(model.nodeData(nodeId, NodeRole::Style));
|
|
|
NodeStyle nodeStyle(json.object());
|
|
|
|
|
|
- for (PortType portType : {PortType::Out, PortType::In}) {
|
|
|
- unsigned int n = model.nodeData<unsigned int>(nodeId,
|
|
|
- (portType == PortType::Out)
|
|
|
- ? NodeRole::OutPortCount
|
|
|
- : NodeRole::InPortCount);
|
|
|
+ for (PortType portType : { PortType::Out, PortType::In }) {
|
|
|
+ unsigned int n = model.nodeData<unsigned int>(
|
|
|
+ nodeId, (portType == PortType::Out) ? NodeRole::OutPortCount : NodeRole::InPortCount);
|
|
|
|
|
|
for (PortIndex portIndex = 0; portIndex < n; ++portIndex) {
|
|
|
auto const &connected = model.connections(nodeId, portType, portIndex);
|
|
@@ -259,8 +251,8 @@ void DefaultNodePainter::drawEntryLabels(QPainter *painter, NodeGraphicsObject &
|
|
|
|
|
|
void DefaultNodePainter::drawResizeRect(QPainter *painter, NodeGraphicsObject &ngo) const
|
|
|
{
|
|
|
- AbstractGraphModel &model = ngo.graphModel();
|
|
|
- NodeId const nodeId = ngo.nodeId();
|
|
|
+ AbstractGraphModel &model = ngo.graphModel();
|
|
|
+ NodeId const nodeId = ngo.nodeId();
|
|
|
AbstractNodeGeometry &geometry = ngo.nodeScene()->nodeGeometry();
|
|
|
|
|
|
if (model.nodeFlags(nodeId) & NodeFlag::Resizable) {
|
|
@@ -270,4 +262,4 @@ void DefaultNodePainter::drawResizeRect(QPainter *painter, NodeGraphicsObject &n
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-} // namespace QtNodes
|
|
|
+} // namespace QtNodes
|