Quantum GIS API Documentation
1.7.4
|
00001 /*************************************************************************** 00002 qgsdoubleboxscalebarstyle.cpp 00003 ----------------------------- 00004 begin : June 2008 00005 copyright : (C) 2008 by Marco Hugentobler 00006 email : marco.hugentobler@karto.baug.ethz.ch 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 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; //alternate brush color/white 00058 00059 00060 00061 QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin(); 00062 for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt ) 00063 { 00064 //draw top half 00065 if ( useColor ) 00066 { 00067 p->setBrush( mScaleBar->brush() ); 00068 } 00069 else //white 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 //draw bottom half 00078 if ( useColor ) 00079 { 00080 p->setBrush( QColor( 255, 255, 255 ) ); 00081 } 00082 else //white 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 //draw labels using the default method 00095 drawLabels( p ); 00096 }