当前位置: 首页>>代码示例>>C++>>正文


C++ QPainterPath::subtracted方法代码示例

本文整理汇总了C++中QPainterPath::subtracted方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::subtracted方法的具体用法?C++ QPainterPath::subtracted怎么用?C++ QPainterPath::subtracted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPainterPath的用法示例。


在下文中一共展示了QPainterPath::subtracted方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: redo

void KarbonBooleanCommand::redo()
{
    if (! d->resultingPath) {
        // transform input pathes to global coordinates
        QPainterPath pa = d->pathA->absoluteTransformation(0).map(d->pathA->outline());
        QPainterPath pb = d->pathB->absoluteTransformation(0).map(d->pathB->outline());
        QPainterPath pr;
        switch (d->operation) {
        case Intersection:
            pr = pa.intersected(pb);
            break;
        case Subtraction:
            pr = pa.subtracted(pb);
            break;
        case Exclusion:
            pr = pa.subtracted(pb);
            pr.addPath(pb.subtracted(pa));
            break;
        case Union:
            pr = pa.united(pb);
            break;
        }

        QTransform transformationA = d->pathA->absoluteTransformation(0);
        // transform resulting path to local coordinate system of input path A
        pr = transformationA.inverted().map(pr);
        // create a path shape from the resulting path in local coordinates
        d->resultingPath = KoPathShape::createShapeFromPainterPath(pr);
        d->resultingPath->setStroke(d->pathA->stroke());
        d->resultingPath->setBackground(d->pathA->background());
        d->resultingPath->setShapeId(d->pathA->shapeId());
        // the created shape has a transformation applied so we have to
        // apply the original transformation instead of replacing with it
        d->resultingPath->applyAbsoluteTransformation(transformationA);
        d->resultingPath->setName(d->pathA->name());
        d->resultingPath->setZIndex(d->pathA->zIndex());
        d->resultingPath->setFillRule(d->pathA->fillRule());

        KoShapeGroup * group = dynamic_cast<KoShapeGroup*>(d->pathA->parent());
        if (group) {
            QList<KoShape*> children;
            d->resultParentCmd = new KoShapeGroupCommand(group, children << d->resultingPath, this);
        }
    }

    if (d->shapeBasedDocument) {
        if (d->resultParent)
            d->resultParent->addShape(d->resultingPath);
        d->shapeBasedDocument->addShape(d->resultingPath);
    }

    KUndo2Command::redo();

    d->isExecuted = true;
}
开发者ID:abhishekmurthy,项目名称:Calligra,代码行数:55,代码来源:KarbonBooleanCommand.cpp

示例2: redo

void KarbonBooleanCommand::redo()
{
    if (! d->resultingPath) {
        QPainterPath pa = d->pathA->absoluteTransformation(0).map(d->pathA->outline());
        QPainterPath pb = d->pathB->absoluteTransformation(0).map(d->pathB->outline());
        QPainterPath pr;
        switch (d->operation) {
        case Intersection:
            pr = pa.intersected(pb);
            break;
        case Subtraction:
            pr = pa.subtracted(pb);
            break;
        case Exclusion:
            pr = pa.subtracted(pb);
            pr.addPath(pb.subtracted(pa));
            break;
        case Union:
            pr = pa.united(pb);
            break;
        }

        QTransform transformation = d->pathA->transformation();
        pr = transformation.inverted().map(pr);
        d->resultingPath = KoPathShape::createShapeFromPainterPath(pr);
        d->resultingPath->setBorder(d->pathA->border());
        d->resultingPath->setBackground(d->pathA->background());
        d->resultingPath->setShapeId(d->pathA->shapeId());
        d->resultingPath->setTransformation(transformation);
        d->resultingPath->setName(d->pathA->name());
        d->resultingPath->setZIndex(d->pathA->zIndex());
        d->resultingPath->setFillRule(d->pathA->fillRule());

        KoShapeGroup * group = dynamic_cast<KoShapeGroup*>(d->pathA->parent());
        if (group) {
            QList<KoShape*> children;
            d->resultParentCmd = new KoShapeGroupCommand(group, children << d->resultingPath, this);
        }
    }

    if (d->controller) {
        if (d->resultParent)
            d->resultParent->addShape(d->resultingPath);
        d->controller->addShape(d->resultingPath);
    }

    QUndoCommand::redo();

    d->isExecuted = true;
}
开发者ID:KDE,项目名称:calligra-history,代码行数:50,代码来源:KarbonBooleanCommand.cpp

