Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

void QPainterPath::addRoundRect ( const QRectF r,
int  xRnd,
int  yRnd 
)

Adds a rectangle r with rounded corners to the path.

The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.

See also:
addRect(), QPen

Definition at line 2861 of file qpainterpath.cpp.

References addRect(), arcMoveTo(), arcTo(), closeSubpath(), QRectF::height(), QRectF::isNull(), QRectF::normalized(), QRectF::width(), QRectF::x(), and QRectF::y().

Referenced by addRoundRect(), and QPainter::drawRoundRect().

{
    if(xRnd >= 100)                          // fix ranges
        xRnd = 99;
    if(yRnd >= 100)
        yRnd = 99;
    if(xRnd <= 0 || yRnd <= 0) {             // add normal rectangle
        addRect(r);
        return;
    }

    QRectF rect = r.normalized();

    if (rect.isNull())
        return;

    qreal x = rect.x();
    qreal y = rect.y();
    qreal w = rect.width();
    qreal h = rect.height();
    qreal rxx = w*xRnd/200;
    qreal ryy = h*yRnd/200;
    // were there overflows?
    if (rxx < 0)
        rxx = w/200*xRnd;
    if (ryy < 0)
        ryy = h/200*yRnd;
    qreal rxx2 = 2*rxx;
    qreal ryy2 = 2*ryy;

    ensureData();
    detach();

    arcMoveTo(x, y, rxx2, ryy2, 90);
    arcTo(x, y, rxx2, ryy2, 90, 90);
    arcTo(x, y+h-ryy2, rxx2, ryy2, 2*90, 90);
    arcTo(x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*90, 90);
    arcTo(x+w-rxx2, y, rxx2, ryy2, 0, 90);
    closeSubpath();

    d_func()->require_moveTo = true;
}


Generated by  Doxygen 1.6.0   Back to index