예제 #1
0
QPainterPath GraphicsUtils::shapeFromPath(const QPainterPath &path, const QPen &pen, double shapeStrokeWidth, bool includeOriginalPath)
{
	// this function mostly copied from QGraphicsItem::qt_graphicsItem_shapeFromPath


    // We unfortunately need this hack as QPainterPathStroker will set a width of 1.0
    // if we pass a value of 0.0 to QPainterPathStroker::setWidth()
    static const double penWidthZero = double(0.00000001);

    if (path == QPainterPath())
        return path;
    QPainterPathStroker ps;
    ps.setCapStyle(pen.capStyle());
    //ps.setCapStyle(Qt::FlatCap);
    if (shapeStrokeWidth <= 0.0)
        ps.setWidth(penWidthZero);
    else
        ps.setWidth(shapeStrokeWidth);

    ps.setJoinStyle(pen.joinStyle());
    ps.setMiterLimit(pen.miterLimit());
    QPainterPath p = ps.createStroke(path);
	if (includeOriginalPath) {
		p.addPath(path);
	}
    return p;
}
예제 #2
0
QRectF QAlphaPaintEnginePrivate::addPenWidth(const QPainterPath &path)
{
    Q_Q(QAlphaPaintEngine);

    QPainterPath tmp = path;

    if (m_pen.style() == Qt::NoPen)
        return (path.controlPointRect() * m_transform).boundingRect();
    bool cosmetic = qt_pen_is_cosmetic(m_pen, q->state->renderHints());
    if (cosmetic)
        tmp = path * m_transform;

    QPainterPathStroker stroker;
    if (m_pen.widthF() == 0.0f)
        stroker.setWidth(1.0);
    else
        stroker.setWidth(m_pen.widthF());
    stroker.setJoinStyle(m_pen.joinStyle());
    stroker.setCapStyle(m_pen.capStyle());
    tmp = stroker.createStroke(tmp);
    if (cosmetic)
        return tmp.controlPointRect();

    return (tmp.controlPointRect() * m_transform).boundingRect();
}
예제 #3
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); 
}
예제 #4
0
static QRectF qwtStrokedPathRect( 
    const QPainter *painter, const QPainterPath &path )
{
    QPainterPathStroker stroker;
    stroker.setWidth( painter->pen().widthF() );
    stroker.setCapStyle( painter->pen().capStyle() );
    stroker.setJoinStyle( painter->pen().joinStyle() );
    stroker.setMiterLimit( painter->pen().miterLimit() );

    QRectF rect;
    if ( qwtHasScalablePen( painter ) )
    {
        QPainterPath stroke = stroker.createStroke(path);
        rect = painter->transform().map(stroke).boundingRect();
    }
    else
    {
        QPainterPath mappedPath = painter->transform().map(path);
        mappedPath = stroker.createStroke( mappedPath );

        rect = mappedPath.boundingRect();
    }

    return rect;
}
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);
}
예제 #6
0
QPainterPath ArrowLinkItem::shape() const
{
    QPainterPath path = originalShape();
    QPainterPathStroker pathStroker;
    pathStroker.setWidth(10);
    return pathStroker.createStroke(path);
}
예제 #7
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;
}
예제 #8
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;
}
/**
 * @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());
}
예제 #10
0
QPainterPath Line::shape() const
{
    // sets the shape of the line for selection
    QPainterPathStroker stroker;
    stroker.setWidth(10);
    return stroker.createStroke(path);
}
예제 #11
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));
    }
}
예제 #12
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;
}
예제 #13
0
static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width)
{
    QPainterPathStroker stroker;
    stroker.setWidth(width);
    QPainterPath stroke = stroker.createStroke(path);
    return stroke.boundingRect();
}
예제 #14
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();
}
예제 #15
0
파일: GEdge.cpp 프로젝트: MIPT-ILab/ICDV
QPainterPath GEdge::shape() const {
    QPainterPath path(sourcePoint);
    QPainterPathStroker stroker;
    path.lineTo(destPoint);
    stroker.setWidth(20);
    return stroker.createStroke(path);
}
예제 #16
0
void LayoutBreak::draw(QPainter* painter) const
      {
      if (score()->printing() || !score()->showUnprintable())
            return;

      QPainterPathStroker stroker;
      stroker.setWidth(lw/2);
      stroker.setJoinStyle(Qt::MiterJoin);
      stroker.setCapStyle(Qt::SquareCap);

      QVector<qreal> dashes ;
      dashes.append(1);
      dashes.append(3);
      stroker.setDashPattern(dashes);
      QPainterPath stroke = stroker.createStroke(path);

      painter->fillPath(stroke, selected() ? MScore::selectColor[0] : MScore::layoutBreakColor);


      painter->setPen(QPen(selected() ? MScore::selectColor[0] : MScore::layoutBreakColor,
         lw, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
      painter->setBrush(Qt::NoBrush);
      painter->drawPath(path2);

      }
예제 #17
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);
}
예제 #18
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);
}
예제 #19
0
QPainterPath GraphicsItemEdge::shape() const
{
    QPainterPathStroker stroker;
    stroker.setWidth(g_settings->edgeWidth);
    stroker.setCapStyle(Qt::RoundCap);
    stroker.setJoinStyle(Qt::RoundJoin);
    return stroker.createStroke(path());
}
예제 #20
0
QRectF Connection::boundingRect() const
{
    if (!areInspectorsValid())
        return QRectF();

    QPainterPathStroker s;
    s.setWidth(20);
    return s.createStroke(path()).boundingRect();
}
예제 #21
0
QPainterPath LatexArrow::contour(qreal width) const
{
    QPainterPathStroker stroker;
    stroker.setJoinStyle(Qt::RoundJoin);
    stroker.setCapStyle(Qt::RoundCap);
    stroker.setWidth(width);

    return stroker.createStroke(path());
}
예제 #22
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);
}
예제 #23
0
QPainterPath QGVEdge::shape() const
{
    QPainterPathStroker ps;
    ps.setCapStyle(_pen.capStyle());
    ps.setWidth(_pen.widthF() + 10);
    ps.setJoinStyle(_pen.joinStyle());
    ps.setMiterLimit(_pen.miterLimit());
    return ps.createStroke(_path);
}
예제 #24
0
파일: line.cpp 프로젝트: genuser/freesch
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);
}
예제 #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);
}
예제 #26
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());//
}
/**
 * @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));
}
예제 #28
0
QPainterPath BoundRegion::shape() const
{
	if (!mStroke) {
		return mBoundItem.shape();
	}

	QPainterPathStroker stroker;
	stroker.setWidth(mStroke);
	return stroker.createStroke(mBoundItem.shape());
}
예제 #29
0
파일: wallItem.cpp 프로젝트: Anna-/qreal
void WallItem::recalculateBorders()
{
	QPainterPath wallPath;
	wallPath.moveTo(begin());
	wallPath.lineTo(end());

	QPainterPathStroker stroker;
	stroker.setWidth(wallWidth * 3 / 2);
	mPath = stroker.createStroke(wallPath);
}
예제 #30
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);
}