diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-09-18 10:38:53 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-09-18 10:38:53 (GMT) |
commit | dd3e430897a222ee9e3c7b923d094401fdeb72dd (patch) | |
tree | 4eca99cb2586a00143352ae22be8c483ea6d4288 /src/gui/painting/qpaintengineex.cpp | |
parent | d3fa072c06dc3ca876ffea2b700f332d4425e56a (diff) | |
download | Qt-dd3e430897a222ee9e3c7b923d094401fdeb72dd.zip Qt-dd3e430897a222ee9e3c7b923d094401fdeb72dd.tar.gz Qt-dd3e430897a222ee9e3c7b923d094401fdeb72dd.tar.bz2 |
Made drawRoundedRect() implementation virtual in QPaintEngineEx
Reviewed-by: Samuel
Diffstat (limited to 'src/gui/painting/qpaintengineex.cpp')
-rw-r--r-- | src/gui/painting/qpaintengineex.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index 656f383..e5da392 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -280,6 +280,29 @@ static QPainterPath::ElementType qpaintengineex_rect4_types_32[] = { QPainterPath::MoveToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, QPainterPath::LineToElement, // 32 }; + +static QPainterPath::ElementType qpaintengineex_roundedrect_types[] = { + QPainterPath::MoveToElement, + QPainterPath::LineToElement, + QPainterPath::CurveToElement, + QPainterPath::CurveToDataElement, + QPainterPath::CurveToDataElement, + QPainterPath::LineToElement, + QPainterPath::CurveToElement, + QPainterPath::CurveToDataElement, + QPainterPath::CurveToDataElement, + QPainterPath::LineToElement, + QPainterPath::CurveToElement, + QPainterPath::CurveToDataElement, + QPainterPath::CurveToDataElement, + QPainterPath::LineToElement, + QPainterPath::CurveToElement, + QPainterPath::CurveToDataElement, + QPainterPath::CurveToDataElement +}; + + + static void qpaintengineex_moveTo(qreal x, qreal y, void *data) { ((StrokeHandler *) data)->pts.add(x); ((StrokeHandler *) data)->pts.add(y); @@ -679,6 +702,49 @@ void QPaintEngineEx::drawRects(const QRectF *rects, int rectCount) } } + +void QPaintEngineEx::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, + Qt::SizeMode mode) +{ + qreal x1 = rect.left(); + qreal x2 = rect.right(); + qreal y1 = rect.top(); + qreal y2 = rect.bottom(); + + if (mode == Qt::RelativeSize) { + xRadius = xRadius * rect.width() / 200.; + yRadius = yRadius * rect.height() / 200.; + } + + xRadius = qMin(xRadius, rect.width() / 2); + yRadius = qMin(yRadius, rect.height() / 2); + + qreal pts[] = { + x1 + xRadius, y1, // MoveTo + x2 - xRadius, y1, // LineTo + x2 - (1 - KAPPA) * xRadius, y1, // CurveTo + x2, y1 + (1 - KAPPA) * yRadius, + x2, y1 + yRadius, + x2, y2 - yRadius, // LineTo + x2, y2 - (1 - KAPPA) * yRadius, // CurveTo + x2 - (1 - KAPPA) * xRadius, y2, + x2 - xRadius, y2, + x1 + xRadius, y2, // LineTo + x1 + (1 - KAPPA) * xRadius, y2, // CurveTo + x1, y2 - (1 - KAPPA) * yRadius, + x1, y2 - yRadius, + x1, y1 + yRadius, // LineTo + x1, y1 + KAPPA * yRadius, // CurveTo + x1 + (1 - KAPPA) * xRadius, y1, + x1 + xRadius, y1 + }; + + QVectorPath path(pts, 17, qpaintengineex_roundedrect_types); + draw(path); +} + + + void QPaintEngineEx::drawLines(const QLine *lines, int lineCount) { int elementCount = lineCount << 1; |