Esempio n. 1
0
void CCJKShapeLine::DrawArrow(QPainter *painter, const QLineF &line)
{
	CJK_D(CCJKShapeLine);
	double angle = ::acos(line.dx() / line.length());
	if (line.dy() >= 0)
		angle = (CJKPi * 2) - angle;
	if (d->arrowBeginType != ArrowNone)
	{
		qreal arrowSize = d->pen.width() + d->arrowBeginSize;
		QPointF arrowP1;
		QPointF arrowP2;
		arrowP1 = line.p1() + QPointF(sin(angle + CJKPi / 3) * arrowSize,
			cos(angle + CJKPi / 3) * arrowSize);
		arrowP2 = line.p1() + QPointF(sin(angle + CJKPi - CJKPi / 3) * arrowSize,
			cos(angle + CJKPi - CJKPi / 3) * arrowSize);
		DrawArrow(painter, d->arrowBeginType, line.p1(), arrowP1, arrowP2, arrowSize);
	}
	if (d->arrowEndType != ArrowNone)
	{
		qreal arrowSize = d->pen.width() + d->arrowEndSize;
		QPointF arrowP1;
		QPointF arrowP2;
		arrowP1 = line.p2() - QPointF(sin(angle + CJKPi / 3) * arrowSize,
			cos(angle + CJKPi / 3) * arrowSize);
		arrowP2 = line.p2() - QPointF(sin(angle + CJKPi - CJKPi / 3) * arrowSize,
			cos(angle + CJKPi - CJKPi / 3) * arrowSize);
		DrawArrow(painter, d->arrowEndType, line.p2(), arrowP1, arrowP2, arrowSize);
	}
}
Esempio n. 2
0
void GEdge::adjust()
{
    if (!source || !dest)
        return;

    QLineF * line = new QLineF (source->x(), source->y(),
                                dest->x(), dest->y());

    qreal length = line->length();

    prepareGeometryChange();

    if (length > qreal(20.)) {
        QPointF edgeOffset((line->dx() * 10) / length, (line->dy() * 10) / length);

        if (is_from_dummy_node)
            sourcePoint = line->p1();
        else
            sourcePoint = line->p1() + edgeOffset;

        if (is_to_dummy_node)
            destPoint = line->p2();
        else
            destPoint = line->p2() - edgeOffset;
    } else {
        sourcePoint = destPoint = line->p1();
    }
}
//----------------------------------------------------------------------------------------------
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;
}
Esempio n. 4
0
//TODO find better way calculate point.
QPointF VToolShoulderPoint::FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder,
                                      const qreal &length)
{
    QLineF line = QLineF(p1Line, p2Line);
    qreal toolLength = length;
    qreal dist = line.length();
    if (dist>toolLength)
    {
        qDebug()<<"Correction of length in shoulder point tool. Parameter length too small.";
        toolLength = dist;
    }
    if (qFuzzyCompare(dist, toolLength))
    {
        return line.p2();
    }
    qreal step = 0.01;
    while (1)
    {
        line.setLength(line.length()+step);
        QLineF line2 = QLineF(pShoulder, line.p2());
        if (line2.length()>=toolLength)
        {
            return line.p2();
        }
    }
}
Esempio n. 5
0
void tst_QLine::testAngleTo_data()
{
    QTest::addColumn<qreal>("xa1");
    QTest::addColumn<qreal>("ya1");
    QTest::addColumn<qreal>("xa2");
    QTest::addColumn<qreal>("ya2");
    QTest::addColumn<qreal>("xb1");
    QTest::addColumn<qreal>("yb1");
    QTest::addColumn<qreal>("xb2");
    QTest::addColumn<qreal>("yb2");
    QTest::addColumn<qreal>("angle");

    QTest::newRow("parallel") << qreal(1.0) << qreal(1.0) << qreal(3.0) << qreal(4.0)
                           << qreal(5.0) << qreal(6.0) << qreal(7.0) << qreal(9.0)
                           << qreal(0.0);
    QTest::newRow("[4,4]-[4,0]") << qreal(1.0) << qreal(1.0) << qreal(5.0) << qreal(5.0)
                              << qreal(0.0) << qreal(4.0) << qreal(3.0) << qreal(4.0)
                              << qreal(45.0);
    QTest::newRow("[4,4]-[-4,0]") << qreal(1.0) << qreal(1.0) << qreal(5.0) << qreal(5.0)
                              << qreal(3.0) << qreal(4.0) << qreal(0.0) << qreal(4.0)
                              << qreal(225.0);

    for (int i = 0; i < 360; ++i) {
        const QLineF l = QLineF::fromPolar(1, i);
        QTest::newRow(("angle:" + QByteArray::number(i)).constData())
            << qreal(0.0) << qreal(0.0) << qreal(1.0) << qreal(0.0)
            << qreal(0.0) << qreal(0.0) << l.p2().x() << l.p2().y()
            << qreal(i);
    }
}
Esempio n. 6
0
static double angle_to(QLineF line1, QLineF line2) {
  // found on code-guru forum- thread 137249
  // calculate the angle between the line from p1 to p2
  // and the line from p3 to p4
  //
  // uses the theorem :
  //
  // given directional vectors v = ai + bj and w = ci + di
  //
  // then cos(angle) = (ac + bd) / ( |v| * |w| )
  //
  double a = (float)line1.p1().x() - line1.p2().x();
  double b = (float)line1.p1().y() - line1.p2().y();
  double c = (float)line2.p1().x() - line2.p2().x();
  double d = (float)line2.p1().y() - line2.p2().y();

  double cos_angle, angle;
  double mag_v1 = sqrt(a * a + b * b);
  double mag_v2 = sqrt(c * c + d * d);

  cos_angle = (a * c + b * d) / (mag_v1 * mag_v2);
  angle = acos(cos_angle);
  angle = angle * 180.0 / PI;

  return angle;
}
void CanvasMode_EditPolygon::updateFromItem()
{
	if (updateFromItemBlocked())
		return;
	PageItem *currItem = m_doc->m_Selection->itemAt(0);
	PageItem_RegularPolygon* item = currItem->asRegularPolygon();
	centerPoint = QPointF(currItem->width() / 2.0, currItem->height() / 2.0);
	startPoint = currItem->PoLine.pointQF(0);
	endPoint = currItem->PoLine.pointQF(2);
	polyCorners = item->polyCorners;
	polyUseFactor = item->polyUseFactor;
	polyFactor = item->polyFactor;
	polyRotation = item->polyRotation;
	polyCurvature = item->polyCurvature;
	polyInnerRot = item->polyInnerRot;
	polyOuterCurvature = item->polyOuterCurvature;
	VectorDialog->polyWidget->blockSignals(true);
	VectorDialog->setValues(polyCorners, polyFactor, polyUseFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
	VectorDialog->polyWidget->blockSignals(false);
	uint cx = polyUseFactor ? polyCorners * 2 : polyCorners;
	double seg = 360.0 / cx;
	double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (item->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (item->height() / 2.0) + (item->height()/2.0) - item->height(), 2));
	QLineF innerLine = QLineF(endPoint, centerPoint);
	innerLine.setAngle(innerLine.angle() + 90);
	innerLine.setLength(trueLength * polyCurvature);
	innerCPoint = innerLine.p2();
	QLineF outerLine = QLineF(startPoint, currItem->PoLine.pointQF(6));
	outerLine.setLength(outerLine.length() * polyOuterCurvature);
	outerCPoint = outerLine.p2();
	m_view->update();
}
void LenJonSim::addline(QLineF l,double dx)
{

    double startx, starty, endx, endy, distance, step,x,y;

    QPointF *p1 = new QPointF(l.p1().x(),l.p1().y());
    qDebug()<<p1->x()<<p1->y();
    QPointF *p2 = new QPointF(l.p2().x(),l.p2().y());

    startx = p1->x();
    starty = p1->y();
    endx = p2->x();
    endy = p2->y();

    distance = sqrt(pow(endx - startx,2)+pow(endy-starty,2));


    step = (dx / distance);
    for(double i = 0; i <= 1; i+=step){
        x = startx + (endx - startx) * i;
        y = starty + (endy - starty) * i;
        addParticle(x,y);
        nonMovableParticles++;
    }
}
smReal getRectM(QLineF line)
{
    return (
        (line.p2().y() - line.p1().y()) 
        / 
        (line.p2().x() - line.p1().x())
    );
}
Esempio n. 10
0
bool CalculateLaylines::checkIntersection( const QLineF &line1, const QLineF &line2 ) {

    QString WKTLine1 = buildWKTLine( line1.p1(), line1.p2() );
    QString WKTLine2 = buildWKTLine( line2.p1(), line2.p2() );

    return checkGeometriesIntersection( WKTLine1, WKTLine2);

}
Esempio n. 11
0
std::vector<QPolygonF> GraphicsArrowItem::compose() {
	const qreal pi = 3.14;
	QLineF l = QLineF(line());
	double arrowSize = (l.length() < 200.0) ? 10.0 : l.length()/20.0;
	//double arrowSize = 10.0;
	int dx = l.p2().x() - l.p1().x();
	int dy = l.p2().y() - l.p1().y();
	double angle = ::acos(dx/l.length());
	if (dx >= 0 && dy > 0)
		angle = (pi * 2) - angle;
	else if (dx >= 0 && dy <= 0)
		{ }
	else if (dx < 0 && dy > 0)
		angle = (pi * 2) - angle;
	else if (dx < 0 && dy <= 0)
		{ }
	QPointF P1 = l.p1() + QPointF(::sin(angle+pi/3.0)*arrowSize, ::cos(angle+pi/3.0)*arrowSize);
	QPointF P2 = l.p1() + QPointF(::sin(angle+pi-pi/3.0)*arrowSize, ::cos(angle+pi-pi/3.0)*arrowSize);
	QPointF P3 = l.p2() + QPointF(::sin(angle-pi/3.0)*arrowSize, ::cos(angle-pi/3.0)*arrowSize);
	QPointF P4 = l.p2() + QPointF(::sin(angle+pi+pi/3.0)*arrowSize, ::cos(angle+pi+pi/3.0)*arrowSize);

	std::vector<QPolygonF> cont;
	//double off = 0.5*arrowSize*1.732;
	//QPointF offset(off, off);
	if (arrowHead == Start) {
		QPolygonF polybuilder;
		polybuilder.push_back(P1);
		polybuilder.push_back(l.p1());
		polybuilder.push_back(P2);
		polybuilder.push_back(P1);
		cont.push_back(polybuilder);
		//QLineF newline(line());
		//newline.setP1(newline.p1()-offset);
	}
	else if (arrowHead == End) {
		QPolygonF polybuilder;
		polybuilder.push_back(P3);
		polybuilder.push_back(l.p2());
		polybuilder.push_back(P4);
		polybuilder.push_back(P3);
		cont.push_back(polybuilder);
	}
	else if (arrowHead == Both) {
		QPolygonF polybuilder;
		polybuilder.push_back(P1);
		polybuilder.push_back(l.p1());
		polybuilder.push_back(P2);
		polybuilder.push_back(P1);
		QPolygonF polybuilder2;
		polybuilder2.push_back(P3);
		polybuilder2.push_back(l.p2());
		polybuilder2.push_back(P4);
		polybuilder2.push_back(P3);
		cont.push_back(polybuilder);
		cont.push_back(polybuilder2);
	}
	return cont;
}
/**
 * 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 UBEditableGraphicsLineItem::forcePointPosition(const QPointF& pos, PointPosition pointPosition, int amplitude)
{
    QLineF line;

    int angles[] = {0, 45, 90, 135, 180, 225, 270, 315};

    int size = sizeof(angles) / sizeof(int);

    if(pointPosition == Start) {
        line.setP1(pos);
        line.setP2(path().elementAt(1));
    } else {
        line.setP1(path().elementAt(0));
        line.setP2(pos);
    }

    int angle = line.angle();

    const float PI_2 = 4*atan(1.f)*2;

    //for each angle we compute the left and right angle
    //then compute the distance between both
    for(int i = 0; i < size; i++) {
        //use the modulo operator to force the angle to stay in [0, 360]
        int leftAmplitude = (angles[i] + amplitude) % 360;
        int rightAmplitude = (angles[i] - amplitude + 360) % 360;

        int leftDist = (leftAmplitude - angle + 360) % 360;
        int rightDist = (angle - rightAmplitude + 360) % 360;

        if(leftDist <= amplitude || rightDist <= amplitude) {
            if(pointPosition == End) {
                line.setAngle(angles[i]);
            } else {
                //compute the position of p1 by hand
                float angleInRadians = angles[i]*PI_2/360;

                qreal l = line.length();

                const qreal dx = -cos(angleInRadians)*l;
                const qreal dy = sin(angleInRadians)*l;

                line.setP1(QPointF(dx + line.p2().x(), dy + line.p2().y()));
            }
            break;
        }
    }

    QPainterPath p;

    p.moveTo(line.p1());
    p.lineTo(line.p2());

    setPath(p);

    mHandles.at(0)->setPos(line.p1().x(), line.p1().y());
    mHandles.at(1)->setPos(line.p2().x(), line.p2().y());
}
Esempio n. 14
0
bool CalculateLaylines::checkOffset( const QLineF &l1, const QLineF &l2, const float &offset ) {

    double diff = UwMath::getDistance(l1.p2(), l2.p2());
    double scale = ( UwMath::getDistance(l1.p1(), l1.p2()) +
                     UwMath::getDistance(l2.p1(), l2.p2()) ) / 2 ;
    double criteria = ( abs(scale) == 0 ) ? offset : offset * scale;

    return diff < criteria;
}
Esempio n. 15
0
QPainterPath GraphicsItemNode::shape() const
{
    //If there is only one segment and it is shorter than half its
    //width, then the arrow head will not be made with 45 degree
    //angles, but rather whatever angle is made by going from the
    //end to the back corners (the final node will be a triangle).
    if (m_hasArrow
            && m_linePoints.size() == 2
            && distance(getLast(), getSecondLast()) < m_width / 2.0)
    {
        QLineF backline = QLineF(getSecondLast(), getLast()).normalVector();
        backline.setLength(m_width / 2.0);
        QPointF backVector = backline.p2() - backline.p1();
        QPainterPath trianglePath;
        trianglePath.moveTo(getLast());
        trianglePath.lineTo(getSecondLast() + backVector);
        trianglePath.lineTo(getSecondLast() - backVector);
        trianglePath.lineTo(getLast());
        return trianglePath;
    }

    //Create a path that outlines the main node shape.
    QPainterPathStroker stroker;
    stroker.setWidth(m_width);
    stroker.setCapStyle(Qt::FlatCap);
    stroker.setJoinStyle(Qt::RoundJoin);
    QPainterPath mainNodePath = stroker.createStroke(path());

    if (!m_hasArrow)
        return mainNodePath;

    //If the node has an arrow head, subtract the part of its
    //final segment to give it a pointy end.
    //NOTE: THIS APPROACH CAN LEAD TO WEIRD EFFECTS WHEN THE NODE'S
    //POINTY END OVERLAPS WITH ANOTHER PART OF THE NODE.  PERHAPS THERE
    //IS A BETTER WAY TO MAKE ARROWHEADS?
    QLineF frontline = QLineF(getLast(), getSecondLast()).normalVector();
    frontline.setLength(m_width / 2.0);
    QPointF frontVector = frontline.p2() - frontline.p1();
    QLineF arrowheadLine(getLast(), getSecondLast());
    arrowheadLine.setLength(1.42 * (m_width / 2.0));
    arrowheadLine.setAngle(arrowheadLine.angle() + 45.0);
    QPointF arrow1 = arrowheadLine.p2();
    arrowheadLine.setAngle(arrowheadLine.angle() - 90.0);
    QPointF arrow2 = arrowheadLine.p2();
    QLineF lastSegmentLine(getSecondLast(), getLast());
    lastSegmentLine.setLength(0.01);
    QPointF additionalForwardBit = lastSegmentLine.p2() - lastSegmentLine.p1();
    QPainterPath subtractionPath;
    subtractionPath.moveTo(getLast());
    subtractionPath.lineTo(arrow1);
    subtractionPath.lineTo(getLast() + frontVector + additionalForwardBit);
    subtractionPath.lineTo(getLast() - frontVector + additionalForwardBit);
    subtractionPath.lineTo(arrow2);
    subtractionPath.lineTo(getLast());
    return mainNodePath.subtracted(subtractionPath);
}
Esempio n. 16
0
void QgsAnnotationItem::updateBalloon()
{
  //first test if the point is in the frame. In that case we don't need a balloon.
  if ( !mMapPositionFixed ||
       ( mOffsetFromReferencePoint.x() < 0 && ( mOffsetFromReferencePoint.x() + mFrameSize.width() ) > 0
         && mOffsetFromReferencePoint.y() < 0 && ( mOffsetFromReferencePoint.y() + mFrameSize.height() ) > 0 ) )
  {
    mBalloonSegment = -1;
    return;
  }

  //edge list
  QList<QLineF> segmentList;
  segmentList << segment( 0 );
  segmentList << segment( 1 );
  segmentList << segment( 2 );
  segmentList << segment( 3 );

  //find  closest edge / closest edge point
  double minEdgeDist = DBL_MAX;
  int minEdgeIndex = -1;
  QLineF minEdge;
  QgsPoint minEdgePoint;
  QgsPoint origin( 0, 0 );

  for ( int i = 0; i < 4; ++i )
  {
    QLineF currentSegment = segmentList.at( i );
    QgsPoint currentMinDistPoint;
    double currentMinDist = origin.sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint );
    if ( currentMinDist < minEdgeDist )
    {
      minEdgeIndex = i;
      minEdgePoint = currentMinDistPoint;
      minEdgeDist = currentMinDist;
      minEdge = currentSegment;
    }
  }

  if ( minEdgeIndex < 0 )
  {
    return;
  }

  //make that configurable for the item
  double segmentPointWidth = 10;

  mBalloonSegment = minEdgeIndex;
  QPointF minEdgeEnd = minEdge.p2();
  mBalloonSegmentPoint1 = QPointF( minEdgePoint.x(), minEdgePoint.y() );
  if ( sqrt( minEdgePoint.sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < segmentPointWidth )
  {
    mBalloonSegmentPoint1 = pointOnLineWithDistance( minEdge.p2(), minEdge.p1(), segmentPointWidth );
  }

  mBalloonSegmentPoint2 = pointOnLineWithDistance( mBalloonSegmentPoint1, minEdge.p2(), 10 );
}
QList<QPointF> QLogicCircuitShapeConnector::defaultConnector() const
{
    QList<QPointF> points;
    QList<QPointF> sections;
    QLineF line(startPos(), endPos());
    QLineF lineEnd;
    QLineF lineStart;

    line = QLineF(startPos(), endPos());

    lineStart.setP1(startPos());
    lineEnd.setP1(endPos());

    switch(orientationAtStart()){
    case QDiagramToolkit::East:
        if (line.dx() < 20){
            lineStart.setP2(startPos() + QPointF(20, 0));

            lineEnd.setP2(lineEnd.p1() - QPointF(20, 0));
            sections << QPointF(lineStart.p2().x(), lineStart.p1().y() + line.dy() / 2)
                          << QPointF(lineEnd.p2().x(), lineEnd.p2().y() - line.dy() / 2);
        } else {
            lineStart.setP2(lineStart.p1() + QPointF(line.dx() / 2 , 0));

            lineEnd.setP2(QPointF(lineStart.p2().x(), lineEnd.p1().y()));
        }
        break;
    case QDiagramToolkit::West:
        if (line.dx() > -20){
            lineStart.setP2(startPos() - QPointF(20, 0));

            lineEnd.setP2(lineEnd.p1() + QPointF(20, 0));
            sections << QPointF(lineStart.p2().x(), lineStart.p1().y() + line.dy() / 2)
                          << QPointF(lineEnd.p2().x(), lineEnd.p2().y() - line.dy() / 2);
        } else {
            lineStart.setP2(lineStart.p1() + QPointF(line.dx() / 2 , 0));

            lineEnd.setP2(QPointF(lineStart.p2().x(), lineEnd.p1().y()));
        }
        break;
    default:
        break;
    }


    points.append(lineStart.p1());
    points.append(lineStart.p2());
    QListIterator<QPointF> it(sections);
    while(it.hasNext()){
        points.append(it.next());
    }
    points.append(lineEnd.p2());
    points.append(lineEnd.p1());
    return points;
}
Esempio n. 18
0
void LineItem::setLine(const QLineF &line_) {
  setPos(line_.p1());
  setViewRect(QRectF(0.0, 0.0, 0.0, sizeOfGrip().height()));

  if (!rect().isEmpty()) {
    rotateTowards(line().p2(), line_.p2());
  }

  QRectF r = rect();
  r.setSize(QSizeF(QLineF(line().p1(), line_.p2()).length(), r.height()));
  setViewRect(r);
}
QPainterPath CopyFilterGUIConnectionItem::shape() const
{
	QLineF l = line();

	QPainterPath path;
	path.setFillRule(Qt::WindingFill);
	double length = line().length();
	if (length > 0)
	{
		double offset = min(length, maxArrowSize);
		QLineF unit = l.unitVector();
		QLineF normal = l.normalVector().unitVector();
		QPointF v(unit.dx(), unit.dy());
		QPointF n(normal.dx(), normal.dy());
		QPointF p2 = l.p2();

		QPointF p3 = p2 - v * offset + 0.5 * n * offset;
		QPointF p4 = p2 - v * offset - 0.5 * n * offset;
		QPolygonF polygon;
		polygon.append(p4);
		polygon.append(p3);
		polygon.append(p2);
		path.addPolygon(polygon);

		QPolygonF polygon2;
		QPointF p1 = l.p1();
		polygon2.append(p2 + 3 * n);
		polygon2.append(p2 - 2 * n);
		polygon2.append(p1 - 2 * n);
		polygon2.append(p1 + 3 * n);
		path.addPolygon(polygon2);

		if (factor != 1.0 || isDecibel)
		{
			QFont font;
			font.setPixelSize(10);
			QPointF center = (l.p1() + l.p2()) / 2;
			QString text = QString("%1").arg(factor);
			if (isDecibel)
				text += " dB";

			QFontMetrics fontMetrics(font);
			QSizeF size = fontMetrics.size(0, text);
			size += QSizeF(2, 0);
			QRectF rect;
			rect.setSize(size);
			rect.moveCenter(center);
			path.addRoundedRect(rect.adjusted(-0.5, 0.5, 0.5, 0.5), 3, 3);
		}
	}

	return path;
}
Esempio n. 20
0
bool Meshing::intersects(QPolygonF poly, QLineF line)
{
    for(int i=0;i<poly.size()-1;i++){
        QLineF l(poly.at(i) , poly.at(i+1));
        QPointF p;
        if(l.p1()==line.p1() || l.p1()==line.p2() || l.p2()==line.p1() || l.p2()==line.p2())
            continue;
        if(l.intersect(line,&p)==QLineF::BoundedIntersection){
                return true;
        }
    }
    return false;
}
Esempio n. 21
0
bool GraphConnection::isPointing(const QRectF &rect) const
{
    //check individual line segments
    for (int i = 1; i < _impl->points.size(); i++)
    {
        const QLineF line(_impl->points[i-1], _impl->points[i]);
        QLineF norm = line.normalVector(); norm.setLength(GraphConnectionSelectPad);
        if (QRectF(line.p2(), norm.p2()).intersects(rect)) return true;
    }

    //check arrow head
    return not _impl->arrowHead.intersected(rect).isEmpty();
}
/**
 * This method aligns *this* Symbol to the line being
 * passed. That is, it ensures that the axis of this symbol aligns
 * exactly with the \a "to" line passed.
 *
 * Also this item is moved such that the second end point of the
 * SymbolEndPoints for the current symbol *collides* with the second end
 * point of \a "to" line.
 */
