void QPainter::drawRects(const QRectF *rects, int rectCount)
{
#ifdef QT_DEBUG_DRAW
if (qt_show_painter_debug_output)
printf("QPainter::drawRects(), count=%d\n", rectCount);
#endif
Q_D(QPainter);
if (!d->engine) {
qWarning("QPainter::drawRects: Painter not active");
return;
}
if (rectCount <= 0)
return;
//(H) QPaintEngineEx *extended;类型
if (d->extended) {
d->extended->drawRects(rects, rectCount);
return;
}
d->updateState(d->state);
// ...............
}
//
// 跟踪drawRect
1. painter.drawRect(rcF);[用户调用]
2. QPainter::drawRects[在qpainter.cpp中]
3. 可能有2中情况
<3.1>d->extended->drawRects(rects, rectCount);
(d的类型为QPainterPrivate)
(extended的类型为QPaintEngineEx)
<3.2>d->engine->drawRects(rects, rectCount);[在qpainter.cpp中]
(engine类型为QPaintEngine, 并且根据不同的平台为不同的类型)
(例:在X11平台就为QX11PaintEngine[在qpaintengine_x11_p.h中])
(在Windows平台就为QRasterPaintEngine[在qpainterengine_raster.cpp中])
///
// 假设在Linux平台使用的是X11
4. QX11PaintEngine::drawRects[在qpaintengine_x11.cpp中]
5. XFillRectangles[qpaintengine_x11.cpp]
(直接使用X11函数绘图)
///
// 假设在Windows平台用的是rasterizer
4.QRasterPaintEngine::drawRects[在qpaintengine_raster.cpp中]
5.QRasterPaintEngine::stroke[在qpaintengine_raster.cpp中]
6.d->rasterizer->rasterizeLine
(d的类型为QRasterPaintEnginePrivate;rasterizer的类型为QRasterizer;)
故上面这句代码实际调用的函数为
QRasterizer::rasterizeLine[在qrasterizer.cpp中]
最终绘制到一个QImage,并通过BitBlt绘制到Windows的HDC上面。