Example #1
0
void Edge::adjust()
{
  if (!source || !dest)
    return;

  QRectF srect = source->boundingRect();
  QRectF drect = dest->boundingRect();

  QLineF line(mapFromItem(source, srect.width() / 2, srect.height() / 2),
              mapFromItem(dest, drect.width() / 2, drect.height() / 2));
  qreal length = line.length();

  prepareGeometryChange();

  if (length > qreal(40.)) {
    qreal line_angle = line.angle();
    qreal angle = line_angle > 90. ? fmod(line_angle, 90.0) : line_angle;
    qreal dist = qMax(angle, 45.0) - qMin(angle, 45.0);
    dist += 80.0 - dist;
    QPointF edgeOffset((line.dx() * dist) / length, (line.dy() * dist) / length);
    sourcePoint = line.p1() + edgeOffset;
    destPoint = line.p2() - edgeOffset;
    qreal new_angle = QLineF(sourcePoint, destPoint).angle();
    if (qAbs(new_angle - line_angle) > 90.)
      sourcePoint = destPoint = line.p1();
  } else {
    sourcePoint = destPoint = line.p1();
  }
}
Example #2
0
void Edge::adjust()
{
	prepareGeometryChange();

	pa = mapFromItem(a, 0, 0);
	pb = mapFromItem(b, 0, 0);
}
Example #3
0
void ArrowItem::setEndItem(HEESGraphicsItem *item)
{
    if(endItem != NULL)
        endItem->removeConverter(startItem);
    endItem = item;
    if(endItem == NULL)
        return;

    switch( endItem->myType() )
    {
    case SOURCE:
        endOffsetX = -25;
        endOffsetY = 0;
        break;
    case BANK:
        endOffsetX = -20;
        endOffsetY = 20;
        break;
    case LOAD:
        endOffsetX = -20;
        endOffsetY = 20;
        break;
    case CTI:
        endOffsetX = 0;
        endOffsetY = 40;
        break;
    }
    endItem->addConverter(startItem);

    QLineF line( mapFromItem(startItem, startOffsetX, startOffsetY), mapFromItem(endItem, endOffsetX, endOffsetY) );
    setLine(line);
}
Example #4
0
void koregui::BindPathItem::paint(QPainter* painter,
                                  const QStyleOptionGraphicsItem* option,
                                  QWidget* widget) {
  // TODO(dospelt) use QPainterPathStroker
  QPointF start = mapFromItem(_start,6,6);
  QPointF dest = (_end)?mapFromItem(_end,6,6):_dragend;
  QPointF dist = QPointF((dest.x()- start.x())/2, 0);
  QPainterPath path(start);
  path.cubicTo(start + dist, dest - dist, dest);
  setPath(path);

  QPen p;
  p.setWidth(2);

  if (isSelected()) {
    p.setColor(QColor(100, 255, 255));
  } else {
    p.setColor(QColor(200, 200, 200));
  }
  if(_animated) {
    QVector<qreal> dashes;
    dashes << 4 << 3;
    p.setDashPattern(dashes);
    p.setDashOffset(_animOffset);
  }
  painter->setPen(p);
  painter->drawPath(path);
}
void TournamentArcDraw::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
	if(!_tail->collidesWithItem(_head))
	{
		const QPointF p1 = mapFromItem(_tail, 0, 0);
		const QPointF p2 = mapFromItem(_head, 0, 0);

		const double x1 = p1.x();
		const double x2 = p2.x();

		if(_tail->order() < _head->order())
		{
			painter->setPen(QPen(QBrush(Qt::gray), isSelected() ? 3 : 1));
		}
		else
		{
			painter->setPen(QPen(QBrush(Qt::black), isSelected() ? 3 : 1));
		}

		int height = (x2 - x1) / 4;
		QRectF rectangle(QPointF(x1, -height), QPointF(x2, height));

		int startAngle = 0 * 16;
		int spanAngle = 180 * 16;

		painter->drawArc(rectangle, startAngle, spanAngle);

		//QList<QColor> colors;
		//colors << Qt::red << Qt::green << Qt::blue << Qt::yellow;

		//painter->setPen(QPen(QBrush(Qt::green), 1, Qt::DashLine));
		//painter->drawPolygon(shape().toFillPolygon());
	}
}
Example #6
0
Wire::Wire(Port* source, Port* destination, QString id, QGraphicsItem *parent, QGraphicsScene *scene)
    : QGraphicsPathItem(parent, scene)
{
    setSource(source);
    setDestination(destination);
    setId(id);

    QPointF src = mapFromItem(d_source, 0, 0);
    QPointF dest = mapFromItem(d_destination, 0, 0);
    d_half = src + (dest-src)/2;

    segment = new QGraphicsRectItem(this);
    segment->setFlag(QGraphicsItem::ItemIsMovable, true);
    segment->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    segment->setFlag(QGraphicsItem::ItemIsSelectable, true);
    segment->setRect(-2,0,4,4);
    segment->setBrush(QBrush(Qt::black));
    //segment->setLine(d_half.x(),src.y(),d_half.x(),dest.y());
    //this->scene()->addItem(segment);
    //scene->addItem(segment);

    QPointF half = mapToScene(d_half);
    segment->setPos(half);

    //setFlag(QGraphicsItem::ItemIsMovable, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);

    updatePosition();
}
QPainterPath TournamentArcDraw::shape() const
{
	QPainterPath path;

	QPointF p1 = mapFromItem(_tail, 0, 0);
	QPointF p2 = mapFromItem(_head, 0, 0);

	double x1 = p1.x();
	double x2 = p2.x();

	if(x1 > x2)
	{
		qSwap(p1, p2);
		qSwap(x1, x2);
	}

	// TODO: Fix this, then make it selectable
	path.moveTo(p2);
	//path.lineTo(x1-2, 10);

	//path.addRect(0, 0, 20, 20);

	int height = (x2 - x1) / 4;

	int startAngle = 0;
	int spanAngle = 180;

	path.arcTo(QRectF(QPointF(x1, -height), QPointF(x2, height)), startAngle, spanAngle);
	path.arcTo(QRectF(QPointF(x1, -height), QPointF(x2, height)), spanAngle, -spanAngle);

	QPainterPathStroker stroker;
	stroker.setWidth(6);

	return stroker.createStroke(path);
}
void GraphicsTransition::updatePosition(){

    if(mCurrentState != nullptr && mNextState != nullptr){
        QLineF line(mapFromItem(mCurrentState, 20, 0), mapFromItem(mNextState, 0, 0));
        setLine(line);

    }
}
Example #9
0
void Ligacao::atualizaPosAutoRelacionamento()
{
    if (( castItem1P != NULL ) && ( castItem2P != NULL ))
    {
        QLineF line(mapFromItem( castItem1P, -30, 0 ), mapFromItem( castItem2P, -30, 0 ));
        setLine(line);
    }
}
Example #10
0
 foreach (Edge *edge, edgeList) {
     QPointF pos;
     if (edge->sourceNode() == this)
         pos = mapFromItem(edge->destNode(), 0, 0);
     else
         pos = mapFromItem(edge->sourceNode(), 0, 0);
     xvel += pos.x() / weight;
     yvel += pos.y() / weight;
 }
