summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-09-18 10:38:53 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-09-18 10:38:53 (GMT)
commitdd3e430897a222ee9e3c7b923d094401fdeb72dd (patch)
tree4eca99cb2586a00143352ae22be8c483ea6d4288
parentd3fa072c06dc3ca876ffea2b700f332d4425e56a (diff)
downloadQt-dd3e430897a222ee9e3c7b923d094401fdeb72dd.zip
Qt-dd3e430897a222ee9e3c7b923d094401fdeb72dd.tar.gz
Qt-dd3e430897a222ee9e3c7b923d094401fdeb72dd.tar.bz2
Made drawRoundedRect() implementation virtual in QPaintEngineEx
Reviewed-by: Samuel
-rw-r--r--src/gui/painting/qpaintengineex.cpp66
-rw-r--r--src/gui/painting/qpaintengineex_p.h2
-rw-r--r--src/gui/painting/qpainter.cpp75
3 files changed, 70 insertions, 73 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;
diff --git a/src/gui/painting/qpaintengineex_p.h b/src/gui/painting/qpaintengineex_p.h
index a12a71f..814a0f0 100644
--- a/src/gui/painting/qpaintengineex_p.h
+++ b/src/gui/painting/qpaintengineex_p.h
@@ -170,6 +170,8 @@ public:
virtual void fillRect(const QRectF &rect, const QBrush &brush);
virtual void fillRect(const QRectF &rect, const QColor &color);
+ virtual void drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, Qt::SizeMode mode);
+
virtual void drawRects(const QRect *rects, int rectCount);
virtual void drawRects(const QRectF *rects, int rectCount);
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index b3aef71..ebaa901 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -4038,7 +4038,6 @@ const QFont &QPainter::font() const
\sa drawRect(), QPen
*/
-// FALCON: Should we add a specialized method in QPaintEngineEx?
void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
{
#ifdef QT_DEBUG_DRAW
@@ -4056,61 +4055,7 @@ void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
}
if (d->extended) {
- QPainterPath::ElementType 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
- };
-
- 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, types);
- d->extended->draw(path);
+ d->extended->drawRoundedRect(rect, xRadius, yRadius, mode);
return;
}
@@ -4152,23 +4097,7 @@ void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius,
*/
void QPainter::drawRoundRect(const QRectF &r, int xRnd, int yRnd)
{
-#ifdef QT_DEBUG_DRAW
- if (qt_show_painter_debug_output)
- printf("QPainter::drawRoundRectangle(), [%.2f,%.2f,%.2f,%.2f]\n", r.x(), r.y(), r.width(), r.height());
-#endif
- Q_D(QPainter);
-
- if (!d->engine)
- return;
-
- if(xRnd <= 0 || yRnd <= 0) { // draw normal rectangle
- drawRect(r);
- return;
- }
-
- QPainterPath path;
- path.addRoundRect(r, xRnd, yRnd);
- drawPath(path);
+ drawRoundedRect(r, xRnd, yRnd, Qt::RelativeSize);
}