void Symbol::alignTo(const QLineF& to)
{
    QLineF toMapped(mapFromParent(to.p1()), mapFromParent(to.p2()));

    QLineF origAxis = Symbol::symbolTable[m_symbolType].axisLine;
    QLineF translatedAxis = origAxis.translated(toMapped.p2() - origAxis.p2());

    qreal angle = translatedAxis.angleTo(toMapped);
    rotate(-angle);

    QPointF delta = to.p2() - mapToParent(symbolEndPoints().second);
    moveBy(delta.x(), delta.y());
}
Esempio n. 23
0
QLineF Projection::project(const QLineF & Map) const
{
    if (p->IsMercator)
        return QLineF(p->mercatorProject(Map.p1()), p->mercatorProject(Map.p2()));
    else
    if (p->IsLatLong)
        return QLineF(p->latlonProject(Map.p1()), p->latlonProject(Map.p2()));
#ifndef _MOBILE
    else
        return QLineF(projProject(Map.p1()), projProject(Map.p2()));
#endif
    return QLineF();
}
void CopyFilterGUIConnectionItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
	QLineF l = line();
	if (!l.isNull())
	{
		painter->setBrush(Qt::black);
		if (isSelected())
		{
			painter->setBrush(Qt::blue);
			painter->setPen(QPen(Qt::blue, 1.5));
		}
		painter->drawLine(line());

		double length = line().length();
		double offset = min(length, maxArrowSize);
		QLineF unit = l.unitVector();
		QLineF normal = l.normalVector().unitVector();
		QPointF v(unit.dx(), unit.dy());
		QPointF n(normal.dx(), normal.dy());
		QPointF p2 = l.p2();

		QPointF p3 = p2 - v * offset + 0.5 * n * offset;
		QPointF p4 = p2 - v * offset - 0.5 * n * offset;
		QPolygonF polygon;
		polygon.append(p2);
		polygon.append(p3);
		polygon.append(p4);

		painter->drawPolygon(polygon);

		if (factor != 1.0 || isDecibel)
		{
			QFont font = painter->font();
			font.setPixelSize(10);
			painter->setFont(font);
			QPointF center = (l.p1() + l.p2()) / 2;
			QString text = QString("%1").arg(factor);
			if (isDecibel)
				text += " dB";

			QSizeF size = painter->fontMetrics().size(0, text);
			size += QSizeF(2, 0);
			QRectF rect;
			rect.setSize(size);
			rect.moveCenter(center);
			painter->setBrush(Qt::white);
			painter->drawRoundedRect(rect.adjusted(-0.5, 0.5, 0.5, 0.5), 3, 3);
			painter->drawText(rect, Qt::AlignCenter, text);
		}
	}
}
bool Intersect(QLineF l1, QLineF l2)
{
    //controllo che i punti siano sui semipiani opposti per entrambi i segmenti
    smReal ml1 = getRectM(l1);
    smReal ql1 = getRectQ(l1,ml1);
    if ( ( l2.p1().y() - ml1*l2.p1().x() - ql1 ) * (l2.p2().y() - ml1*l2.p2().x() - ql1) > 0)
        return false;
    
    smReal ml2 = getRectM(l2);
    smReal ql2 = getRectQ(l2,ml2);
    if ( ( l1.p1().y() - ml2*l1.p1().x() - ql2 ) * (l1.p2().y() - ml2*l1.p2().x() - ql2) > 0)
        return false;
    
    return true;
}
/**
 * Draws a 2D line in 3D space by painting it with a z-coordinate of props.depth / 2.0
 *
 * @param line The line to draw
 * @param pen The pen to use to draw the line
 * @param props The 3D properties to draw the line with
 * @return The drawn line, but with a width of 2px, as a polygon
 */
