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();
}
Esempio n. 2
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. 3
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. 4
0
void Edge::paint(QPainter *painter,
                const QStyleOptionGraphicsItem *,
                QWidget *)
{
    if ( !is_visible() && !highlight)
        return;

    QPen pen(QColor("#0088ff"),2);
    pen.setCosmetic(true);

    if ( highlight && is_visible() )
    {
        pen.setColor(QColor("#00ccff"));
        pen.setWidth(pen.width()*2);
    }

    if ( type == WALL )
    {
        pen.setWidth(pen.width()*3);
        pen.setCapStyle(Qt::FlatCap);
    }
    else if ( type == INVERTED )
        pen.setStyle(Qt::DashLine);

    painter->setPen(pen);

    //if ( type != WALL )
        painter->drawLine(start->pos(),end->pos());
    /*else
    {
        QPainterPathStroker pps;
        pps.setWidth(pen.width()+1);
        QPainterPath pp(start->pos());
        pp.lineTo(end->pos());
        painter->drawPath(pps.createStroke(pp));
    }*/

    if ( type == WALL )
    {
        QPen p(Qt::white,pen.width()/3);
        p.setCosmetic(true);
        painter->setPen(p);
        painter->drawLine(start->pos(),end->pos());
    }

    if ( type == HOLE )
    {
        QLineF l = QLineF( start->pos(),end->pos() ).normalVector();
        l.setLength(5);
        l.translate((end->pos()-start->pos())/2);
        painter->drawLine(l);
        l.setLength(-5);
        painter->drawLine(l);
    }

}
Esempio n. 5
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);
    }
}
Esempio n. 6
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. 7
0
QPointF AngleVariation::calcVarExtremePoint(QLineF norm, QPointF point, float len)
{
    norm.setLength(len);
    QPointF newPoint = norm.p2();
    QPointF tempPoint = norm.p1() - point;
    newPoint = newPoint - tempPoint;
    return newPoint;
}
/**
 * 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 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)));
}
Esempio n. 10
0
static QLineF labelAttachmentLine( const QPointF &center, const QPointF &start, const QPainterPath &label )
{
    Q_ASSERT ( label.elementCount() == 5 );

    // start is assumed to lie on the outer rim of the slice(!), making it possible to derive the
    // radius of the pie
    const qreal pieRadius = QLineF( center, start ).length();

    // don't draw a line at all when the label is connected to its slice due to at least one of its
    // corners falling inside the slice.
    for ( int i = 0; i < 4; i++ ) { // point 4 is just a duplicate of point 0
        if ( QLineF( label.elementAt( i ), center ).length() < pieRadius ) {
            return QLineF();
        }
    }

    // find the closest edge in the polygon, and its two neighbors
    QPointF closeCorners[3];
    {
        QPointF closest = QPointF( 1000000, 1000000 );
        int closestIndex = 0; // better misbehave than crash
        for ( int i = 0; i < 4; i++ ) { // point 4 is just a duplicate of point 0
            QPointF p = label.elementAt( i );
            if ( QLineF( p, center ).length() < QLineF( closest, center ).length() ) {
                closest = p;
                closestIndex = i;
            }
        }

        closeCorners[ 0 ] = label.elementAt( wraparound( closestIndex - 1, 4 ) );
        closeCorners[ 1 ] = closest;
        closeCorners[ 2 ] = label.elementAt( wraparound( closestIndex + 1, 4 ) );
    }

    QLineF edge1 = QLineF( closeCorners[ 0 ], closeCorners[ 1 ] );
    QLineF edge2 = QLineF( closeCorners[ 1 ], closeCorners[ 2 ] );
    QLineF connection1 = QLineF( ( closeCorners[ 0 ] + closeCorners[ 1 ] ) / 2.0, center );
    QLineF connection2 = QLineF( ( closeCorners[ 1 ] + closeCorners[ 2 ] ) / 2.0, center );
    QLineF ret;
    // prefer the connecting line meeting its edge at a more perpendicular angle
    if ( normProjection( edge1, connection1 ) < normProjection( edge2, connection2 ) ) {
        ret = connection1;
    } else {
        ret = connection2;
    }

    // This tends to look a bit better than not doing it *shrug*
    ret.setP2( ( start + center ) / 2.0 );

    // make the line end at the rim of the slice (not 100% accurate because the line is not precisely radial)
    qreal p1Radius = QLineF( ret.p1(), center ).length();
    ret.setLength( p1Radius - pieRadius );

    return ret;
}
Esempio n. 11
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);
}
Esempio n. 12
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();
}
Esempio n. 13
0
/*!
 * \brief Places a line into given rectangle
 * \param the line
 * \param the rectangle
 * \return QLineF beginning and ending at the edges of the rectangle.
 */
