void ReportScene::drawBackground ( QPainter* painter, const QRectF & clip ) { painter->setRenderHint ( QPainter::Antialiasing, true ); if ( _rd->propertySet()->property ( "ShowGrid" ).value().toBool() ) { qreal major; int minor; qreal pixel_increment; bool found; QString u = _rd->propertySet()->property ( "PageUnit" ).value().toString(); u = u.mid ( u.find ( "(" ) + 1, 2 ); KoUnit unit = KoUnit::unit ( u, &found ); if ( !found ) { kDebug() << "Unable to find page unit" << endl; return; } if ( u == "cc" || u == "pi" || u == "mm" ) major = POINT_TO_INCH ( unit.fromUserValue ( 10 ) ) * KoGlobal::dpiX(); else if ( u == "pt" ) major = POINT_TO_INCH ( unit.fromUserValue ( 100 ) ) * KoGlobal::dpiX(); else major = POINT_TO_INCH ( unit.fromUserValue ( 1 ) ) * KoGlobal::dpiX(); minor = _rd->propertySet()->property ( "GridDivisions" ).value().toInt(); pixel_increment = ( major/minor ); QPen pen = painter->pen(); painter->setPen(QColor(212,212,212)); if ( pixel_increment > 2 ) // dont bother painting points if increments are so small { for ( qreal y = 0.0; y < sceneRect().bottom(); y += pixel_increment ) { for ( qreal x = 0.0; x < sceneRect().right(); x += pixel_increment ) { if ( x >= clip.left() && y >= clip.top() ) { painter->drawPoint ( QPointF ( x, y ) ); } } } } //now draw the lines for ( qreal y = 0.0; y < sceneRect().bottom(); y += major ) { for ( qreal x = 0.0; x < sceneRect().right(); x += major ) { if ( x >= clip.left() && y >= clip.top() ) { painter->drawLine ( QPointF ( x,y ),QPointF ( x,y+major ) ); painter->drawLine ( QPointF ( x,y ),QPointF ( x+major,y ) ); } } } pen.setWidth(1); update ( clip ); } }