void ChordLine::read(const QDomElement& de) { path = QPainterPath(); for (QDomElement e = de.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) { QString tag(e.tagName()); if (tag == "Path") { path = QPainterPath(); QPointF curveTo; QPointF p1; int state = 0; for (QDomElement ee = e.firstChildElement(); !ee.isNull(); ee = ee.nextSiblingElement()) { QString tag(ee.tagName()); if (tag == "Element") { int type = ee.attribute("type").toInt(); qreal x = ee.attribute("x").toDouble(); qreal y = ee.attribute("y").toDouble(); switch(QPainterPath::ElementType(type)) { case QPainterPath::MoveToElement: path.moveTo(x, y); break; case QPainterPath::LineToElement: path.lineTo(x, y); break; case QPainterPath::CurveToElement: curveTo.rx() = x; curveTo.ry() = y; state = 1; break; case QPainterPath::CurveToDataElement: if (state == 1) { p1.rx() = x; p1.ry() = y; state = 2; } else if (state == 2) { path.cubicTo(curveTo, p1, QPointF(x, y)); state = 0; } break; } } else domError(ee); } modified = true; setSubtype(ChordLineType(0)); } else if (tag == "subtype") setSubtype(ChordLineType(e.text().toInt())); else if (!Element::readProperties(e)) domError(e); } }
void ChordLine::read(XmlReader& e) { path = QPainterPath(); while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "Path") { path = QPainterPath(); QPointF curveTo; QPointF p1; int state = 0; while (e.readNextStartElement()) { const QStringRef& tag(e.name()); if (tag == "Element") { int type = e.intAttribute("type"); qreal x = e.doubleAttribute("x"); qreal y = e.doubleAttribute("y"); switch(QPainterPath::ElementType(type)) { case QPainterPath::MoveToElement: path.moveTo(x, y); break; case QPainterPath::LineToElement: path.lineTo(x, y); break; case QPainterPath::CurveToElement: curveTo.rx() = x; curveTo.ry() = y; state = 1; break; case QPainterPath::CurveToDataElement: if (state == 1) { p1.rx() = x; p1.ry() = y; state = 2; } else if (state == 2) { path.cubicTo(curveTo, p1, QPointF(x, y)); state = 0; } break; } e.skipCurrentElement(); //needed to go to next Element in Path } else e.unknown(); } modified = true; } else if (tag == "subtype") setChordLineType(ChordLineType(e.readInt())); else if (tag == "straight") setStraight(e.readInt()); else if (tag == "lengthX") setLengthX(e.readInt()); else if (tag == "lengthY") setLengthY(e.readInt()); else if (!Element::readProperties(e)) e.unknown(); } }
void ChordLine::editDrag(const EditData& ed) { int n = path.elementCount(); QPainterPath p; qreal sp = spatium(); qreal dx = ed.delta.x() / sp; qreal dy = ed.delta.y() / sp; for (int i = 0; i < n; ++i) { const QPainterPath::Element& e = path.elementAt(i); qreal x = e.x; qreal y = e.y; if (ed.curGrip == i) { x += dx; y += dy; } switch(e.type) { case QPainterPath::CurveToDataElement: break; case QPainterPath::MoveToElement: p.moveTo(x, y); break; case QPainterPath::LineToElement: p.lineTo(x, y); break; case QPainterPath::CurveToElement: { qreal x2 = path.elementAt(i+1).x; qreal y2 = path.elementAt(i+1).y; qreal x3 = path.elementAt(i+2).x; qreal y3 = path.elementAt(i+2).y; if (i + 1 == ed.curGrip) { x2 += dx; y2 += dy; } else if (i + 2 == ed.curGrip) { x3 += dx; y3 += dy; } p.cubicTo(x, y, x2, y2, x3, y3); i += 2; } break; } } path = p; modified = true; setSubtype(ChordLineType(0)); }