QLineF GT::intersectLineRect(const QLineF &st, const QRectF &rect) {
  QLineF start = st;
  QPointF iss[3];
  int i = 0;
  // Půlnoční velkorysý odhad:
  double longEnough = fabs(rect.bottom()) + fabs(rect.top()) + fabs(rect.left()) + fabs(rect.right()) + fabs(start.x1()) + fabs(start.x2()) + fabs(start.y1()) + fabs(start.y2());
  start.setLength(longEnough);
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.bottomRight()), iss + i)) i++;
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.topLeft()), iss + i)) i++;
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.bottomRight()), iss + i)) i++;
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.topLeft()), iss + i)) i++;

  start.setLength(-longEnough);
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.bottomRight()), iss + i)) i++;
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.bottomLeft(),rect.topLeft()), iss + i)) i++;
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.bottomRight()), iss + i)) i++;
  if (QLineF::BoundedIntersection == start.intersect(QLineF(rect.topRight(),rect.topLeft()), iss + i)) i++;

  if (2 == i)
    return QLineF(iss[0],iss[1]);
  else return QLineF();
}
Esempio n. 14
0
void ArcItem::updateArrowPath(){
	QPainterPath path;
	if((_endItem && _startItem->primaryShape().intersects(_endItem->primaryShape())) ||
	   (!_endItem && _startItem->primaryShape().contains(_end))){
	   _cachedArrowPath = path;
		return;
	}
	QPointF start(0,0),
			point = _end - pos();

	//The arrow line and reverse liune
	QLineF revline(point, start);

	//Compute various points
	QLineF s = revline.normalVector();
	s.setAngle(revline.angle() - 45);
	s.setLength(ARROW_SIZE);
	QPointF side1 = s.p2();
	s = revline.normalVector();
	s.setAngle(revline.angle() + 45);
	s.setLength(ARROW_SIZE);
	QPointF side2 = s.p2();

	s = QLineF(side1, side2);
	QPointF head = point;
	s.intersect(revline, &head);

	path.moveTo(start);
	path.lineTo(head);
	path.lineTo(side1);
	path.lineTo(point);
	path.lineTo(side2);
	path.lineTo(head);

	_cachedArrowPath = path;
}
Esempio n. 15
0
/**
 * @brief Create help create tool.
 * @param _id tool id, 0 if tool doesn't exist yet.
 * @param pointName point name. point name.
 * @param typeLine line type.
 * @param formula string with length formula.
 * @param firstPointId id first point of line.
 * @param secondPointId id second point of line.
 * @param mx label bias x axis.
 * @param my label bias y axis.
 * @param scene pointer to scene.
 * @param doc dom document container.
 * @param data container with variables.
 * @param parse parser file mode.
 * @param typeCreation way we create this tool.
 */
VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine,
                                       QString &formula, const quint32 &firstPointId, const quint32 &secondPointId,
                                       const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc,
                                       VContainer *data, const Document &parse, const Source &typeCreation)
{
    const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
    const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
    QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF());

    line.setLength(qApp->toPixel(CheckFormula(formula, data)));

    quint32 id = _id;
    if (typeCreation == Source::FromGui)
    {
        id = data->AddGObject( new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
        data->AddLine(firstPointId, id);
        data->AddLine(id, secondPointId);
    }
    else
    {
        data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
        data->AddLine(firstPointId, id);
        data->AddLine(id, secondPointId);
        if (parse != Document::FullParse)
        {
            doc->UpdateToolData(id, data);
        }
    }
    VDrawTool::AddRecord(id, Tool::AlongLineTool, doc);
    if (parse == Document::FullParse)
    {
        VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId,
                                                   secondPointId, typeLine, typeCreation);
        scene->addItem(point);
        connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
        connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolAlongLine::SetFactor);
        connect(scene, &VMainGraphicsScene::DisableItem, point, &VToolAlongLine::Disable);
        doc->AddTool(id, point);
        doc->IncrementReferens(firstPointId);
        doc->IncrementReferens(secondPointId);
        return point;
    }
    return nullptr;
}
Esempio n. 16
0
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    if ( isSelected() )
    {
        QPen pen(color_selected,2);
        pen.setCosmetic(true);
        painter->setPen(pen);
        QLineF nv = to_line().normalVector();
        nv.setLength((Node::external_radius()-2)/painter->matrix().m11());
        painter->drawLine(to_line().translated(nv.dx(),nv.dy()));
        painter->drawLine(to_line().translated(-nv.dx(),-nv.dy()));
    }

    if ( visible && highlighted )
        m_style.edge_type->paint_highlighted(painter,*this);
    else if ( visible || highlighted )
        m_style.edge_type->paint_regular(painter,*this);

}
Esempio n. 17
0
QVector<QPointF> RoundedRectItem::calculatePoints(QPointF start_pnt, double start_angle, double end_angle)
{
	QVector<QPointF> points;
	QLineF lin;
	double inc=(start_angle > end_angle ? -10 : 10), ang=start_angle;
	bool end=false;

	while(!end)
	{
		lin.setP1(start_pnt);
		lin.setLength(radius);
		lin.setAngle(ang);
		points.append(lin.p2());
		ang+=inc;

		end=((inc > 0 && ang > end_angle) ||
			 (inc < 0 && ang < end_angle));
	}

	return(points);
}
Esempio n. 18
0
void EdgeItem::adjust()
{
    if (m_startNode == nullptr || m_endNode == nullptr)
        return;

    prepareGeometryChange();

    // update the line object
    m_line.setP1(m_startNode->pos());
    m_line.setP2(m_endNode->pos());

    // recalculate the start and end positions
    if (m_line.length() > 0.0) {
        QLineF trans = m_line.unitVector();
        trans.setLength(NodeItem::Radius);
        m_line.translate(trans.dx(), trans.dy());

        float newLength = m_line.length() - 2 * NodeItem::Radius;
        if (m_arrowhead) {
            newLength -= ArrowHeight / 2;
        }
        m_line.setLength(newLength);
    }
}
Esempio n. 19
0
void SelectionItem::updateDeltaLines()
{
    qreal x1, x2;
    x1 = this->leftSelected->x();
    x2 = this->rightSelected->sceneBoundingRect().bottomRight().x();

    // Text label for the delta between the left selected and the earlier item
    if (this->before) {
        if (textBefore == NULL && lineBefore == NULL) {
            // Create the elements
            textBefore = new QGraphicsTextItem(this);
            textBefore->setPlainText(QString::number(this->leftSelected->x() - this->before->pos().x()));
            textBefore->setPos(this->mapFromScene(x1 - textBefore->sceneBoundingRect().width(), 30.0));

            lineBefore = new QGraphicsLineItem(this);
            //qDebug() << "new lineBefore "<<this->leftSelected->x()<<this->before->pos().x();
            lineBefore->setLine(QLineF(this->mapFromScene(this->leftSelected->x(), 30.0),
                                       this->mapFromScene(this->before->pos().x(), 30.0)));
        }
        else {
            // Update the line and text label
            qreal d = this->leftSelected->x() - this->before->pos().x();
            //if (d < 0) {
                // We have crossed one item, update the atfer and before item
                TimelineScene *timeline = qobject_cast<TimelineScene *>(this->leftSelected->scene());
                this->before = timeline->getTriggerItemBefore(this->leftSelected);
                this->after = timeline->getTriggerItemAfter(this->rightSelected);

                if (this->before) {
                    // Update the before line
                    d = this->leftSelected->x() - this->before->pos().x();
                    QLineF line = this->lineBefore->line();
                    QPointF p2 = line.p2();
                    p2.setX(this->mapFromScene(this->before->pos()).x());
                    line.setP2(p2);
                    line.setLength(d);
                    this->lineBefore->setLine(line);
                    textBefore->setPlainText(QString::number(d));
                } else {
                    // No more before item, remove everything
                    qDebug() << "Remove before item";
                    timeline->removeItem(this->lineBefore);
                    delete this->lineBefore;
                    this->lineBefore = NULL;
                    timeline->removeItem(this->textBefore);
                    delete this->textBefore;
                    this->textBefore = NULL;
                }
                // the after line will be handled in the next part of this method
            /*} else {
                textBefore->setPlainText(QString::number(d));
                QLineF line = this->lineBefore->line();
                line.setLength(d);
                this->lineBefore->setLine(line);
            }*/
        }
    }

    // Text label for the delta between the right selected and the later item
    if (this->after) {
        if (textAfter == NULL && lineAfter == NULL) {
            // Create
            textAfter = new QGraphicsTextItem(this);
            textAfter->setPlainText(QString::number(this->after->pos().x() - this->rightSelected->x()));
            textAfter->setPos(this->mapFromScene(x2, 40.0));

            lineAfter = new QGraphicsLineItem(this);
            lineAfter->setLine(QLineF(this->mapFromScene(this->rightSelected->x(), 40.0),
                                      this->mapFromScene(this->after->pos().x(), 40.0)));
            qDebug() << "Create lineAfter" << QLineF(this->mapFromScene(this->rightSelected->x(), 40.0),
                                                     this->mapFromScene(this->after->pos().x(), 40.0));
        }
        else {
            // Update
            qreal d = this->after->pos().x() - this->rightSelected->x();
            //if (d < 0) {
                // We have crossed one item, update the atfer and before item
                TimelineScene *timeline = qobject_cast<TimelineScene *>(this->leftSelected->scene());
                this->before = timeline->getTriggerItemBefore(this->leftSelected);
                this->after = timeline->getTriggerItemAfter(this->rightSelected);

                if (this->after) {
                    // Update the after line
                    d = this->after->pos().x() - this->rightSelected->x();
                    QLineF line = this->lineAfter->line();
                    QPointF p2 = line.p2();
                    p2.setX(this->mapFromScene(this->after->pos()).x());
                    line.setP2(p2);
                    line.setLength(d);
                    this->lineAfter->setLine(line);
                    textAfter->setPlainText(QString::number(d));
                    qDebug() << "Update lineAfter" << line;
                } else {
                    // No more after item, remove everything
                    qDebug() << "Remove after item";
                    timeline->removeItem(this->lineAfter);
                    delete this->lineAfter;
                    this->lineAfter = NULL;
                    timeline->removeItem(this->textAfter);
                    delete this->textAfter;
                    this->textAfter = NULL;
                }
            /*} else {
                textAfter->setPlainText(QString::number(d));
                QLineF line = this->lineAfter->line();
                line.setLength(d);
                this->lineAfter->setLine(line);
            }*/
        }
    }
}
Esempio n. 20
0
void SelectionItem::updateDeltaLines()
{
    qreal x1, x2;
    x1 = this->leftSelected->x();
    x2 = this->rightSelected->sceneBoundingRect().bottomRight().x();

    // Update before and after items since we may have crossed over an item
    TimelineScene *timeline = qobject_cast<TimelineScene *>(this->leftSelected->scene());
    this->before = timeline->getTriggerItemBefore(this->leftSelected);
    this->after = timeline->getTriggerItemAfter(this->rightSelected);

    if (this->before) {
        qreal d = this->leftSelected->x() - this->before->pos().x();
        if (textBefore == NULL && lineBefore == NULL) {
            // Create the elements
            QPointF p1 = this->mapFromScene(this->leftSelected->x(), 30.0);
            QPointF p2 = this->mapFromScene(this->before->pos().x(), 30.0);

            textBefore = new QGraphicsTextItem(this);
            textBefore->setPlainText(QString::number(d * timeline->ratio(), 'f', 1));
            //textBefore->setPos(this->mapFromScene(x1 - textBefore->sceneBoundingRect().width(), 30.0));
            textBefore->setPos( (p1.x() + p2.x()) / 2, p1.y());
            lineBefore = new QGraphicsLineItem(this);
            lineBefore->setLine(QLineF(p1, p2));
            lineBeforeRight = new QGraphicsLineItem(p1.x(), 0.0, p1.x(), 40.0, this);
            lineBeforeLeft = new QGraphicsLineItem(p2.x(), 0.0, p2.x(), 40.0, this);
        }
        else {
            // Update the before line and label
            QLineF line = this->lineBefore->line();
            QPointF p2 = line.p2();
            p2.setX(this->mapFromScene(this->before->pos()).x());
            line.setP2(p2);
            line.setLength(d);
            this->lineBefore->setLine(line);
            textBefore->setPos((line.p1().x() + line.p2().x())/2,
                               line.p1().y());
            textBefore->setPlainText(QString::number(d * timeline->ratio(), 'f', 1));

            // the left before line should not move
            this->lineBeforeLeft->setLine(QLine(this->mapFromScene(this->before->pos()).x(),
                                                this->lineBeforeLeft->line().y1(),
                                                this->mapFromScene(this->before->pos()).x(),
                                                this->lineBeforeLeft->line().y2()));
        }
    } else {
        // No more before item, remove everything
        if (this->lineBefore) {
            timeline->removeItem(this->lineBefore);
            timeline->removeItem(this->lineBeforeLeft);
            timeline->removeItem(this->lineBeforeRight);
            delete this->lineBefore;
            delete this->lineBeforeLeft;
            delete this->lineBeforeRight;
            this->lineBefore = NULL; this->lineBeforeLeft = NULL; this->lineBeforeRight = NULL;
        }
        if (this->textBefore) {
            timeline->removeItem(this->textBefore);
            delete this->textBefore;
            this->textBefore = NULL;
        }
    }

    // Text label for the delta between the right selected and the later item
    if (this->after) {
        qreal d = this->after->pos().x() - this->rightSelected->x();
        if (textAfter == NULL && lineAfter == NULL) {
            // Create
            QPointF p1 = this->mapFromScene(this->rightSelected->x(), 30.0);
            QPointF p2 = this->mapFromScene(this->after->pos().x(), 30.0);
            textAfter = new QGraphicsTextItem(this);
            textAfter->setPlainText(QString::number(d * timeline->ratio(), 'f', 1));
            textAfter->setPos(this->mapFromScene(x2, 30.0));

            lineAfter = new QGraphicsLineItem(this);
            lineAfter->setLine(QLineF(p1, p2));
            lineAfterLeft = new QGraphicsLineItem(p1.x(), 0.0, p1.x(), 40.0, this);
            lineAfterRight = new QGraphicsLineItem(p2.x(), 0.0, p2.x(), 40.0, this);
        }
        else {
            // Update the after line and label
            QLineF line = this->lineAfter->line();
            QPointF p = line.p2();
            p.setX(this->mapFromScene(this->after->pos()).x());
            line.setP2(p);
            line.setLength(d);
            this->lineAfter->setLine(line);
            textAfter->setPlainText(QString::number(d * timeline->ratio(), 'f', 1));

            // the right after line should not move
            this->lineAfterRight->setLine(QLine(this->mapFromScene(this->after->pos()).x(),
                                                this->lineAfterRight->line().y1(),
                                                this->mapFromScene(this->after->pos()).x(),
                                                this->lineAfterRight->line().y2()));
        }
    } else {
        // No more after item, remove everything
        if (this->lineAfter) {
            timeline->removeItem(this->lineAfter);
            timeline->removeItem(this->lineAfterLeft);
            timeline->removeItem(this->lineAfterRight);
            delete this->lineAfter;
            delete this->lineAfterLeft;
            delete this->lineAfterRight;
            this->lineAfter = NULL; this->lineAfterLeft = NULL; this->lineAfterRight = NULL;
        }
        if (this->textAfter) {
            timeline->removeItem(this->textAfter);
            delete this->textAfter;
            this->textAfter = NULL;
        }
    }
}
Esempio n. 21
0
void Ray::adjust(qreal adjustment)
{
    QLineF l = line();
    l.setLength(l.length() * adjustment);
    setLine(l);
}
Esempio n. 22
0
QLineF Branch::moveBranchToEdgeOfRect(QPointF currPoint, QLineF newBranch, float posOnParent)
{
    QLineF tempLine = QLineF(branchLine.p1(), lv.getMaxPoint());
    tempLine.setLength(tempLine.length() * posOnParent);

    currPoint = tempLine.p2();

    QPointF differenceVec = newBranch.p1() - currPoint;
    newBranch.setP1(currPoint);
    newBranch.setP2(newBranch.p2() - differenceVec);

    QLineF tempNewBranch = newBranch;
    tempNewBranch.setLength(1000);

    QLineF sideLine1 = QLineF(maxRect[0], maxRect[3]);
    QLineF sideLine1Temp = sideLine1;
    sideLine1Temp.setLength(1000);
    sideLine1Temp = QLineF(sideLine1Temp.p2(), sideLine1Temp.p1());
    sideLine1Temp.setLength(1000);
    QLineF sideLine2 = QLineF(maxRect[1], maxRect[2]);
    QLineF topLine = QLineF(maxRect[2], maxRect[3]);

    QLineF finalLine;

    if (posOnParent < 0.95)
    {
        bool isSide1 = doLineSegmentsIntersect(sideLine1Temp, tempNewBranch);
        // find relative position of point on branchLine
        //float fullDistance = findDistance(branchLine.p1(), branchLine.p2());
        //float segDistance = findDistance(branchLine.p1(), currPoint);
        //float posOnParent = segDistance / fullDistance;

        // transpose to relative position on intersected rectangle line
        float outerRectLength;
        if (isSide1)
            outerRectLength = sideLine1.length();
        else
            outerRectLength = sideLine2.length();
        outerRectLength *= posOnParent;
        QPointF newStartPos;
        if (isSide1)
        {
            sideLine1.setLength(outerRectLength);
            newStartPos = sideLine1.p2();
        }
        else
        {
            sideLine2.setLength(outerRectLength);
            newStartPos = sideLine2.p2();
        }
        // find vector from point to newPoint
        QPointF changeVector = currPoint - newStartPos;
        // create newLine which moves newBranch by newPointVector
        finalLine.setP1(newStartPos);
        finalLine.setP2(newBranch.p2() - changeVector);
    }
    else
    {
        QPointF midPoint;
        midPoint.setX((topLine.p1().x() + topLine.p2().x())/2);
        midPoint.setY((topLine.p1().y() + topLine.p2().y())/2);

        QPointF diffVec = currPoint - midPoint;
        finalLine.setP1(midPoint);
        finalLine.setP2(newBranch.p2() - diffVec);
    }

    return finalLine;
}
void CanvasMode_EditPolygon::mouseMoveEvent(QMouseEvent *m)
{
	const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
	m->accept();
	double newX = mousePointDoc.x();
	double newY = mousePointDoc.y();
	if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed())
	{
		PageItem *currItem = m_doc->m_Selection->itemAt(0);
		QTransform itemMatrix = currItem->getTransform();
		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;
			double factor = 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));
			int maxF = qRound(getUserValFromFactor(factor));
			if (maxF <= 100)
				polyFactor = factor;
		}
		if (m_polygonPoint == useControlOuter)
		{
			polyRotation = stLinA.angle() - 90;
			if (polyRotation < -180)
				polyRotation += 360;
			if (polyRotation > 180)
				polyRotation -= 360;
		}
		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();
		}
		QPainterPath path = RegularPolygonPath(currItem->width(), currItem->height(), polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
		FPointArray ar;
		ar.fromQPainterPath(path);
		endPoint = ar.pointQF(2);
		startPoint = ar.pointQF(0);
		QLineF innerLine = QLineF(endPoint, centerPoint);
		innerLine.setAngle(innerLine.angle() + 90);
		innerLine.setLength(trueLength * polyCurvature);
		innerCPoint = innerLine.p2();
		QLineF outerLine = QLineF(startPoint, ar.pointQF(6));
		outerLine.setLength(outerLine.length() * polyOuterCurvature);
		outerCPoint = outerLine.p2();
		VectorDialog->setValues(polyCorners, polyFactor, polyUseFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature);
		blockUpdateFromItem(true);
		currItem->update();
		blockUpdateFromItem(false);
		path = itemMatrix.map(path);
		m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10));
	}
	Mxp = newX;
	Myp = newY;
}