Ejemplo n.º 1
0
/**
 * @return The shape of the AssociationLine.
 */
QPainterPath AssociationLine::shape() const
{
    QPainterPathStroker stroker;
    stroker.setWidth(qMax<qreal>(2*SelectedPointDiameter, pen().widthF()) + 2.0);  // allow delta region
    stroker.setCapStyle(Qt::FlatCap);
    return stroker.createStroke(path());
}
Ejemplo n.º 2
0
QPainterPath GEdge::shape() const {
    QPainterPath path(sourcePoint);
    QPainterPathStroker stroker;
    path.lineTo(destPoint);
    stroker.setWidth(20);
    return stroker.createStroke(path);
}
Ejemplo n.º 3
0
QPainterPath Line::shape() const
{
    // sets the shape of the line for selection
    QPainterPathStroker stroker;
    stroker.setWidth(10);
    return stroker.createStroke(path);
}
Ejemplo n.º 4
0
qreal PortHandler::linePortId(const QPointF &location, const QStringList &types) const
{
	for (int linePortNumber = 0; linePortNumber < mLinePorts.count(); linePortNumber++) {
		const StatLine * const linePort = mLinePorts.at(linePortNumber);
		if (!types.contains(linePort->type())) {
			continue;
		}

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

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

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

	return nonexistentPortId;
}
Ejemplo n.º 5
0
static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width)
{
    QPainterPathStroker stroker;
    stroker.setWidth(width);
    QPainterPath stroke = stroker.createStroke(path);
    return stroke.boundingRect();
}
Ejemplo n.º 6
0
void LineObject::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* /*widget*/)
{
    QGraphicsScene* objScene = scene();
    if(!objScene) return;

    QPen paintPen = pen();
    painter->setPen(paintPen);
    updateRubber(painter);
    if(option->state & QStyle::State_Selected)  { paintPen.setStyle(Qt::DashLine); }
    if(objScene->property(ENABLE_LWT).toBool()) { paintPen = lineWeightPen(); }
    painter->setPen(paintPen);

    if(objectRubberMode() != OBJ_RUBBER_LINE) painter->drawLine(line());

    //TODO: This is the initial concept for what realistic rendering be like. It's somewhat decent but needs improvement.
    if(objScene->property(ENABLE_LWT).toBool() && objScene->property(ENABLE_REAL).toBool())
    {
        painter->setPen(objectColor().darker(150)); //TODO: Improve this for black and dark colors
        QPainterPathStroker stroker;
        stroker.setWidth(0.35);
        stroker.setCapStyle(Qt::RoundCap);
        stroker.setJoinStyle(Qt::RoundJoin);
        QPainterPath realPath = stroker.createStroke(path());
        painter->drawPath(realPath);

        QLinearGradient grad(mapFromScene(objectMidPoint()), mapFromScene(objectEndPoint1()));
        grad.setColorAt(0, objectColor());
        grad.setColorAt(1, objectColor().darker(150)); //TODO: Improve this for black and dark colors
        grad.setSpread(QGradient::ReflectSpread);

        painter->fillPath(realPath, QBrush(grad));
    }
}
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);
}
Ejemplo n.º 8
0
static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject* object, const RenderStyle* style)
{ 
    QPainterPathStroker s;
    s.setWidth(KSVGPainterFactory::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));

    if (style->svgStyle()->capStyle() == ButtCap)
        s.setCapStyle(Qt::FlatCap);
    else if (style->svgStyle()->capStyle() == RoundCap)
        s.setCapStyle(Qt::RoundCap);

    if (style->svgStyle()->joinStyle() == MiterJoin) {
        s.setJoinStyle(Qt::MiterJoin);
        s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());
    } else if(style->svgStyle()->joinStyle() == RoundJoin)
        s.setJoinStyle(Qt::RoundJoin);

    const KCDashArray& dashes = KSVGPainterFactory::dashArrayFromRenderingStyle(style);
    double dashOffset = KSVGPainterFactory::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);

    unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;
    if(dashLength) {
        QVector<qreal> pattern;
        unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;

        for(unsigned int i = 0; i < count; i++)
            pattern.append(dashes[i % dashLength] / (float)s.width());

        s.setDashPattern(pattern);
    
        Q_UNUSED(dashOffset);
        // TODO: dash-offset, does/will qt4 API allow it? (Rob)
    }

    return s.createStroke(path);
}
Ejemplo n.º 9
0
static inline QRectF boundsOnStroke(QPainter *p, const QPainterPath &path, qreal width)
{
    QPainterPathStroker stroker;
    stroker.setWidth(width);
    QPainterPath stroke = stroker.createStroke(path);
    return p->transform().map(stroke).boundingRect();
}
Ejemplo n.º 10
0
QPainterPath ArrowLinkItem::shape() const
{
    QPainterPath path = originalShape();
    QPainterPathStroker pathStroker;
    pathStroker.setWidth(10);
    return pathStroker.createStroke(path);
}
Ejemplo n.º 11
0
qreal PortHandler::circularPortId(const QPointF &location, const QStringList &types) const
{
	for (int circularPortNumber = 0; circularPortNumber < mCircularPorts.count(); circularPortNumber++) {
		const StatCircular * const circularPort = mCircularPorts.at(circularPortNumber);
		if (!types.contains(circularPort->type())) {
			continue;
		}

		QPainterPathStroker ps;
		ps.setWidth(kvadratik);

		QPainterPath path;
		StatCircular::CircularPort circular = transformPortForNodeSize(circularPort);

		path.addEllipse({circular.x, circular.y}, circular.rx, circular.ry);

		path = ps.createStroke(path);
		if (path.contains(location)) {
			return circularPortNumber + mPointPorts.size() + mLinePorts.size()
				+ (pointByCircularPortAngle(circularPortNumber, location) / 360.0);
		}
	}

	return nonexistentPortId;
}
Ejemplo n.º 12
0
QPainterPath 
EdgeItem::shape() const
{
    QPainterPath path( srcP);
    QPainterPathStroker stroker;
        
    if ( srcP == dstP)
        return path;
    
    if ( edge()->isSelf())
    {
        path = selfEdgePath();
    } else
    {
        path.cubicTo( cp1, cp2, dstP);
    }
    if ( isNotNullP( edge()->style()))
    {
        stroker.setWidth( edge()->style()->pen().width() + 1);
    } else
    {
        stroker.setWidth( 2);
    }
    return stroker.createStroke( path); 
}
Ejemplo n.º 13
0
QGraphicsItemGroup *ProfileGraphicsView::plot_text(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent)
{
    QFont fnt(font());
    QFontMetrics fm(fnt);

    if (printMode)
        fnt.setPixelSize(tro->size);

    QPointF point(SCALEGC(pos.x(), pos.y())); // This is neded because of the SCALE macro.
    double dx = tro->hpos * (fm.width(text));
    double dy = tro->vpos * (fm.height());

    QGraphicsItemGroup *group = new QGraphicsItemGroup(parent);
    QPainterPath textPath;
    /* addText() uses bottom-left text baseline and the -3 offset is probably slightly off
     * for different font sizes. */
    textPath.addText(0, fm.height() - 3, fnt, text);
    QPainterPathStroker stroker;
    stroker.setWidth(3);
    QGraphicsPathItem *strokedItem = new QGraphicsPathItem(stroker.createStroke(textPath), group);
    strokedItem->setBrush(QBrush(getColor(TEXT_BACKGROUND)));
    strokedItem->setPen(Qt::NoPen);

    QGraphicsPathItem *textItem = new QGraphicsPathItem(textPath, group);
    textItem->setBrush(QBrush(getColor(tro->color)));
    textItem->setPen(Qt::NoPen);

    group->setPos(point.x() + dx, point.y() + dy);
    if (!printMode)
        group->setFlag(QGraphicsItem::ItemIgnoresTransformations);

    if (!parent)
        scene()->addItem(group);
    return group;
}
Ejemplo n.º 14
0
/**
 * Shape
 */