示例3: cutCircle

void QChain::cutCircle(Circle circle) {
  if (m_vertices.size() == 0) return;
  circle.setCenter(circle.pos());

  QPainterPath cr;
  cr.addEllipse(circle.x - circle.r, circle.y - circle.r, 2 * circle.r,
                2 * circle.r);

  QPolygonF polygon;
  for (QPointF p : m_vertices) polygon.append(p);
  QPainterPath chain;
  chain.addPolygon(polygon);

  if (!chain.intersects(cr)) return;

  chain = chain.subtracted(cr);

  for (const QPolygonF &poly : chain.toSubpathPolygons()) {
    std::vector<Vector2d> pts(poly.begin(), poly.end() - 1);

    if (std::fabs(Geometry::area(pts.begin(), pts.end())) > 5.f) {
      auto chain = std::make_unique<QChain>(world());
      chain->setVertices(std::vector<QPointF>(pts.begin(), pts.end()));
      chain->initializeLater(world());

      world()->itemSet()->addBody(std::move(chain));
    }
  }

  m_vertices.clear();
  destroyLater();
}
开发者ID:Hakiko,项目名称:GameEngine,代码行数:32,代码来源:QChain.cpp

示例4: shape

QPainterPath UBGraphicsProtractor::shape() const
{
    QPainterPath path = QGraphicsEllipseItem::shape();
    QPainterPath buttonPath;
    QRectF markerRect = markerButtonRect();

    QPointF center = rect().center();
    qreal centerX = center.x();
    qreal centerY = center.y();

    buttonPath.addRect(resizeButtonRect().adjusted(centerX, centerY, centerX, centerY));
    if (!resizeButtonRect().contains(markerRect))
    {
        buttonPath.addRect(markerRect.adjusted(centerX - markerRect.left() * 2 - markerRect.width(), centerY
                                               , centerX - markerRect.left() * 2 - markerRect.width(), centerY));
        buttonPath.addRect(markerRect.adjusted(centerX, centerY, centerX, centerY));
    }
    buttonPath.addRect(closeButtonRect().adjusted(centerX, centerY, centerX, centerY));
    buttonPath.addRect(resetButtonRect().adjusted(centerX, centerY, centerX, centerY));
    QTransform t;
    t.translate(centerX, centerY);
    t.rotate(-mStartAngle);
    t.translate(-centerX, -centerY);
    buttonPath = t.map(buttonPath);
    buttonPath = buttonPath.subtracted(path);
    path.addPath(buttonPath);

    return path;
}
开发者ID:xxbastekxx,项目名称:Sankore-3.1,代码行数:29,代码来源:UBGraphicsProtractor.cpp

示例5: shape

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);
}
开发者ID:adamnovak,项目名称:Bandage,代码行数:57,代码来源:graphicsitemnode.cpp

示例6: paint

void LongPressSpinner::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
	painter->save();
	//painter->setClipRect( option->exposedRect );

	int iconSize = boundingRect().size().toSize().width();
	//painter->translate(-iconSize/2,-iconSize/2);

	if(m_goodPressFlag)
	{
		// Draw inner gradient
		QColor centerColor = Qt::green;
		QRadialGradient rg(boundingRect().center(),iconSize);
		rg.setColorAt(0, centerColor/*.lighter(100)*/);
		rg.setColorAt(1, centerColor.darker(500));
		//p.setPen(Qt::black);
		painter->setBrush(QBrush(rg));

		//painter->setPen(QPen(Qt::black,3));
		painter->drawEllipse(boundingRect());
	}
	else
	{
		painter->setOpacity(0.75);

		// Draw inner gradient
		QColor centerColor("#0277fd"); // cream blue
		QRadialGradient rg(boundingRect().center(),iconSize);
		rg.setColorAt(0, centerColor/*.lighter(100)*/);
		rg.setColorAt(1, centerColor.darker(500));
		//p.setPen(Qt::black);
		painter->setBrush(QBrush(rg));

		//qDebug() << "LongPressSpinner::paint(): progress:"<<m_progress<<", rect:"<<boundingRect()<<", iconSize:"<<iconSize;

		QPainterPath outerPath;
		outerPath.addEllipse(boundingRect());

		QPainterPath innerPath;
		innerPath.addEllipse(boundingRect().adjusted(12.5,12.5,-12.5,-12.5));

		// Clip center of circle
		painter->setClipPath(outerPath.subtracted(innerPath));

		// Draw outline
		painter->setPen(QPen(Qt::black,3));
		//painter->drawEllipse(0,0,iconSize,iconSize);
		painter->drawChord(boundingRect().adjusted(3,3,-3,-3),
				0, -(int)(360 * 16 * m_progress)); // clockwise

		painter->setBrush(Qt::white);
		painter->drawChord(boundingRect().adjusted(10,10,-10,-10),
				0, -(int)(360 * 16 * m_progress)); // clocwise
	}

	painter->restore();
}
开发者ID:aicconsulting,项目名称:wifisigmap,代码行数:57,代码来源:LongPressSpinner.cpp

