diff options
Diffstat (limited to 'src/declarative/fx/qfxrect.cpp')
-rw-r--r-- | src/declarative/fx/qfxrect.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index a068fd4..2ad8536 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -55,9 +55,9 @@ QML_DEFINE_TYPE(QFxGradient,Gradient) \brief The QFxPen class provides a pen used for drawing rect borders on a QFxView. By default, the pen is invalid and nothing is drawn. You must either set a color (then the default - width is 0) or a width (then the default color is black). + width is 1) or a width (then the default color is black). - A width of 0 indicates a cosmetic pen, a single-pixel line on the border of the item being painted. + A width of 1 indicates is a single-pixel line on the border of the item being painted. Example: \qml @@ -68,9 +68,9 @@ QML_DEFINE_TYPE(QFxGradient,Gradient) /*! \property QFxPen::width \brief the width of the pen. - A width of 0 is a single-pixel line on the border of the item being painted. + A width of 1 is a single-pixel line on the border of the item being painted. - If the width is less than 0 the pen is considered invalid and won't be used. + If the width is less than 1 the pen is considered invalid and won't be used. */ /*! @@ -103,18 +103,18 @@ void QFxPen::setColor(const QColor &c) \brief the width of the pen. \qml - // rect with green border using hexidecimal notation Rect { pen.width: 4 } \endqml - A width of 0 creates a thin line. For no line, use a negative width or a transparent color. + A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color. - Odd pen widths generally lead to half-pixel painting. + To keep the border smooth (rather than blurry), odd pen widths cause the rect to be painted at + a half-pixel offset; */ void QFxPen::setWidth(int w) { _width = w; - _valid = (_width < 0) ? false : true; + _valid = (_width < 1) ? false : true; emit updated(); } @@ -472,7 +472,10 @@ void QFxRect::generateRoundedRect() p.setPen(Qt::NoPen); } p.setBrush(d->color); - p.drawRoundedRect((pw+1)/2, (pw+1)/2, d->rectImage.width()-(pw+1)/2*2, d->rectImage.height()-(pw+1)/2*2, d->radius, d->radius); + if (pw%2) + p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius); + else + p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius); } } @@ -487,12 +490,16 @@ void QFxRect::generateBorderedRect() p.setRenderHint(QPainter::Antialiasing); if (d->pen && d->pen->isValid()) { QPen pn(QColor(d->pen->color()), d->pen->width()); + pn.setJoinStyle(Qt::MiterJoin); p.setPen(pn); } else { p.setPen(Qt::NoPen); } p.setBrush(d->color); - p.drawRect(qreal(pw+1)/2, qreal(pw+1)/2, d->rectImage.width()-(pw+1)/2*2, d->rectImage.height()-(pw+1)/2*2); + if (pw%2) + p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1))); + else + p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw)); } } @@ -512,7 +519,7 @@ void QFxRect::drawRect(QPainter &p) if (d->gradient && d->gradient->gradient() /*|| p.usingQt() */) { // XXX This path is still slower than the image path // Image path won't work for gradients though - QPainter::RenderHints oldHints = p.renderHints(); + bool oldAA = p.testRenderHint(QPainter::Antialiasing); p.setRenderHint(QPainter::Antialiasing); if (d->pen && d->pen->isValid()) { QPen pn(QColor(d->pen->color()), d->pen->width()); @@ -525,7 +532,7 @@ void QFxRect::drawRect(QPainter &p) p.drawRoundedRect(0, 0, width(), height(), d->radius, d->radius); else p.drawRect(0, 0, width(), height()); - p.setRenderHints(oldHints); + p.setRenderHint(QPainter::Antialiasing, oldAA); } else { int offset = 0; const int pw = d->pen && d->pen->isValid() ? (d->pen->width()+1)/2*2 : 0; |