Exemplo n.º 1
0
QTransform
ImageTransformation::calcPostScaleXform(Dpi const& target_dpi)
{
	if (target_dpi.isNull()) {
		return QTransform();
	}

	// We are going to measure the effective DPI after the previous transforms.
	// Normally m_preScaledDpi would be symmetric, so we could just
	// use that, but just in case ...

	QTransform const to_orig(m_postScaleXform * m_transform.inverted());
	// IMPORTANT: in the above line we assume post-scale is the last transform.

	QLineF const hor_unit(QPointF(0, 0), QPointF(1, 0));
	QLineF const vert_unit(QPointF(0, 0), QPointF(0, 1));
	QLineF const orig_hor_unit(to_orig.map(hor_unit));
	QLineF const orig_vert_unit(to_orig.map(vert_unit));
	
	double const xscale = target_dpi.horizontal() * orig_hor_unit.length() / m_origDpi.horizontal();
	double const yscale = target_dpi.vertical() * orig_vert_unit.length() / m_origDpi.vertical();
	QTransform xform;
	xform.scale(xscale, yscale);
	return xform;
}
Exemplo n.º 2
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();
        }
    }
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
QRectF GraphicsArrowItem::boundingRect() const {
	QLineF l = line();
	double arrowSize = (l.length() < 40.0) ? 2.0 : l.length()/20.0;
	double extra = (pen().width() + ::sin(3.14/3.0) * arrowSize) / 2.0;
	QPointF p1 = l.p1();
	QPointF p2 = l.p2();
	return QRectF(p1, QSizeF(p2.x() - p1.x(), p2.y() - p1.y())).normalized().adjusted(-extra, -extra, extra, extra);
}
Exemplo n.º 5
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;
}
void CanvasMode_EditPolygon::mouseReleaseEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	m_canvas->m_viewMode.m_MouseButtonPressed = false;
	m_canvas->resetRenderMode();
	m->accept();
	PageItem *currItem = m_doc->m_Selection->itemAt(0);
	PageItem_RegularPolygon* item = currItem->asRegularPolygon();
	QTransform itemMatrix = currItem->getTransform();
	if ((m_polygonPoint == useControlInner) || (m_polygonPoint == useControlOuter) || (m_polygonPoint == useControlInnerCurve) || (m_polygonPoint == useControlOuterCurve))
	{
		double newX = mousePointDoc.x();
		double newY = mousePointDoc.y();
		QPointF cPoint = itemMatrix.map(centerPoint);
		QLineF stLinA = QLineF(cPoint, QPointF(newX, newY));
		uint cx = polyUseFactor ? polyCorners * 2 : polyCorners;
		double seg = 360.0 / cx;
		double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (currItem->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (currItem->height() / 2.0) + (currItem->height()/2.0) - currItem->height(), 2));
		if (m_polygonPoint == useControlInner)
		{
			polyInnerRot = stLinA.angle() - 90 - polyRotation - seg;
			polyFactor = stLinA.length() / sqrt(pow(sin(stLinA.angle() * M_PI / 180.0) * currItem->height() / 2.0, 2) + pow(cos(stLinA.angle() * M_PI / 180.0) * currItem->width() / 2.0, 2));
		}
		if (m_polygonPoint == useControlOuter)
			polyRotation = stLinA.angle() - 90;
		if (m_polygonPoint == useControlInnerCurve)
		{
			QPointF ePoint = itemMatrix.map(endPoint);
			QLineF stLinC = QLineF(ePoint, QPointF(newX, newY));
			polyCurvature = stLinC.length() / trueLength;
		}
		if (m_polygonPoint == useControlOuterCurve)
		{
			QPointF sPoint = itemMatrix.map(startPoint);
			QPointF sPoint2 = itemMatrix.map(currItem->PoLine.pointQF(6));
			QLineF stLinCo = QLineF(sPoint, QPointF(newX, newY));
			QLineF stLinCo2 = QLineF(sPoint, sPoint2);
			polyOuterCurvature = stLinCo.length() / stLinCo2.length();
		}
		item->polyFactor = polyFactor;
		item->polyRotation = polyRotation;
		item->polyCurvature = polyCurvature;
		item->polyInnerRot = polyInnerRot;
		item->polyOuterCurvature = polyOuterCurvature;
		item->recalcPath();
		VectorDialog->setValues(polyCorners, polyFactor, polyUseFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
		if (m_transaction)
		{
			m_transaction.commit();
			m_transaction.reset();
		}
	}
	QPainterPath path = itemMatrix.map(RegularPolygonPath(item->width(), item->height(), polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature));
	m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10));
}
Exemplo n.º 7
0
void Color_Wheel::mousePressEvent(QMouseEvent *ev)
{
    if ( ev->buttons() & Qt::LeftButton )
    {
        QLineF ray = line_to_point(ev->pos());
        if ( ray.length() <= inner_radius() )
            mouse_status = Drag_Square;
        else if ( ray.length() <= outer_radius() )
            mouse_status = Drag_Circle;
    }
}
Exemplo n.º 8
0
void MainWindow::sample() {
    if (m_points.size() > 1) {
        for (int i = 0; i < m_lines.size(); i++)
            delete m_lines[i];
        m_lines.clear();

        float length = 0;
        QPointF *prev = m_points.value(0);
        QList<float> lens;
        for (int i = 1; i < m_points.size(); i++) {
            QLineF *line = new QLineF(*prev, *m_points.value(i));
            m_lines.push_back(line);
            lens.push_back(line->length());
            length += line->length();
            prev = m_points.value(i);
        }

        for (int i = 0; i < m_samples.size(); i++)
            delete m_samples[i];
        m_samples.clear();

        float step = 1;
        int which = 0;
        float currdelta = 0;

        while (which < m_lines.size()) {
            float alpha = currdelta / lens[which];
            if (alpha < 0 || alpha > 1)
                printf("Error: alpha is not unit valued");
            m_samples.push_back(new QPointF(m_lines[which]->pointAt(alpha)));

            currdelta += step;

            if (currdelta > lens[which]) {
                currdelta -= lens[which];
                which++;
            }
        }

        if (m_sectval)
            delete m_sectval;

        m_sectval = new FloatImage(m_hsi->bands(), m_samples.size(), 1);
        m_hsi->section(m_samples, m_sectval);
    } else {
        if (m_sectval)
            delete m_sectval;

        m_sectval = new FloatImage(1, 1, 1);
    }

    updateSect();
}
Exemplo n.º 9
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();
    }
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
Meshing::Meshing(QPolygonF polyIn, double dist, QList<QPolygonF> polyOut) : original_(polyIn)
{
    if(original_.isEmpty())
        return;

    if(!original_.isClosed())
        original_ << original_.at(0);

    //Test poly
    if(!isGood())
        return;

    mesh_.clear();
    mesh_.push_back(original_);

    //qDebug();
    splitDiag();

    //int id = findBiggestPoly();
    //QPointF p = addMiddlePoint(id);

    double length = 0.0;
    do{
        QLineF l = findLongestLine();
        length = l.length();
        cutLine(l);
    }while(length>dist);

}
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();
}
Exemplo n.º 13
0
void SvgFlattener::unRotateChild(QDomElement & element, QMatrix transform) {

	// TODO: missing ellipse element

    if(!element.hasChildNodes()) {

		QString sw = element.attribute("stroke-width");
		if (!sw.isEmpty()) {
			bool ok;
			double strokeWidth = sw.toDouble(&ok);
			if (ok) {
                QLineF line(0, 0, strokeWidth, 0);
                QLineF newLine = transform.map(line);
				element.setAttribute("stroke-width", newLine.length());
			}
		}

		// I'm a leaf node.
		QString tag = element.nodeName().toLower();
		if(tag == "path"){
            QString data = element.attribute("d").trimmed();
            if (!data.isEmpty()) {
                const char * slot = SLOT(rotateCommandSlot(QChar, bool, QList<double> &, void *));
                PathUserData pathUserData;
                pathUserData.transform = transform;
                if (parsePath(data, slot, pathUserData, this, true)) {
                    element.setAttribute("d", pathUserData.string);
                }
            }
        }
Exemplo n.º 14
0
void MainWindow::drawLine(double rangle, int i,int n,int x2, int y2, double length, double angle, QGraphicsScene *scene)
{
    //base case, we recurse back out once this condition reached
    if (i == n)
        return;
    else{
        //create new line, based on previously drawn line
        QLineF q2;
        q2.setP1(QPointF(x2,y2));
        q2.setLength(length*.95);
        q2.setAngle(angle +rangle);
        scene->addLine(q2);
        QLineF q3;
        q3.setP1(QPointF(x2,y2));
        q3.setLength(length*.95);
        q3.setAngle(angle -rangle);
        scene->addLine(q3);
        QLineF q;
        q.setP1(QPointF(x2,y2));
        q.setLength(length*.95);
        q.setAngle(angle);
        scene->addLine(q);
        ui->graphicsView->setScene(scene);
        x2 = q.x2();
        y2 = q.y2();
        i = i+1;
        //call drawLine again, using new values
        drawLine(rangle, i,n,x2,y2,q.length(),q.angle(), scene);
    }
}
Exemplo n.º 15
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);
	}
}
Exemplo n.º 16
0
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());
}
Exemplo n.º 17
0
/**
 * Calcul le point sur la fleche le plus près du point donné en parametre
 * @brief Fleche::PointLePlusPres
 * @param Position  La osition à analyser
 * @return  La position sur la fleche la plus proche
 */
QPointF Fleche::PointLePlusPres(QPointF Position)
{
    //Calcul de la projection orthogonale de la position de la souris sur les segments verticaux de la flèche.
    QPointF Retour ;
    QPointF Projection ;
    qreal   Distance    (0);
    qreal   DistanceMini(INFINITY) ;
    QLineF  LigneBase ;
    QLineF  LigneSourisProj ;

    LigneSourisProj.setPoints(Position, Projection);

    //Pour tout les segments
    for(register int i = 0; i < this->ListePoints.length() -1; i++)
    {
        LigneBase.setPoints(this->ListePoints[i], this->ListePoints[i+1]);

        //S'il sont verticaux
        if(LigneBase.dx() == 0)
        {
            //On calcul les coordonnées du point
            Projection.setX(this->ListePoints[i].x());
            Projection.setY(Position.y());

            //Si le point sort du segment
            if(Projection.y() < this->ListePoints[i].y() || Projection.y() > this->ListePoints[i+1].y())
            {
                QLineF  LigneSourisP1 ;
                QLineF  LigneSourisP2 ;

                LigneSourisP1.setPoints(Position, this->ListePoints[i]);
                LigneSourisP2.setPoints(Position, this->ListePoints[i+1]);

                //On le recale sur l'extrémité la plus proche
                if(LigneSourisP1.length() < LigneSourisP2.length())
                {
                    Projection = this->ListePoints[i] ;
                }
                else
                {
                    Projection = this->ListePoints[i+1] ;
                }
            }

            //On renvois le point le plus proche de la souris
            Distance = LigneSourisProj.length() ;
            if(Distance < DistanceMini)
            {
                Retour          = Projection ;
                DistanceMini    = Distance ;
            }
        }
    }

    return Retour;
}
Exemplo n.º 18
0
/*!
  \fn qreal QLineF::angle(const QLineF &line) const

  \obsolete

  Returns the angle (in degrees) between this line and the given \a
  line, taking the direction of the lines into account. If the lines
  do not intersect within their range, it is the intersection point of
  the extended lines that serves as origin (see
  QLineF::UnboundedIntersection).

  \table
  \row
  \o \inlineimage qlinef-angle-identicaldirection.png
  \o \inlineimage qlinef-angle-oppositedirection.png
  \endtable

  When the lines are parallel, this function returns 0 if they have
  the same direction; otherwise it returns 180.

  \sa intersect()
*/
qreal QLineF::angle(const QLineF &l) const
{
    if (isNull() || l.isNull())
        return 0;
    qreal cos_line = (dx()*l.dx() + dy()*l.dy()) / (length()*l.length());
    qreal rad = 0;
    // only accept cos_line in the range [-1,1], if it is outside, use 0 (we return 0 rather than PI for those cases)
    if (cos_line >= -1.0 && cos_line <= 1.0) rad = acos( cos_line );
    return rad * 360 / M_2PI;
}
Exemplo n.º 19
0
void CollectableInputComponent::setPath(QPointF* start, QPointF* end) {
    parent_->setPos(*start);
    parent_->setStartPoint(start);
    QLineF tempPath = QLineF(*start, *end);

    while (!validateMovement(*end)) {
        if (tempPath.length() < 5)
        {
            tempPath.setLength(0);
            *end = tempPath.p2();
            break;
        }
        else
        {
            tempPath.setLength(tempPath.length() - 5);
        }
        *end = tempPath.p2();
    }

    parent_->setEndPoint(end);
    parent_->getPath().setPoints(*end, *start);
}
Exemplo n.º 20
0
Position FractalPresenter::positionFromTransform( const QTransform& transform )
{
    QPointF center( m_resolution.width() / 2.0, m_resolution.height() / 2.0 );

    QLineF line( center, QPointF( center.x() + m_resolution.height(), center.y() ) );
    QLineF mapped = preciselyMap( transform, line );

    Position position;
    position.setCenter( mapped.p1() );
    position.setZoomFactor( -log10( mapped.length() ) );
    position.setAngle( -atan2( mapped.dy(), mapped.dx() ) * 180.0 / M_PI );

    if ( position.angle() < 0.0 )
        position.setAngle( position.angle() + 360.0 );

    return position;
}
Exemplo n.º 21
0
void CollectableInputComponent::makeForce(){
    QVector2D force;
    QLineF distance = QLineF(parent_->getPos().x(), parent_->getPos().y(),
                             parent_->getPath().p1().x(),
                             parent_->getPath().p1().y());
    if (distance.length() <= parent_->getVelocity().length()) {
        if (parent_->getType() == RESOURCE_GEM) {
            parent_->setScale(GEM_SIZE);
        } else {
            parent_->setScale(RESOURCE_SIZE);
        }
        parent_->setAtEndOfPath(true);
    } else {
        force = QVector2D(parent_->getPath().unitVector().dx() * -1,
                          parent_->getPath().unitVector().dy() * -1);
        parent_->setForce(force);
    }
}
Exemplo n.º 22
0
QLineF Meshing::findLongestLine()
{
    QLineF line;

    for(int i=0;i<mesh_.size();i++){
        if(mesh_.at(i).size()<2)
            continue;
        if(!mesh_.at(i).isClosed())
            mesh_[i] << mesh_.at(i).at(0);
        for(int j=0;j<mesh_.at(i).size()-1;j++){
            QLineF l(mesh_.at(i).at(j),mesh_.at(i).at(j+1));
            if(l.length()>line.length())
                line = l;
        }
    }

    return line;
}
Exemplo n.º 23
0
void QgsColorWheel::mousePressEvent( QMouseEvent *event )
{
  //calculate where the event occurred -- on the wheel or inside the triangle?

  //create a line from the widget's center to the event
  QLineF line = QLineF( width() / 2.0, height() / 2.0, event->pos().x(), event->pos().y() );

  double innerLength = mWheelImage->width() / 2.0 - mWheelThickness;
  if ( line.length() < innerLength )
  {
    mClickedPart = QgsColorWheel::Triangle;
  }
  else
  {
    mClickedPart = QgsColorWheel::Wheel;
  }
  setColorFromPos( event->posF() );
}
void CanvasMode_EditPolygon::activate(bool fromGesture)
{
	m_polygonPoint = noPointDefined;
	m_canvas->m_viewMode.m_MouseButtonPressed = false;
	m_canvas->resetRenderMode();
	m_doc->DragP = false;
	m_doc->leaveDrag = false;
	m_canvas->m_viewMode.operItemMoving = false;
	m_canvas->m_viewMode.operItemResizing = false;
	m_view->MidButt = false;
	Mxp = Myp = -1;
	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 = new PolyVectorDialog(m_ScMW, polyCorners, polyFactor, polyUseFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
	VectorDialog->show();
	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();
	setModeCursor();
	if (fromGesture)
		m_view->update();
	connect(m_doc, SIGNAL(docChanged()), this, SLOT(updateFromItem()));
	
	connect(VectorDialog, SIGNAL(NewVectors(int, double, bool, double, double, double, double)), this, SLOT(applyValues(int, double, bool, double, double, double, double)));
	connect(VectorDialog, SIGNAL(endEdit()), this, SLOT(endEditing()));
	connect(VectorDialog, SIGNAL(paletteShown(bool)), this, SLOT(endEditing(bool)));
}
Exemplo n.º 25
0
qreal PortHandler::minDistanceFromLinePort(int linePortNumber, QPointF const &location) const
{
	QLineF const linePort = transformPortForNodeSize(mLinePorts[linePortNumber]);

	// Triangle side values.
	qreal const a = linePort.length();
	qreal const b = QLineF(linePort.p1(), location).length();
	qreal const c = QLineF(linePort.p2(), location).length();

	qreal const nearestPoint= nearestPointOfLinePort(linePortNumber, location);
	if ((nearestPoint < 0) || (nearestPoint > mMaximumFractionPartValue)) {
		return qMin(b, c);
	} else {
		qreal const p = (a + b + c) / 2;
		qreal const triangleSquare = sqrt(p * (p - a) * (p - b) * (p - c));
		qreal const minDistance = 2 * triangleSquare / a;
		return minDistance;
	}
}
Exemplo n.º 26
0
QPolygonF GraphicalRobotElement::calculateArrowHeadPosition (QLineF aLine) {
	int arrowSize = 10;
	QPolygonF polyF;
	QLineF Line;
	Line.setP1 (aLine.p2() );
	Line.setP2 (aLine.p1() );
	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);
	polyF.clear();
	polyF << Line.p1() << arrowP1 << arrowP2;
	return polyF;
}
Exemplo n.º 27
0
void Edge::adjust()
{
  if (!m_source_node || !m_dest_node) return;

  const QLineF line(mapFromItem(m_source_node, 0, 0), mapFromItem(m_dest_node, 0, 0));
  const double length{line.length()};

  prepareGeometryChange();

  if (length > 20.0)
  {
    const QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
    m_source_point = line.p1() + edgeOffset;
    m_dest_point = line.p2() - edgeOffset;
  }
  else
  {
    m_source_point = m_dest_point = line.p1();
  }
}
Exemplo n.º 28
0
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;
    }  
}
Exemplo n.º 29
0
void Robot::setGuardianLine(const QLineF &line,
                            const QPointF &footPoint)
{
    //Clear the previous data.
    resetGuardianLine();
    //Check the length of the line.
    if(line.length()==0.0)
    {
        return;
    }
    //Set has guardian line flag.
    m_hasGuardianLine=true;
    //Save the guardian line.
    m_guardianLine=line;
    //Get the opposite guardian line.
    m_oppositeGuardianLine=QLineF(m_guardianLine.p2(), m_guardianLine.p1());
    QLineF directionAngle=QLineF(QPointF(0.0, 0.0), QPointF(10.0, 0));
    directionAngle.setAngle(m_angle);
    //If the current angle is nearly to the angle, then the moving speed will be
    //1.0(follow the direction of the line), or -1.0(reverse direction of the
    //line)
    if(m_oppositeGuardianLine.angleTo(directionAngle) <
            m_guardianLine.angleTo(directionAngle))
    {
        m_movingSpeed=1.0;
        m_angle=m_guardianLine.angle();
    }
    else
    {
        m_movingSpeed=-1.0;
        m_angle=m_oppositeGuardianLine.angle();
    }
    //Move the robot to the foot point.
    setPos(footPoint);
    //Save the initial distance to p1.
    m_toP1Distance=pointDistance(m_guardianLine.p1(), footPoint);
}
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if (None == mCurrentTool)
        return;

    QLineF move = QLineF(mStartingPoint, event->scenePos());
    qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
    qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
    qreal width = delegated()->boundingRect().width() * mTotalScaleX;
    qreal height = delegated()->boundingRect().height() * mTotalScaleY;

    if (mOperationMode == Scaling)
    {
        if(!rotating())
        {
            mTranslateX = moveX;
            // Perform the resize
            if (resizingBottomRight())
            {
                // -----------------------------------------------------
                // ! We want to keep the aspect ratio with this resize !
                // -----------------------------------------------------
                qreal scaleX;
                qreal scaleY;

                if(!mMirrorX) {
                    scaleX = (width + moveX) / width;
                } else {
                    scaleX = (width - moveX) / width;
                }

                if(!mMirrorY) {
                    scaleY = (height + moveY) / height;
                } else {
                    scaleY = (height - moveY) / height;
                }

                qreal scaleFactor = (scaleX + scaleY) / 2;

                // Do not allow resizing of image size under frame size
                if (canResizeBottomRight(width, height, scaleFactor))
                {
                    if (mRespectRatio)
                    {
                        mScaleX = scaleFactor;
                        mScaleY = scaleFactor;
                    }
                    else
                    {
                        mScaleX = scaleX;
                        mScaleY = scaleY;
                    }
                }
            } else if (resizingLeft() || resizingRight())
            {
                if(width != 0) {
                    qreal scaleX = 0.0;
                    if(resizingLeft()) {
                        scaleX = (width - moveX) / width;
                    } else if(resizingRight()) {
                        scaleX = (width + moveX) / width;
                    }
                    if(mDelegate->isFlippable() && qAbs(scaleX) != 0) {
                        if((qAbs(width * scaleX)) < 2*mFrameWidth) {
                            bool negative = (scaleX < 0)?true:false;
                            if(negative) {
                                if(mMirrorX)
                                    scaleX = 2*mFrameWidth/width;
                                else
                                    scaleX = -2*mFrameWidth/width;
                            } else {
                                scaleX = -1;
                                mFlippedX = !mFlippedX;
                            }
                        }
                        mScaleX = scaleX;
                    } else if (scaleX > 1 || (width * scaleX) > 2 * mFrameWidth) {
                        mScaleX = scaleX;
                        if(resizingLeft()) {
                            mTranslateX = moveX;
                        }
                    }
                }
            } else if(resizingTop() || resizingBottom()) {
                if(height != 0) {
                    qreal scaleY = 0.0;
                    if(resizingTop()) {
                        scaleY = (height - moveY) / height;
                    } else if(resizingBottom()) {
                        scaleY = (height + moveY) / height;
                    }

                    if(mDelegate->isFlippable() && qAbs(scaleY) != 0) {
                        if((qAbs(height * scaleY)) < 2*mFrameWidth) {
                            bool negative = (scaleY < 0)?true:false;
                            if(negative) {
                                if(mMirrorY)
                                    scaleY = 2*mFrameWidth/width;
                                else
                                    scaleY = -2*mFrameWidth/width;
                            } else {
                                scaleY = -1;
                                mFlippedY = !mFlippedY;
                            }
                        }
                        mScaleY = scaleY;
                    } else if (scaleY > 1 || (height * scaleY) > 2 * mFrameWidth)
                    {
                        mScaleY = scaleY;
                        if(resizingTop()) {
                            mTranslateY = moveY;
                        }
                    }
                }
            }
        }
    }

    if (rotating())
    {
        mTranslateX = 0;
        mTranslateY = 0;

        QLineF startLine(sceneBoundingRect().center(), event->lastScenePos());
        QLineF currentLine(sceneBoundingRect().center(), event->scenePos());
        mAngle += startLine.angleTo(currentLine);

        if ((int)mAngle % 45 >= 45 - mAngleTolerance || (int)mAngle % 45 <= mAngleTolerance)
        {
            mAngle = qRound(mAngle / 45) * 45;
            mAngleOffset += startLine.angleTo(currentLine);
            if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance)
            {
                mAngle += mAngleOffset;
                mAngleOffset = 0;
            }
        }
        else if ((int)mAngle % 30 >= 30 - mAngleTolerance || (int)mAngle % 30 <= mAngleTolerance)
        {
            mAngle = qRound(mAngle / 30) * 30;
            mAngleOffset += startLine.angleTo(currentLine);
            if ((int)mAngleOffset % 360 > mAngleTolerance && (int)mAngleOffset % 360 < 360 - mAngleTolerance)
            {
                mAngle += mAngleOffset;
                mAngleOffset = 0;
            }
        }

        setCursorFromAngle(QString::number((int)mAngle % 360));
    }
    else if (moving())
    {
        mTranslateX = move.dx();
        mTranslateY = move.dy();
        moveLinkedItems(move);
    }

    if (mOperationMode == Scaling || moving() || rotating())
    {
        QTransform tr = buildTransform();

        if (resizingRight() || resizingBottom() || resizingBottomRight())
        {
            QPointF ref;

            // we just detects coordinates of corner before and after scaling and then moves object at diff between them.
            if (resizingBottomRight() && (mMirrorX || mMirrorY))
            {
                if (mFlippedX && !mMirrorX && mFlippedY)// && !mMirrorY)
                {
                    mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x();
                    mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y();
                }
                else if ((mFlippedX || mMirrorX) && (mFlippedY || mMirrorY))
                {
                    mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x();
                    mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y();
                }
                else if (mFlippedX || mMirrorX)
                {
                    mTranslateX += mInitialTransform.map(delegated()->boundingRect().topRight()).x() - tr.map(delegated()->boundingRect().topRight()).x();
                    mTranslateY += mInitialTransform.map(delegated()->boundingRect().topRight()).y() - tr.map(delegated()->boundingRect().topRight()).y();
                }
                else if (mFlippedY || mMirrorY)
                {
                    mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).x() - tr.map(delegated()->boundingRect().bottomLeft()).x();
                    mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomLeft()).y() - tr.map(delegated()->boundingRect().bottomLeft()).y();
                }
                else
                {
                    mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x();
                    mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y();
                }
            }
            else
            {
                mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x();
                mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y();
            }
        }
        else if (resizingTop() || resizingLeft())
        {
            QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight());
            QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight());
            mTranslateX += fixedPoint.x() - bottomRight.x();
            mTranslateY += fixedPoint.y() - bottomRight.y();
        }
        delegated()->setTransform(buildTransform());
    }
    else // resizing/resizing horizontally
    {

        if (resizingBottomRight())
        {
            static QSizeF incV = QSizeF();
            static QSizeF incH = QSizeF();

            if (mMirrorX && mMirrorY)
                mCurrentTool = ResizeTop;
            else
                mCurrentTool = ResizeBottom;

            incV = resizeDelegate(moveX, moveY);
            mOriginalSize += incV;

            if (mMirrorX && mMirrorY)
                mCurrentTool = ResizeLeft;
            else
                mCurrentTool = ResizeRight;

            move = QLineF(event->lastScenePos(), event->scenePos());
            moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
            moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);

            mFixedPoint = getFixedPointFromPos();

            incH = resizeDelegate(moveX, moveY);

            mOriginalSize -= incV;
            mOriginalSize += incH;

            mCurrentTool = ResizeBottomRight;
        }
        else
            resizeDelegate(moveX, moveY);
    }
    event->accept();
}