QPainterPath GuiEdge::shape() const
{
//    QPainterPath path( edge_start_point_priv);
    QPainterPathStroker stroker;
//    path.lineTo( edge_end_point_priv.x(), edge_end_point_priv.y());
    stroker.setWidth( 10);
    return stroker.createStroke( edge_curve_priv);
}
Ejemplo n.º 15
0
QPainterPath GraphicsItemEdge::shape() const
{
    QPainterPathStroker stroker;
    stroker.setWidth(g_settings->edgeWidth);
    stroker.setCapStyle(Qt::RoundCap);
    stroker.setJoinStyle(Qt::RoundJoin);
    return stroker.createStroke(path());
}
Ejemplo n.º 16
0
void tst_QPainterPathStroker::strokeEmptyPath()
{
    QPainterPath path;
    path.moveTo(10, 10);
    path.lineTo(10, 10);
    QPainterPathStroker stroker;
    QCOMPARE(stroker.createStroke(path), path);
}
Ejemplo n.º 17
0
QRectF Connection::boundingRect() const
{
    if (!areInspectorsValid())
        return QRectF();

    QPainterPathStroker s;
    s.setWidth(20);
    return s.createStroke(path()).boundingRect();
}
Ejemplo n.º 18
0
QPainterPath LatexArrow::contour(qreal width) const
{
    QPainterPathStroker stroker;
    stroker.setJoinStyle(Qt::RoundJoin);
    stroker.setCapStyle(Qt::RoundCap);
    stroker.setWidth(width);

    return stroker.createStroke(path());
}
Ejemplo n.º 19
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);
}
Ejemplo n.º 20
0
QPainterPath Line::shape() const
{
	QPainterPath path;
	path.moveTo(line().p1());
	path.lineTo(line().p2());
	QPainterPathStroker stroker;
	stroker.setWidth(100);
	stroker.setCapStyle(Qt::FlatCap);
	return stroker.createStroke(path);
}
Ejemplo n.º 21
0
QPainterPath BoundRegion::shape() const
{
	if (!mStroke) {
		return mBoundItem.shape();
	}

	QPainterPathStroker stroker;
	stroker.setWidth(mStroke);
	return stroker.createStroke(mBoundItem.shape());
}
Ejemplo n.º 22
0
void WallItem::recalculateBorders()
{
	QPainterPath wallPath;
	wallPath.moveTo(begin());
	wallPath.lineTo(end());

	QPainterPathStroker stroker;
	stroker.setWidth(wallWidth * 3 / 2);
	mPath = stroker.createStroke(wallPath);
}
/**
 * @brief PartTerminal::shape
 * @return the shape of this item
 */
