Example #1
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();
    }
}
Example #2
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 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++;
    }
}
Example #4
0
qreal PortHandler::linePortId(const QPointF &location, const QStringList &types) const
{
	for (int linePortNumber = 0; linePortNumber < mLinePorts.count(); linePortNumber++) {
		const StatLine * const linePort = mLinePorts.at(linePortNumber);
		if (!types.contains(linePort->type())) {
			continue;
		}

		QPainterPathStroker ps;
		ps.setWidth(kvadratik - 5);

		QPainterPath path;
		const QLineF line = transformPortForNodeSize(linePort);
		path.moveTo(line.p1());
		path.lineTo(line.p2());

		path = ps.createStroke(path);
		if (path.contains(location)) {
			return linePortNumber + mPointPorts.size()
				+ qMin(QLineF(line.p1(), location).length() / line.length()
					, mMaximumFractionPartValue);
		}
	}

	return nonexistentPortId;
}
Example #5
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);
	}
}
//----------------------------------------------------------------------------------------------
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;
}
Example #7
0
//This function tests to see if two given points, p1 and p2, are on different sides of a line.
bool MyGraphicsView::differentSidesOfLine(QPointF p1, QPointF p2, QLineF line)
{
    bool testPoint1Side = ((p1.y() - line.p1().y() - (p1.x() - line.p1().x())*(line.p2().y() - line.p1().y())/(line.p2().x() - line.p1().x())) > 0);
    bool testPoint2Side = ((p2.y() - line.p1().y() - (p2.x() - line.p1().x())*(line.p2().y() - line.p1().y())/(line.p2().x() - line.p1().x())) > 0);

    return (testPoint1Side != testPoint2Side);
}
smReal getRectM(QLineF line)
{
    return (
        (line.p2().y() - line.p1().y()) 
        / 
        (line.p2().x() - line.p1().x())
    );
}
Example #9
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);

}
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());
}
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;
}
Example #12
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);
}
Example #13
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;
}
Example #14
0
void UniAssociation::paintEndB(QPainter* painter, const QLineF& segment) {
    QPointF v1 = QLineF::fromPolar(arrowLength, segment.angle() + arrowAngle).p2();
    QPointF end1 = v1 + segment.p1();
    painter->drawLine(QLineF(segment.p1(), end1));

    QPointF v2 = QLineF::fromPolar(arrowLength, segment.angle() + -arrowAngle).p2();
    QPointF end2 = v2 + segment.p1();
    painter->drawLine(QLineF(segment.p1(), end2));
}
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;
}
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;
}
Example #17
0
QPolygonF QGVEdge::toBox(const QLineF &line) const
{
    QLineF n = line.normalVector();
    QPointF o(n.dx() * 0.5, n.dy() * 0.5);

    QPolygonF polygon;
    polygon.append(line.p1() + o);
    polygon.append(line.p2() + o);
    polygon.append(line.p2() - o);
    polygon.append(line.p1() - o);
    return polygon;
}
Example #18
0
float RayDisplayScene::pointToLineDistSquared(const QPointF &point, const QLineF &line) const
{
	const float x2x1 = line.p2().x() - line.p1().x();
	const float y2y1 = line.p2().y() - line.p1().y();
	const float d = (x2x1) * (line.p1().y() - point.y()) - (line.p1().x() - point.x()) * (y2y1);
	const float dSq = d * d;
	const float y2y1Sq = y2y1 * y2y1;
	const float x2x1Sq = x2x1 * x2x1;
	const float distSq = dSq / (x2x1Sq + y2y1Sq);

	return distSq;
}
Example #19
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;
}
Example #20
0
QPolygonF QGVEdge::toArrow(const QLineF &line) const
{
    QLineF n = line.normalVector();
    QPointF o(n.dx() / 3.0, n.dy() / 3.0);

    //Only support normal arrow type
    QPolygonF polygon;
    polygon.append(line.p1() + o);
    polygon.append(line.p2());
    polygon.append(line.p1() - o);

    return polygon;
}
Example #21
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();
}
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 an ordinary line in 3D by expanding it in the z-axis by the given depth.
 *
 * @param line The line to draw
 * @param brush The brush to fill the resulting polygon with
 * @param pen The pen to paint the borders of the resulting polygon with
 * @param props The 3D properties to draw the line with
 * @return The 3D shape drawn
 */