示例7: updatePositions

void OverlayWidget::updatePositions()
{
    if (!m_currentWidget || !m_currentToplevelWidget) {
        return;
    }

    if (!m_currentWidget->isVisible() || m_currentWidget->isHidden()) {
        m_widgetColor = Qt::green;
    } else {
        m_widgetColor = Qt::red;
    }

    const QPoint parentPos = m_currentWidget->mapTo(m_currentToplevelWidget, QPoint(0, 0));
    m_widgetRect = QRect(parentPos.x(), parentPos.y(),
                         m_currentWidget->width(),
                         m_currentWidget->height()).adjusted(0, 0, -1, -1);

    m_layoutPath = QPainterPath();

    if (m_currentWidget->layout() &&
            qstrcmp(m_currentWidget->layout()->metaObject()->className(), "QMainWindowLayout") != 0) {
        const QRect layoutGeometry = m_currentWidget->layout()->geometry();

        const QRect mappedOuterRect =
            QRect(m_currentWidget->mapTo(m_currentToplevelWidget,
                                         layoutGeometry.topLeft()), layoutGeometry.size());

        QPainterPath outerPath;
        outerPath.addRect(mappedOuterRect.adjusted(1, 1, -2, -2));

        QPainterPath innerPath;
        for (int i = 0; i < m_currentWidget->layout()->count(); ++i) {
            QLayoutItem *item = m_currentWidget->layout()->itemAt(i);
            if (item->widget() && !item->widget()->isVisible())
                continue;
            const QRect mappedInnerRect =
                QRect(m_currentWidget->mapTo(m_currentToplevelWidget,
                                             item->geometry().topLeft()), item->geometry().size());
            innerPath.addRect(mappedInnerRect);
        }

        m_layoutPath.setFillRule(Qt::OddEvenFill);
        m_layoutPath = outerPath.subtracted(innerPath);

        if (m_layoutPath.isEmpty()) {
            m_layoutPath = outerPath;
            m_layoutPath.addPath(innerPath);
            m_drawLayoutOutlineOnly = true;
        } else {
            m_drawLayoutOutlineOnly = false;
        }
    }

    update();
}
开发者ID:02JanDal,项目名称:GammaRay,代码行数:55,代码来源:overlaywidget.cpp

示例8: testSimplified

