static QPainterPath createRotateArrow() { const qreal arrowHeadPos = 12; const qreal arrowHeadLength = 4.5; const qreal arrowHeadWidth = 5; const qreal bodyWidth = 1.5; const qreal outerArcSize = arrowHeadPos + bodyWidth - arrowHeadLength; const qreal innerArcSize = arrowHeadPos - bodyWidth - arrowHeadLength; QPainterPath path; path.moveTo(arrowHeadPos, 0); path.lineTo(arrowHeadPos + arrowHeadWidth, arrowHeadLength); path.lineTo(arrowHeadPos + bodyWidth, arrowHeadLength); path.arcTo(QRectF(arrowHeadLength - outerArcSize, arrowHeadLength - outerArcSize, outerArcSize * 2, outerArcSize * 2), 0, -90); path.lineTo(arrowHeadLength, arrowHeadPos + arrowHeadWidth); path.lineTo(0, arrowHeadPos); path.lineTo(arrowHeadLength, arrowHeadPos - arrowHeadWidth); path.lineTo(arrowHeadLength, arrowHeadPos - bodyWidth); path.arcTo(QRectF(arrowHeadLength - innerArcSize, arrowHeadLength - innerArcSize, innerArcSize * 2, innerArcSize * 2), -90, 90); path.lineTo(arrowHeadPos - arrowHeadWidth, arrowHeadLength); path.closeSubpath(); return path; }
QPainterPath Shapes::unAboveBelow(const QRectF &bound, Style style) { _S(6) _S(3) _S(4) QPainterPath path; switch (style) { case Square: case LasseKongo: path.addRect(bound.adjusted(0, s4, -2*s3, -s4)); path.addRect(bound.adjusted(2*s3, s4, 0, -s4)); break; default: case Round: case TheRob: QRectF rect = bound.adjusted(0,0,-s6, 0); path.moveTo(rect.center()); path.arcTo(rect, 90, 180); path.closeSubpath(); rect.translate(s6,0); path.moveTo(rect.center()); path.arcTo(rect, -90, 180); path.closeSubpath(); break; } return path; }
QPainterPath Shapes::keepBelow(const QRectF &bound, Style style) { _S(2) _S(3) _S(4) QPainterPath path; switch (style) { case Square: case LasseKongo: path.addRect(bound.adjusted(s4, 2*s3, -s4, 0)); path.addRect(bound.adjusted(0, 0, -2*s3, -2*s3)); path.addRect(bound.adjusted(2*s3, 0, 0, -2*s3)); break; default: case Round: case TheRob: QRectF rect = bound.adjusted(0, 0, -s2, -s2); path.moveTo(bound.center() + QPointF(0, s2)); path.arcTo(bound.translated(0, s2), 0, 180); path.closeSubpath(); path.moveTo(rect.center()); path.arcTo(rect, 0, 180); path.closeSubpath(); rect.translate(s2, 0); path.moveTo(rect.center()); path.arcTo(rect, 0, 180); path.closeSubpath(); break; } return path; }
void CustomStyle::drawHoverRect(QPainter *painter, const QRect &rect) const { /* double h = r.height(); double h2 = r.height() / 2.0; QPainterPath path; path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height()); path.addEllipse(r.x(), r.y(), h, h); path.addEllipse(r.x() + r.width() - h, r.y(), h, h); path.setFillRule(Qt::WindingFill); painter->setPen(Qt::NoPen); painter->setBrush(QColor(191, 215, 191)); painter->setRenderHint(QPainter::Antialiasing); painter->drawPath(path);*/ int radius = qMin(rect.width(), rect.height()) / 2; int diam = 2 * radius; int x1, y1, x2, y2; rect.getCoords(&x1, &y1, &x2, &y2); QPainterPath path; QColor color; color = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6)); QPen pen(color, 4); painter->setPen(pen); path.moveTo(x2, y1 + radius); path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0); path.lineTo(x1 + radius, y1); path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0); path.lineTo(x1, y2 - radius); path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0); path.lineTo(x1 + radius, y2); path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0); painter->drawPath(path); }
void tst_QPainterPath::testArcMoveTo() { QFETCH(QRectF, rect); QFETCH(qreal, angle); QPainterPath path; path.arcMoveTo(rect, angle); path.arcTo(rect, angle, 30); path.arcTo(rect, angle + 30, 30); QPointF pos = path.elementAt(0); QVERIFY((path.elementCount()-1) % 3 == 0); qreal x_radius = rect.width() / 2.0; qreal y_radius = rect.height() / 2.0; QPointF shouldBe = rect.center() + QPointF(x_radius * cos(ANGLE(angle)), -y_radius * sin(ANGLE(angle))); qreal iw = 1 / rect.width(); qreal ih = 1 / rect.height(); QVERIFY(pathFuzzyCompare(pos.x() * iw, shouldBe.x() * iw)); QVERIFY(pathFuzzyCompare(pos.y() * ih, shouldBe.y() * ih)); }
//------------------------------------------------------------------------------ void Canvas::DrawAnnulus(int x, int y, unsigned inner_r, unsigned outer_r, Angle start, Angle end) { QPainterPath p; QRectF ri(x - inner_r, y - inner_r, 2 * inner_r, 2 * inner_r); QRectF ro(x - outer_r, y - outer_r, 2 * outer_r, 2 * outer_r); // Draw the inner radius of the annulus. p.arcMoveTo(ri, start.Degrees()); p.arcTo(ri, start.Degrees(), end.Degrees() - start.Degrees()); if (start != end) { // Only draw the end caps when needed. // The currentPosition() will be at the end of the inner circle. Draw // one side of the annulus. // \todo This doesn't work because Angle(360) != Angle(0)! double xx = (outer_r - inner_r) * cos(end.Radians()) + p.currentPosition().rx(); double yy = (outer_r - inner_r) * -sin(end.Radians()) + p.currentPosition().ry(); p.lineTo(xx, yy); } else p.arcMoveTo(ro, end.Degrees()); // Set up for the outer circle. // The currentPosition() will be at the 'end' of the outer circle. Draw the // outer to the start. p.arcTo(ro, end.Degrees(), start.Degrees() - end.Degrees()); if (start != end) {// And close it off to finish up. p.closeSubpath(); } this->pushObject(p, this->pen(), this->brush()); }
QPainterPath DArrowRectangle::getBottomCornerPath() { qreal delta = shadowBlurRadius() + shadowDistance(); QRect rect = this->rect().marginsRemoved(QMargins(delta, delta, delta, delta)); QPoint cornerPoint(rect.x() + (m_arrowX > 0 ? m_arrowX : rect.width() / 2), rect.y() + rect.height()); QPoint topLeft(rect.x(), rect.y()); QPoint topRight(rect.x() + rect.width(), rect.y()); QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height() - m_arrowHeight); QPoint bottomLeft(rect.x(), rect.y() + rect.height() - m_arrowHeight); int radius = this->m_radius > (rect.height() / 2 - m_arrowHeight) ? rect.height() / 2 -m_arrowHeight : this->m_radius; QPainterPath border; border.moveTo(topLeft.x() + radius, topLeft.y()); border.lineTo(topRight.x() - radius, topRight.y()); border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90); border.lineTo(bottomRight.x(), bottomRight.y() - radius); border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90); border.lineTo(cornerPoint.x() + m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight); border.lineTo(cornerPoint); border.lineTo(cornerPoint.x() - m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight); border.lineTo(bottomLeft.x() + radius, bottomLeft.y()); border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, -90, -90); border.lineTo(topLeft.x(), topLeft.y() + radius); border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90); return border; }
void SwitchButton::drawBg(QPainter *painter) { painter->save(); painter->setPen(Qt::NoPen); if (!checked) { painter->setBrush(bgColorOff); } else { painter->setBrush(bgColorOn); } if (buttonStyle == ButtonStyle_Rect) { painter->drawRoundedRect(rect(), rectRadius, rectRadius); } else if (buttonStyle == ButtonStyle_CircleIn) { QRect rect(0, 0, width(), height()); //半径为高度的一半 int radius = qMin(rect.width(), rect.height()) / 2; //圆的宽度为高度 int circleWidth = radius * 2; QPainterPath path; path.moveTo(radius, rect.left()); path.arcTo(QRectF(rect.left(), rect.top(), circleWidth, circleWidth), 90, 180); path.lineTo(rect.width() - radius, rect.height()); path.arcTo(QRectF(rect.width() - rect.height(), rect.top(), circleWidth, circleWidth), 270, 180); path.lineTo(radius, rect.top()); painter->drawPath(path); } else if (buttonStyle == ButtonStyle_CircleOut) { QRect rect(height() / 2, space, width() - height(), height() - space * 2); painter->drawRoundedRect(rect, rectRadius, rectRadius); } painter->restore(); }
void QuickSwitchButton::paintEvent(QPaintEvent *e) { if (m_selected && m_showBackground) { const QRect r = rect(); const int radius = 6; const int margin_bottom = 5; QPainterPath path; path.moveTo(0, 0); path.arcTo(QRectF(QPointF(-radius, 0), QPointF(radius, radius * 2)), 90, -90); path.lineTo(radius, r.bottom() - margin_bottom - radius * 2); path.arcTo(QRectF(QPointF(radius, r.bottom() - margin_bottom - radius * 2), QPointF(radius * 3, r.bottom() - margin_bottom)), 180, 90); path.lineTo(r.right() - radius * 2, r.bottom() - margin_bottom); path.arcTo(QRectF(QPointF(r.right() - radius * 3, r.bottom() - margin_bottom - radius * 2), QPointF(r.right() - radius, r.bottom() - margin_bottom)), 270, 90); path.lineTo(r.right() - radius, radius); path.arcTo(QRectF(QPointF(r.right() - radius, 0), QPointF(r.right() + radius, radius * 2)), 180, -90); path.closeSubpath(); QPainter painter(this); painter.setPen(Qt::transparent); painter.setBrush(QColor(255, 255, 255, 255 * .2)); painter.setRenderHint(QPainter::Antialiasing); painter.drawPath(path); } QLabel::paintEvent(e); }
QPainterPath BoxStyle::getRectanglePath(qreal x, qreal y, int width, int height) const { QPainterPath path; int radius = cornerRadius_; if (radius > width/2) radius = width/2; if (radius > height/2) radius = height/2; path.moveTo(width + x, radius + y); if ( corner_ == CornerType::RightAngle ) path.lineTo(width + x, y); else if ( corner_ == CornerType::Cut ) path.lineTo(width + x - radius, y); else path.arcTo(width - 2 * radius + x, y, radius * 2, radius * 2, 0.0, 90.0); path.lineTo(radius + x, y); if ( corner_ == CornerType::RightAngle ) path.lineTo(x, y); else if ( corner_ == CornerType::Cut ) path.lineTo(x, radius + y); else path.arcTo(x, y, radius * 2, radius * 2, 90.0, 90.0); path.lineTo(x, height - radius + y); if ( corner_ == CornerType::RightAngle ) path.lineTo(x, height + y); else if ( corner_ == CornerType::Cut ) path.lineTo(x + radius, height + y); else path.arcTo(x, height - 2 * radius + y, radius * 2, radius * 2, 180.0, 90.0); path.lineTo(width - radius + x, height + y); if ( corner_ == CornerType::RightAngle ) path.lineTo(width + x, height + y); else if ( corner_ == CornerType::Cut ) path.lineTo(x + width, height - radius + y); else path.arcTo(width - 2 * radius + x, height - 2 * radius + y, radius * 2, radius * 2, 270.0, 90.0); path.closeSubpath(); return path; }
QPainterPath UBGraphicsCompass::hingeShape() const { QPainterPath path; path.moveTo(hingeRect().left() + 4, hingeRect().top()); path.lineTo(hingeRect().right() - 4, hingeRect().top()); path.arcTo( hingeRect().right() - 8, hingeRect().top(), 8, 8, 90, -90); path.lineTo(hingeRect().right(), hingeRect().bottom() - 4); path.arcTo( hingeRect().right() - 8, hingeRect().bottom() - 8, 8, 8, 0, -90); path.lineTo(hingeRect().left() + 4, hingeRect().bottom()); path.arcTo( hingeRect().left(), hingeRect().bottom() - 8, 8, 8, -90, -90); path.lineTo(hingeRect().left(), hingeRect().top() + 4); path.arcTo( hingeRect().left(), hingeRect().top(), 8, 8, -180, -90); path.closeSubpath(); return path; }
static QPainterPath createArrow() { const qreal arrowHeadPos = 10; const qreal arrowHeadLength = 4; const qreal arrowHeadWidth = 4; const qreal arcWidth = 2; const qreal outerArcSize = arrowHeadPos + arcWidth - arrowHeadLength; const qreal innerArcSize = arrowHeadPos - arcWidth - arrowHeadLength; QPainterPath path; path.moveTo(arrowHeadPos, 0); path.lineTo(arrowHeadPos + arrowHeadWidth, arrowHeadLength); path.lineTo(arrowHeadPos + arcWidth, arrowHeadLength); path.arcTo(QRectF(arrowHeadLength - outerArcSize, arrowHeadLength - outerArcSize, outerArcSize * 2, outerArcSize * 2), 0, -90); path.lineTo(arrowHeadLength, arrowHeadPos + arrowHeadWidth); path.lineTo(0, arrowHeadPos); path.lineTo(arrowHeadLength, arrowHeadPos - arrowHeadWidth); path.lineTo(arrowHeadLength, arrowHeadPos - arcWidth); path.arcTo(QRectF(arrowHeadLength - innerArcSize, arrowHeadLength - innerArcSize, innerArcSize * 2, innerArcSize * 2), -90, 90); path.lineTo(arrowHeadPos - arrowHeadWidth, arrowHeadLength); path.closeSubpath(); path.translate(-3, -3); return path; }
QPainterPath roundedRect(const QRect& rc, int nRadius) { QPainterPath path; // Diameter qreal d = nRadius * 2 + 1; if (rc.width() < d || rc.height() < d) return path; qreal x0 = rc.left() + 0.5; qreal x3 = rc.right() - 1 + 0.5; qreal y0 = rc.top() + 0.5; qreal y3 = rc.bottom() - 1 + 0.5; QRectF rcTR(x3 - d, y0, d, d); QRectF rcBR(x3 - d, y3 - d, d, d); QRectF rcBL(x0, y3 - d, d, d); QRectF rcTL(x0, y0, d, d); path.moveTo(rcTR.topLeft()); path.arcTo(rcTR, 90, -90); path.arcTo(rcBR, 0, -90); path.arcTo(rcBL, -90, -90); path.arcTo(rcTL, -180, -90); path.closeSubpath(); return path; }
void KeyboardLayoutWidget::drawCurveRectangle(QPainter* painter, bool filled, QColor color, int x, int y, int width, int height, double radius) { double x1, y1; if (!width || !height) return; x1 = x + width; y1 = y + height; radius = qMin (radius, (double) qMin (width / 2, height / 2)); QPainterPath path; path.moveTo(x, y + radius); path.arcTo(x, y, 2 * radius, 2 * radius, 180, -90); path.lineTo (x1 - radius, y); path.arcTo (x1 - 2 * radius, y, 2 * radius, 2 * radius, 90, - 90); path.lineTo (x1, y1 - radius); path.arcTo (x1 - 2 * radius, y1 - 2 * radius, 2 * radius, 2 * radius, 0, -90); path.lineTo (x + radius, y1); path.arcTo (x , y1 - 2 * radius, 2 * radius, 2 * radius, -90, -90); path.closeSubpath(); painter->save(); if (filled) { QBrush brush(color); painter->fillPath (path, brush); } else { painter->setPen(color); painter->drawPath(path); } painter->restore(); }
void EditorArea::paintMeshElToBeHigh(QPainter &painter) { qreal radius = size2screen(8); float fontSize = size2screen(12); qreal width = radius * 2; qreal height = radius * 2; QPainterPath path; QPainterPath text; QPainterPath circle; path.arcTo(QRectF(-radius, -radius, width, height), 0, 360); text.addText(-radius / 2.0, radius / 2.0, QFont("Arial", fontSize), meshElsType.value(meshElToBeHigh)); circle.arcTo(QRectF(-radius * 3 / 2, -radius * 3 / 2, width * 3 / 2, height * 3 / 2), 0, 360); path.translate(meshElsPos.value(meshElToBeHigh)); text.translate(meshElsPos.value(meshElToBeHigh)); circle.translate(meshElsPos.value(meshElToBeHigh)); painter.setPen(Qt::NoPen); painter.setBrush(Qt::magenta); painter.drawPath(circle); painter.setBrush(Qt::darkCyan); painter.drawPath(path); painter.setPen(Qt::yellow); painter.setBrush(Qt::yellow); painter.drawPath(text); }
void Widget::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter; QPainterPath path; QPen pen(Qt::darkGray); painter.begin(this); pen.setWidth(3); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); painter.setBrush(Qt::darkGray); painter.drawRect(ui->crossBlock->x(),ui->crossBlock->y(),ui->crossBlock->width(),ui->crossBlock->height()); pen.setColor(Qt::black); painter.setPen(pen); painter.drawLine(ui->crossBlock->x()+1,ui->crossBlock->y()+1,ui->crossBlock->x()+ui->crossBlock->width(),ui->crossBlock->y()+ui->crossBlock->height()); painter.drawLine(ui->crossBlock->x()+1,ui->crossBlock->y()+ui->crossBlock->height(),ui->crossBlock->x()+ui->crossBlock->width(),ui->crossBlock->y()+1); pen.setColor(Qt::yellow); painter.setPen(pen); int mca_x = ui->mcaImage->x(); int mca_y = ui->mcaImage->y(); int mcb_x = ui->mcbImage->x(); int mcb_y = ui->mcbImage->y(); int mc_width = ui->mcaImage->width(); int mc_height = ui->mcaImage->height(); painter.setBrush(Qt::NoBrush); // painter.drawRoundedRect(mca_x,mca_y,mc_width,mc_height,5,5); // painter.drawRoundedRect(mcb_x,mcb_y,mc_width,mc_height,5,5); painter.drawRect(mca_x,mca_y,mc_width,mc_height); painter.drawRect(mcb_x,mcb_y,mc_width,mc_height); // painter.setPen(Qt::NoPen); painter.setBrush(Qt::NoBrush); painter.eraseRect(mca_x-5,mca_y-5,mc_width*0.1,mc_height*1.2); painter.eraseRect(mcb_x+mc_width*0.9+5,mcb_y-5,mc_width*0.1+2,mc_height*1.2); path.moveTo(mca_x+mc_width*0.1,mca_y); path.arcTo(QRectF(mca_x+mc_width*0.1-mc_height/2,mca_y,mc_height,mc_height),90,180); pen.setColor(Qt::yellow); painter.setPen(pen); painter.drawPath(path); path.moveTo(mcb_x+mc_width*0.8,mcb_y); path.arcTo(QRectF(mcb_x+mc_width*0.9-mc_height/2,mcb_y,mc_height,mc_height),90,-180); painter.drawPath(path); int smallRectWidth =mc_width/6; int smallRectHeight= mc_height/4; painter.setBrush(Qt::yellow); painter.drawRect(mca_x+mc_width*0.3-smallRectWidth,mca_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight); painter.drawRect(mca_x+mc_width-smallRectWidth*0.5-smallRectWidth,mca_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight); painter.drawRect(mca_x+mc_width*0.3-smallRectWidth,mca_y+mc_height-smallRectHeight*1.3,smallRectWidth,smallRectHeight); painter.drawRect(mca_x+mc_width-smallRectWidth*0.5-smallRectWidth,mca_y+mc_height-smallRectHeight*1.3,smallRectWidth,smallRectHeight); painter.drawRect(QRectF(mcb_x+smallRectWidth*0.5,mcb_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight)); painter.drawRect(QRectF(mcb_x+smallRectWidth*0.5,mcb_y+mc_height-smallRectHeight*0.3-smallRectHeight,smallRectWidth,smallRectHeight)); painter.drawRect(QRectF(mcb_x+mc_width*0.7,mcb_y+smallRectHeight*0.3,smallRectWidth,smallRectHeight)); painter.drawRect(QRectF(mcb_x+mc_width*0.7,mcb_y+mc_height-smallRectHeight*0.3-smallRectHeight,smallRectWidth,smallRectHeight)); QSize Size = painter.fontMetrics().size(Qt::TextSingleLine, str); painter.setPen(Qt::white); painter.drawText(QPointF(mca_x+mc_width/2-Size.width()/2,mca_y+mc_height/2+Size.height()/2),str); painter.drawText(QPointF(mcb_x+mc_width/2-Size.width()/2,mcb_y+mc_height/2+Size.height()/2),str); painter.end(); }
void TurnAndBank::createBall(void){ QImage _glassImage = QImage(QSize(800,800), QImage::Format_ARGB32); _glassImage.fill(0x00ffffff); QPainter p; p.setRenderHint(QPainter::Antialiasing, true); p.begin(&_glassImage); p.translate(400, 400); // QLinearGradient gradient(0,101,0,199); // gradient.setColorAt(0, SKYBLUE); // gradient.setColorAt(1, GROUNDBROWN); QRadialGradient gradient(0,-4500, 4750, 0, 30000); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::green); gradient.setSpread(QGradient::ReflectSpread); QBrush gbrush(gradient); p.setBrush(gbrush); // p.drawRect(-350, 120, 700, 150); QPainterPath pathBottom; pathBottom.moveTo(-310, 150); pathBottom.arcTo(-2500+50,-3830-1000,5000,5000, -96, 12); //pathBottom.lineTo(310, 250); pathBottom.arcTo(-2000,-3700,4000,4000, -81, -18); //pathBottom.lineTo(-310, 150); // pathBottom.lineTo(-240,0); //pathBottom.arcTo(-240,-240,480,480, 180, 180); // p.setPen(QPen(QColor(79, 106, 25), 0, Qt::SolidLine, // Qt::FlatCap, Qt::MiterJoin)); p.setPen(QPen(Qt::white, 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p.setPen(Qt::NoPen); p.setBrush(gbrush); // p.setBrush(GROUNDBROWN); p.drawPath(pathBottom); p.setBrush(Qt::black); p.setPen(QPen(Qt::black, 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p.drawLine(-50,170, -50, 300); p.drawLine(50,170, 50, 300); p.end(); _ball = QPixmap::fromImage(_glassImage, Qt::AutoColor); }
//! [0] DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent) : QGraphicsPolygonItem(parent) { myDiagramType = diagramType; myContextMenu = contextMenu; QPainterPath path; switch (myDiagramType) { case StartEnd: path.moveTo(200, 50); path.arcTo(150, 0, 50, 50, 0, 90); path.arcTo(50, 0, 50, 50, 90, 90); path.arcTo(50, 50, 50, 50, 180, 90); path.arcTo(150, 50, 50, 50, 270, 90); path.lineTo(200, 25); myPolygon = path.toFillPolygon(); break; case Conditional: myPolygon << QPointF(-100, 0) << QPointF(0, 100) << QPointF(100, 0) << QPointF(0, -100) << QPointF(-100, 0); break; case Step: myPolygon << QPointF(-100, -100) << QPointF(100, -100) << QPointF(100, 100) << QPointF(-100, 100) << QPointF(-100, -100); break; case Oval: path.moveTo(-50,50); path.arcTo(0, -50, 100, 100, 270,180); path.lineTo(-50,-50); path.arcTo(-100, -50, 100, 100, 90, 180); myPolygon = path.toFillPolygon(); break; case Hexagon: myPolygon << QPointF(-100, 0) << QPointF(-50, 100) << QPointF(50, 100) << QPointF(100, 0) << QPointF(50, -100) << QPointF(-50,-100) << QPointF(-100,0); break; case Pentagon: myPolygon << QPointF(100, 50) << QPointF(100, -100) << QPointF(-100, -100) << QPointF(-100, 50) << QPointF(0,100) << QPointF(100,50); break; default: myPolygon << QPointF(-120, -80) << QPointF(-70, 80) << QPointF(120, 80) << QPointF(70, -80) << QPointF(-120, -80); break; } setPolygon(myPolygon); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); }
void EllipseObject::updatePath() { QPainterPath path; QRectF r = rect(); path.arcMoveTo(r, 0); path.arcTo(r, 0, 360); //NOTE: Reverse the path so that the inside area isn't considered part of the ellipse path.arcTo(r, 0, -360); setObjectPath(path); }
void QgsLayoutReportSectionLabel::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) { if ( !mLayout || !mLayout->renderContext().isPreviewRender() ) { //don't draw label in outputs return; } if ( mLabel.isEmpty() ) return; QFont f; f.setPointSizeF( 8 ); QFontMetrics fm( f ); QSize s = fm.size( 0, mLabel ); double margin = fm.height() / 5.0; double scaleValue = scale() / painter->transform().m11(); painter->save(); painter->setRenderHint( QPainter::Antialiasing, true ); painter->scale( scaleValue, scaleValue ); QRectF r = rect(); QRectF scaledRect( r.left() / scaleValue, r.top() / scaleValue, r.width() / scaleValue, r.height() / scaleValue ); if ( scaledRect.width() < s.width() + 2 * margin || scaledRect.height() < s.height() + 2 * margin ) { // zoomed out too far to fully draw label inside item rect return; } QRectF textRect = QRectF( scaledRect.left() + margin, scaledRect.top() + margin, scaledRect.width() - 2 * margin, scaledRect.height() - 2 * margin ); QRectF boxRect = QRectF( scaledRect.left(), scaledRect.bottom() - ( s.height() + 2 * margin ), s.width() + 2 * margin, s.height() + 2 * margin ); QPainterPath p; p.moveTo( boxRect.bottomRight() ); p.lineTo( boxRect.right(), boxRect.top() + margin ); p.arcTo( boxRect.right() - 2 * margin, boxRect.top(), 2 * margin, 2 * margin, 0, 90 ); p.lineTo( boxRect.left() + margin, boxRect.top() ); p.arcTo( boxRect.left(), boxRect.top(), 2 * margin, 2 * margin, 90, 90 ); p.lineTo( boxRect.bottomLeft() ); p.lineTo( boxRect.bottomRight() ); painter->setPen( QColor( 150, 150, 150, 150 ) ); QLinearGradient g( 0, boxRect.top(), 0, boxRect.bottom() ); g.setColorAt( 0, QColor( 200, 200, 200, 150 ) ); g.setColorAt( 1, QColor( 150, 150, 150, 150 ) ); painter->setBrush( QBrush( g ) ); painter->drawPath( p ); painter->setPen( QPen( QColor( 0, 0, 0, 100 ) ) ); painter->setFont( f ); painter->drawText( textRect, Qt::AlignBottom, mLabel ); painter->restore(); }
void UIGDetailsElement::paintBackground(QPainter *pPainter, const QStyleOptionGraphicsItem *pOption) { /* Save painter: */ pPainter->save(); /* Prepare variables: */ int iMargin = data(ElementData_Margin).toInt(); int iHeaderHeight = 2 * iMargin + m_iMinimumHeaderHeight; QRect optionRect = pOption->rect; QRect fullRect = !m_fAnimationRunning ? optionRect : QRect(optionRect.topLeft(), QSize(optionRect.width(), iHeaderHeight + m_iAdditionalHeight)); int iFullHeight = fullRect.height(); /* Prepare color: */ QPalette pal = palette(); QColor headerColor = pal.color(QPalette::Active, QPalette::Button); QColor strokeColor = pal.color(QPalette::Active, QPalette::Mid); QColor bodyColor = pal.color(QPalette::Active, QPalette::Base); /* Add clipping: */ QPainterPath path; path.moveTo(m_iCornerRadius, 0); path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-m_iCornerRadius, 0), 90, 90); path.lineTo(path.currentPosition().x(), iFullHeight - m_iCornerRadius); path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(0, -m_iCornerRadius), 180, 90); path.lineTo(fullRect.width() - m_iCornerRadius, path.currentPosition().y()); path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-m_iCornerRadius, -2 * m_iCornerRadius), 270, 90); path.lineTo(path.currentPosition().x(), m_iCornerRadius); path.arcTo(QRectF(path.currentPosition(), QSizeF(2 * m_iCornerRadius, 2 * m_iCornerRadius)).translated(-2 * m_iCornerRadius, -m_iCornerRadius), 0, 90); path.closeSubpath(); pPainter->setClipPath(path); /* Calculate top rectangle: */ QRect tRect = fullRect; tRect.setBottom(tRect.top() + iHeaderHeight); /* Calculate bottom rectangle: */ QRect bRect = fullRect; bRect.setTop(tRect.bottom()); /* Prepare top gradient: */ QLinearGradient tGradient(tRect.bottomLeft(), tRect.topLeft()); tGradient.setColorAt(0, headerColor.darker(110)); tGradient.setColorAt(1, headerColor.darker(animationDarkness())); /* Paint all the stuff: */ pPainter->fillRect(tRect, tGradient); pPainter->fillRect(bRect, bodyColor); /* Stroke path: */ pPainter->setClipping(false); pPainter->strokePath(path, strokeColor); /* Restore painter: */ pPainter->restore(); }
void QedRoundLED::paintEvent(QPaintEvent *event) { qreal lowerInset, upperInset; (void)event; QPainterPath baseCirclePath; QRectF baseBox(0.0, 0.0, my.bound, my.bound); baseCirclePath.arcTo(baseBox, 0.0, 360.0); baseCirclePath.closeSubpath(); QLinearGradient baseGradient(0, 0, 0, 1.33846 * my.bound); baseGradient.setColorAt(0.0, Qt::lightGray); baseGradient.setColorAt(1.0, Qt::white); QPainterPath seatCirclePath; lowerInset = 0.06666 * my.bound; upperInset = my.bound - (lowerInset * 2.0); QRectF seatBox(lowerInset, lowerInset, upperInset, upperInset); seatCirclePath.arcTo(seatBox, 0.0, 360.0); seatCirclePath.closeSubpath(); QLinearGradient seatGradient(0, 0, 0, 0.7692 * my.bound); seatGradient.setColorAt(0.0, Qt::lightGray); seatGradient.setColorAt(1.0, Qt::darkGray); QPainterPath mainCirclePath; lowerInset = 0.1 * my.bound; upperInset = my.bound - (lowerInset * 2.0); QRectF mainBox(lowerInset, lowerInset, upperInset, upperInset); mainCirclePath.arcTo(mainBox, 0.0, 360.0); mainCirclePath.closeSubpath(); QLinearGradient mainGradient(0, 0, 0, 1.23076 * my.bound); mainGradient.setColorAt(0.0, my.color); mainGradient.setColorAt(1.0, Qt::white); QPainterPath reflectCirclePath; QRectF reflectBox(0.18538 * my.bound, 0.12969 * my.bound, 0.61384 * my.bound, 0.48615 * my.bound); reflectCirclePath.arcTo(reflectBox, 0.0, 360.0); reflectCirclePath.closeSubpath(); QLinearGradient reflectGradient(0, 0, 0, 1.22953 * my.bound); reflectGradient.setColorAt(0.0, Qt::white); reflectGradient.setColorAt(1.0, my.color); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); painter.setBrush(baseGradient); painter.drawPath(baseCirclePath); painter.setBrush(seatGradient); painter.drawPath(seatCirclePath); painter.setBrush(mainGradient); painter.drawPath(mainCirclePath); painter.setBrush(reflectGradient); painter.drawPath(reflectCirclePath); }
static QPainterPath buildPath(const QRectF &r, double radius) { QPainterPath path; double diameter(radius*2); path.moveTo(r.x()+r.width(), r.y()+r.height()-radius); path.arcTo(r.x()+r.width()-diameter, r.y(), diameter, diameter, 0, 90); path.arcTo(r.x(), r.y(), diameter, diameter, 90, 90); path.arcTo(r.x(), r.y()+r.height()-diameter, diameter, diameter, 180, 90); path.arcTo(r.x()+r.width()-diameter, r.y()+r.height()-diameter, diameter, diameter, 270, 90); return path; }
void SoundVolume::paintEvent(QPaintEvent * /*event*/) { Q_D(const SoundVolume); QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing); QPainterPath path; auto penWidthf = 1.0; auto background = d->background; auto borderColor = d->borderColor; const qreal radius = d->radius;; const qreal triHeight = 6; const qreal triWidth = 8; const qreal height = this->height() - triHeight; const qreal width = this->width(); QRectF topRightRect(QPointF(0, 0), QPointF(2 * radius, 2 * radius)); QRectF bottomRightRect(QPointF(0, height - 2 * radius), QPointF(2 * radius, height)); QRectF topLeftRect(QPointF(width, 0), QPointF(width - 2 * radius, 2 * radius)); QRectF bottomLeftRect(QPointF(width, height), QPointF(width - 2 * radius, height - 2 * radius)); path.moveTo(radius, 0.0); path.lineTo(width - radius, 0.0); path.arcTo(topLeftRect, 90.0, 90.0); path.lineTo(width, height - radius); path.arcTo(bottomLeftRect, 180.0, -90.0); path.lineTo(width / 2 + triWidth / 2, height); path.lineTo(width / 2, height + triHeight); path.lineTo(width / 2 - triWidth / 2, height); path.lineTo(radius, height); path.arcTo(bottomRightRect, 270.0, -90.0); path.lineTo(0.0, radius); path.arcTo(topRightRect, 180.0, -90.0); path.lineTo(radius, 0.0); // FIXME: light: white // painter.fillPath(path, QColor(49, 49, 49)); painter.fillPath(path, background); // FIXME: light: QColor(0, 0, 0, 51) // QPen pen(QColor(0, 0, 0, 0.1 * 255)); QPen pen(borderColor); pen.setWidth(penWidthf); painter.strokePath(path, pen); }
void CircleObject::updatePath() { QPainterPath path; QRectF r = rect(); //Add the center point path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002); //Add the circle path.arcMoveTo(r, 0); path.arcTo(r, 0, 360); //NOTE: Reverse the path so that the inside area isn't considered part of the circle path.arcTo(r, 0, -360); setObjectPath(path); }
static QPainterPath createPath(const QRect &rect, double radius) { QPainterPath path; double diameter(radius*2); QRectF r(rect.x()+0.5, rect.y()+0.5, rect.width()-1, rect.height()-1); path.moveTo(r.x()+r.width(), r.y()+r.height()-radius); path.arcTo(r.x()+r.width()-diameter, r.y(), diameter, diameter, 0, 90); path.arcTo(r.x(), r.y(), diameter, diameter, 90, 90); path.arcTo(r.x(), r.y()+r.height()-diameter, diameter, diameter, 180, 90); path.arcTo(r.x()+r.width()-diameter, r.y()+r.height()-diameter, diameter, diameter, 270, 90); return path; }
void WatchFieldGraphics::drawBounds() { double FIELD_MAIN_LENGHT = 7400; double FIELD_MAIN_WIDTH = 5400; scene.setSceneRect(-FIELD_MAIN_LENGHT/2, -FIELD_MAIN_WIDTH/2, FIELD_MAIN_LENGHT, FIELD_MAIN_WIDTH); // scene.setSceneRect(-FIELD_MAIN_LENGHT/2, -FIELD_MAIN_WIDTH/2, FIELD_MAIN_LENGHT, FIELD_MAIN_WIDTH); scene.addRect(-FIELD_MAIN_LENGHT/2, -FIELD_MAIN_WIDTH/2, FIELD_MAIN_LENGHT, FIELD_MAIN_WIDTH,QPen(Qt::green),QBrush(Qt::green)); QPen drawBoundsPen(Qt::white); scene.addLine(-FIELD_LENGTH/2, -FIELD_WIDTH/2, -FIELD_LENGTH/2, FIELD_WIDTH/2, drawBoundsPen); scene.addLine(FIELD_LENGTH/2, -FIELD_WIDTH/2, FIELD_LENGTH/2, FIELD_WIDTH/2, drawBoundsPen); scene.addLine(-FIELD_LENGTH/2, -FIELD_WIDTH/2, FIELD_LENGTH/2, -FIELD_WIDTH/2, drawBoundsPen); scene.addLine(-FIELD_LENGTH/2, FIELD_WIDTH/2, FIELD_LENGTH/2, FIELD_WIDTH/2, drawBoundsPen); // half-field line scene.addLine(0, -FIELD_WIDTH/2, 0, FIELD_WIDTH/2, drawBoundsPen); scene.addEllipse(-FIELD_CENTER_RADIUS, -FIELD_CENTER_RADIUS, FIELD_CENTER_RADIUS*2, FIELD_CENTER_RADIUS*2, drawBoundsPen); QPainterPath leftPenaltyArea; leftPenaltyArea.moveTo(-FIELD_LENGTH/2, -FIELD_PENALTY_AREA_RADIUS - FIELD_PENALTY_AREA_WIDTH/2); leftPenaltyArea.arcTo(-FIELD_LENGTH/2 - FIELD_PENALTY_AREA_RADIUS, -FIELD_PENALTY_AREA_WIDTH/2-FIELD_PENALTY_AREA_RADIUS, 2*FIELD_PENALTY_AREA_RADIUS,2*FIELD_PENALTY_AREA_RADIUS,90,-90); leftPenaltyArea.arcTo(-FIELD_LENGTH/2-FIELD_PENALTY_AREA_RADIUS,FIELD_PENALTY_AREA_WIDTH/2-FIELD_PENALTY_AREA_RADIUS, 2*FIELD_PENALTY_AREA_RADIUS,2*FIELD_PENALTY_AREA_RADIUS,0,-90); scene.addPath(leftPenaltyArea, drawBoundsPen); QPainterPath Goal1; Goal1.moveTo(-FIELD_LENGTH/2,-FIELD_GOAL_WIDTH/2); Goal1.lineTo(-FIELD_LENGTH/2-180,-FIELD_GOAL_WIDTH/2); Goal1.lineTo(-FIELD_LENGTH/2-180,FIELD_GOAL_WIDTH/2); Goal1.lineTo(-FIELD_LENGTH/2,FIELD_GOAL_WIDTH/2); scene.addPath(Goal1,QPen(QColor(Qt::black),20)); QPainterPath rightPenaltyArea; rightPenaltyArea.moveTo(FIELD_LENGTH/2, -FIELD_PENALTY_AREA_RADIUS - FIELD_PENALTY_AREA_WIDTH/2); rightPenaltyArea.arcTo(FIELD_LENGTH/2 - FIELD_PENALTY_AREA_RADIUS, -FIELD_PENALTY_AREA_WIDTH/2-FIELD_PENALTY_AREA_RADIUS, 2*FIELD_PENALTY_AREA_RADIUS,2*FIELD_PENALTY_AREA_RADIUS,90,90); rightPenaltyArea.arcTo(FIELD_LENGTH/2-FIELD_PENALTY_AREA_RADIUS,FIELD_PENALTY_AREA_WIDTH/2-FIELD_PENALTY_AREA_RADIUS, 2*FIELD_PENALTY_AREA_RADIUS,2*FIELD_PENALTY_AREA_RADIUS,180,90); scene.addPath(rightPenaltyArea, drawBoundsPen); QPainterPath Goal2; Goal2.moveTo(FIELD_LENGTH/2,-FIELD_GOAL_WIDTH/2); Goal2.lineTo(FIELD_LENGTH/2+180,-FIELD_GOAL_WIDTH/2); Goal2.lineTo(FIELD_LENGTH/2+180,FIELD_GOAL_WIDTH/2); Goal2.lineTo(FIELD_LENGTH/2,FIELD_GOAL_WIDTH/2); scene.addPath(Goal2,QPen(QColor(Qt::black),20)); }
void tst_QPainterPath::arcWinding_data() { QTest::addColumn<QPainterPath>("path"); QTest::addColumn<QPointF>("point"); QTest::addColumn<bool>("inside"); QPainterPath a; a.addEllipse(0, 0, 100, 100); a.addRect(50, 50, 100, 100); QTest::newRow("Case A (oddeven)") << a << QPointF(55, 55) << false; a.setFillRule(Qt::WindingFill); QTest::newRow("Case A (winding)") << a << QPointF(55, 55) << true; QPainterPath b; b.arcMoveTo(0, 0, 100, 100, 10); b.arcTo(0, 0, 100, 100, 10, 360); b.addRect(50, 50, 100, 100); QTest::newRow("Case B (oddeven)") << b << QPointF(55, 55) << false; b.setFillRule(Qt::WindingFill); QTest::newRow("Case B (winding)") << b << QPointF(55, 55) << false; QPainterPath c; c.arcMoveTo(0, 0, 100, 100, 0); c.arcTo(0, 0, 100, 100, 0, 360); c.addRect(50, 50, 100, 100); QTest::newRow("Case C (oddeven)") << c << QPointF(55, 55) << false; c.setFillRule(Qt::WindingFill); QTest::newRow("Case C (winding)") << c << QPointF(55, 55) << false; QPainterPath d; d.arcMoveTo(0, 0, 100, 100, 10); d.arcTo(0, 0, 100, 100, 10, -360); d.addRect(50, 50, 100, 100); QTest::newRow("Case D (oddeven)") << d << QPointF(55, 55) << false; d.setFillRule(Qt::WindingFill); QTest::newRow("Case D (winding)") << d << QPointF(55, 55) << true; QPainterPath e; e.arcMoveTo(0, 0, 100, 100, 0); e.arcTo(0, 0, 100, 100, 0, -360); e.addRect(50, 50, 100, 100); QTest::newRow("Case E (oddeven)") << e << QPointF(55, 55) << false; e.setFillRule(Qt::WindingFill); QTest::newRow("Case E (winding)") << e << QPointF(55, 55) << true; }
//______________________________________ void ShadowDemoWidget::updateBackgroundPixmap( void ) { // check if background pixmap needs update QRect backgroundRect( QPoint( 0, 0 ), size() - QSize( 2*_shadowSize, 2*_shadowSize ) ); if( !_backgroundPixmap.isNull() && _backgroundPixmap.size() == backgroundRect.size() ) { return; } _backgroundPixmap = QPixmap( backgroundRect.size() ); _backgroundPixmap.fill( Qt::transparent ); QPainter painter( &_backgroundPixmap ); painter.setRenderHint( QPainter::Antialiasing ); _dummy.resize( backgroundRect.size() ); helper().renderWindowBackground( &painter, backgroundRect, &_dummy, &_dummy, palette().color( QPalette::Window ), 0, 64 ); // float frame helper().drawFloatFrame( &painter, backgroundRect.adjusted( -1, -1, 1, 1 ), palette().color( QPalette::Window ), false ); // add rounded mask painter.save(); painter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); painter.setBrush( Qt::black ); painter.setPen( Qt::NoPen ); if( _square ) { QRectF rectF( backgroundRect ); QPainterPath path; // rotate counterclockwise, cause that makes angles easier path.moveTo( rectF.topLeft() + QPointF( 3.5, 0 ) ); path.arcTo( QRectF( rectF.topLeft(), QSize( 7, 7 ) ), 90, 90 ); path.lineTo( rectF.bottomLeft() ); path.lineTo( rectF.bottomRight() ); path.lineTo( rectF.topRight() + QPointF( 0, 3.5 ) ); path.arcTo( QRectF( rectF.topRight() + QPointF( -7, 0 ), QSize( 7, 7 ) ), 0, 90 ); path.lineTo( rectF.topLeft() + QPointF( 3.5, 0 ) ); painter.drawPath( path ); } else { painter.drawRoundedRect( QRectF( backgroundRect ), 3.5, 3.5 ); } painter.restore(); }
QPainterPath Shapes::menu(const QRectF &bound, bool leftSide, Style style) { _S(2) QPainterPath path; switch (style) { case Square: { _S(4) path.addRect(bound); path.addRect(bound.adjusted(leftSide ? s2 : 0, s4, leftSide ? 0 : -s2, 0)); break; } case LasseKongo: path.moveTo(bound.topLeft() + QPointF(0, s2)); path.lineTo(bound.topRight() + QPointF(0, s2)); path.lineTo(bound.bottomLeft() + QPointF(s2, 0)); path.closeSubpath(); break; default: case Round: case TheRob: { _S(9) path.moveTo(bound.center()); path.arcTo(bound, leftSide ? -90 : 0, 270); path.closeSubpath(); path.addRect(bound.adjusted(leftSide ? 0 : 5*s9, 5*s9, leftSide ? -5*s9 : 0, 0)); break; } } return path; }