void QgsDoubleBoxScaleBarRenderer::draw( QgsRenderContext &context, const QgsScaleBarSettings &settings, const ScaleBarContext &scaleContext ) const { if ( !context.painter() ) { return; } QPainter *painter = context.painter(); double barTopPosition = QgsComposerUtils::fontAscentMM( settings.font() ) + settings.labelBarSpace() + settings.boxContentSpace(); double segmentHeight = settings.height() / 2; painter->save(); if ( context.flags() & QgsRenderContext::Antialiasing ) painter->setRenderHint( QPainter::Antialiasing, true ); painter->setPen( settings.pen() ); bool useColor = true; //alternate brush color/white double xOffset = firstLabelXOffset( settings ); QList<double> positions = segmentPositions( scaleContext, settings ); QList<double> widths = segmentWidths( scaleContext, settings ); for ( int i = 0; i < positions.size(); ++i ) { //draw top half if ( useColor ) { painter->setBrush( settings.brush() ); } else //secondary color { painter->setBrush( settings.brush2() ); } QRectF segmentRectTop( positions.at( i ) + xOffset, barTopPosition, widths.at( i ), segmentHeight ); painter->drawRect( segmentRectTop ); //draw bottom half if ( useColor ) { //secondary color painter->setBrush( settings.brush2() ); } else //primary color { painter->setBrush( settings.brush() ); } QRectF segmentRectBottom( positions.at( i ) + xOffset, barTopPosition + segmentHeight, widths.at( i ), segmentHeight ); painter->drawRect( segmentRectBottom ); useColor = !useColor; } painter->restore(); //draw labels using the default method drawDefaultLabels( context, settings, scaleContext ); }
void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const { if ( !mScaleBar ) { return; } double barTopPosition = QgsComposerUtils::fontAscentMM( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace(); double segmentHeight = mScaleBar->height() / 2; p->save(); //antialiasing on p->setRenderHint( QPainter::Antialiasing, true ); p->setPen( mScaleBar->pen() ); QList<QPair<double, double> > segmentInfo; mScaleBar->segmentPositions( segmentInfo ); bool useColor = true; //alternate brush color/white QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin(); for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt ) { //draw top half if ( useColor ) { p->setBrush( mScaleBar->brush() ); } else //secondary color { p->setBrush( mScaleBar->brush2() ); } QRectF segmentRectTop( segmentIt->first + xOffset, barTopPosition, segmentIt->second, segmentHeight ); p->drawRect( segmentRectTop ); //draw bottom half if ( useColor ) { //secondary color p->setBrush( mScaleBar->brush2() ); } else //primary color { p->setBrush( mScaleBar->brush() ); } QRectF segmentRectBottom( segmentIt->first + xOffset, barTopPosition + segmentHeight, segmentIt->second, segmentHeight ); p->drawRect( segmentRectBottom ); useColor = !useColor; } p->restore(); //draw labels using the default method drawLabels( p ); }