void tst_QPainterPath::testSimplified()
{
    QFETCH(QPainterPath, path);
    QFETCH(int, elements);

    QPainterPath simplified = path.simplified();

    QCOMPARE(simplified.elementCount(), elements);

    QVERIFY(simplified.subtracted(path).isEmpty());
    QVERIFY(path.subtracted(simplified).isEmpty());
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:12,代码来源:tst_qpainterpath.cpp

示例9: drawFrame

void FrameWidget::drawFrame(QPainter *p, const QRect& rect)
{
	QColor background = palette().color(QPalette::Window);

	p->save();
	if (d_frame == Line){
		QPen pen = QwtPainter::scaledPen(d_frame_pen);
		p->setPen(pen);
		int lw = pen.width()/2;
		QRect r = rect.adjusted(lw, lw, -lw - 1, -lw - 1);
		if (background.alpha() != 0)
			p->fillRect(r, background);
		if (d_brush.style() != Qt::NoBrush)
			p->setBrush(d_brush);

        QwtPainter::drawRect(p, r);
	} else if (d_frame == Shadow){
		int lw = d_frame_pen.width()/2;

		// calculate resolution factor
		double factorX = (double)p->paintEngine()->paintDevice()->logicalDpiX()/(double)plot()->logicalDpiX();
		double factorY = (double)p->paintEngine()->paintDevice()->logicalDpiY()/(double)plot()->logicalDpiY();

		int d = d_shadow_width + lw;
		if (!(lw % 2))
			d += 1;

		QPainterPath contents;
		QRect r = rect.adjusted(lw, lw, -qRound(d*factorX), -qRound(d*factorY));
		contents.addRect(r);

		QPainterPath shadow;
		shadow.addRect(rect.adjusted(qRound(d_shadow_width*factorX), qRound(d_shadow_width*factorY), 0, 0));

		p->fillPath(shadow.subtracted(contents), Qt::black);//draw shadow
		if (background.alpha() != 0)
			p->fillRect(r, background);
		p->setPen(QwtPainter::scaledPen(d_frame_pen));
		if (d_brush.style() != Qt::NoBrush)
			p->setBrush(d_brush);
		QwtPainter::drawRect(p, r);
	} else {
		if (background.alpha() != 0)
			p->fillRect(rect, background);
		if (d_brush.style() != Qt::NoBrush)
			p->fillRect(rect, d_brush);
	}

	p->restore();
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:50,代码来源:FrameWidget.cpp

示例10: operators_data

void tst_QPainterPath::operators_data()
{
    QTest::addColumn<QPainterPath>("test");
    QTest::addColumn<QPainterPath>("expected");

    QPainterPath a;
    QPainterPath b;
    a.addRect(0, 0, 100, 100);
    b.addRect(50, 50, 100, 100);

    QTest::newRow("a & b") << (a & b) << a.intersected(b);
    QTest::newRow("a | b") << (a | b) << a.united(b);
    QTest::newRow("a + b") << (a + b) << a.united(b);
    QTest::newRow("a - b") << (a - b) << a.subtracted(b);

    QPainterPath c = a;
    QTest::newRow("a &= b") << (a &= b) << a.intersected(b);
    c = a;
    QTest::newRow("a |= b") << (a |= b) << a.united(b);
    c = a;
    QTest::newRow("a += b") << (a += b) << a.united(b);
    c = a;
    QTest::newRow("a -= b") << (a -= b) << a.subtracted(b);
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:24,代码来源:tst_qpainterpath.cpp

示例11: shape

QPainterPath UBGraphicsDelegateFrame::shape() const
{
    QPainterPath path;

    //We do not use the rounded rect here because we want the bottom right corner
    //to be included in the frame (for resize grip handling : #702)
    path.addRect(rect());

    if (rect().width() > 0 && rect().height() > 0)
    {
        QPainterPath extruded;
        extruded.addRect(rect().adjusted(mFrameWidth, mFrameWidth, mFrameWidth * -1, mFrameWidth * -1));
        path = path.subtracted(extruded);
    }

    return path;
}
开发者ID:anaselli,项目名称:Sankore-3.1,代码行数:17,代码来源:UBGraphicsDelegateFrame.cpp

示例12: paint

void UBGraphicsDelegateFrame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    QPainterPath path;
    path.addRoundedRect(rect(), mFrameWidth / 2, mFrameWidth / 2);

    if (rect().width() > 1 && rect().height() > 1)
    {
        QPainterPath extruded;
        extruded.addRect(rect().adjusted(mFrameWidth, mFrameWidth, (mFrameWidth * -1), (mFrameWidth * -1)));
        path = path.subtracted(extruded);
    }

    painter->fillPath(path, brush());
}
开发者ID:anaselli,项目名称:Sankore-3.1,代码行数:17,代码来源:UBGraphicsDelegateFrame.cpp

示例13: painterPath

QPainterPath SquareThermalOpenCornersSymbol::painterPath(void)
{
  QPainterPath path;

  qreal angle_div = 360.0 / m_num_spokes;
  QPainterPath sub;
  QMatrix mat;

  // From what we seen in Genesis 2000, num_spokes can only be 1, 2, 4
  // angle can only be multiple of 45
  if ((m_num_spokes != 1 && m_num_spokes != 2 && m_num_spokes != 4) ||
      ((int)m_angle % 45 != 0)) {
    return path;
  }

  path.addRect(-m_od / 2, -m_od / 2, m_od, m_od);
  path.addRect(-m_id / 2, -m_id / 2, m_id, m_id);

  if ((int)m_angle % 90 == 0) {
    QPainterPath bar;
    bar.addRect(0, -m_gap / 2, m_od, m_gap);

    for (int i = 0; i < m_num_spokes; ++i) {
      sub.addPath(mat.map(bar));
      mat.rotate(-angle_div);
    }
  } else {
    qreal side = m_gap * qCos(M_PI / 4) + (m_od - m_id) / 2;
    qreal offset = (m_od - side) / 2;

    QPainterPath box;
    box.addRect(-side / 2, -side / 2, side, side);

    for (int i = 0; i < m_num_spokes; ++i) {
      QMatrix mat;
      mat.translate(offset * sign(qCos((m_angle + angle_div * i) * D2R)),
                    -offset * sign(qSin((m_angle + angle_div * i) * D2R)));
      sub.addPath(mat.map(box));
    }
  }

  path = path.subtracted(sub);

  return path;
}
开发者ID:aitjcize,项目名称:QCamber,代码行数:45,代码来源:squarethermalopencornerssymbol.cpp

示例14: paintEvent

/** paintEvent call with the update in the mouseMoveEvent */
void KPrPresentationHighlightWidget::paintEvent( QPaintEvent * event )
{
    Q_UNUSED(event);
    QPainter painter( this );
    QPen myPen;
    QColor c( Qt::black );
    // TODO make alpha configurable
    c.setAlphaF( 0.5 );
    // The circle we want
    QPainterPath ellipse;
    // TODO make radius configurable
    ellipse.addEllipse( m_center.x() - 75, m_center.y() - 75, 150, 150 );
    // All the 'background'
    QPainterPath myPath;
    myPath.addRect( 0, 0, m_size.rwidth(), m_size.rheight() );
    // We draw the difference
    painter.setPen( myPen );
    painter.fillPath( myPath.subtracted( ellipse ), c );
}
开发者ID:KDE,项目名称:calligra-history,代码行数:20,代码来源:KPrPresentationHighlightWidget.cpp

示例15: doDraw

void PeakRepresentationSphere::doDraw(
    QPainter &painter, PeakViewColor &foregroundColor,
    PeakViewColor &backgroundColor,
    std::shared_ptr<PeakPrimitives> drawingInformation,
    PeakRepresentationViewInformation viewInformation) {
  auto drawingInformationSphere =
      std::static_pointer_cast<PeakPrimitiveCircle>(drawingInformation);

  // Setup the QPainter
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setOpacity(drawingInformationSphere->peakOpacityAtDistance);

  // Add a pen with color, style and stroke, and a painter path
  auto foregroundColorSphere = foregroundColor.colorSphere;
  QPainterPath peakRadiusInnerPath;
  const QPointF originWindows(viewInformation.xOriginWindow,
                              viewInformation.yOriginWindow);
  peakRadiusInnerPath.addEllipse(originWindows,
                                 drawingInformationSphere->peakInnerRadiusX,
                                 drawingInformationSphere->peakInnerRadiusY);

  QPen pen(foregroundColorSphere);
  pen.setWidth(drawingInformationSphere->peakLineWidth);
  pen.setStyle(Qt::DashLine);
  painter.strokePath(peakRadiusInnerPath, pen);

  // Draw the background if this is requested
  if (m_showBackgroundRadius) {
    QPainterPath backgroundOuterPath;
    backgroundOuterPath.setFillRule(Qt::WindingFill);
    backgroundOuterPath.addEllipse(
        originWindows, drawingInformationSphere->backgroundOuterRadiusX,
        drawingInformationSphere->backgroundOuterRadiusY);
    QPainterPath backgroundInnerPath;
    backgroundInnerPath.addEllipse(
        originWindows, drawingInformationSphere->backgroundInnerRadiusX,
        drawingInformationSphere->backgroundInnerRadiusY);
    QPainterPath backgroundRadiusFill =
        backgroundOuterPath.subtracted(backgroundInnerPath);
    painter.fillPath(backgroundRadiusFill, backgroundColor.colorSphere);
  }
  painter.end();
}
开发者ID:mantidproject,项目名称:mantid,代码行数:43,代码来源:PeakRepresentationSphere.cpp


注:本文中的QPainterPath::subtracted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。