TrackActivities ViewInteractionItemDrawer::AddTrackingVertex( const QPointF &src, bool force) { QPainterPath p = _vitem->path(); QList<QPolygonF> ps = p.toSubpathPolygons(); Q_ASSERT(ps.size() <= 1); Q_ASSERT(_vitem->_feature != nullptr); Q_ASSERT(_vitem->_feature->paths().size() == 1); _vitem->ClearTempItems(); TrackActivities ret; int n = _vitem->_feature->get_geometry(0).size(); if (n == 0) { ret = TryTrackingMulti(src); if (force && ret.is_tracked()) { _vitem->add_temp_vertex(ret.closest()._vpos); } } else { Q_ASSERT(p.elementCount() == n || p.elementCount() == n + 1); if (p.elementCount() == n) { p.lineTo(src); } else { ret = TryTrackingMulti(src); if (force && ret.is_tracked()) { p.setElementPositionAt(n, ret.closest()._vpos.x(), ret.closest()._vpos.y()); _vitem->add_temp_vertex(ret.closest()._vpos); } else { p.setElementPositionAt(n, src.x(), src.y()); } } } _vitem->setPath(p); return force ? ret : TrackActivities(); }
/*! \overload Creates and returns a QPainterPath object that is a copy of the given \a path, mapped into the coordinate system defined by this matrix. */ QPainterPath QMatrix::map(const QPainterPath &path) const { if (path.isEmpty()) return QPainterPath(); QPainterPath copy = path; // Translate or identity if (_m11 == 1.0 && _m22 == 1.0 && _m12 == 0.0 && _m21 == 0.0) { // Translate if (_dx != 0.0 || _dy != 0.0) { copy.detach(); for (int i=0; i<path.elementCount(); ++i) { QPainterPath::Element &e = copy.d_ptr->elements[i]; e.x += _dx; e.y += _dy; } } // Full xform } else { copy.detach(); for (int i=0; i<path.elementCount(); ++i) { QPainterPath::Element &e = copy.d_ptr->elements[i]; qreal fx = e.x, fy = e.y; e.x = _m11*fx + _m21*fy + _dx; e.y = _m12*fx + _m22*fy + _dy; } } return copy; }
void UBEditableGraphicsPolygonItem::addPoint(const QPointF & point) { QPainterPath painterPath = path(); if (painterPath.elementCount() == 0) { painterPath.moveTo(point); // For the first point added, we must use moveTo(). setPath(painterPath); mStartEndPoint[0] = point; } else { // If clic on first point, close the polygon // TODO à terme : utiliser la surface de la première poignée. QPointF pointDepart(painterPath.elementAt(0).x, painterPath.elementAt(0).y); QPointF pointFin(painterPath.elementAt(painterPath.elementCount()-1).x, painterPath.elementAt(painterPath.elementCount()-1).y); QGraphicsEllipseItem poigneeDepart(pointDepart.x()-10, pointDepart.y()-10, 20, 20); QGraphicsEllipseItem poigneeFin(pointFin.x()-10, pointFin.y()-10, 20, 20); if (poigneeDepart.contains(point)) { setClosed(true); } else { if(poigneeFin.contains(point)){ mIsInCreationMode = false; mOpened = true; }else{ painterPath.lineTo(point); setPath(painterPath); } } mStartEndPoint[1] = point; } if(!mClosed && !mOpened){ UBFreeHandle *handle = new UBFreeHandle(); addHandle(handle); handle->setParentItem(this); handle->setEditableObject(this); handle->setPos(point); handle->setId(path().elementCount()-1); handle->hide(); } }
void UBGraphicsPathItem::updateHandle(UBAbstractHandle *handle) { setSelected(true); Delegate()->showFrame(false); int id = handle->getId(); QPainterPath oldPath = path(); QPainterPath newPath; if(mClosed && id == 0){ newPath.moveTo(handle->pos()); for(int i = 1; i < oldPath.elementCount()-1; i++){ newPath.lineTo(oldPath.elementAt(i).x, oldPath.elementAt(i).y); } newPath.lineTo(handle->pos()); }else{ for(int i = 0; i < oldPath.elementCount(); i++){ if(i == 0){ if(i == id){ newPath.moveTo(handle->pos()); }else{ newPath.moveTo(oldPath.elementAt(i).x, oldPath.elementAt(i).y); } }else{ if(i == id){ newPath.lineTo(handle->pos()); }else{ newPath.lineTo(oldPath.elementAt(i).x, oldPath.elementAt(i).y); } } } } setPath(newPath); if(fillingProperty()->gradient()){ QLinearGradient g(path().boundingRect().topLeft(), path().boundingRect().topRight()); g.setColorAt(0, fillingProperty()->gradient()->stops().at(0).second); g.setColorAt(1, fillingProperty()->gradient()->stops().at(1).second); setFillingProperty(new UBFillProperty(g)); } }
void QgsDxfPaintEngine::drawPath( const QPainterPath& path ) { int pathLength = path.elementCount(); for ( int i = 0; i < pathLength; ++i ) { const QPainterPath::Element& pathElem = path.elementAt( i ); if ( pathElem.type == QPainterPath::MoveToElement ) { moveTo( pathElem.x, pathElem.y ); } else if ( pathElem.type == QPainterPath::LineToElement ) { lineTo( pathElem.x, pathElem.y ); } else if ( pathElem.type == QPainterPath::CurveToElement ) { curveTo( pathElem.x, pathElem.y ); } else if ( pathElem.type == QPainterPath::CurveToDataElement ) { mCurrentCurve.append( QPointF( pathElem.x, pathElem.y ) ); } } endCurve(); endPolygon(); }
QString PolaroidBorderDrawer::pathToSvg(const QPainterPath & path) const { int count = path.elementCount(); QString str_path_d; for (int i = 0; i < count; ++i) { QPainterPath::Element e = path.elementAt(i); switch (e.type) { case QPainterPath::LineToElement: str_path_d.append("L " + QString::number(e.x) + ' ' + QString::number(e.y) + ' '); break; case QPainterPath::MoveToElement: str_path_d.append("M " + QString::number(e.x) + ' ' + QString::number(e.y) + ' '); break; case QPainterPath::CurveToElement: str_path_d.append("C " + QString::number(e.x) + ' ' + QString::number(e.y) + ' '); break; case QPainterPath::CurveToDataElement: str_path_d.append(QString::number(e.x) + ' ' + QString::number(e.y) + ' '); break; } } str_path_d.append("z"); return str_path_d; }
//============================================================================= int sstQt01PathStoreViewCls::AppendPathSymbol(int iKey, QPainterPath oTmpPath, sstQt01ShapeType_enum eTmpPathType, QColor oTmpColor, QPen oTmpPen) { //----------------------------------------------------------------------------- if ( iKey != 0) return -1; int iEleNum = oTmpPath.elementCount(); for (int ii =1; ii <= iEleNum; ii++) { sstQt01PathElementCsv3Cls oShapeItemCsv; QPainterPath::Element oElement; oElement = oTmpPath.elementAt(ii-1); oShapeItemCsv.setAll(oElement.type,oElement.x,oElement.y, oTmpColor); if (oElement.type == 0) { oShapeItemCsv.setIPenStyle(oTmpPen.style()); oShapeItemCsv.setIPenWidth(oTmpPen.width()); oShapeItemCsv.setShapeType(eTmpPathType); } } return 0; }
//============================================================================= void sstQt01PathPaintWidgetCls::createShapeItem(const QPainterPath &path, // const QString &toolTip, const QPoint &pos, const QColor &color, const QPen &oPen, const sstQt01ShapeType_enum eShapeType) { sstQt01ShapeItem shapeItem; shapeItem.setPath(path); // shapeItem.setToolTip(toolTip); shapeItem.setPosition(pos); shapeItem.setColor(color); shapeItem.setPen(oPen); shapeItem.setShapeType(eShapeType); // Generate tooltip (Type and row number) std::string oTooltipStr; sstQt01ShapeTypeCls oShapeType; oShapeType.Enm2Str( 0, eShapeType, &oTooltipStr); sstStr01Cls oStrCnvt; oStrCnvt.Csv_UInt4_2String(0,this->oPathStorage->RecordCount()+1,&oTooltipStr); QString oQTooltipStr; oQTooltipStr.append(oTooltipStr.c_str()); shapeItem.setToolTip(oQTooltipStr); int iBegin=0; int iEnd=0; // Insert rows at end of table iBegin = (int) this->oPathStorage->RecordCount() +1; iEnd = iBegin + (int) path.elementCount() -1; emit sstSgnlBeginInsertRows(iBegin,iEnd); this->oPathStorage->appendShapeItem(shapeItem); emit sstSgnlEndInsertRows(); update(); }
void tst_QPainterPath::testArcMoveTo() { QFETCH(QRectF, rect); QFETCH(qreal, angle); QPainterPath path; path.arcMoveTo(rect, angle); path.arcTo(rect, angle, 30); path.arcTo(rect, angle + 30, 30); QPointF pos = path.elementAt(0); QVERIFY((path.elementCount()-1) % 3 == 0); qreal x_radius = rect.width() / 2.0; qreal y_radius = rect.height() / 2.0; QPointF shouldBe = rect.center() + QPointF(x_radius * cos(ANGLE(angle)), -y_radius * sin(ANGLE(angle))); qreal iw = 1 / rect.width(); qreal ih = 1 / rect.height(); QVERIFY(pathFuzzyCompare(pos.x() * iw, shouldBe.x() * iw)); QVERIFY(pathFuzzyCompare(pos.y() * ih, shouldBe.y() * ih)); }
void QJsonPaintEngine::drawPath(const QPainterPath &path) { Q_D(QJsonPaintEngine); #ifdef QT_PICTURE_DEBUG qDebug() << " -> drawPath():" << path.boundingRect(); #endif QString command; d->s << QString("\t{\"p\": \r\n\t\t[\r\n"); for(int i=0; i< path.elementCount(); i++) { QPainterPath::Element e = path.elementAt(i); switch (e.type) { case QPainterPath::MoveToElement: command = QString("\t\t{\"m\": {\"x\": %1, \"y\":%2}},\r\n").arg(e.x).arg(e.y); break; case QPainterPath::LineToElement: command = QString("\t\t{\"l\": {\"x\": %1, \"y\":%2}},\r\n").arg(e.x).arg(e.y); break; case QPainterPath::CurveToElement: command = QString("\t\t{\"a\": (\"x1\": %1, \"y1\": %2, \"x2\": %3, \"y2\": %4}},\r\n").arg(d->pos.x()).arg(d->pos.y()).arg(e.x).arg(e.y); break; case QPainterPath::CurveToDataElement: command = QString("\t\t{\"ax\": (\"x1\": %1, \"y2\": %2, \"x2\": %3, \"y2\": %4}},\r\n").arg(d->pos.x()).arg(d->pos.y()).arg(e.x).arg(e.y); break; default: break; } d->s << command; d->pos.setX(e.x); d->pos.setX(e.y); } d->s << QString("\t\t]\r\n\t},\r\n"); }
//============================================================================= int sstQt01PathStoreViewCls::appendItemSymbol(sstQt01ShapeItem oItem) { // Append to element table QPainterPath oPath = oItem.getPath(); int iStat = this->AppendPathSymbol(0,oPath,oItem.getShapeType(), oItem.getColor(),oItem.getPen()); assert(iStat >= 0); // Append to main table sstQt01PathMainRecCls oMainRec; oMainRec.setQCol(oItem.getColor()); oMainRec.setPosition(oItem.getPosition()); int iNumElements = oPath.elementCount(); dREC04RECNUMTYP dLastRecNo = 0; oMainRec.setStartElementRecNo(dLastRecNo-iNumElements+1); oMainRec.setNumElements(iNumElements); oMainRec.setShapeType(oItem.getShapeType()); QString oToolTipStr = oItem.getToolTip(); oMainRec.setTooltip(oToolTipStr.toStdString()); // Store Extern Id for example dxf in sstPathStorage dREC04RECNUMTYP dExternId = oItem.getExternId(); oMainRec.setExternId(dExternId); dREC04RECNUMTYP dRecNo = 0; // move position from main table to element table this->addPositionSym(dRecNo); return iStat; }
QPainterPath PathDeformRenderer::lensDeform(const QPainterPath &source, const QPointF &offset) { QPainterPath path; path.addPath(source); qreal flip = m_intensity / qreal(100); for (int i=0; i<path.elementCount(); ++i) { const QPainterPath::Element &e = path.elementAt(i); qreal x = e.x + offset.x(); qreal y = e.y + offset.y(); qreal dx = x - m_pos.x(); qreal dy = y - m_pos.y(); qreal len = m_radius - qSqrt(dx * dx + dy * dy); if (len > 0) { path.setElementPositionAt(i, x + flip * dx * len / m_radius, y + flip * dy * len / m_radius); } else { path.setElementPositionAt(i, x, y); } } return path; }
QList<QPointF> Geometry::intersection(QLineF const &line, QPainterPath const &path, qreal eps) { QList<QPointF> result; QPointF startPoint; QPointF endPoint; for (int i = 0; i < path.elementCount(); ++i) { QPainterPath::Element const element = path.elementAt(i); // Checking that element belongs to the wall path if (element.isMoveTo()) { endPoint = QPointF(element.x, element.y); continue; } startPoint = endPoint; endPoint = QPointF(element.x, element.y); QLineF currentLine(startPoint, endPoint); QPointF intersectionPoint; // TODO: consider curve cases if (line.intersect(currentLine, &intersectionPoint) != QLineF::NoIntersection && belongs(intersectionPoint, currentLine, eps)) { result << intersectionPoint; } } return result; }
bool Editor::moved( const QPoint& pos ) { if ( plot() == NULL ) return false; const QwtScaleMap xMap = plot()->canvasMap( d_editedItem->xAxis() ); const QwtScaleMap yMap = plot()->canvasMap( d_editedItem->yAxis() ); const QPointF p1 = QwtScaleMap::invTransform( xMap, yMap, d_currentPos ); const QPointF p2 = QwtScaleMap::invTransform( xMap, yMap, pos ); #if QT_VERSION >= 0x040600 const QPainterPath shape = d_editedItem->shape().translated( p2 - p1 ); #else const double dx = p2.x() - p1.x(); const double dy = p2.y() - p1.y(); QPainterPath shape = d_editedItem->shape(); for ( int i = 0; i < shape.elementCount(); i++ ) { const QPainterPath::Element &el = shape.elementAt( i ); shape.setElementPositionAt( i, el.x + dx, el.y + dy ); } #endif d_editedItem->setShape( shape ); d_currentPos = pos; return true; }
static QPainterPath qwtTransformPath( const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QPainterPath &path, bool doAlign ) { QPainterPath shape; shape.setFillRule( path.fillRule() ); for ( int i = 0; i < path.elementCount(); i++ ) { const QPainterPath::Element &element = path.elementAt( i ); double x = xMap.transform( element.x ); double y = yMap.transform( element.y ); switch( element.type ) { case QPainterPath::MoveToElement: { if ( doAlign ) { x = qRound( x ); y = qRound( y ); } shape.moveTo( x, y ); break; } case QPainterPath::LineToElement: { if ( doAlign ) { x = qRound( x ); y = qRound( y ); } shape.lineTo( x, y ); break; } case QPainterPath::CurveToElement: { const QPainterPath::Element& element1 = path.elementAt( ++i ); const double x1 = xMap.transform( element1.x ); const double y1 = yMap.transform( element1.y ); const QPainterPath::Element& element2 = path.elementAt( ++i ); const double x2 = xMap.transform( element2.x ); const double y2 = yMap.transform( element2.y ); shape.cubicTo( x, y, x1, y1, x2, y2 ); break; } case QPainterPath::CurveToDataElement: { break; } } } return shape; }
//============================================================================= int sstQt01PathPaintWidgetCls::updateTooltips (int iKey) //----------------------------------------------------------------------------- { // QPoint oPnt(0,0); QPainterPath *poPath; QColor oColor; int iPathNo = 0; int iRet = 0; int iStat = 0; int iStat1 = 0; //----------------------------------------------------------------------------- if ( iKey != 0) return -1; // read next path from shape item table poPath = new (QPainterPath); iStat1 = this->oPathStorage->ReadNextPath( 0, poPath, &oColor); while (iStat1 >= 0) { iPathNo++; int iElements = poPath->elementCount(); assert(iElements > 0); switch (iElements) { case 2: this->oPathStorage->setToolTip( iPathNo, tr("Line")); break; case 4: this->oPathStorage->setToolTip( iPathNo, tr("Triangle")); break; case 5: this->oPathStorage->setToolTip( iPathNo, tr("Square")); break; case 13: this->oPathStorage->setToolTip( iPathNo, tr("Circle")); break; default: this->oPathStorage->setToolTip( iPathNo, tr("Object")); // assert(0); break; } delete poPath; poPath = new (QPainterPath); iStat1 = this->oPathStorage->ReadNextPath( 0, poPath, &oColor); } delete poPath; assert(iRet >= 0); // Small Errors will given back iRet = iStat; return iRet; }
static QPolygonF polygonFromPainterPath( const QPainterPath &pp ) { QPolygonF ret; for ( int i = 0; i < pp.elementCount(); i++ ) { const QPainterPath::Element& el = pp.elementAt( i ); Q_ASSERT( el.type == QPainterPath::MoveToElement || el.type == QPainterPath::LineToElement ); ret.append( el ); } return ret; }
static QLineF labelAttachmentLine( const QPointF ¢er, const QPointF &start, const QPainterPath &label ) { Q_ASSERT ( label.elementCount() == 5 ); // start is assumed to lie on the outer rim of the slice(!), making it possible to derive the // radius of the pie const qreal pieRadius = QLineF( center, start ).length(); // don't draw a line at all when the label is connected to its slice due to at least one of its // corners falling inside the slice. for ( int i = 0; i < 4; i++ ) { // point 4 is just a duplicate of point 0 if ( QLineF( label.elementAt( i ), center ).length() < pieRadius ) { return QLineF(); } } // find the closest edge in the polygon, and its two neighbors QPointF closeCorners[3]; { QPointF closest = QPointF( 1000000, 1000000 ); int closestIndex = 0; // better misbehave than crash for ( int i = 0; i < 4; i++ ) { // point 4 is just a duplicate of point 0 QPointF p = label.elementAt( i ); if ( QLineF( p, center ).length() < QLineF( closest, center ).length() ) { closest = p; closestIndex = i; } } closeCorners[ 0 ] = label.elementAt( wraparound( closestIndex - 1, 4 ) ); closeCorners[ 1 ] = closest; closeCorners[ 2 ] = label.elementAt( wraparound( closestIndex + 1, 4 ) ); } QLineF edge1 = QLineF( closeCorners[ 0 ], closeCorners[ 1 ] ); QLineF edge2 = QLineF( closeCorners[ 1 ], closeCorners[ 2 ] ); QLineF connection1 = QLineF( ( closeCorners[ 0 ] + closeCorners[ 1 ] ) / 2.0, center ); QLineF connection2 = QLineF( ( closeCorners[ 1 ] + closeCorners[ 2 ] ) / 2.0, center ); QLineF ret; // prefer the connecting line meeting its edge at a more perpendicular angle if ( normProjection( edge1, connection1 ) < normProjection( edge2, connection2 ) ) { ret = connection1; } else { ret = connection2; } // This tends to look a bit better than not doing it *shrug* ret.setP2( ( start + center ) / 2.0 ); // make the line end at the rim of the slice (not 100% accurate because the line is not precisely radial) qreal p1Radius = QLineF( ret.p1(), center ).length(); ret.setLength( p1Radius - pieRadius ); return ret; }
void QGIViewPart::dumpPath(const char* text,QPainterPath path) { QPainterPath::Element elem; Base::Console().Message(">>>%s has %d elements\n",text,path.elementCount()); char* typeName; for(int iElem = 0; iElem < path.elementCount(); iElem++) { elem = path.elementAt(iElem); if(elem.isMoveTo()) { typeName = "MoveTo"; } else if (elem.isLineTo()) { typeName = "LineTo"; } else if (elem.isCurveTo()) { typeName = "CurveTo"; } else { typeName = "Unknown"; } Base::Console().Message(">>>>> element %d: type:%d/%s pos(%.3f,%.3f) M:%d L:%d C:%d\n",iElem, elem.type,typeName,elem.x,elem.y,elem.isMoveTo(),elem.isLineTo(),elem.isCurveTo()); } }
static inline void qwtRevertPath( QPainterPath &path ) { if ( path.elementCount() == 4 ) { QPainterPath::Element el0 = path.elementAt(0); QPainterPath::Element el3 = path.elementAt(3); path.setElementPositionAt( 0, el3.x, el3.y ); path.setElementPositionAt( 3, el0.x, el0.y ); } }
void tst_QPainterPath::testSimplified() { QFETCH(QPainterPath, path); QFETCH(int, elements); QPainterPath simplified = path.simplified(); QCOMPARE(simplified.elementCount(), elements); QVERIFY(simplified.subtracted(path).isEmpty()); QVERIFY(path.subtracted(simplified).isEmpty()); }
QString QTikzPicturePrivate::toTikzPath(const QPainterPath & path) const { if (path.isEmpty()) return QString(); QStringList pathList; QString currentPath; int currentControlPoint = 0; // convert QPainterPath to a TikZ path string for (int i = 0; i < path.elementCount(); i++) { const QPainterPath::Element & element = path.elementAt(i); switch (element.type) { case QPainterPath::MoveToElement: { // close current path + append to path list if (!currentPath.isEmpty()) { currentPath += " -- cycle"; pathList << currentPath; } // indent with spaces for better readability const char * indentString = pathList.count() ? " " : ""; // start new path currentPath.clear(); currentPath += indentString + toCoord(element); break; } case QPainterPath::LineToElement: { currentPath += " -- " + toCoord(element); break; } case QPainterPath::CurveToElement: { currentPath += " .. controls " + toCoord(element); currentControlPoint = 1; break; } case QPainterPath::CurveToDataElement: { if (currentControlPoint == 1) { currentPath += " and " + toCoord(element); ++currentControlPoint; } else if (currentControlPoint == 2) { currentPath += " .. " + toCoord(element); currentControlPoint = 0; } break; } } } return pathList.join("\n"); }
static inline void qwtRevertPath( QPainterPath &path ) { if ( path.elementCount() == 4 ) { QPainterPath::Element &el0 = const_cast<QPainterPath::Element &>( path.elementAt(0) ); QPainterPath::Element &el2 = const_cast<QPainterPath::Element &>( path.elementAt(3) ); qSwap( el0.x, el2.x ); qSwap( el0.y, el2.y ); } }
QString TupPathItem::pathToString() const { QPainterPath route = path(); QString strPath = ""; QChar t; int total = route.elementCount(); for(int i=0; i < total; i++) { QPainterPath::Element e = route.elementAt(i); switch (e.type) { case QPainterPath::MoveToElement: { if (t != 'M') { t = 'M'; strPath += "M " + QString::number(e.x) + " " + QString::number(e.y) + " "; } else { strPath += QString::number(e.x) + " " + QString::number(e.y) + " "; } } break; case QPainterPath::LineToElement: { if (t != 'L') { t = 'L'; strPath += " L " + QString::number(e.x) + " " + QString::number(e.y) + " "; } else { strPath += QString::number(e.x) + " " + QString::number(e.y) + " "; } } break; case QPainterPath::CurveToElement: { if (t != 'C') { t = 'C'; strPath += " C " + QString::number(e.x) + " " + QString::number(e.y) + " "; } else { strPath += " " + QString::number(e.x) + " " + QString::number(e.y) + " "; } } break; case QPainterPath::CurveToDataElement: { if (t == 'C') strPath += " " + QString::number(e.x) + " " + QString::number(e.y) + " "; } break; } } return strPath; }
void tst_QPainterPath::translate() { QPainterPath path; // Path with no elements. QCOMPARE(path.currentPosition(), QPointF()); path.translate(50.5, 50.5); QCOMPARE(path.currentPosition(), QPointF()); QCOMPARE(path.translated(50.5, 50.5).currentPosition(), QPointF()); // path.isEmpty(), but we have one MoveTo element that should be translated. path.moveTo(50, 50); QCOMPARE(path.currentPosition(), QPointF(50, 50)); path.translate(99.9, 99.9); QCOMPARE(path.currentPosition(), QPointF(149.9, 149.9)); path.translate(-99.9, -99.9); QCOMPARE(path.currentPosition(), QPointF(50, 50)); QCOMPARE(path.translated(-50, -50).currentPosition(), QPointF(0, 0)); // Complex path. QRegion shape(100, 100, 300, 200, QRegion::Ellipse); shape -= QRect(225, 175, 50, 50); QPainterPath complexPath; complexPath.addRegion(shape); QVector<QPointF> untranslatedElements; for (int i = 0; i < complexPath.elementCount(); ++i) untranslatedElements.append(QPointF(complexPath.elementAt(i))); const QPainterPath untranslatedComplexPath(complexPath); const QPointF offset(100, 100); complexPath.translate(offset); for (int i = 0; i < complexPath.elementCount(); ++i) QCOMPARE(QPointF(complexPath.elementAt(i)) - offset, untranslatedElements.at(i)); QCOMPARE(complexPath.translated(-offset), untranslatedComplexPath); }
void UBEditableGraphicsRegularShapeItem::addPoint(const QPointF & point) { QPainterPath painterPath = path(); if (painterPath.elementCount() == 0) { painterPath.moveTo(point); // For the first point added, we must use moveTo(). } else { painterPath.lineTo(point); } setPath(painterPath); }
QPainterPath LensItem::lensDeform(const QPainterPath &source, const QPointF &offset, double m_radius, double s) { QPainterPath path; path.addPath(source); for (int i = 0; i < path.elementCount(); ++i) { const QPainterPath::Element &e = path.elementAt(i); double dx = e.x - offset.x(); double dy = e.y - offset.y(); double len = m_radius - sqrt(dx * dx + dy * dy); if (len > 0) path.setElementPositionAt(i, e.x - s * dx * len / m_radius, e.y - s * dy * len / m_radius); } return path; }
QPainterPath MapObjectItem::shape() const { QPainterPath path = mMapDocument->renderer()->shape(mObject); #if QT_VERSION >= 0x040600 path.translate(-pos()); #else const QPointF p = pos(); const int elementCount = path.elementCount(); for (int i = 0; i < elementCount; i++) { const QPainterPath::Element &element = path.elementAt(i); path.setElementPositionAt(i, element.x - p.x(), element.y - p.y()); } #endif return path; }
QPainterPath trySimplifyPath(const QPainterPath &path, qreal lengthThreshold) { QPainterPath newPath; QPointF startPoint; qreal distance = 0; int count = path.elementCount(); for (int i = 0; i < count; i++) { QPainterPath::Element e = path.elementAt(i); QPointF endPoint = QPointF(e.x, e.y); switch (e.type) { case QPainterPath::MoveToElement: newPath.moveTo(endPoint); break; case QPainterPath::LineToElement: if (!tryMergePoints(newPath, startPoint, endPoint, distance, lengthThreshold, i == count - 1)) { newPath.lineTo(endPoint); } break; case QPainterPath::CurveToElement: { Q_ASSERT(i + 2 < count); if (!tryMergePoints(newPath, startPoint, endPoint, distance, lengthThreshold, i == count - 1)) { e = path.elementAt(i + 1); Q_ASSERT(e.type == QPainterPath::CurveToDataElement); QPointF ctrl1 = QPointF(e.x, e.y); e = path.elementAt(i + 2); Q_ASSERT(e.type == QPainterPath::CurveToDataElement); QPointF ctrl2 = QPointF(e.x, e.y); newPath.cubicTo(ctrl1, ctrl2, endPoint); } i += 2; } default: ; } startPoint = endPoint; } return newPath; }
void UBGraphicsFreehandItem::addPoint(const QPointF & point) { prepareGeometryChange(); QPainterPath painterPath = path(); if (painterPath.elementCount() == 0) { painterPath.moveTo(point); // For the first point added, we must use moveTo(). } else { painterPath.lineTo(point); } setPath(painterPath); update(); }