QPainterPath PartTerminal::shape() const
{
	QPainterPath shape;
	shape.lineTo(second_point);

	QPainterPathStroker pps;
	pps.setWidth(1);

	return (pps.createStroke(shape));
}
Ejemplo n.º 24
0
QRectF EdgeItem::boundingRect() const
{
    //qDebug("rect");
    // QRectF r = m_path.boundingRect();
    //  qDebug()<<(void*)this<<" left "<<r.left()<<" top "<<r.top()<<" width  "<<r.width()<<" height "<<r.height();
    QPainterPathStroker s;
    s.setWidth(20);
    return s.createStroke( path() ).boundingRect();
    //QRectF(0,0, 20*m_curve,m_p1.x() - m_p0.x());//
}
Ejemplo n.º 25
0
void PainterBezier::updatePath()
{
    QPainterPath bezierPath;
    bezierPath.moveTo(m_p1);
    bezierPath.cubicTo( m_p2, m_p3, m_p4 );
    QPainterPathStroker outliner;
    outliner.setWidth(m_FillWidth);
    outliner.setCapStyle( Qt::FlatCap );
    m_Path = outliner.createStroke(bezierPath);
}
Ejemplo n.º 26
0
QPainterPath QtArrowItem::shape() const
{
  //Thanks to norobro for posting this code at 
  //http://www.qtcentre.org/threads/49201-Increase-margin-for-detecting-tooltip-events-of-QGraphicsLineItem
  QPainterPath path;
  QPainterPathStroker stroker;
  path.moveTo(line().p1());
  path.lineTo(line().p2());
  stroker.setWidth(10);
  return stroker.createStroke(path);
}
Ejemplo n.º 27
0
QPainterPath WorldModel::buildWallPath() const
{
	// TODO: Maintain a cache for this.
	QPainterPathStroker pathStroker;
	pathStroker.setWidth(3);
	QPainterPath wallPath;

	foreach (WallItem* wall, mWalls) {
		wallPath.moveTo(wall->begin());
		wallPath.lineTo(wall->end());
	}
Ejemplo n.º 28
0
bool WorldModel::checkCollision(QPolygonF const &robotRegion) const
{
	QPainterPath robotPath;
	robotPath.addPolygon(robotRegion);
	QPainterPathStroker pathStroker;
	pathStroker.setWidth(3);
	robotPath = pathStroker.createStroke(robotPath);

	QPainterPath wallPath = buildWallPath();
	return wallPath.intersects(robotPath);
}
Ejemplo n.º 29
0
void GraphicsArrowProgram::addRule(AbstractRulePtr abstract)
{
	ConfigurationStack &stack=ConfigurationStack::instance();

	//Append the rule to our list
	_rules << abstract;

	//Reset the tooltip
	Program program=stack.current().getProgramByName(_app_name, true);
	QString tooltip="<big><b>"+program.displayName()+"</b></big>";

	QVectorIterator<AbstractRulePtr> i(_rules);
	while(i.hasNext())
	{
		AbstractRulePtr rule=i.next();
		QVectorIterator<MRule> j(rule->mRules());

		tooltip+="<br />"+rule->displayName();

		while(j.hasNext())
			tooltip+="<br /> &nbsp; - "+j.next().displayName();
	}

	setToolTip(tooltip);

	//If the rule has warnings, calculate the new warning type of the arrow program
	if(stack.ruleHasWarnings(abstract->id()) && EditorConfig::outlineArrowPrograms() && _parent)
	{
		_warning_type|=stack.warningTypesForRuleAndSourceDomain(abstract->id(), _parent->source()->domain().name());

		//If there is a warning to display, change the border's color
		if(_warning_type!=InvalidType)
		{
			//Create the border if it didn't exist
			if(_border==0)
			{
				QPainterPathStroker stroker;
				stroker.setWidth(3);

				_border=new QGraphicsPathItem(stroker.createStroke(shape()), this, scene());
				_border->setPen(QPen(QBrush(), 0, Qt::NoPen));
				_border->setFlag(ItemStacksBehindParent, true);
			}

			ArrowColorAnimation &anim=ArrowColorAnimation::instance();
			_border->setBrush(anim.getColorFromRuleWarningType(_parent->warningType()));
			_border->setGraphicsEffect(new QGraphicsBlurEffect());
		}
	}

	//Hide the rule if necessary
	if(_hidden ^ stack.isRuleHidden(abstract->id()))
		setHiddenByUser(allRulesHidden() || stack.isProgramHidden(_app_name));
}
Ejemplo n.º 30
0
QPainterPath QgsLayoutItemPolyline::shape() const
{
  QPainterPath path;
  path.addPolygon( mPolygon );

  QPainterPathStroker ps;

  ps.setWidth( 2 * mMaxSymbolBleed );
  QPainterPath strokedOutline = ps.createStroke( path );

  return strokedOutline;
}