MCPcopy Create free account
hub / github.com/Linloir/GraphBuilder / drawLine

Method drawLine

graph_view.cpp:764–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

762}
763
764void MyGraphicsLineItem::drawLine(){
765 //draw invisible line
766 this->setLine(sP.x(), sP.y(), eP.x(), eP.y());
767 //this->setPen(curPen);
768 QPen bgPen;
769 bgPen.setColor(QColor(255, 255, 255, 0));
770 bgPen.setWidth(lineWidth + 5);
771 this->setPen(bgPen);
772
773 if(line1){
774 scene()->removeItem(line1);
775 line1 = nullptr;
776 }
777 if(line2){
778 scene()->removeItem(line2);
779 line2 = nullptr;
780 }
781
782 center = (startVex->scenePos() + startVex->rect().center() + endVex->scenePos() + endVex->rect().center())/2;
783
784 drawText();
785
786 if(text != "" && (eP - center).x() * (sP - center).x() <= 0){
787 qreal dx = 0;
788 qreal dy = 0;
789 int f1 = 1, f2 = 1;
790 if(textItem->boundingRect().width() != 0){
791 if(abs(textItem->boundingRect().height() / textItem->boundingRect().width()) < abs(tan(angle))){
792 dx = (textItem->boundingRect().height() + 10) / (2 * tan(angle));
793 dy = (textItem->boundingRect().height() + 10) / 2;
794 f2 = angle > 0 ? -1 : 1;
795 }
796 else{
797 dy = (textItem->boundingRect().width() + 10) * tan(angle) / 2;
798 dx = (textItem->boundingRect().width() + 10) / 2;
799 f1 = tan(angle) < 0 ? -1 : 1;
800 f2 = angle >= 0 ? -1 : 1;
801 }
802 }
803 dx *= f1 * f2;
804 dy *= f1 * f2;
805 QGraphicsLineItem *newLine1 = new QGraphicsLineItem(sP.x(), sP.y(), center.x() + dx, center.y() + dy);
806 QGraphicsLineItem *newLine2 = new QGraphicsLineItem(center.x() - dx, center.y() - dy, eP.x(), eP.y());
807
808 newLine1->setZValue(this->zValue() - 1);
809 newLine2->setZValue(this->zValue() - 1);
810 newLine1->setPen(curPen);
811 newLine2->setPen(curPen);
812
813 scene()->addItem(newLine1);
814 scene()->addItem(newLine2);
815 line1 = newLine1;
816 line2 = newLine2;
817 }
818 else{
819 QGraphicsLineItem *newLine = new QGraphicsLineItem(sP.x(), sP.y(), eP.x(), eP.y());
820 newLine->setPen(curPen);
821 newLine->setZValue(this->zValue() - 1);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected