00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "qgsdoubleboxscalebarstyle.h"
00018 #include "qgscomposerscalebar.h"
00019 #include <QList>
00020 #include <QPainter>
00021
00022 QgsDoubleBoxScaleBarStyle::QgsDoubleBoxScaleBarStyle( const QgsComposerScaleBar* bar ): QgsScaleBarStyle( bar )
00023 {
00024
00025 }
00026
00027 QgsDoubleBoxScaleBarStyle::QgsDoubleBoxScaleBarStyle(): QgsScaleBarStyle( 0 )
00028 {
00029
00030 }
00031
00032 QgsDoubleBoxScaleBarStyle::~QgsDoubleBoxScaleBarStyle()
00033 {
00034
00035 }
00036
00037 QString QgsDoubleBoxScaleBarStyle::name() const
00038 {
00039 return "Double Box";
00040 }
00041
00042 void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
00043 {
00044 if ( !mScaleBar )
00045 {
00046 return;
00047 }
00048 double barTopPosition = mScaleBar->fontAscentMillimeters( mScaleBar->font() ) + mScaleBar->labelBarSpace() + mScaleBar->boxContentSpace();
00049 double segmentHeight = mScaleBar->height() / 2;
00050
00051 p->save();
00052 p->setPen( p->pen() );
00053
00054 QList<QPair<double, double> > segmentInfo;
00055 mScaleBar->segmentPositions( segmentInfo );
00056
00057 bool useColor = true;
00058
00059
00060
00061 QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
00062 for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
00063 {
00064
00065 if ( useColor )
00066 {
00067 p->setBrush( mScaleBar->brush() );
00068 }
00069 else
00070 {
00071 p->setBrush( QColor( 255, 255, 255 ) );
00072 }
00073
00074 QRectF segmentRectTop( segmentIt->first + xOffset, barTopPosition, segmentIt->second, segmentHeight );
00075 p->drawRect( segmentRectTop );
00076
00077
00078 if ( useColor )
00079 {
00080 p->setBrush( QColor( 255, 255, 255 ) );
00081 }
00082 else
00083 {
00084 p->setBrush( mScaleBar->brush() );
00085 }
00086
00087 QRectF segmentRectBottom( segmentIt->first + xOffset, barTopPosition + segmentHeight, segmentIt->second, segmentHeight );
00088 p->drawRect( segmentRectBottom );
00089 useColor = !useColor;
00090 }
00091
00092 p->restore();
00093
00094
00095 drawLabels( p );
00096 }