Example #11
0
/**
 * Returns the start point of the arrow
 * @return the start point
 */
QPointF Arrow::startPoint()
{
    QPointF startLT = mapFromItem(myStartItem, 0, 0);
    QPointF endLT = mapFromItem(myEndItem, 0, 0);
    if(startLT.x() + myStartItem->idealSize().width() + S
        < endLT.x() + myEndItem->idealSize().width())
        return startLT + QPointF(myStartItem->idealSize().width(), 0);
    else
        return startLT;
}
QRectF TournamentArcDraw::boundingRect() const
{
	const QPointF p1 = mapFromItem(_tail, 0, 0);
	const QPointF p2 = mapFromItem(_head, 0, 0);

	const double x1 = p1.x();
	const double x2 = p2.x();

	int height = (x2 - x1) / 4;
	return QRectF(QPointF(x1, -height), QPointF(x2, height));
}
Example #13
0
void Edge::adjust()
{
    if (!source || !dest)
        return;

    QPointF pStart = mapFromItem(source, 0, 0);
    QPointF pEnd = mapFromItem(dest, 0, 0);
    QRectF sourceBounds = source->boundingRect();
    QRectF destBounds = dest->boundingRect();

    //move points to middle of boundingboxes
    pStart.setX(pStart.x() + source->boundingRect().width()/2);
    pEnd.setX(pEnd.x() + dest->boundingRect().width()/2);
    pStart.setY(pStart.y() + source->boundingRect().height()/2);
    pEnd.setY(pEnd.y() + dest->boundingRect().height()/2);

    //adjust docking edges relative to point positions
    if (abs(pStart.y() - pEnd.y()) < destBounds.height()+30.f)//start and end are approximately at same height
    {
    	if (pStart.x() > pEnd.x()) //start is to the right of end
    	{
    		pStart.setX(pStart.x()-sourceBounds.width()/2);
    		pEnd.setX(pEnd.x()+destBounds.width()/2);
    	}
    	else //start is to the left of end
    	{
    		pStart.setX(pStart.x()+sourceBounds.width()/2);
    		pEnd.setX(pEnd.x()-destBounds.width()/2);
    	}
    }
    else if (pStart.y() > pEnd.y())//start is over end
    {
    	pStart.setY(pStart.y()-sourceBounds.height()/2);
    	pEnd.setY(pEnd.y()+destBounds.height()/2);
    }
    else //start is under end
    {
    	pStart.setY(pStart.y()+sourceBounds.height()/2);
    	pEnd.setY(pEnd.y()-destBounds.height()/2);
    }

    QLineF line(pStart, pEnd);
    qreal length = line.length();

    prepareGeometryChange();

    if (length > qreal(20.)) {
    	QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
    	sourcePoint = line.p1() + edgeOffset;
    	destPoint = line.p2() - edgeOffset;
    } else {
    	sourcePoint = destPoint = line.p1();
    }
}
Example #14
0
void Connection::resizeLine()
{
    QLineF line( mapFromItem( m_fromNode, 0, 0 ), mapFromItem( m_toNode, 0, 0 ) );
    const qreal length = line.length();

    QPointF edgeOffset(( line.dx() * 10 ) / length, ( line.dy() * 10 ) / length );

    prepareGeometryChange(); //prepareGeometryChange() will call update() if this is necessary
    m_sourcePoint = line.p1() + edgeOffset;
    m_destPoint = line.p2() - edgeOffset;
}
void GuiLink::UpdatePosition()
{
    QPointF tPoint0 = mapFromItem(mGuiNode0, 0, 0);
    tPoint0.setX(tPoint0.x() + mGuiNode0->GetWidth() / 2);
    tPoint0.setY(tPoint0.y() + mGuiNode0->GetHeight() / 2);
    QPointF tPoint1 = mapFromItem(mGuiNode1, 0, 0);
    tPoint1.setX(tPoint1.x() + mGuiNode1->GetWidth() / 2);
    tPoint1.setY(tPoint1.y() + mGuiNode1->GetHeight() / 2);
    //LOG(LOG_VERBOSE, "Line from %d,%d to %d,%d", (int)tPoint0.x(), (int)tPoint0.y(), (int)tPoint1.x(), (int)tPoint1.y());
    QLineF tLine(tPoint0, tPoint1);
    setLine(tLine);
}
Example #16
0
void ArrowItem::updatePosition()
{
    if( endItem != NULL )
    {
        QLineF line( mapFromItem(startItem, startOffsetX, startOffsetY), mapFromItem(endItem, endOffsetX, endOffsetY) );
        setLine(line);
    }
    else
    {
        QLineF line( mapFromItem(startItem, startOffsetX, startOffsetY), mapFromItem(startItem, startOffsetX, startOffsetY) );
        setLine(line);
    }
}
Example #17
0
void Edge::updatePosition()
{
    QLineF line(mapFromItem(source, 0, 0), mapFromItem(destination, 0, 0));
    this->setLine(line);
    textV->setPos((mapFromItem(source, 0, 0).x()+mapFromItem(destination, 0, 0).x())/2 + 2, (mapFromItem(source, 0, 0).y()+mapFromItem(destination, 0, 0).y())/2 + 10);
    //qDebug() << textV->pos();
    if (collidesWithItem(textV, Qt::IntersectsItemShape))
    {
        //qDebug() << "collission";
        //textV->setPos((mapFromItem(source, 0, 0).x()+mapFromItem(destination, 0, 0).x())/2 + 2, (mapFromItem(source, 0, 0).y()+mapFromItem(destination, 0, 0).y())/2 -10);
    }
    //qDebug() << textV->pos();
}
Example #18
0
 void Edge::adjust()
 {
     if (!source || !dest)
         return;

     QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
     qreal length = line.length();
     QPointF edgeOffset((line.dx() * 30) / length, (line.dy() * 30) / length);

     prepareGeometryChange();
     sourcePoint = line.p1() + edgeOffset;
     destPoint = line.p2() - edgeOffset;
 }
