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; }
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; }
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(); }
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; }
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); }
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(); }
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(); }
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()); }
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(); }
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); }
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; }
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()); }
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; }
/** 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 ); }
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(); }
void tst_QPainterPath::testStroker() { QFETCH(QPainterPath, path); QFETCH(QPen, pen); QFETCH(QPainterPath, stroke); QPainterPathStroker stroker; stroker.setWidth(pen.widthF()); stroker.setCapStyle(pen.capStyle()); stroker.setJoinStyle(pen.joinStyle()); stroker.setMiterLimit(pen.miterLimit()); stroker.setDashPattern(pen.style()); stroker.setDashOffset(pen.dashOffset()); QPainterPath result = stroker.createStroke(path); // check if stroke == result QVERIFY(result.subtracted(stroke).isEmpty()); QVERIFY(stroke.subtracted(result).isEmpty()); }
void PieChart3D::paintLeft( QPainter& painter, QColor color ) { if ( myRender == WireFrame ) { return; } painter.save(); color.setAlpha( 125 ); configureColor( painter, color, 0 ); int width = painter.pen().width()/2; painter.setPen( Qt::NoPen ); QPainterPath path; QPainterPath ellipse1, ellipse2; ellipse1.addEllipse( myRect ); ellipse2.addEllipse( myRect.translated( 0, myHeight ) ); path.moveTo( ellipse1.pointAtPercent( 0.5 ) + QPointF( -width, 0 ) ); path.lineTo( ellipse2.pointAtPercent( 0.5 ) + QPointF( -width, 0 ) ); path.arcTo( myRect.translated( 0, myHeight ), 180, -90 ); path.moveTo( ellipse1.pointAtPercent( 0.5 ) ); path.arcTo( myRect, 180, 90 ); path = path.subtracted( ellipse1 ); painter.fillPath( path, color ); painter.restore(); }
QPainterPath BarnDoorWipeStrategy::clipPath(int step, const QRect &area) { qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount); if(reverse()) percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount); int stepx = static_cast<int>(area.width() * percent); int stepy = static_cast<int>(area.height() * percent); int width_2 = area.width() >> 1; int height_2 = area.height() >> 1; QPainterPath path; switch(subType()) { case BarnDoorWipeEffectFactory::Vertical: case BarnDoorWipeEffectFactory::VerticalReverse: { stepx = static_cast<int>(width_2 * percent); QPoint top(width_2, 0); QPoint bottom(width_2, area.height()); path.moveTo(top - QPoint(stepx, 0)); path.lineTo(top + QPoint(stepx, 0)); path.lineTo(bottom + QPoint(stepx, 0)); path.lineTo(bottom - QPoint(stepx, 0)); break; } case BarnDoorWipeEffectFactory::Horizontal: case BarnDoorWipeEffectFactory::HorizontalReverse: { stepy = static_cast<int>(height_2 * percent); QPoint left(0, height_2); QPoint right(area.width(), height_2); path.moveTo(left + QPoint(0, stepy)); path.lineTo(left - QPoint(0, stepy)); path.lineTo(right - QPoint(0, stepy)); path.lineTo(right + QPoint(0, stepy)); break; } case BarnDoorWipeEffectFactory::DiagonalBottomLeft: case BarnDoorWipeEffectFactory::DiagonalBottomLeftReverse: { path.moveTo(area.bottomLeft() + QPoint(stepx, 0)); path.lineTo(area.bottomLeft()); path.lineTo(area.bottomLeft() - QPoint(0, stepy)); path.lineTo(area.topRight() - QPoint(stepx, 0)); path.lineTo(area.topRight()); path.lineTo(area.topRight() + QPoint(0, stepy)); break; } case BarnDoorWipeEffectFactory::DiagonalTopLeft: case BarnDoorWipeEffectFactory::DiagonalTopLeftReverse: { path.moveTo(area.topLeft() + QPoint(0, stepy)); path.lineTo(area.topLeft()); path.lineTo(area.topLeft() + QPoint(stepx, 0)); path.lineTo(area.bottomRight() - QPoint(0, stepy)); path.lineTo(area.bottomRight()); path.lineTo(area.bottomRight() - QPoint(stepx, 0)); break; } default: return QPainterPath(); } path.closeSubpath(); if(reverse()) { QPainterPath areaPath; areaPath.addRect(area); path = areaPath.subtracted(path); } return path; }
bool PathCutPlugin::run(ScribusDoc* doc, QString) { QString vers = QString(qVersion()).left(5); if (vers < "4.3.3") { QMessageBox::information(doc->scMW(), tr("Qt Version too old"), tr("This plugin requires at least version 4.3.3 of the Qt library")); return true; } ScribusDoc* currDoc = doc; if (currDoc == 0) currDoc = ScCore->primaryMainWindow()->doc; if (currDoc->m_Selection->count() > 1) { PageItem *Item1 = currDoc->m_Selection->itemAt(0); PageItem *Item2 = currDoc->m_Selection->itemAt(1); if (Item1->itemType() != PageItem::PolyLine) { Item1 = currDoc->m_Selection->itemAt(1); Item2 = currDoc->m_Selection->itemAt(0); } FPointArray path = Item1->PoLine; QPainterPathStroker stroke; stroke.setWidth(Item1->lineWidth()); QPainterPath cutter = stroke.createStroke(path.toQPainterPath(false)); QMatrix ms; ms.translate(Item1->xPos() - Item2->xPos(), Item1->yPos() - Item2->yPos()); ms.rotate(Item1->rotation()); cutter = ms.map(cutter); path.map(ms); FPoint start = path.point(0); FPoint end = path.point(path.size()-2); QMatrix mm; mm.rotate(Item2->rotation()); QPainterPath objekt = mm.map(Item2->PoLine.toQPainterPath(true)); if ((objekt.contains(QPointF(start.x(), start.y()))) || (objekt.contains(QPointF(end.x(), end.y())))) { QMessageBox::information(doc->scMW(), tr("Error"), tr("The cutting line must cross the polygon and\nboth end points must lie outside of the polygon")); return true; } QPainterPath result = objekt.subtracted(cutter); FPointArray points; points.fromQPainterPath(result); Item2->PoLine = points; Item2->Frame = false; Item2->ClipEdited = true; Item2->FrameType = 3; currDoc->AdjustItemSize(Item2); Item2->OldB2 = Item2->width(); Item2->OldH2 = Item2->height(); Item2->updateClip(); Item2->ContourLine = Item2->PoLine.copy(); currDoc->m_Selection->clear(); currDoc->m_Selection->addItem(Item1); currDoc->itemSelection_DeleteItem(); currDoc->m_Selection->clear(); currDoc->m_Selection->addItem(Item2); currDoc->itemSelection_SplitItems(); currDoc->changed(); } return true; }
// This function generates puzzle piece shapes. // ---------- // unit - the size of the rectangular base of the puzzle piece // status - flags of TabStatus values that describe the shape of this puzzle piece // tabFull - the full size of tabs including stroke, offset, tolerance // tabSize - size of tabs // tabOffset - offset of tabs (meaning: how far away they are from the edge of the piece) // tabTolerance - extra size to the tabs (so that merging works flawlessly, without visual artifacts) // blankSize - size of blanks // blankOffset - offset of blanks (meaning: how far away they are from the edge of the piece) // ---------- static QPainterPath createPuzzleShape(QSize unit, int status, qreal tabFull, qreal tabSize, qreal tabOffset, qreal tabTolerance, qreal blankSize, qreal blankOffset) { QPainterPath rectClip; rectClip.addRect(tabFull - 1, tabFull - 1, unit.width() + 1, unit.height() + 1); QPainterPath clip = rectClip; // Left if (status & Puzzle::Creation::LeftBlank) { QPainterPath leftBlank; leftBlank.addEllipse(QPointF(tabFull + blankOffset, tabFull + unit.height() / 2.0), blankSize, blankSize); clip = clip.subtracted(leftBlank); } else if (status & Puzzle::Creation::LeftTab) { QPainterPath leftTab; leftTab.addEllipse(QPointF(tabSize + tabTolerance, tabFull + unit.height() / 2.0), tabSize + tabTolerance, tabSize + tabTolerance); clip = clip.united(leftTab); } // Top if (status & Puzzle::Creation::TopBlank) { QPainterPath topBlank; topBlank.addEllipse(QPointF(tabFull + unit.width() / 2.0, tabFull + blankOffset), blankSize, blankSize); clip = clip.subtracted(topBlank); } else if (status & Puzzle::Creation::TopTab) { QPainterPath topTab; topTab.addEllipse(QPointF(tabFull + unit.width() / 2.0, tabSize + tabTolerance), tabSize + tabTolerance, tabSize + tabTolerance); clip = clip.united(topTab); } // Right if (status & Puzzle::Creation::RightTab) { QPainterPath rightTab; rightTab.addEllipse(QPointF(tabFull + unit.width() + tabOffset, tabFull + unit.height() / 2.0), tabSize + tabTolerance, tabSize + tabTolerance); clip = clip.united(rightTab); } else if (status & Puzzle::Creation::RightBlank) { QPainterPath rightBlank; rightBlank.addEllipse(QPointF(tabFull + unit.width() - blankOffset, tabFull + unit.height() / 2.0), blankSize, blankSize); clip = clip.subtracted(rightBlank); } // Bottom if (status & Puzzle::Creation::BottomTab) { QPainterPath bottomTab; bottomTab.addEllipse(QPointF(tabFull + unit.width() / 2.0, tabFull + unit.height() + tabOffset), tabSize + tabTolerance, tabSize + tabTolerance); clip = clip.united(bottomTab); } else if (status & Puzzle::Creation::BottomBlank) { QPainterPath bottomBlank; bottomBlank.addEllipse(QPointF(tabFull + unit.width() / 2.0, tabFull + unit.height() - blankOffset), blankSize, blankSize); clip = clip.subtracted(bottomBlank); } clip = clip.simplified(); return clip; }
void tSunMoonDialog::ProcessMoonPixmap( QPixmap& moonPixmap ) { if( m_MoonData.Phase < 0.99 ) { QRect r = moonPixmap.rect(); qreal diameter = r.width() * 0.744; QRectF rF( r.center().x() - 0.5 - diameter / 2, r.center().y() + 1 - diameter / 2, diameter, diameter ); QPainterPath darkMoonPath; if( m_MoonData.Phase > 0.01 ) { QPainterPath halfMoonPath; halfMoonPath.moveTo( rF.left() + rF.width() / 2, rF.top() + rF.height() ); qreal sweep = 180; if( m_MoonData.Waxing ) { sweep *= -1; } halfMoonPath.arcTo( rF.left(), rF.top(), diameter, diameter, 90, sweep ); halfMoonPath.lineTo( rF.left() + rF.width() / 2, rF.top() ); QPainterPath cresentMoonPath; cresentMoonPath.addEllipse( rF.center(), diameter * cos( m_MoonData.Phase * M_PI ) / 2, diameter / 2 ); if( m_MoonData.Phase < 0.5 ) { darkMoonPath = halfMoonPath.united( cresentMoonPath ); } else { darkMoonPath = halfMoonPath.subtracted( cresentMoonPath ); } } else { darkMoonPath.addEllipse( rF.center(), diameter / 2, diameter / 2 ); } QPainter painter( &moonPixmap ); painter.setRenderHint( QPainter::Antialiasing ); painter.setPen( Qt::NoPen ); QColor c( 0, 0, 0, 170 ); painter.setBrush( QBrush( c ) ); painter.drawPath( darkMoonPath ); painter.end(); } // invert the image if in northern hemisphere if( m_Position.Y() >= 0 ) { QPixmap tempPixmap( moonPixmap ); moonPixmap.fill( QColor( 0, 0, 0, 0 ) ); QPainter painter( &moonPixmap ); painter.rotate( 180 ); painter.drawPixmap( QPoint( -moonPixmap.width(), -moonPixmap.height() ), tempPixmap ); painter.end(); } }
QPainterPath VeeWipeStrategy::clipPath(int step, const QRect &area) { qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount); if(reverse()) percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount); int stepx = static_cast<int>(2 * area.width() * percent); int stepy = static_cast<int>(2 * area.height() * percent); int width_2 = area.width() >> 1; int height_2 = area.height() >> 1; QPainterPath path; switch(subType()) { case VeeWipeEffectFactory::FromTop: { QPoint move(0, stepy - 2 * area.height()); path.moveTo(move + area.topLeft()); path.lineTo(move + area.bottomLeft()); path.lineTo(move + QPoint(width_2, 2 * area.height())); path.lineTo(move + area.bottomRight()); path.lineTo(move + area.topRight()); break; } case VeeWipeEffectFactory::FromRight: { QPoint move(2 * area.width()-stepx, 0); path.moveTo(move + area.topRight()); path.lineTo(move + area.topLeft()); path.lineTo(move + QPoint(-area.width(), height_2)); path.lineTo(move + area.bottomLeft()); path.lineTo(move + area.bottomRight()); break; } case VeeWipeEffectFactory::FromBottom: { QPoint move(0, 2 * area.height() - stepy); path.moveTo(move + area.bottomLeft()); path.lineTo(move + area.topLeft()); path.lineTo(move + QPoint(width_2, -area.height())); path.lineTo(move + area.topRight()); path.lineTo(move + area.bottomRight()); break; } case VeeWipeEffectFactory::FromLeft: { QPoint move(stepx - 2 * area.width(), 0); path.moveTo(move + area.topLeft()); path.lineTo(move + area.topRight()); path.lineTo(move + QPoint(2 * area.width(), height_2)); path.lineTo(move + area.bottomRight()); path.lineTo(move + area.bottomLeft()); break; } default: return QPainterPath(); } path.closeSubpath(); if(reverse()) { QPainterPath areaPath; areaPath.addRect(area); path = areaPath.subtracted(path); } return path; }
QPainterPath ZigZagWipeStrategy::clipPath(int step, const QRect &area) { const int zigZagCount = 10; const qreal zigZagHeight = area.height() / static_cast<qreal>(zigZagCount); const qreal zigZagWidth = area.width() / static_cast<qreal>(zigZagCount); qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount); if(reverse()) percent = static_cast<qreal>(StepCount-step) / static_cast<qreal>(StepCount); int stepx = static_cast<int>((area.width() + 2*zigZagWidth) * percent); int stepy = static_cast<int>((area.height() + 2*zigZagHeight) * percent); qreal zigZagHeight_2 = 0.5 * zigZagHeight; qreal zigZagWidth_2 = 0.5 * zigZagWidth; QPainterPath path; switch(subType()) { case ZigZagWipeEffectFactory::FromTop: case ZigZagWipeEffectFactory::FromBottom: { qreal zigZagBase = stepy - zigZagHeight; qreal zigZagTip = stepy; path.moveTo(area.topLeft() - QPointF(0, zigZagHeight)); path.lineTo(QPointF(area.left(), zigZagBase)); for(int i = 0; i < zigZagCount; ++i) { path.lineTo(area.topLeft() + QPointF((2*i+1) * zigZagWidth_2, zigZagTip)); path.lineTo(area.topLeft() + QPointF((i+1) * zigZagWidth, zigZagBase)); } path.lineTo(area.topRight() - QPointF(0, zigZagHeight)); break; } case ZigZagWipeEffectFactory::FromLeft: case ZigZagWipeEffectFactory::FromRight: { qreal zigZagBase = stepx - zigZagWidth; qreal zigZagTip = stepx; path.moveTo(area.topLeft() - QPointF(zigZagWidth, 0)); path.lineTo(QPointF(zigZagBase, area.top())); for(int i = 0; i < zigZagCount; ++i) { path.lineTo(area.topLeft() + QPointF(zigZagTip, (2*i+1) * zigZagHeight_2)); path.lineTo(area.topLeft() + QPointF(zigZagBase, (i+1) * zigZagHeight)); } path.lineTo(area.bottomLeft() - QPointF(zigZagWidth, 0)); break; } default: return QPainterPath(); } path.closeSubpath(); if(reverse()) { QPainterPath areaPath; areaPath.addRect(area); path = areaPath.subtracted(path); } return path; }
/*! Paint event \param event Paint event */ void QwtPlotCanvas::paintEvent( QPaintEvent *event ) { QPainter painter( this ); painter.setClipRegion( event->region() ); if ( testPaintAttribute( QwtPlotCanvas::BackingStore ) && d_data->backingStore != NULL ) { QPixmap &bs = *d_data->backingStore; if ( bs.size() != size() ) { bs = QPixmap( size() ); #ifdef Q_WS_X11 if ( bs.x11Info().screen() != x11Info().screen() ) bs.x11SetScreen( x11Info().screen() ); #endif if ( testAttribute(Qt::WA_StyledBackground) ) { QPainter p( &bs ); qwtFillBackground( &p, this ); drawCanvas( &p, true ); } else { QPainter p; if ( d_data->borderRadius <= 0.0 ) { qwtFillPixmap( this, bs ); p.begin( &bs ); drawCanvas( &p, false ); } else { p.begin( &bs ); qwtFillBackground( &p, this ); drawCanvas( &p, true ); } if ( frameWidth() > 0 ) drawBorder( &p ); } } painter.drawPixmap( 0, 0, *d_data->backingStore ); } else { if ( testAttribute(Qt::WA_StyledBackground ) ) { if ( testAttribute( Qt::WA_OpaquePaintEvent ) ) { qwtFillBackground( &painter, this ); drawCanvas( &painter, true ); } else { drawCanvas( &painter, false ); } } else { if ( testAttribute( Qt::WA_OpaquePaintEvent ) ) { if ( autoFillBackground() ) { qwtFillBackground( &painter, this ); qwtDrawBackground( &painter, this ); } } else { if ( borderRadius() > 0.0 ) { QPainterPath clipPath; clipPath.addRect( rect() ); clipPath = clipPath.subtracted( borderPath( rect() ) ); painter.save(); painter.setClipPath( clipPath, Qt::IntersectClip ); qwtFillBackground( &painter, this ); qwtDrawBackground( &painter, this ); painter.restore(); } } drawCanvas( &painter, false ); if ( frameWidth() > 0 ) drawBorder( &painter ); } } if ( hasFocus() && focusIndicator() == CanvasFocusIndicator ) drawFocusIndicator( &painter ); }