本文整理汇总了C++中NodeBase::getGuiItem方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeBase::getGuiItem方法的具体用法?C++ NodeBase::getGuiItem怎么用?C++ NodeBase::getGuiItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeBase
的用法示例。
在下文中一共展示了NodeBase::getGuiItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updatePaintNode
QSGNode* NodeConnectionLines::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*) {
if (!m_nodeObject) return nullptr;
const QVector<QPointer<NodeBase>>& connectedNodes = m_nodeObject->getConnectedNodes();
int connectionCount = connectedNodes.size();
// -------------------- Prepare QSG Nodes:
QSGNode* parentNode = oldNode;
if (!oldNode) {
parentNode = new QSGNode();
} else {
// update color in case it changed:
// FIXME: is there a more efficient way to do this?
for (int i=0; i<parentNode->childCount(); ++i) {
QSGGeometryNode* childNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(i));
if (!childNode) continue;
QSGFlatColorMaterial* material = static_cast<QSGFlatColorMaterial*>(childNode->material());
if (!material) continue;
material->setColor(m_color);
}
}
// adapt child count:
int childCount = parentNode->childCount();
if (childCount < connectionCount) {
for (int i=0; i<(connectionCount - childCount); ++i) {
QSGGeometryNode* node = new QSGGeometryNode;
QSGGeometry* geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3);
geometry->setDrawingMode(GL_TRIANGLE_STRIP);
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
QSGFlatColorMaterial* material = new QSGFlatColorMaterial;
material->setColor(m_color);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);
parentNode->appendChildNode(node);
}
} else if (childCount > connectionCount) {
for (int i=0; i<(childCount - connectionCount); ++i) {
parentNode->removeChildNode(parentNode->childAtIndex(0));
}
}
Q_ASSERT(parentNode->childCount() == connectionCount);
// calculate common start point:
const QPointF p0(width(), height() / 2);
double widthOffset = m_lineWidth / 2;
//const QPointF posInScene = mapToScene(QPointF(0, 0));
for (int i=0; i<connectionCount; ++i) {
NodeBase* otherNode = connectedNodes[i];
if (!otherNode) continue;
QQuickItem* otherGuiItem = otherNode->getGuiItem();
if (!otherGuiItem) continue;
const QPointF p3 = mapFromItem(otherGuiItem, QPointF(-otherGuiItem->width() / 2, otherGuiItem->height() / 2));
int handleLength = std::max(50, std::min(int(p3.x() - p0.x()), 80));
const QPointF p1(p0.x() + handleLength, p0.y());
const QPointF p2(p3.x() - handleLength, p3.y());
// calculate reasonable segment count:
int segmentCount = qMax(16.0, qMin(qAbs(p3.y() - p0.y()) / 25, 50.0));
int verticesCount = segmentCount * 2;
QSGGeometryNode* qsgNode = static_cast<QSGGeometryNode*>(parentNode->childAtIndex(i));
if (!qsgNode) continue;
QSGGeometry* geometry = qsgNode->geometry();
if (!geometry) continue;
geometry->allocate(verticesCount);
QSGGeometry::Point2D* vertices = geometry->vertexDataAsPoint2D();
// triangulate cubic bezier curve:
for (int i = 0; i < segmentCount; ++i) {
// t is the position on the line:
const qreal t = i / qreal(segmentCount - 1);
// pos is the point on the curve at "t":
const QPointF pos = calculateBezierPoint(t, p0, p1, p2, p3);
// normal is the normal vector at that point
const QPointF normal = normalFromTangent(calculateBezierTangent(t, p0, p1, p2, p3));
// first is a point offsetted in the normal direction by lineWidth / 2 from pos
const QPointF first = pos - normal * widthOffset;
// ssecond is a point offsetted in the negative normal direction by lineWidth / 2 from pos
const QPointF second = pos + normal * widthOffset;
// add first and second as vertices to this geometry:
vertices[i*2].set(first.x(), first.y());
vertices[i*2+1].set(second.x(), second.y());
}
// tell Scene Graph that this items needs to be drawn:
qsgNode->markDirty(QSGNode::DirtyGeometry);
}
return parentNode;
}