Example #19
0
void MultipleConnectionItem::rejigEndPoints()
{
	QPainterPath p;
	QPointF to = mapFromItem(m_to, m_to->tip());
	QPointF from = mapFromItem(m_from, m_from->tip());
	p.moveTo(from);
	QPointF c1((to.x() * 3 + from.x()) / 4.0, from.y());
	QPointF c2((to.x() + from.x() * 3) / 4.0, to.y());
	p.cubicTo(c1, c2, to);
	m_centre = QPointF((from.x() + to.x()) / 2, (from.y() + to.y()) / 2);
	p.addEllipse(m_centre, 5, 5);
	setPath(p);
}
Example #20
0
void CableItem::adjust() {
  QLineF line;
  boost::shared_ptr<ToolConnection> input = this->input.lock(), output = this->output.lock();
  if (input && output)
    line = QLineF(mapFromItem(input->parent, input->attachmentPos()), mapFromItem(output->parent, output->attachmentPos()));
  else if (input && dragPoint)
    line = QLineF(mapFromItem(input->parent, input->attachmentPos()), mapFromScene(*dragPoint));
  else if (dragPoint && output)
    line = QLineF(mapFromScene(*dragPoint), mapFromItem(output->parent, output->attachmentPos()));
  prepareGeometryChange();
  sourcePoint = line.p1();
  destPoint = line.p2();
}
Example #21
0
/**
 * Returns the middle point of the arrow
 * @return the middle point
 */