QPolygonF StockDiagram::Private::ThreeDPainter::drawTwoDLine( const QLineF &line, const QPen &pen,
                                                              const ThreeDProperties &props )
{
    // Restores the painting properties when destroyed
    PainterSaver painterSaver( painter );

    // The z coordinate to use (i.e., at what depth to draw the line)
    const qreal z = props.depth / 2.0;

    // Projec the 2D points of the line in 3D
    const QPointF deepP1 = projectPoint( line.p1(), z, props.angle );
    const QPointF deepP2 = projectPoint( line.p2(), z, props.angle );

    // The drawn line with a width of 2px
    QPolygonF threeDArea;
    // The offset of the line "borders" from the center to each side
    const QPointF offset( 0.0, 1.0 );
    threeDArea << deepP1 - offset << deepP2 - offset
               << deepP1 + offset << deepP2 + offset << deepP1 - offset;

    painter->setPen( pen );
    painter->drawLine( QLineF( deepP1, deepP2 ) );

    return threeDArea;
}
Esempio n. 27
0
void QgsAnnotationItem::drawFrame( QPainter* p )
{
  QPen framePen( mFrameColor );
  framePen.setWidthF( mFrameBorderWidth );

  p->setPen( framePen );
  QBrush frameBrush( mFrameBackgroundColor );
  p->setBrush( frameBrush );
  p->setRenderHint( QPainter::Antialiasing, true );

  QPolygonF poly;
  for ( int i = 0; i < 4; ++i )
  {
    QLineF currentSegment = segment( i );
    poly << currentSegment.p1();
    if ( i == mBalloonSegment && mMapPositionFixed )
    {
      poly << mBalloonSegmentPoint1;
      poly << QPointF( 0, 0 );
      poly << mBalloonSegmentPoint2;
    }
    poly << currentSegment.p2();
  }
  p->drawPolygon( poly );
}
Esempio n. 28
0
void QgsComposerItem::setItemRotation( double r, bool adjustPosition )
{
  if ( adjustPosition )
  {
    //adjustPosition set, so shift the position of the item so that rotation occurs around item center
    //create a line from the centrepoint of the rect() to its origin, in scene coordinates
    QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) );
    //rotate this line by the current rotation angle
    refLine.setAngle( refLine.angle() - r + mItemRotation );
    //get new end point of line - this is the new item position
    QPointF rotatedReferencePoint = refLine.p2();
    setPos( rotatedReferencePoint );
    emit sizeChanged();
  }

  if ( r > 360 )
  {
    mItemRotation = (( int )r ) % 360;
  }
  else
  {
    mItemRotation = r;
  }

  setTransformOriginPoint( 0, 0 );
  QGraphicsItem::setRotation( mItemRotation );

  emit itemRotationChanged( r );
  update();
}
Esempio n. 29
0
void Projectile::setPath(QPointF source, QPointF target, Unit* enemy) {
    if (type_ >= PROJ_FIRE && type_ <= PROJ_FIRE_5) {
        QLineF distance = QLineF(source.x(), source.y(),
                target.x(), target.y());
        switch(type_) {
        case PROJ_FIRE_2:
            distance.setLength(distance.length() * 90 / RADIUS_FLAME_2);
            break;
        case PROJ_FIRE_3:
            distance.setLength(distance.length() * 90 / RADIUS_FLAME_3);
            break;
        case PROJ_FIRE_4:
            distance.setLength(distance.length() * 90 / RADIUS_FLAME_4);
            break;
        case PROJ_FIRE_5:
            distance.setLength(distance.length() * 120 / RADIUS_FLAME_5);
            break;
        }
        end_ = new QPointF(distance.p2());
    } else {
        end_ = new QPointF(target);
    }
    start_ = new QPointF(source);
    setEnemy(enemy);
}
Esempio n. 30
0
bool CalculateLaylines::checkIntersection( const QString &layerName, const QLineF &heading ) {

    QString WKTLine = buildWKTLine( heading.p1(), heading.p2() );

    return checkIntersection( layerName, WKTLine);

}