QPolygonF StockDiagram::Private::ThreeDPainter::drawThreeDLine( const QLineF &line, const QBrush &brush,
                                                                const QPen &pen, const ThreeDProperties &props )
{
    // Restores the painting properties when destroyed
    PainterSaver painterSaver( painter );

    const QPointF p1 = line.p1();
    const QPointF p2 = line.p2();

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

    // The result is a 3D representation of the 2D line
    QPolygonF threeDArea;
    threeDArea << p1 << p2 << deepP2 << deepP1 << p1;

    // Use shadow colors if ThreeDProperties::useShadowColors is set
    // Note: Setting a new color on a brush or pen does not effect gradients or textures
    if ( props.useShadowColors ) {
        QBrush shadowBrush( brush );
        QPen shadowPen( pen );
        shadowBrush.setColor( calcShadowColor( brush.color(), props.angle ) );
        shadowPen.setColor( calcShadowColor( pen.color(), props.angle ) );
        painter->setBrush( shadowBrush );
        painter->setPen( shadowPen );
    } else {
        painter->setBrush( brush );
        painter->setPen( pen );
    }

    painter->drawPolygon( threeDArea );

    return threeDArea;
}
Example #24
0
QRect CurveTracker::trackerRect( const QFont &font ) const
{
    QRect r = QwtPlotPicker::trackerRect( font );
    
    // align r to the first curve

    const QwtPlotItemList curves = plot()->itemList( QwtPlotItem::Rtti_PlotCurve );
    if ( curves.size() > 0 )
    {
        QPointF pos = invTransform( trackerPosition() );

        const QLineF line = curveLineAt(    
            static_cast<const QwtPlotCurve *>( curves[0] ), pos.x() );
        if ( !line.isNull() )
        {
            const double curveY = line.pointAt(
                ( pos.x() - line.p1().x() ) / line.dx() ).y();

            pos.setY( curveY );
            pos = transform( pos );

            r.moveBottom( pos.y() );            
        }
    }

    return r;
}
Example #25
0
WebWheelEvent WebEventFactory::createWebWheelEvent(QWheelEvent* e, const QTransform& fromItemTransform)
{
    float deltaX                            = 0;
    float deltaY                            = 0;
    float wheelTicksX                       = 0;
    float wheelTicksY                       = 0;
    WebWheelEvent::Granularity granularity  = WebWheelEvent::ScrollByPixelWheelEvent;
    WebEvent::Modifiers modifiers           = modifiersForEvent(e->modifiers());
    double timestamp                        = currentTimeForEvent(e);

    if (e->orientation() == Qt::Horizontal) {
        deltaX = e->delta();
        wheelTicksX = deltaX / 120.0f;
    } else {
        deltaY = e->delta();
        wheelTicksY = deltaY / 120.0f;
    }

    // Since we report the scroll by the pixel, convert the delta to pixel distance using standard scroll step.
    // Use the same single scroll step as QTextEdit (in QTextEditPrivate::init [h,v]bar->setSingleStep)
    static const float cDefaultQtScrollStep = 20.f;
    // ### FIXME: Default from QtGui. Should use Qt platform theme API once configurable.
    const int wheelScrollLines = 3;
    deltaX = wheelTicksX * wheelScrollLines * cDefaultQtScrollStep;
    deltaY = wheelTicksY * wheelScrollLines * cDefaultQtScrollStep;

    // Transform the position and the pixel scrolling distance.
    QLineF transformedScroll = fromItemTransform.map(QLineF(e->posF(), e->posF() + QPointF(deltaX, deltaY)));
    IntPoint transformedPoint = transformedScroll.p1().toPoint();
    IntPoint globalPoint = e->globalPosF().toPoint();
    FloatSize transformedDelta(transformedScroll.dx(), transformedScroll.dy());
    FloatSize wheelTicks(wheelTicksX, wheelTicksY);
    return WebWheelEvent(WebEvent::Wheel, transformedPoint, globalPoint, transformedDelta, wheelTicks, granularity, modifiers, timestamp);
}
void fmSegmentsImpl::changeSegment(const SegmentItem *cpLnItem)
{
	
	QPointF p = cpLnItem->scenePos();
	QLineF l = cpLnItem->line();
	SegmentSpace::segments().segmentByNumber(cpLnItem->data(0).toInt())->setPoints(l.p1() += p, l.p2() += p);
}
Example #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 );
}
Example #28
0
void KReportDesignerItemLine::setLineScene(QLineF l)
{
    m_start->setValue(positionFromScene(l.p1()));
    m_end->setValue(positionFromScene(l.p2()));
    
    setLine(l);
}
/**
 * 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;
}
Example #30
0
bool CalculateLaylines::checkIntersection( const QString &layerName, const QLineF &heading ) {

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

    return checkIntersection( layerName, WKTLine);

}