QPointF Arrow::midPoint()
{
    QPointF startLT = mapFromItem(myStartItem, 0, 0);
    QPointF endLT = mapFromItem(myEndItem, 0, 0);
    qreal x;

    if (startLT.x() + myStartItem->idealSize().width() + S
        < endLT.x() + myEndItem->idealSize().width())
        x = startLT.x() + myStartItem->idealSize().width() + S;
    else
        x = startLT.x() - S;

    return QPointF(x, endLT.y());
}
Example #22
0
void Edge::adjust()
{
    /// sourcePoint=source->myPos;
    /// NOTE: mapfrom Item is the key;)
    QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
    //QLineF line(sourcePoint,destPoint);
    qreal length = line.length();
    QPointF edgeOffset((line.dx() * 3) / length, (line.dy() * 3) / length);
    //prepareGeometryChange();
    update();
    sourcePoint = line.p1() ;//+ edgeOffset;
    destPoint = line.p2() ;//- edgeOffset;

}
Example #23
0
void LegendGroup::updateRect() {
	QPointF tl = mapFromItem(legends.at(0), legends.at(0)->boundingRect().topLeft());
	//Search for longest words:
	int count = 0;
	RichTextItem* txt;
	for (auto t : texts) {
		if (t->toPlainText().count() > count) {
			count = t->toPlainText().count();
			txt = t;
		}
	}
	QPointF br = mapFromItem(texts.at(texts.size()-1), texts.at(texts.size()-1)->boundingRect().bottomRight());
	br.setX(tl.x()+legends.at(0)->boundingRect().width()+txt->boundingRect().width()+10);
	frame->setRect(QRectF(tl + QPointF(-10, -10), br + QPointF(10, 10)));
}
Example #24
0
void Edge::adjust()
{
    if (!source || !dest)
	return;
    QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
    qreal length = line.length();
    prepareGeometryChange();
    if (!qFuzzyCompare(length, qreal(0.0))) {
	QPointF edgeOffset((line.dx() * 10) / length, (line.dy() * 10) / length);
	sourcePoint = line.p1() + edgeOffset;
	destPoint = line.p2() - edgeOffset;
    } else {
	sourcePoint = destPoint = line.p1();
    }
}
Example #25
0
QRectF TCBSpline::boundingRect() const
{
    static double left = 0.0;
    static double top = 0.0;
    static double right = 0.0;
    static double bottom = 0.0;

    // перебираем все вершины и строим по ним область рисования
    foreach (SplineVertex *vertex, controlVertices)
    {
        QPointF coord = mapFromItem(vertex, 0,0);

        qreal rx = coord.rx();
        qreal ry = coord.ry();

        if (left > rx)
            left = rx;

        if (top < ry)
            top = ry;

        if (right < rx)
            right = rx;

        if (bottom > ry)
            bottom = ry;
    }
Example #26
0
void Edge::adjust()
{
    if (!source_ || !target_)
        return;

	const QRectF source_rect(source_->boundingRect());
	const QRectF target_rect(target_->boundingRect());

    const QLineF line(
		mapFromItem(source_, source_rect.center()), 
		mapFromItem(target_, target_rect.center()));
       
    prepareGeometryChange();
    source_point_ = line.p1();
    target_point_ = line.p2();
}
Example #27
0
void core::Connector::setEndObject(GraphicObject *end)
{
	if(!end) return;

	endObject = end;

//	qDebug() << currentMousePos;
	//we use currentMousePos instead internal currentMousePos from "end" object due update mouse position problems
	//there are conflicts when moving mouse so using this currentMousePos ensures mouse pos is always updated

//	qDebug() << portRect;
	endPoint = mapFromItem(end, end->getCurrentPortPos(mapToItem(end, currentMousePos)));
	isBuildingConector = false;
//	qDebug() << portCenter;

	QRectF container = getContainerRect();


	if(currentMousePos.x() < 0 && currentMousePos.y() < 0){
		container.setTopLeft(endPoint );
	}else if(currentMousePos.x() < 0 && currentMousePos.y() >= 0){
		container.setBottomLeft(endPoint );
	}else if(currentMousePos.x() >= 0 && currentMousePos.y() < 0){
		container.setTopRight(endPoint );
	}else if(currentMousePos.x() >= 0 && currentMousePos.y() >= 0){
		container.setBottomRight(endPoint );
	}else{
		container= QRectF(0, 0, 0, 0);
	}

	setContainerRect(container);
}
Example #28
0
void Bond::adjust()
{
    if (!source || !dest)
        return;

    QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
    qreal length = line.length();

    prepareGeometryChange();

    if (length > qreal(20.) && length < qreal(190.0)) {
        sourcePoint = line.p1();
        destPoint = line.p2();
    } else {
        sourcePoint = destPoint = line.p1();
    }
}
Example #29
0
void RulerItem2::recalculate()
{
	char buffer[500];
	QPointF tmp;
	QFont font;
	QFontMetrics fm(font);

	if (timeAxis == NULL || depthAxis == NULL || pInfo.nr == 0)
		return;

	prepareGeometryChange();
	startPoint = mapFromItem(source, 0, 0);
	endPoint = mapFromItem(dest, 0, 0);

	if (startPoint.x() > endPoint.x()) {
		tmp = endPoint;
		endPoint = startPoint;
		startPoint = tmp;
	}
	QLineF line(startPoint, endPoint);
	setLine(line);
	compare_samples(source->entry, dest->entry, buffer, 500, 1);
	text = QString(buffer);

	// draw text
	QGraphicsView *view = scene()->views().first();
	QPoint begin = view->mapFromScene(mapToScene(startPoint));
	textItem->setText(text);
	qreal tgtX = startPoint.x();
	const qreal diff = begin.x() + textItem->boundingRect().width();
	// clamp so that the text doesn't go out of the screen to the right
	if (diff > view->width()) {
		begin.setX(begin.x() - (diff - view->width()));
		tgtX = mapFromScene(view->mapToScene(begin)).x();
	}
	// always show the text bellow the lowest of the start and end points
	qreal tgtY = (startPoint.y() >= endPoint.y()) ? startPoint.y() : endPoint.y();
	// this isn't exactly optimal, since we want to scale the 1.0, 4.0 distances as well
	textItem->setPos(tgtX - 1.0, tgtY + 4.0);

	// setup the text background
	textItemBack->setVisible(startPoint.x() != endPoint.x());
	textItemBack->setPos(textItem->x(), textItem->y());
	textItemBack->setRect(0, 0, textItem->boundingRect().width(), textItem->boundingRect().height());
}
Example #30
0
void Ligacao::atualizaPos()
{
    Poligono * properPoligono = (castItem1P != NULL) ? castItem1P : castItem2P;

    if (( castItem1P != NULL ) && ( castItem2P != NULL ))
    {
        if (( castItem1P->getAutoRelacionamento() ) && ( castItem2P->getAutoRelacionamento() ))
        {
            QLineF line(mapFromItem( castItem1P, 30,0 ), mapFromItem( castItem2P, 30,0 ));
            setLine(line);
        }
        else
        {
            QLineF line(mapFromItem( castItem1P, 0, 0 ), mapFromItem( castItem2P, 0, 0 ));
            setLine(line);
            //emit linhaAlterada(line);
        }
    }

    else if (( castItem1T != NULL ) && ( castItem2T != NULL ))
    {
        QLineF line(mapFromItem( castItem1T, castItem1T->rect().width()/2, castItem1T->rect().height()/2 ), mapFromItem( castItem2T, castItem2T->rect().width()/2, castItem2T->rect().height()/2 ));
        setLine(line);
    }

    else if (( properPoligono != NULL ) && ( castItemA != NULL ))
    {
        QLineF line(mapFromItem( properPoligono, 0, 0 ),
                    mapFromItem( castItemA, castItemA->rect().width()/2, castItemA->rect().height()/2 ));
        setLine(line);
    }
}