//---------------------------------------------------------------------------------------------- QPainterPath GraphEdgeView::shape() const { QPainterPath path;// = QGraphicsLineItem::shape(); QLineF normal = this->line().unitVector().normalVector(); qreal dx = normal.dx(); qreal dy = normal.dy(); QLineF myLine; myLine = this->line(); myLine.translate(dx * 4, dy * 4); path.lineTo(myLine.p1()); path.lineTo(myLine.p2()); myLine = this->line(); myLine.translate(-dx * 4,-dy * 4); path.lineTo(myLine.p2()); path.lineTo(myLine.p1()); path.closeSubpath(); path.addPolygon(m_arrowHead); return path; }
/*! Show the snap line. fade-in animation is started on the line if the line is positioned at a different place. Before starting the fade-in animation, the fade-out animation is stoped if it is running. */ void HsSnapLine::showLine(const QLineF &snapLine) { QLineF displayLine = snapLine; qreal angle = displayLine.angle(); if (qAbs(angle) == 0.0 || qAbs(angle) == 180.0) { //this is a horizontal line //adding 1 is required below, as the line is 3 pixels wide and is translated by 1 point before displaying if (displayLine.y1() != (line().y1()+1.0) ) { //this horizontal line is at new position horizontally if (isFadeOutAnimationRunning()) { //if fade-out animation is running, stop it, animation is running at old position stopFadeOutAnimation(); } //start fade-in animation at new position. startFadeInAnimation(); } else { //this horizontal line is at the old position horizontally if (isFadeOutAnimationRunning()) { //if fade-out animation is running, stop it, animation is running at old position stopFadeOutAnimation(); //start fade-in animation at the old position startFadeInAnimation(); } } displayLine.translate(0.0, -1.0); } if (qAbs(angle) == 90.0 || qAbs(angle) == 270.0) { //this is a vertical line if (displayLine.x1() != (line().x1()+1)) { //this Vertical line is at different position vertically if (isFadeOutAnimationRunning()) { stopFadeOutAnimation(); } startFadeInAnimation(); } else { if (isFadeOutAnimationRunning()) { stopFadeOutAnimation(); startFadeInAnimation(); } } displayLine.translate(-1.0, 0.0); } QLinearGradient gradient(displayLine.p1(), displayLine.p2()); gradient.setColorAt(0.0, Qt::white); QColor snapLineColor = HbColorScheme::color("qtc_hs_snapguide"); if (!snapLineColor.isValid()) { //if valid color is not loaded from the theme, the darkCyan color is used as a backup.color snapLineColor = Qt::darkCyan; } gradient.setColorAt(0.4, snapLineColor); gradient.setColorAt(0.6, snapLineColor); gradient.setColorAt(1.0, Qt::white); QBrush brush(gradient); QPen pen; pen.setWidth(3); pen.setCapStyle(Qt::RoundCap); pen.setBrush(brush); setPen(pen); setLine(displayLine); show(); }
//! [4] void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (myStartItem->collidesWithItem(myEndItem)) return; QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(myColor); //! [4] //! [5] QLineF centerLine(myStartItem->pos(), myEndItem->pos()); QPolygonF endPolygon = myEndItem->polygon(); QPointF p1 = endPolygon.first() + myEndItem->pos(); QPointF p2; QPointF intersectPoint; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + myEndItem->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } setLine(QLineF(intersectPoint, myStartItem->pos())); //! [5] //! [6] double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; //! [6] //! [7] painter->drawLine(line()); painter->drawPolygon(arrowHead); if (isSelected()) { painter->setPen(QPen(myColor, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } }
void PathLine::paint(QPainter *poPainter, const QStyleOptionGraphicsItem *poOption, QWidget *poWidget) { poPainter->setPen(QPen(Qt::black, 2, Qt::SolidLine)); poPainter->drawLine(line()); if (isSelected()) { poPainter->setPen(QPen(Qt::gray, 1, Qt::DashLine)); QLineF oLine = line(); oLine.translate(0, 4.0); poPainter->drawLine(oLine); oLine.translate(0,-8.0); poPainter->drawLine(oLine); } }
void MazePainter::paint(MazeModel *pModel, QPainter &painter) { if (!pModel->hasMaze()) return; QRect rSize = painter.viewport(); int nMazeWidth = pModel->width(); int nMazeHeight = pModel->height(); float nCellSize = std::min((float)rSize.width()/nMazeWidth, (float)rSize.height()/nMazeHeight); //draw the big left and top walls of the maze QLineF wall; wall.setP1(QPointF(0, 0)); wall.setP2(QPointF(nCellSize, 0)); for (int col = 0; col < nMazeWidth; col++) { if (pModel->cellWalls(col, 0) & MazeModel::UP) painter.drawLine(wall); wall.translate(nCellSize, 0); } wall.setP1(QPointF(0, 0)); wall.setP2(QPointF(0, nCellSize)); for (int row = 0; row < nMazeHeight; row++) { if (pModel->cellWalls(0, row) & MazeModel::LEFT) painter.drawLine(wall); wall.translate(0, nCellSize); } //draw the rest of the maze's walls for (int row = 0; row < nMazeHeight; row++) { QLineF wallDown(0, (row+1)*nCellSize, nCellSize, (row+1)*nCellSize); QLineF wallRight(nCellSize, row*nCellSize, nCellSize, (row+1)*nCellSize); for (int col = 0; col < nMazeWidth; col++) { int walls = pModel->cellWalls(col, row); if (walls & MazeModel::RIGHT) painter.drawLine(wallRight); if (walls & MazeModel::DOWN) painter.drawLine(wallDown); wallDown.translate(nCellSize, 0); wallRight.translate(nCellSize, 0); } } }
/** * This method aligns both the \b "start" and \b "end" symbols to * the current angles of the \b "first" and the \b "last" line * segment respectively. */ void AssociationLine::alignSymbols() { const int sz = m_points.size(); if (sz < 2) { // cannot align if there is no line (one line = 2 points) return; } QList<QPolygonF> polygons = path().toSubpathPolygons(); if (m_startSymbol) { QPolygonF firstLine = polygons.first(); QLineF segment(firstLine.at(1), firstLine.at(0)); m_startSymbol->alignTo(segment); } if (m_endSymbol) { QPolygonF lastLine = polygons.last(); int maxIndex = lastLine.size(); QLineF segment(lastLine.at(maxIndex-2), lastLine.at(maxIndex-1)); m_endSymbol->alignTo(segment); } if (m_subsetSymbol) { QPointF p1 = path().pointAtPercent(0.4); QPointF p2 = path().pointAtPercent(0.5); QLineF segment(p1, p2); m_subsetSymbol->alignTo(segment); } if (m_collaborationLineItem) { const qreal distance = 10; const int midSegmentIndex = (sz - 1) / 2; const QPointF a = m_points.at(midSegmentIndex); const QPointF b = m_points.at(midSegmentIndex + 1); if (a == b) return; const QPointF p1 = (a + b) / 2.0; const QPointF p2 = (p1 + b) / 2.0; // Reversed line as we want normal in opposite direction. QLineF segment(p2, p1); QLineF normal = segment.normalVector().unitVector(); normal.setLength(distance); QLineF actualLine; actualLine.setP2(normal.p2()); normal.translate(p1 - p2); actualLine.setP1(normal.p2()); m_collaborationLineItem->setLine(actualLine); m_collaborationLineHead->alignTo(actualLine); } }
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if ( !is_visible() && !highlight) return; QPen pen(QColor("#0088ff"),2); pen.setCosmetic(true); if ( highlight && is_visible() ) { pen.setColor(QColor("#00ccff")); pen.setWidth(pen.width()*2); } if ( type == WALL ) { pen.setWidth(pen.width()*3); pen.setCapStyle(Qt::FlatCap); } else if ( type == INVERTED ) pen.setStyle(Qt::DashLine); painter->setPen(pen); //if ( type != WALL ) painter->drawLine(start->pos(),end->pos()); /*else { QPainterPathStroker pps; pps.setWidth(pen.width()+1); QPainterPath pp(start->pos()); pp.lineTo(end->pos()); painter->drawPath(pps.createStroke(pp)); }*/ if ( type == WALL ) { QPen p(Qt::white,pen.width()/3); p.setCosmetic(true); painter->setPen(p); painter->drawLine(start->pos(),end->pos()); } if ( type == HOLE ) { QLineF l = QLineF( start->pos(),end->pos() ).normalVector(); l.setLength(5); l.translate((end->pos()-start->pos())/2); painter->drawLine(l); l.setLength(-5); painter->drawLine(l); } }
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (source->collidesWithItem(destination)) return; QPen myPen = pen(); myPen.setColor(color); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(color); QLineF centerLine(source->pos(), destination->pos()); centerLine.setLength(centerLine.length()-20.0); setLine(QLineF(centerLine.p2(), source->pos())); double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (3.14 * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + 3.14 / 3) * arrowSize, cos(angle + 3.14 / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + 3.14 - 3.14 / 3) * arrowSize, cos(angle + 3.14 - 3.14 / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; painter->drawLine(line()); painter->drawPolygon(arrowHead); if (isSelected()) { painter->setPen(QPen(color, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } }
QLineF GroupBox::positionToPoint(int pos) const { QLineF result; foreach (const Box *box, boxes()) { if (box->containsPos(pos)) { result = box->positionToPoint(pos); } } if (!result.isNull()) result.translate(x(), y()); return result; }
void ImageView::lineMoveRequest(int line_idx, QLineF line) { // Intersect with top and bottom. QPointF p_top; QPointF p_bottom; QRectF const valid_area(getOccupiedWidgetRect()); line.intersect(QLineF(valid_area.topLeft(), valid_area.topRight()), &p_top); line.intersect(QLineF(valid_area.bottomLeft(), valid_area.bottomRight()), &p_bottom); // Limit movement. double const min_x = qMin(p_top.x(), p_bottom.x()); double const max_x = qMax(p_top.x(), p_bottom.x()); double const left = valid_area.left() - min_x; double const right = max_x - valid_area.right(); if (left > right && left > 0.0) { line.translate(left, 0.0); } else if (right > 0.0) { line.translate(-right, 0.0); } m_virtLayout.setCutterLine(line_idx, widgetToVirtual().map(line)); update(); }
void SplineTransferFunction::updateNormals() { m_normals.clear(); m_rightNormals.clear(); m_leftNormals.clear(); for (int i=0; i<m_points.size(); ++i) { QLineF ln; if (i == 0) ln = QLineF(m_points[i], m_points[i+1]); else if (i == m_points.size()-1) ln = QLineF(m_points[i-1], m_points[i]); else ln = QLineF(m_points[i-1], m_points[i+1]); QLineF unitVec; if (ln.length() > 0) unitVec = ln.normalVector().unitVector(); else unitVec = QLineF(QPointF(0,0), QPointF(1,0)); unitVec.translate(-unitVec.p1()); float a = m_normalRotations[i]; QPointF p1 = unitVec.p2(); QPointF p2; p2.setX(p1.x()*cos(a) + p1.y()*sin(a)); p2.setY(-p1.x()*sin(a) + p1.y()*cos(a)); unitVec = QLineF(QPointF(0,0), p2); QPointF v1, v2; v1 = m_points[i] + m_normalWidths[i].x()*unitVec.p2(); v2 = m_points[i] - m_normalWidths[i].y()*unitVec.p2(); m_normals << unitVec.p2(); m_rightNormals << v1; m_leftNormals << v2; } }
void GraphicsTransition::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ //If the collide no need to draw an arrow if (mCurrentState->collidesWithItem(mNextState)) return; QPen myPen = pen(); myPen.setColor(Qt::white); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(Qt::white); QLineF centerLine(mCurrentState->getCenterPoint(), mNextState->getCenterPoint()); QPolygonF endPolygon = mNextState->boundingRect(); QPointF p1 = endPolygon.first() + mNextState->pos(); QPointF p2; QPointF intersectPoint; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + mNextState->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } setLine(QLineF(intersectPoint, mCurrentState->getCenterPoint())); double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (PI * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + PI / 3) * arrowSize, cos(angle + PI / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + PI - PI / 3) * arrowSize, cos(angle + PI - PI / 3) * arrowSize); mArrowHead.clear(); mArrowHead << line().p1() << arrowP1 << arrowP2; painter->drawLine(line()); painter->drawPolygon(mArrowHead); //painter->drawEllipse(line().p1(), 10,10); //Selection square if (isSelected()) { painter->setPen(QPen(Qt::yellow, 3, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } }
void knob::drawKnob( QPainter * _p ) { if( updateAngle() == false && !m_cache.isNull() ) { _p->drawImage( 0, 0, m_cache ); return; } m_cache = QImage( size(), QImage::Format_ARGB32 ); m_cache.fill( qRgba( 0, 0, 0, 0 ) ); QPainter p( &m_cache ); QPoint mid; if( m_knobNum == knobStyled ) { p.setRenderHint( QPainter::Antialiasing ); // Perhaps this can move to setOuterRadius() if( m_outerColor ) { QRadialGradient gradient( centerPoint(), outerRadius() ); gradient.setColorAt(0.4, _p->pen().brush().color() ); gradient.setColorAt(1, *m_outerColor ); p.setPen( QPen( gradient, lineWidth(), Qt::SolidLine, Qt::RoundCap ) ); } else { QPen pen = p.pen(); pen.setWidth( (int) lineWidth() ); pen.setCapStyle( Qt::RoundCap ); p.setPen( pen ); } p.drawLine( calculateLine( centerPoint(), outerRadius(), innerRadius() ) ); p.end(); _p->drawImage( 0, 0, m_cache ); return; } // Old-skool knobs const float radius = m_knobPixmap->width() / 2.0f - 1; mid = QPoint( width() / 2, m_knobPixmap->height() / 2 ); p.drawPixmap( static_cast<int>( width() / 2 - m_knobPixmap->width() / 2 ), 0, *m_knobPixmap ); p.setRenderHint( QPainter::Antialiasing ); const int centerAngle = angleFromValue( model()->centerValue(), model()->minValue(), model()->maxValue(), m_totalAngle ); const int arcLineWidth = 2; const int arcRectSize = m_knobPixmap->width() - arcLineWidth; QColor col; if( m_knobNum == knobVintage_32 ) { col = QApplication::palette().color( QPalette::Active, QPalette::Shadow ); } else { col = QApplication::palette().color( QPalette::Active, QPalette::WindowText ); } col.setAlpha( 70 ); p.setPen( QPen( col, 2 ) ); p.drawArc( mid.x() - arcRectSize/2, 1, arcRectSize, arcRectSize, 315*16, 16*m_totalAngle ); switch( m_knobNum ) { case knobSmall_17: { p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::WindowText ), 2 ) ); p.drawLine( calculateLine( mid, radius-2 ) ); break; } case knobBright_26: { p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::WindowText ), 2 ) ); p.drawLine( calculateLine( mid, radius-5 ) ); break; } case knobDark_28: { p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::WindowText ), 2 ) ); const float rb = qMax<float>( ( radius - 10 ) / 3.0, 0.0 ); const float re = qMax<float>( ( radius - 4 ), 0.0 ); QLineF ln = calculateLine( mid, re, rb ); ln.translate( 1, 1 ); p.drawLine( ln ); break; } case knobGreen_17: { p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::BrightText), 2 ) ); p.drawLine( calculateLine( mid, radius ) ); break; } case knobVintage_32: { p.setPen( QPen( QApplication::palette().color( QPalette::Active, QPalette::Shadow), 2 ) ); p.drawLine( calculateLine( mid, radius-2, 2 ) ); break; } } p.drawArc( mid.x() - arcRectSize/2, 1, arcRectSize, arcRectSize, (90-centerAngle)*16, -16*(m_angle-centerAngle) ); p.end(); _p->drawImage( 0, 0, m_cache ); }
//! [4] void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (myStartNode->collidesWithItem(myEndNode)) return; QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 10; painter->setPen(myPen); painter->setBrush(myColor); //! [4] //! [5] // ----- gilgil temp 2012.06.29 ----- /* QLineF centerLine(myStartNode->pos(), myEndNode->pos()); QPolygonF endPolygon = myEndNode->polygon(); QPointF p1 = endPolygon.first() + myEndNode->pos(); QPointF p2; QPointF intersectPoint; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + myEndNode->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } */ // ---------------------------------- QPointF start, end; start.setX(myStartNode->pos().x() + myStartNode->boundingRect().width() / 2); start.setY(myStartNode->pos().y() + myStartNode->boundingRect().height() / 2); end.setX (myEndNode->pos().x() + myEndNode->boundingRect().width() / 2); end.setY (myEndNode->pos().y() + myEndNode->boundingRect().height() / 2); QLineF centerLine(start, end); QPointF intersectPoint; QLineF::IntersectType intersectType; QLineF polyLine; while (true) { polyLine = QLineF(myEndNode->sceneBoundingRect().topLeft(), myEndNode->sceneBoundingRect().topRight()); intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; polyLine = QLineF(myEndNode->sceneBoundingRect().topLeft(), myEndNode->sceneBoundingRect().bottomLeft()); intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; polyLine = QLineF(myEndNode->sceneBoundingRect().topRight(), myEndNode->sceneBoundingRect().bottomRight()); intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; polyLine = QLineF(myEndNode->sceneBoundingRect().bottomLeft(), myEndNode->sceneBoundingRect().bottomRight()); intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; break; } setLine(QLineF(intersectPoint, start)); //! [5] //! [6] double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; //! [6] //! [7] painter->drawLine(line()); painter->drawPolygon(arrowHead); if (isSelected()) { painter->setPen(QPen(myColor, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } }
void Lien::redraw(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget *) { qDebug()<<"void lien::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget *)"; if (t1->collidesWithItem(t2)) return; QColor myColor(Qt::red); QPen myPen = laLigne->pen(); myPen.setColor(myColor); painter->setPen(myPen); painter->setBrush(myColor); QPointF origine=t1->pos()+QPointF(t1->boundingRect().width()/2,10); QPointF destination=t2->pos()+QPointF(t2->boundingRect().width()/2,10); QLineF centerLine(origine,destination); QPolygonF endPolygon = t2->polygon(); QPolygonF beginPolygon = t1->polygon(); QPointF p1 = endPolygon.first()+t2->pos() ; QPointF p2; QPointF intersectPointT2; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i)+t2->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointT2); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } p1 = beginPolygon.first()+t1->pos() ; QPointF intersectPointT1; for (int i = 1; i < beginPolygon.count(); ++i) { p2 = beginPolygon.at(i)+t1->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPointT1); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } laLigne->setLine(QLineF(intersectPointT1,intersectPointT2)); if(typeDeJointure=="Cross") { texte1->document()->setPlainText("X"); texte2->document()->setPlainText("X"); } else { if(typeDeJointure=="Natural") { texte1->document()->setPlainText("?"); texte2->document()->setPlainText("?"); } else { if(typeDeJointure=="Inner") { texte1->document()->setPlainText("="); texte2->document()->setPlainText("="); } else { if(typeDeJointure=="left outer") { texte1->document()->setPlainText("+="); texte2->document()->setPlainText(""); } else { if(typeDeJointure=="right outer") { texte1->document()->setPlainText(""); texte2->document()->setPlainText("+="); } } } } } QPointF posTexte1,posTexte2; if(intersectPointT1.x()<intersectPointT2.x()) { posTexte1.setX(intersectPointT1.x()); posTexte2.setX(intersectPointT2.x()-texte2->document()->size().width()); } else { posTexte2.setX(intersectPointT2.x()); posTexte1.setX(intersectPointT1.x()-texte1->document()->size().width()); } if(intersectPointT1.y()<intersectPointT2.y()) { posTexte1.setY(intersectPointT1.y()); posTexte2.setY(intersectPointT2.y()-texte2->document()->size().height()); } else { posTexte2.setY(intersectPointT2.y()); posTexte1.setY(intersectPointT1.y()-texte1->document()->size().height()); } texte1->setPos(posTexte1); texte2->setPos(posTexte2); painter->drawLine(laLigne->line()); // if (isSelected()) { painter->setPen(QPen(myColor, 1, Qt::DashLine)); QLineF myLine = laLigne->line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } }
void EllipseObject::updateRubber(QPainter* painter) { int rubberMode = objectRubberMode(); if(rubberMode == OBJ_RUBBER_ELLIPSE_LINE) { QPointF sceneLinePoint1 = objectRubberPoint("ELLIPSE_LINE_POINT1"); QPointF sceneLinePoint2 = objectRubberPoint("ELLIPSE_LINE_POINT2"); QPointF itemLinePoint1 = mapFromScene(sceneLinePoint1); QPointF itemLinePoint2 = mapFromScene(sceneLinePoint2); QLineF itemLine(itemLinePoint1, itemLinePoint2); if(painter) painter->drawLine(itemLine); updatePath(); } else if(rubberMode == OBJ_RUBBER_ELLIPSE_MAJORDIAMETER_MINORRADIUS) { QPointF sceneAxis1Point1 = objectRubberPoint("ELLIPSE_AXIS1_POINT1"); QPointF sceneAxis1Point2 = objectRubberPoint("ELLIPSE_AXIS1_POINT2"); QPointF sceneCenterPoint = objectRubberPoint("ELLIPSE_CENTER"); QPointF sceneAxis2Point2 = objectRubberPoint("ELLIPSE_AXIS2_POINT2"); qreal ellipseWidth = objectRubberPoint("ELLIPSE_WIDTH").x(); qreal ellipseRot = objectRubberPoint("ELLIPSE_ROT").x(); //TODO: incorporate perpendicularDistance() into libcgeometry qreal px = sceneAxis2Point2.x(); qreal py = sceneAxis2Point2.y(); qreal x1 = sceneAxis1Point1.x(); qreal y1 = sceneAxis1Point1.y(); QLineF line(sceneAxis1Point1, sceneAxis1Point2); QLineF norm = line.normalVector(); qreal dx = px-x1; qreal dy = py-y1; norm.translate(dx, dy); QPointF iPoint; norm.intersect(line, &iPoint); qreal ellipseHeight = QLineF(px, py, iPoint.x(), iPoint.y()).length()*2.0; setObjectCenter(sceneCenterPoint); setObjectSize(ellipseWidth, ellipseHeight); setRotation(-ellipseRot); QPointF itemCenterPoint = mapFromScene(sceneCenterPoint); QPointF itemAxis2Point2 = mapFromScene(sceneAxis2Point2); QLineF itemLine(itemCenterPoint, itemAxis2Point2); if(painter) painter->drawLine(itemLine); updatePath(); } else if(rubberMode == OBJ_RUBBER_ELLIPSE_MAJORRADIUS_MINORRADIUS) { QPointF sceneAxis1Point2 = objectRubberPoint("ELLIPSE_AXIS1_POINT2"); QPointF sceneCenterPoint = objectRubberPoint("ELLIPSE_CENTER"); QPointF sceneAxis2Point2 = objectRubberPoint("ELLIPSE_AXIS2_POINT2"); qreal ellipseWidth = objectRubberPoint("ELLIPSE_WIDTH").x(); qreal ellipseRot = objectRubberPoint("ELLIPSE_ROT").x(); //TODO: incorporate perpendicularDistance() into libcgeometry qreal px = sceneAxis2Point2.x(); qreal py = sceneAxis2Point2.y(); qreal x1 = sceneCenterPoint.x(); qreal y1 = sceneCenterPoint.y(); QLineF line(sceneCenterPoint, sceneAxis1Point2); QLineF norm = line.normalVector(); qreal dx = px-x1; qreal dy = py-y1; norm.translate(dx, dy); QPointF iPoint; norm.intersect(line, &iPoint); qreal ellipseHeight = QLineF(px, py, iPoint.x(), iPoint.y()).length()*2.0; setObjectCenter(sceneCenterPoint); setObjectSize(ellipseWidth, ellipseHeight); setRotation(-ellipseRot); QPointF itemCenterPoint = mapFromScene(sceneCenterPoint); QPointF itemAxis2Point2 = mapFromScene(sceneAxis2Point2); QLineF itemLine(itemCenterPoint, itemAxis2Point2); if(painter) painter->drawLine(itemLine); updatePath(); } }
void Arrow::readGraphicAttributes(const QXmlStreamAttributes &attributes) { // Check for legacy arrow type auto legacyArrowType = attributes.value("type").toString(); // if not legacy type, read arrow tip type and return if ("ReactionArrow" != legacyArrowType // TODO make these names constants (see MolScene::produceChild()) && "MechanismArrow" != legacyArrowType) { d->arrowType = (ArrowType) (attributes.value("arrowType").toString().toInt()) ; d->spline = ! (attributes.value("splineDisabled").toString().toInt()); return; } // Code for legacy version if ("ReactionArrow" == legacyArrowType) { enum LegacyReactionArrowType { SingleArrow = 0, DoubleArrow, Equilibrium, EqRightShifted, EqLeftShifted }; // Arrow tip auto legacyReactionArrowType = (LegacyReactionArrowType) (attributes.value("arrowType").toString().toInt()); switch(legacyReactionArrowType) { case SingleArrow: setArrowType(UpperBackward | LowerBackward); break; case DoubleArrow: setArrowType(LowerForward | UpperForward | LowerBackward | UpperBackward); break; case Equilibrium: case EqRightShifted: case EqLeftShifted: setArrowType(UpperBackward); break; default: setArrowType(NoArrow); } // Coordinates QPointF origin(attributes.value("posx").toString().toDouble(), attributes.value("posy").toString().toDouble()); QLineF arrowLine(origin, origin + QPointF(attributes.value("endx").toString().toDouble(), attributes.value("endy").toString().toDouble())); setCoordinates(QPolygonF() << arrowLine.p1() << arrowLine.p2()); if (!scene()) return; // Fix equilibrium arrows: if (Equilibrium == legacyReactionArrowType || EqLeftShifted == legacyReactionArrowType || EqRightShifted == legacyReactionArrowType) { // shift both arrows in equilibrium QLineF normalVector = arrowLine.normalVector().unitVector(); QLineF unitVector = arrowLine.unitVector(); QPointF normalTranslation = 2*(normalVector.p2() - normalVector.p1()); QPointF unitTranslation = 15*(unitVector.p2() - unitVector.p1()); QLineF reverseArrowLine = arrowLine; arrowLine.translate(normalTranslation); reverseArrowLine.translate(-normalTranslation); if (EqRightShifted == legacyReactionArrowType) { reverseArrowLine.setP1(reverseArrowLine.p1() + unitTranslation); reverseArrowLine.setP2(reverseArrowLine.p2() - unitTranslation); } if (EqLeftShifted == legacyReactionArrowType) { arrowLine.setP1(arrowLine.p1() + unitTranslation); arrowLine.setP2(arrowLine.p2() - unitTranslation); } auto reverseArrow = new Arrow; reverseArrow->setParentItem(parentItem()); scene()->addItem(reverseArrow); reverseArrow->setCoordinates(QPolygonF() << reverseArrowLine.p1() << reverseArrowLine.p2()); reverseArrow->setArrowType(LowerForward); setCoordinates(QPolygonF() << arrowLine.p1() << arrowLine.p2()); } } if ("MechanismArrow" == legacyArrowType) { enum LegacyMechanismArrowType { SingleArrowRight = 0, SingleArrowLeft, DoubleMechanismArrow, SingleHookRight, SingleHookLeft, DoubleHook }; // Arrow tip auto legacyMechanismArrowType = (LegacyMechanismArrowType) (attributes.value("arrowType").toString().toInt()); switch(legacyMechanismArrowType) { case SingleArrowRight: setArrowType(UpperBackward | LowerBackward); break; case SingleArrowLeft: setArrowType(UpperForward | LowerForward); break; case DoubleMechanismArrow: setArrowType(LowerForward | UpperForward | LowerBackward | UpperBackward); break; case SingleHookRight: setArrowType(UpperBackward); break; case SingleHookLeft: setArrowType(UpperForward); break; case DoubleHook: setArrowType(UpperForward | UpperBackward); break; default: setArrowType(NoArrow); } // Setting coordinates QPolygonF points; for (int i = 0 ; i < 4 ; ++i) points << QPointF(attributes.value("p" + QString::number(i+1) + "x").toString().toDouble(), attributes.value("p" + QString::number(i+1) + "y").toString().toDouble()); points.translate(attributes.value("posx").toString().toDouble(), attributes.value("posy").toString().toDouble()); setCoordinates(points); } }
//---------------------------------------------------------------------------------------------- void GraphEdgeView::paint(QPainter *p_painter, const QStyleOptionGraphicsItem *p_option, QWidget *p_widget) { if (m_startNode->collidesWithItem(m_endNode)) return; QPen myPen = pen(); myPen.setColor(m_color); qreal arrowSize = m_arrowSize; p_painter->setPen(myPen); p_painter->setBrush(m_color); QLineF centerLine(m_startNode->mapToScene(m_startNode->rect().center()), m_endNode->mapToScene(m_endNode->rect().center())); QPolygonF endPolygon; QPointF p1; QPointF p2; QPointF intersectPoint1; QPointF intersectPoint2; QLineF polyLine; endPolygon = QPolygonF(m_endNode->rect()); p1 = endPolygon.first() + m_endNode->pos(); for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + m_endNode->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint1); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } endPolygon = QPolygonF(m_startNode->rect()); p1 = endPolygon.first() + m_startNode->pos(); for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + m_startNode->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint2); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } setLine(QLineF(intersectPoint1, intersectPoint2)); double angle = ::acos(this->line().dx() / this->line().length()); if (this->line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = this->line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = this->line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); m_arrowHead.clear(); m_arrowHead << this->line().p1() << arrowP1 << arrowP2; p_painter->drawLine(this->line()); p_painter->drawPolygon(m_arrowHead); if (isSelected()) { p_painter->setPen(QPen(m_color, 1, Qt::DotLine)); QLineF normal = this->line().unitVector().normalVector(); qreal dx = normal.dx(); qreal dy = normal.dy(); QLineF myLine; myLine = this->line(); myLine.translate(dx * 4, dy * 4); p_painter->drawLine(myLine); myLine = this->line(); myLine.translate(-dx * 4,-dy * 4); p_painter->drawLine(myLine); } }
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { qDebug() << "Arrow: paint"; if (myStartItem->collidesWithItem(myEndItem)) return; /* QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(myColor); QLineF centerLine(myStartItem->pos(), myEndItem->pos()); QPolygonF endPolygon = myEndItem->polygon(); //p1 = coordinates of first pointer of enditem in //scene coordinates QPointF p1 = endPolygon.first() + myEndItem->pos(); QPointF p2; QPointF intersectPoint; QLineF polyLine; //.count()=.size() for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + myEndItem->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } */ //qreal comp1=intersectPoint.x(); //qreal comp2; //TODO: //This is my patch to define input and output points for lines //All code above this point is rendered useless and should be removed QPointF intersectPoint; QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(myColor); intersectPoint=myEndItem->pos(); intersectPoint.setX(intersectPoint.x()-myEndItem->boundingRect().width()/2); QPointF otherPoint; otherPoint=myStartItem->pos(); otherPoint.setX(otherPoint.x()+myStartItem->boundingRect().width()/2); //original setLine(QLineF(otherPoint, intersectPoint)); if(isZone2()){ zone2(otherPoint); } else{ zone1(otherPoint); } //double angle = ::acos(line().dx() / line().length()); double angle=Pi; if (line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line().p2() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = line().p2() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p2() << arrowP1 << arrowP2; for(int i=0;i<part.size();++i) painter->drawLine(*part[i]); //setLine(*part[0]); //painter->drawLine(line()); painter->drawPolygon(arrowHead); if (isSelected()) { painter->setPen(QPen(myColor, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); } //qDebug() << "PAINT ORDER FINISH"; }