void graphitemclass::addMyLine(lineclass *lclass){ MyPaintLine.append(lclass); for(int i = 0; i < MyPaintLine.count(); i++) { MyPaintLine.at(i)->updatePosition(); }}
void lineclass::updatePosition(){ QLineF line(mapFromItem(_beginItem, 0, 0), mapFromItem(_endItem, 0, 0)); setLine(line);}
void lineclass::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ if(_beginItem->collidesWithItem(_endItem)) return; QLineF BegToEndItemLine(_beginItem->scenePos(), _endItem->scenePos()); QRectF pp = _endItem->sceneBoundingRect(); QPolygonF _endPolygon = _endItem->polygon(); QPointF p1 = _endPolygon.first() + _endItem->pos(); QPointF p2, _point; QLineF polyLine; int i; for(i = 1; i < _endPolygon.count(); ++i) { p2 = _endPolygon.at(i) + _endItem->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersT = polyLine.intersect(BegToEndItemLine, &_point); if(intersT == QLineF::BoundedIntersection) break; p1 = p2; }this->setLine(QLineF(pervPolygon, vtorPolygon)); if(K7Line != NULL) painter->setPen(QPen(Qt::black, 4, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin)); if(p296Line != NULL) painter->setPen(QPen(Qt::black, 4, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); if(p2Line != NULL) painter->setPen(QPen(Qt::black, 4, Qt::DotLine, Qt::RoundCap, Qt::RoundJoin)); if(p268Line != NULL) painter->setPen(QPen(Qt::black, 4, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin)); if(p269Line != NULL) painter->setPen(QPen(Qt::black, 4, Qt::DashDotDotLine, Qt::RoundCap, Qt::RoundJoin)); if(p274Line != NULL) painter->setPen(QPen(Qt::green, 4, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); if(shLine != NULL) painter->setPen(QPen(Qt::gray, 4, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin)); painter->setRenderHint(QPainter::Antialiasing, true); painter->setBrush(Qt::black); painter->drawLine(line()); painter->drawPolygon(linePolygon); if (isSelected()) { painter->setPen(QPen(Qt::black, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); }}